Code Duplication    Length = 50-50 lines in 2 locations

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

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