Code Duplication    Length = 50-50 lines in 2 locations

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

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