Code Duplication    Length = 50-50 lines in 2 locations

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

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