Code Duplication    Length = 48-50 lines in 2 locations

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

@@ 4715-4762 (lines=48) @@
4712
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4713
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4714
     */
4715
    public function testCopyContentInTransactionWithRollback()
4716
    {
4717
        $repository = $this->getRepository();
4718
4719
        $contentId = $this->generateId('object', 11);
4720
        $locationId = $this->generateId('location', 13);
4721
        /* BEGIN: Use Case */
4722
        // $contentId is the ID of the "Members" user group in an eZ Publish
4723
        // demo installation
4724
4725
        // $locationId is the ID of the "Administrator users" group location
4726
4727
        // Get services
4728
        $contentService = $repository->getContentService();
4729
        $locationService = $repository->getLocationService();
4730
4731
        // Load content object to copy
4732
        $content = $contentService->loadContent($contentId);
4733
4734
        // Create new target location
4735
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4736
4737
        // Start a new transaction
4738
        $repository->beginTransaction();
4739
4740
        try {
4741
            // Copy content with all versions and drafts
4742
            $contentService->copyContent(
4743
                $content->contentInfo,
4744
                $locationCreate
4745
            );
4746
        } catch (Exception $e) {
4747
            // Cleanup hanging transaction on error
4748
            $repository->rollback();
4749
            throw $e;
4750
        }
4751
4752
        // Rollback all changes
4753
        $repository->rollback();
4754
4755
        // This array will only contain a single admin user object
4756
        $locations = $locationService->loadLocationChildren(
4757
            $locationService->loadLocation($locationId)
4758
        )->locations;
4759
        /* END: Use Case */
4760
4761
        $this->assertEquals(1, count($locations));
4762
    }
4763
4764
    /**
4765
     * Test for the copyContent() method.
@@ 4773-4822 (lines=50) @@
4770
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4771
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4772
     */
4773
    public function testCopyContentInTransactionWithCommit()
4774
    {
4775
        $repository = $this->getRepository();
4776
4777
        $contentId = $this->generateId('object', 11);
4778
        $locationId = $this->generateId('location', 13);
4779
        /* BEGIN: Use Case */
4780
        // $contentId is the ID of the "Members" user group in an eZ Publish
4781
        // demo installation
4782
4783
        // $locationId is the ID of the "Administrator users" group location
4784
4785
        // Get services
4786
        $contentService = $repository->getContentService();
4787
        $locationService = $repository->getLocationService();
4788
4789
        // Load content object to copy
4790
        $content = $contentService->loadContent($contentId);
4791
4792
        // Create new target location
4793
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4794
4795
        // Start a new transaction
4796
        $repository->beginTransaction();
4797
4798
        try {
4799
            // Copy content with all versions and drafts
4800
            $contentCopied = $contentService->copyContent(
4801
                $content->contentInfo,
4802
                $locationCreate
4803
            );
4804
4805
            // Commit all changes
4806
            $repository->commit();
4807
        } catch (Exception $e) {
4808
            // Cleanup hanging transaction on error
4809
            $repository->rollback();
4810
            throw $e;
4811
        }
4812
4813
        $this->refreshSearch($repository);
4814
4815
        // This will contain the admin user and the new child location
4816
        $locations = $locationService->loadLocationChildren(
4817
            $locationService->loadLocation($locationId)
4818
        )->locations;
4819
        /* END: Use Case */
4820
4821
        $this->assertEquals(2, count($locations));
4822
    }
4823
4824
    public function testURLAliasesCreatedForNewContent()
4825
    {