Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 2733-2791 (lines=59) @@
2730
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2731
     * @group field-type
2732
     */
2733
    public function testCopyContent()
2734
    {
2735
        $parentLocationId = $this->generateId('location', 56);
2736
2737
        $repository = $this->getRepository();
2738
2739
        $contentService = $repository->getContentService();
2740
        $locationService = $repository->getLocationService();
2741
2742
        /* BEGIN: Use Case */
2743
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
2744
2745
        // Configure new target location
2746
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2747
2748
        $targetLocationCreate->priority = 42;
2749
        $targetLocationCreate->hidden = true;
2750
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2751
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2752
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2753
2754
        // Copy content with all versions and drafts
2755
        $contentCopied = $contentService->copyContent(
2756
            $contentVersion2->contentInfo,
2757
            $targetLocationCreate
2758
        );
2759
        /* END: Use Case */
2760
2761
        $this->assertInstanceOf(
2762
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2763
            $contentCopied
2764
        );
2765
2766
        $this->assertNotEquals(
2767
            $contentVersion2->contentInfo->remoteId,
2768
            $contentCopied->contentInfo->remoteId
2769
        );
2770
2771
        $this->assertNotEquals(
2772
            $contentVersion2->id,
2773
            $contentCopied->id
2774
        );
2775
2776
        $this->assertEquals(
2777
            2,
2778
            count($contentService->loadVersions($contentCopied->contentInfo))
2779
        );
2780
2781
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
2782
2783
        $this->assertAllFieldsEquals($contentCopied->getFields());
2784
2785
        $this->assertDefaultContentStates($contentCopied->contentInfo);
2786
2787
        $this->assertNotNull(
2788
            $contentCopied->contentInfo->mainLocationId,
2789
            'Expected main location to be set given we provided a LocationCreateStruct'
2790
        );
2791
    }
2792
2793
    /**
2794
     * Test for the copyContent() method.
@@ 2801-2856 (lines=56) @@
2798
     *
2799
     * @todo Fix to more descriptive name
2800
     */
2801
    public function testCopyContentWithThirdParameter()
2802
    {
2803
        $parentLocationId = $this->generateId('location', 56);
2804
2805
        $repository = $this->getRepository();
2806
2807
        $contentService = $repository->getContentService();
2808
        $locationService = $repository->getLocationService();
2809
2810
        /* BEGIN: Use Case */
2811
        $contentVersion2 = $this->createContentVersion2();
2812
2813
        // Configure new target location
2814
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2815
2816
        $targetLocationCreate->priority = 42;
2817
        $targetLocationCreate->hidden = true;
2818
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2819
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2820
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2821
2822
        // Copy only the initial version
2823
        $contentCopied = $contentService->copyContent(
2824
            $contentVersion2->contentInfo,
2825
            $targetLocationCreate,
2826
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
2827
        );
2828
        /* END: Use Case */
2829
2830
        $this->assertInstanceOf(
2831
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2832
            $contentCopied
2833
        );
2834
2835
        $this->assertNotEquals(
2836
            $contentVersion2->contentInfo->remoteId,
2837
            $contentCopied->contentInfo->remoteId
2838
        );
2839
2840
        $this->assertNotEquals(
2841
            $contentVersion2->id,
2842
            $contentCopied->id
2843
        );
2844
2845
        $this->assertEquals(
2846
            1,
2847
            count($contentService->loadVersions($contentCopied->contentInfo))
2848
        );
2849
2850
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
2851
2852
        $this->assertNotNull(
2853
            $contentCopied->contentInfo->mainLocationId,
2854
            'Expected main location to be set given we provided a LocationCreateStruct'
2855
        );
2856
    }
2857
2858
    /**
2859
     * Test for the addRelation() method.