|
@@ 4044-4088 (lines=45) @@
|
| 4041 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4042 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4043 |
|
*/ |
| 4044 |
|
public function testUpdateContentMetadataInTransactionWithRollback() |
| 4045 |
|
{ |
| 4046 |
|
$repository = $this->getRepository(); |
| 4047 |
|
|
| 4048 |
|
$contentId = $this->generateId('object', 12); |
| 4049 |
|
/* BEGIN: Use Case */ |
| 4050 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4051 |
|
|
| 4052 |
|
// Get the content service |
| 4053 |
|
$contentService = $repository->getContentService(); |
| 4054 |
|
|
| 4055 |
|
// Load a ContentInfo object |
| 4056 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4057 |
|
|
| 4058 |
|
// Store remoteId for later testing |
| 4059 |
|
$remoteId = $contentInfo->remoteId; |
| 4060 |
|
|
| 4061 |
|
// Start a transaction |
| 4062 |
|
$repository->beginTransaction(); |
| 4063 |
|
|
| 4064 |
|
try { |
| 4065 |
|
// Get metadata update struct and change remoteId |
| 4066 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4067 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4068 |
|
|
| 4069 |
|
// Update the metadata of the published content object |
| 4070 |
|
$contentService->updateContentMetadata( |
| 4071 |
|
$contentInfo, |
| 4072 |
|
$metadataUpdate |
| 4073 |
|
); |
| 4074 |
|
} catch (Exception $e) { |
| 4075 |
|
// Cleanup hanging transaction on error |
| 4076 |
|
$repository->rollback(); |
| 4077 |
|
throw $e; |
| 4078 |
|
} |
| 4079 |
|
|
| 4080 |
|
// Rollback all changes. |
| 4081 |
|
$repository->rollback(); |
| 4082 |
|
|
| 4083 |
|
// Load current remoteId |
| 4084 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4085 |
|
/* END: Use Case */ |
| 4086 |
|
|
| 4087 |
|
$this->assertEquals($remoteId, $remoteIdReloaded); |
| 4088 |
|
} |
| 4089 |
|
|
| 4090 |
|
/** |
| 4091 |
|
* Test for the updateContentMetadata() method. |
|
@@ 4097-4141 (lines=45) @@
|
| 4094 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4095 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4096 |
|
*/ |
| 4097 |
|
public function testUpdateContentMetadataInTransactionWithCommit() |
| 4098 |
|
{ |
| 4099 |
|
$repository = $this->getRepository(); |
| 4100 |
|
|
| 4101 |
|
$contentId = $this->generateId('object', 12); |
| 4102 |
|
/* BEGIN: Use Case */ |
| 4103 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4104 |
|
|
| 4105 |
|
// Get the content service |
| 4106 |
|
$contentService = $repository->getContentService(); |
| 4107 |
|
|
| 4108 |
|
// Load a ContentInfo object |
| 4109 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4110 |
|
|
| 4111 |
|
// Store remoteId for later testing |
| 4112 |
|
$remoteId = $contentInfo->remoteId; |
| 4113 |
|
|
| 4114 |
|
// Start a transaction |
| 4115 |
|
$repository->beginTransaction(); |
| 4116 |
|
|
| 4117 |
|
try { |
| 4118 |
|
// Get metadata update struct and change remoteId |
| 4119 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4120 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4121 |
|
|
| 4122 |
|
// Update the metadata of the published content object |
| 4123 |
|
$contentService->updateContentMetadata( |
| 4124 |
|
$contentInfo, |
| 4125 |
|
$metadataUpdate |
| 4126 |
|
); |
| 4127 |
|
|
| 4128 |
|
// Commit all changes. |
| 4129 |
|
$repository->commit(); |
| 4130 |
|
} catch (Exception $e) { |
| 4131 |
|
// Cleanup hanging transaction on error |
| 4132 |
|
$repository->rollback(); |
| 4133 |
|
throw $e; |
| 4134 |
|
} |
| 4135 |
|
|
| 4136 |
|
// Load current remoteId |
| 4137 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4138 |
|
/* END: Use Case */ |
| 4139 |
|
|
| 4140 |
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
| 4141 |
|
} |
| 4142 |
|
|
| 4143 |
|
/** |
| 4144 |
|
* Test for the deleteVersion() method. |