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