Code Duplication    Length = 46-46 lines in 2 locations

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

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