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