|
@@ 4719-4763 (lines=45) @@
|
| 4716 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4717 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4718 |
|
*/ |
| 4719 |
|
public function testUpdateContentMetadataInTransactionWithRollback() |
| 4720 |
|
{ |
| 4721 |
|
$repository = $this->getRepository(); |
| 4722 |
|
|
| 4723 |
|
$contentId = $this->generateId('object', 12); |
| 4724 |
|
/* BEGIN: Use Case */ |
| 4725 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4726 |
|
|
| 4727 |
|
// Get the content service |
| 4728 |
|
$contentService = $repository->getContentService(); |
| 4729 |
|
|
| 4730 |
|
// Load a ContentInfo object |
| 4731 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4732 |
|
|
| 4733 |
|
// Store remoteId for later testing |
| 4734 |
|
$remoteId = $contentInfo->remoteId; |
| 4735 |
|
|
| 4736 |
|
// Start a transaction |
| 4737 |
|
$repository->beginTransaction(); |
| 4738 |
|
|
| 4739 |
|
try { |
| 4740 |
|
// Get metadata update struct and change remoteId |
| 4741 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4742 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4743 |
|
|
| 4744 |
|
// Update the metadata of the published content object |
| 4745 |
|
$contentService->updateContentMetadata( |
| 4746 |
|
$contentInfo, |
| 4747 |
|
$metadataUpdate |
| 4748 |
|
); |
| 4749 |
|
} catch (Exception $e) { |
| 4750 |
|
// Cleanup hanging transaction on error |
| 4751 |
|
$repository->rollback(); |
| 4752 |
|
throw $e; |
| 4753 |
|
} |
| 4754 |
|
|
| 4755 |
|
// Rollback all changes. |
| 4756 |
|
$repository->rollback(); |
| 4757 |
|
|
| 4758 |
|
// Load current remoteId |
| 4759 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4760 |
|
/* END: Use Case */ |
| 4761 |
|
|
| 4762 |
|
$this->assertEquals($remoteId, $remoteIdReloaded); |
| 4763 |
|
} |
| 4764 |
|
|
| 4765 |
|
/** |
| 4766 |
|
* Test for the updateContentMetadata() method. |
|
@@ 4772-4816 (lines=45) @@
|
| 4769 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4770 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4771 |
|
*/ |
| 4772 |
|
public function testUpdateContentMetadataInTransactionWithCommit() |
| 4773 |
|
{ |
| 4774 |
|
$repository = $this->getRepository(); |
| 4775 |
|
|
| 4776 |
|
$contentId = $this->generateId('object', 12); |
| 4777 |
|
/* BEGIN: Use Case */ |
| 4778 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4779 |
|
|
| 4780 |
|
// Get the content service |
| 4781 |
|
$contentService = $repository->getContentService(); |
| 4782 |
|
|
| 4783 |
|
// Load a ContentInfo object |
| 4784 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4785 |
|
|
| 4786 |
|
// Store remoteId for later testing |
| 4787 |
|
$remoteId = $contentInfo->remoteId; |
| 4788 |
|
|
| 4789 |
|
// Start a transaction |
| 4790 |
|
$repository->beginTransaction(); |
| 4791 |
|
|
| 4792 |
|
try { |
| 4793 |
|
// Get metadata update struct and change remoteId |
| 4794 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4795 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4796 |
|
|
| 4797 |
|
// Update the metadata of the published content object |
| 4798 |
|
$contentService->updateContentMetadata( |
| 4799 |
|
$contentInfo, |
| 4800 |
|
$metadataUpdate |
| 4801 |
|
); |
| 4802 |
|
|
| 4803 |
|
// Commit all changes. |
| 4804 |
|
$repository->commit(); |
| 4805 |
|
} catch (Exception $e) { |
| 4806 |
|
// Cleanup hanging transaction on error |
| 4807 |
|
$repository->rollback(); |
| 4808 |
|
throw $e; |
| 4809 |
|
} |
| 4810 |
|
|
| 4811 |
|
// Load current remoteId |
| 4812 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4813 |
|
/* END: Use Case */ |
| 4814 |
|
|
| 4815 |
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
| 4816 |
|
} |
| 4817 |
|
|
| 4818 |
|
/** |
| 4819 |
|
* Test for the deleteVersion() method. |