Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 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 testCopyContentInTransactionWithRollback()
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
            $contentService->copyContent(
4884
                $content->contentInfo,
4885
                $locationCreate
4886
            );
4887
        } catch (Exception $e) {
4888
            // Cleanup hanging transaction on error
4889
            $repository->rollback();
4890
            throw $e;
4891
        }
4892
4893
        // Rollback all changes
4894
        $repository->rollback();
4895
4896
        $this->refreshSearch($repository);
4897
4898
        // This array will only contain a single admin user object
4899
        $locations = $locationService->loadLocationChildren(
4900
            $locationService->loadLocation($locationId)
4901
        )->locations;
4902
        /* END: Use Case */
4903
4904
        $this->assertEquals(1, count($locations));
4905
    }
4906
4907
    /**
4908
     * Test for the copyContent() method.
@@ 4916-4965 (lines=50) @@
4913
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4914
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4915
     */
4916
    public function testCopyContentInTransactionWithCommit()
4917
    {
4918
        $repository = $this->getRepository();
4919
4920
        $contentId = $this->generateId('object', 11);
4921
        $locationId = $this->generateId('location', 13);
4922
        /* BEGIN: Use Case */
4923
        // $contentId is the ID of the "Members" user group in an eZ Publish
4924
        // demo installation
4925
4926
        // $locationId is the ID of the "Administrator users" group location
4927
4928
        // Get services
4929
        $contentService = $repository->getContentService();
4930
        $locationService = $repository->getLocationService();
4931
4932
        // Load content object to copy
4933
        $content = $contentService->loadContent($contentId);
4934
4935
        // Create new target location
4936
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4937
4938
        // Start a new transaction
4939
        $repository->beginTransaction();
4940
4941
        try {
4942
            // Copy content with all versions and drafts
4943
            $contentCopied = $contentService->copyContent(
4944
                $content->contentInfo,
4945
                $locationCreate
4946
            );
4947
4948
            // Commit all changes
4949
            $repository->commit();
4950
        } catch (Exception $e) {
4951
            // Cleanup hanging transaction on error
4952
            $repository->rollback();
4953
            throw $e;
4954
        }
4955
4956
        $this->refreshSearch($repository);
4957
4958
        // This will contain the admin user and the new child location
4959
        $locations = $locationService->loadLocationChildren(
4960
            $locationService->loadLocation($locationId)
4961
        )->locations;
4962
        /* END: Use Case */
4963
4964
        $this->assertEquals(2, count($locations));
4965
    }
4966
4967
    public function testURLAliasesCreatedForNewContent()
4968
    {