Code Duplication    Length = 50-50 lines in 2 locations

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

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