Code Duplication    Length = 56-59 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 2 locations

@@ 2660-2718 (lines=59) @@
2657
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2658
     * @group field-type
2659
     */
2660
    public function testCopyContent()
2661
    {
2662
        $parentLocationId = $this->generateId('location', 56);
2663
2664
        $repository = $this->getRepository();
2665
2666
        $contentService = $repository->getContentService();
2667
        $locationService = $repository->getLocationService();
2668
2669
        /* BEGIN: Use Case */
2670
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
2671
2672
        // Configure new target location
2673
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2674
2675
        $targetLocationCreate->priority = 42;
2676
        $targetLocationCreate->hidden = true;
2677
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2678
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2679
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2680
2681
        // Copy content with all versions and drafts
2682
        $contentCopied = $contentService->copyContent(
2683
            $contentVersion2->contentInfo,
2684
            $targetLocationCreate
2685
        );
2686
        /* END: Use Case */
2687
2688
        $this->assertInstanceOf(
2689
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2690
            $contentCopied
2691
        );
2692
2693
        $this->assertNotEquals(
2694
            $contentVersion2->contentInfo->remoteId,
2695
            $contentCopied->contentInfo->remoteId
2696
        );
2697
2698
        $this->assertNotEquals(
2699
            $contentVersion2->id,
2700
            $contentCopied->id
2701
        );
2702
2703
        $this->assertEquals(
2704
            2,
2705
            count($contentService->loadVersions($contentCopied->contentInfo))
2706
        );
2707
2708
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
2709
2710
        $this->assertAllFieldsEquals($contentCopied->getFields());
2711
2712
        $this->assertDefaultContentStates($contentCopied->contentInfo);
2713
2714
        $this->assertNotNull(
2715
            $contentCopied->contentInfo->mainLocationId,
2716
            'Expected main location to be set given we provided a LocationCreateStruct'
2717
        );
2718
    }
2719
2720
    /**
2721
     * Test for the copyContent() method.
@@ 2728-2783 (lines=56) @@
2725
     *
2726
     * @todo Fix to more descriptive name
2727
     */
2728
    public function testCopyContentWithThirdParameter()
2729
    {
2730
        $parentLocationId = $this->generateId('location', 56);
2731
2732
        $repository = $this->getRepository();
2733
2734
        $contentService = $repository->getContentService();
2735
        $locationService = $repository->getLocationService();
2736
2737
        /* BEGIN: Use Case */
2738
        $contentVersion2 = $this->createContentVersion2();
2739
2740
        // Configure new target location
2741
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2742
2743
        $targetLocationCreate->priority = 42;
2744
        $targetLocationCreate->hidden = true;
2745
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2746
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2747
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2748
2749
        // Copy only the initial version
2750
        $contentCopied = $contentService->copyContent(
2751
            $contentVersion2->contentInfo,
2752
            $targetLocationCreate,
2753
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
2754
        );
2755
        /* END: Use Case */
2756
2757
        $this->assertInstanceOf(
2758
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2759
            $contentCopied
2760
        );
2761
2762
        $this->assertNotEquals(
2763
            $contentVersion2->contentInfo->remoteId,
2764
            $contentCopied->contentInfo->remoteId
2765
        );
2766
2767
        $this->assertNotEquals(
2768
            $contentVersion2->id,
2769
            $contentCopied->id
2770
        );
2771
2772
        $this->assertEquals(
2773
            1,
2774
            count($contentService->loadVersions($contentCopied->contentInfo))
2775
        );
2776
2777
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
2778
2779
        $this->assertNotNull(
2780
            $contentCopied->contentInfo->mainLocationId,
2781
            'Expected main location to be set given we provided a LocationCreateStruct'
2782
        );
2783
    }
2784
2785
    /**
2786
     * Test for the addRelation() method.