Code Duplication    Length = 50-50 lines in 2 locations

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

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