Code Duplication    Length = 56-59 lines in 2 locations

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

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