Code Duplication    Length = 50-50 lines in 2 locations

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

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