Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 2781-2839 (lines=59) @@
2778
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2779
     * @group field-type
2780
     */
2781
    public function testCopyContent()
2782
    {
2783
        $parentLocationId = $this->generateId('location', 56);
2784
2785
        $repository = $this->getRepository();
2786
2787
        $contentService = $repository->getContentService();
2788
        $locationService = $repository->getLocationService();
2789
2790
        /* BEGIN: Use Case */
2791
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
2792
2793
        // Configure new target location
2794
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2795
2796
        $targetLocationCreate->priority = 42;
2797
        $targetLocationCreate->hidden = true;
2798
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2799
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2800
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2801
2802
        // Copy content with all versions and drafts
2803
        $contentCopied = $contentService->copyContent(
2804
            $contentVersion2->contentInfo,
2805
            $targetLocationCreate
2806
        );
2807
        /* END: Use Case */
2808
2809
        $this->assertInstanceOf(
2810
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2811
            $contentCopied
2812
        );
2813
2814
        $this->assertNotEquals(
2815
            $contentVersion2->contentInfo->remoteId,
2816
            $contentCopied->contentInfo->remoteId
2817
        );
2818
2819
        $this->assertNotEquals(
2820
            $contentVersion2->id,
2821
            $contentCopied->id
2822
        );
2823
2824
        $this->assertEquals(
2825
            2,
2826
            count($contentService->loadVersions($contentCopied->contentInfo))
2827
        );
2828
2829
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
2830
2831
        $this->assertAllFieldsEquals($contentCopied->getFields());
2832
2833
        $this->assertDefaultContentStates($contentCopied->contentInfo);
2834
2835
        $this->assertNotNull(
2836
            $contentCopied->contentInfo->mainLocationId,
2837
            'Expected main location to be set given we provided a LocationCreateStruct'
2838
        );
2839
    }
2840
2841
    /**
2842
     * Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
@@ 2903-2958 (lines=56) @@
2900
     *
2901
     * @todo Fix to more descriptive name
2902
     */
2903
    public function testCopyContentWithThirdParameter()
2904
    {
2905
        $parentLocationId = $this->generateId('location', 56);
2906
2907
        $repository = $this->getRepository();
2908
2909
        $contentService = $repository->getContentService();
2910
        $locationService = $repository->getLocationService();
2911
2912
        /* BEGIN: Use Case */
2913
        $contentVersion2 = $this->createContentVersion2();
2914
2915
        // Configure new target location
2916
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
2917
2918
        $targetLocationCreate->priority = 42;
2919
        $targetLocationCreate->hidden = true;
2920
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
2921
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
2922
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
2923
2924
        // Copy only the initial version
2925
        $contentCopied = $contentService->copyContent(
2926
            $contentVersion2->contentInfo,
2927
            $targetLocationCreate,
2928
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
2929
        );
2930
        /* END: Use Case */
2931
2932
        $this->assertInstanceOf(
2933
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2934
            $contentCopied
2935
        );
2936
2937
        $this->assertNotEquals(
2938
            $contentVersion2->contentInfo->remoteId,
2939
            $contentCopied->contentInfo->remoteId
2940
        );
2941
2942
        $this->assertNotEquals(
2943
            $contentVersion2->id,
2944
            $contentCopied->id
2945
        );
2946
2947
        $this->assertEquals(
2948
            1,
2949
            count($contentService->loadVersions($contentCopied->contentInfo))
2950
        );
2951
2952
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
2953
2954
        $this->assertNotNull(
2955
            $contentCopied->contentInfo->mainLocationId,
2956
            'Expected main location to be set given we provided a LocationCreateStruct'
2957
        );
2958
    }
2959
2960
    /**
2961
     * Test for the addRelation() method.