Code Duplication    Length = 56-59 lines in 2 locations

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

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