Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 4791-4840 (lines=50) @@
4788
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4789
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4790
     */
4791
    public function testCopyContentInTransactionWithRollback()
4792
    {
4793
        $repository = $this->getRepository();
4794
4795
        $contentId = $this->generateId('object', 11);
4796
        $locationId = $this->generateId('location', 13);
4797
        /* BEGIN: Use Case */
4798
        // $contentId is the ID of the "Members" user group in an eZ Publish
4799
        // demo installation
4800
4801
        // $locationId is the ID of the "Administrator users" group location
4802
4803
        // Get services
4804
        $contentService = $repository->getContentService();
4805
        $locationService = $repository->getLocationService();
4806
4807
        // Load content object to copy
4808
        $content = $contentService->loadContent($contentId);
4809
4810
        // Create new target location
4811
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4812
4813
        // Start a new transaction
4814
        $repository->beginTransaction();
4815
4816
        try {
4817
            // Copy content with all versions and drafts
4818
            $contentService->copyContent(
4819
                $content->contentInfo,
4820
                $locationCreate
4821
            );
4822
        } catch (Exception $e) {
4823
            // Cleanup hanging transaction on error
4824
            $repository->rollback();
4825
            throw $e;
4826
        }
4827
4828
        // Rollback all changes
4829
        $repository->rollback();
4830
4831
        $this->refreshSearch($repository);
4832
4833
        // This array will only contain a single admin user object
4834
        $locations = $locationService->loadLocationChildren(
4835
            $locationService->loadLocation($locationId)
4836
        )->locations;
4837
        /* END: Use Case */
4838
4839
        $this->assertEquals(1, count($locations));
4840
    }
4841
4842
    /**
4843
     * Test for the copyContent() method.
@@ 4851-4900 (lines=50) @@
4848
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4849
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4850
     */
4851
    public function testCopyContentInTransactionWithCommit()
4852
    {
4853
        $repository = $this->getRepository();
4854
4855
        $contentId = $this->generateId('object', 11);
4856
        $locationId = $this->generateId('location', 13);
4857
        /* BEGIN: Use Case */
4858
        // $contentId is the ID of the "Members" user group in an eZ Publish
4859
        // demo installation
4860
4861
        // $locationId is the ID of the "Administrator users" group location
4862
4863
        // Get services
4864
        $contentService = $repository->getContentService();
4865
        $locationService = $repository->getLocationService();
4866
4867
        // Load content object to copy
4868
        $content = $contentService->loadContent($contentId);
4869
4870
        // Create new target location
4871
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4872
4873
        // Start a new transaction
4874
        $repository->beginTransaction();
4875
4876
        try {
4877
            // Copy content with all versions and drafts
4878
            $contentCopied = $contentService->copyContent(
4879
                $content->contentInfo,
4880
                $locationCreate
4881
            );
4882
4883
            // Commit all changes
4884
            $repository->commit();
4885
        } catch (Exception $e) {
4886
            // Cleanup hanging transaction on error
4887
            $repository->rollback();
4888
            throw $e;
4889
        }
4890
4891
        $this->refreshSearch($repository);
4892
4893
        // This will contain the admin user and the new child location
4894
        $locations = $locationService->loadLocationChildren(
4895
            $locationService->loadLocation($locationId)
4896
        )->locations;
4897
        /* END: Use Case */
4898
4899
        $this->assertEquals(2, count($locations));
4900
    }
4901
4902
    public function testURLAliasesCreatedForNewContent()
4903
    {