Code Duplication    Length = 50-50 lines in 2 locations

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

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