|
@@ 4711-4758 (lines=48) @@
|
| 4708 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4709 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4710 |
|
*/ |
| 4711 |
|
public function testCopyContentInTransactionWithRollback() |
| 4712 |
|
{ |
| 4713 |
|
$repository = $this->getRepository(); |
| 4714 |
|
|
| 4715 |
|
$contentId = $this->generateId('object', 11); |
| 4716 |
|
$locationId = $this->generateId('location', 13); |
| 4717 |
|
/* BEGIN: Use Case */ |
| 4718 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4719 |
|
// demo installation |
| 4720 |
|
|
| 4721 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4722 |
|
|
| 4723 |
|
// Get services |
| 4724 |
|
$contentService = $repository->getContentService(); |
| 4725 |
|
$locationService = $repository->getLocationService(); |
| 4726 |
|
|
| 4727 |
|
// Load content object to copy |
| 4728 |
|
$content = $contentService->loadContent($contentId); |
| 4729 |
|
|
| 4730 |
|
// Create new target location |
| 4731 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 4732 |
|
|
| 4733 |
|
// Start a new transaction |
| 4734 |
|
$repository->beginTransaction(); |
| 4735 |
|
|
| 4736 |
|
try { |
| 4737 |
|
// Copy content with all versions and drafts |
| 4738 |
|
$contentService->copyContent( |
| 4739 |
|
$content->contentInfo, |
| 4740 |
|
$locationCreate |
| 4741 |
|
); |
| 4742 |
|
} catch (Exception $e) { |
| 4743 |
|
// Cleanup hanging transaction on error |
| 4744 |
|
$repository->rollback(); |
| 4745 |
|
throw $e; |
| 4746 |
|
} |
| 4747 |
|
|
| 4748 |
|
// Rollback all changes |
| 4749 |
|
$repository->rollback(); |
| 4750 |
|
|
| 4751 |
|
// This array will only contain a single admin user object |
| 4752 |
|
$locations = $locationService->loadLocationChildren( |
| 4753 |
|
$locationService->loadLocation($locationId) |
| 4754 |
|
)->locations; |
| 4755 |
|
/* END: Use Case */ |
| 4756 |
|
|
| 4757 |
|
$this->assertEquals(1, count($locations)); |
| 4758 |
|
} |
| 4759 |
|
|
| 4760 |
|
/** |
| 4761 |
|
* Test for the copyContent() method. |
|
@@ 4769-4818 (lines=50) @@
|
| 4766 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4767 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4768 |
|
*/ |
| 4769 |
|
public function testCopyContentInTransactionWithCommit() |
| 4770 |
|
{ |
| 4771 |
|
$repository = $this->getRepository(); |
| 4772 |
|
|
| 4773 |
|
$contentId = $this->generateId('object', 11); |
| 4774 |
|
$locationId = $this->generateId('location', 13); |
| 4775 |
|
/* BEGIN: Use Case */ |
| 4776 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4777 |
|
// demo installation |
| 4778 |
|
|
| 4779 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4780 |
|
|
| 4781 |
|
// Get services |
| 4782 |
|
$contentService = $repository->getContentService(); |
| 4783 |
|
$locationService = $repository->getLocationService(); |
| 4784 |
|
|
| 4785 |
|
// Load content object to copy |
| 4786 |
|
$content = $contentService->loadContent($contentId); |
| 4787 |
|
|
| 4788 |
|
// Create new target location |
| 4789 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 4790 |
|
|
| 4791 |
|
// Start a new transaction |
| 4792 |
|
$repository->beginTransaction(); |
| 4793 |
|
|
| 4794 |
|
try { |
| 4795 |
|
// Copy content with all versions and drafts |
| 4796 |
|
$contentCopied = $contentService->copyContent( |
| 4797 |
|
$content->contentInfo, |
| 4798 |
|
$locationCreate |
| 4799 |
|
); |
| 4800 |
|
|
| 4801 |
|
// Commit all changes |
| 4802 |
|
$repository->commit(); |
| 4803 |
|
} catch (Exception $e) { |
| 4804 |
|
// Cleanup hanging transaction on error |
| 4805 |
|
$repository->rollback(); |
| 4806 |
|
throw $e; |
| 4807 |
|
} |
| 4808 |
|
|
| 4809 |
|
$this->refreshSearch($repository); |
| 4810 |
|
|
| 4811 |
|
// This will contain the admin user and the new child location |
| 4812 |
|
$locations = $locationService->loadLocationChildren( |
| 4813 |
|
$locationService->loadLocation($locationId) |
| 4814 |
|
)->locations; |
| 4815 |
|
/* END: Use Case */ |
| 4816 |
|
|
| 4817 |
|
$this->assertEquals(2, count($locations)); |
| 4818 |
|
} |
| 4819 |
|
|
| 4820 |
|
/** |
| 4821 |
|
*/ |