Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 4755-4804 (lines=50) @@
4752
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4753
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4754
     */
4755
    public function testCopyContentInTransactionWithRollback()
4756
    {
4757
        $repository = $this->getRepository();
4758
4759
        $contentId = $this->generateId('object', 11);
4760
        $locationId = $this->generateId('location', 13);
4761
        /* BEGIN: Use Case */
4762
        // $contentId is the ID of the "Members" user group in an eZ Publish
4763
        // demo installation
4764
4765
        // $locationId is the ID of the "Administrator users" group location
4766
4767
        // Get services
4768
        $contentService = $repository->getContentService();
4769
        $locationService = $repository->getLocationService();
4770
4771
        // Load content object to copy
4772
        $content = $contentService->loadContent($contentId);
4773
4774
        // Create new target location
4775
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4776
4777
        // Start a new transaction
4778
        $repository->beginTransaction();
4779
4780
        try {
4781
            // Copy content with all versions and drafts
4782
            $contentService->copyContent(
4783
                $content->contentInfo,
4784
                $locationCreate
4785
            );
4786
        } catch (Exception $e) {
4787
            // Cleanup hanging transaction on error
4788
            $repository->rollback();
4789
            throw $e;
4790
        }
4791
4792
        // Rollback all changes
4793
        $repository->rollback();
4794
4795
        $this->refreshSearch($repository);
4796
4797
        // This array will only contain a single admin user object
4798
        $locations = $locationService->loadLocationChildren(
4799
            $locationService->loadLocation($locationId)
4800
        )->locations;
4801
        /* END: Use Case */
4802
4803
        $this->assertEquals(1, count($locations));
4804
    }
4805
4806
    /**
4807
     * Test for the copyContent() method.
@@ 4815-4864 (lines=50) @@
4812
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4813
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4814
     */
4815
    public function testCopyContentInTransactionWithCommit()
4816
    {
4817
        $repository = $this->getRepository();
4818
4819
        $contentId = $this->generateId('object', 11);
4820
        $locationId = $this->generateId('location', 13);
4821
        /* BEGIN: Use Case */
4822
        // $contentId is the ID of the "Members" user group in an eZ Publish
4823
        // demo installation
4824
4825
        // $locationId is the ID of the "Administrator users" group location
4826
4827
        // Get services
4828
        $contentService = $repository->getContentService();
4829
        $locationService = $repository->getLocationService();
4830
4831
        // Load content object to copy
4832
        $content = $contentService->loadContent($contentId);
4833
4834
        // Create new target location
4835
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4836
4837
        // Start a new transaction
4838
        $repository->beginTransaction();
4839
4840
        try {
4841
            // Copy content with all versions and drafts
4842
            $contentCopied = $contentService->copyContent(
4843
                $content->contentInfo,
4844
                $locationCreate
4845
            );
4846
4847
            // Commit all changes
4848
            $repository->commit();
4849
        } catch (Exception $e) {
4850
            // Cleanup hanging transaction on error
4851
            $repository->rollback();
4852
            throw $e;
4853
        }
4854
4855
        $this->refreshSearch($repository);
4856
4857
        // This will contain the admin user and the new child location
4858
        $locations = $locationService->loadLocationChildren(
4859
            $locationService->loadLocation($locationId)
4860
        )->locations;
4861
        /* END: Use Case */
4862
4863
        $this->assertEquals(2, count($locations));
4864
    }
4865
4866
    public function testURLAliasesCreatedForNewContent()
4867
    {