Code Duplication    Length = 46-46 lines in 2 locations

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

@@ 4721-4766 (lines=46) @@
4718
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4719
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4720
     */
4721
    public function testCopyContentInTransactionWithRollback()
4722
    {
4723
        $repository = $this->getRepository();
4724
4725
        $contentId = $this->generateId('object', 11);
4726
        $locationId = $this->generateId('location', 13);
4727
        /* BEGIN: Use Case */
4728
        // $contentId is the ID of the "Members" user group in an eZ Publish
4729
        // demo installation
4730
4731
        // $locationId is the ID of the "Administrator users" group location
4732
4733
        // Load content object to copy
4734
        $content = $this->contentService->loadContent($contentId);
4735
4736
        // Create new target location
4737
        $locationCreate = $this->locationService->newLocationCreateStruct($locationId);
4738
4739
        // Start a new transaction
4740
        $repository->beginTransaction();
4741
4742
        try {
4743
            // Copy content with all versions and drafts
4744
            $this->contentService->copyContent(
4745
                $content->contentInfo,
4746
                $locationCreate
4747
            );
4748
        } catch (Exception $e) {
4749
            // Cleanup hanging transaction on error
4750
            $repository->rollback();
4751
            throw $e;
4752
        }
4753
4754
        // Rollback all changes
4755
        $repository->rollback();
4756
4757
        $this->refreshSearch($repository);
4758
4759
        // This array will only contain a single admin user object
4760
        $locations = $this->locationService->loadLocationChildren(
4761
            $this->locationService->loadLocation($locationId)
4762
        )->locations;
4763
        /* END: Use Case */
4764
4765
        $this->assertEquals(1, count($locations));
4766
    }
4767
4768
    /**
4769
     * Test for the copyContent() method.
@@ 4777-4822 (lines=46) @@
4774
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4775
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4776
     */
4777
    public function testCopyContentInTransactionWithCommit()
4778
    {
4779
        $repository = $this->getRepository();
4780
4781
        $contentId = $this->generateId('object', 11);
4782
        $locationId = $this->generateId('location', 13);
4783
        /* BEGIN: Use Case */
4784
        // $contentId is the ID of the "Members" user group in an eZ Publish
4785
        // demo installation
4786
4787
        // $locationId is the ID of the "Administrator users" group location
4788
4789
        // Load content object to copy
4790
        $content = $this->contentService->loadContent($contentId);
4791
4792
        // Create new target location
4793
        $locationCreate = $this->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 = $this->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 = $this->locationService->loadLocationChildren(
4817
            $this->locationService->loadLocation($locationId)
4818
        )->locations;
4819
        /* END: Use Case */
4820
4821
        $this->assertEquals(2, count($locations));
4822
    }
4823
4824
    public function testURLAliasesCreatedForNewContent()
4825
    {