|
@@ 4092-4138 (lines=47) @@
|
| 4089 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4090 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4091 |
|
*/ |
| 4092 |
|
public function testUpdateContentInTransactionWithRollback() |
| 4093 |
|
{ |
| 4094 |
|
$repository = $this->getRepository(); |
| 4095 |
|
|
| 4096 |
|
$contentId = $this->generateId('object', 12); |
| 4097 |
|
/* BEGIN: Use Case */ |
| 4098 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4099 |
|
|
| 4100 |
|
// Load content service |
| 4101 |
|
$contentService = $repository->getContentService(); |
| 4102 |
|
|
| 4103 |
|
// Create a new user group draft |
| 4104 |
|
$draft = $contentService->createContentDraft( |
| 4105 |
|
$contentService->loadContentInfo($contentId) |
| 4106 |
|
); |
| 4107 |
|
|
| 4108 |
|
// Get an update struct and change the group name |
| 4109 |
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
| 4110 |
|
$contentUpdate->setField('name', 'Administrators', 'eng-US'); |
| 4111 |
|
|
| 4112 |
|
// Start a transaction |
| 4113 |
|
$repository->beginTransaction(); |
| 4114 |
|
|
| 4115 |
|
try { |
| 4116 |
|
// Update the group name |
| 4117 |
|
$draft = $contentService->updateContent( |
| 4118 |
|
$draft->getVersionInfo(), |
| 4119 |
|
$contentUpdate |
| 4120 |
|
); |
| 4121 |
|
|
| 4122 |
|
// Publish updated version |
| 4123 |
|
$contentService->publishVersion($draft->getVersionInfo()); |
| 4124 |
|
} catch (Exception $e) { |
| 4125 |
|
// Cleanup hanging transaction on error |
| 4126 |
|
$repository->rollback(); |
| 4127 |
|
throw $e; |
| 4128 |
|
} |
| 4129 |
|
|
| 4130 |
|
// Rollback all changes. |
| 4131 |
|
$repository->rollback(); |
| 4132 |
|
|
| 4133 |
|
// Name will still be "Administrator users" |
| 4134 |
|
$name = $contentService->loadContent($contentId)->getFieldValue('name'); |
| 4135 |
|
/* END: Use Case */ |
| 4136 |
|
|
| 4137 |
|
$this->assertEquals('Administrator users', $name); |
| 4138 |
|
} |
| 4139 |
|
|
| 4140 |
|
/** |
| 4141 |
|
* Test for the updateContent() method. |
|
@@ 4148-4194 (lines=47) @@
|
| 4145 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4146 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4147 |
|
*/ |
| 4148 |
|
public function testUpdateContentInTransactionWithCommit() |
| 4149 |
|
{ |
| 4150 |
|
$repository = $this->getRepository(); |
| 4151 |
|
|
| 4152 |
|
$contentId = $this->generateId('object', 12); |
| 4153 |
|
/* BEGIN: Use Case */ |
| 4154 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4155 |
|
|
| 4156 |
|
// Load content service |
| 4157 |
|
$contentService = $repository->getContentService(); |
| 4158 |
|
|
| 4159 |
|
// Create a new user group draft |
| 4160 |
|
$draft = $contentService->createContentDraft( |
| 4161 |
|
$contentService->loadContentInfo($contentId) |
| 4162 |
|
); |
| 4163 |
|
|
| 4164 |
|
// Get an update struct and change the group name |
| 4165 |
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
| 4166 |
|
$contentUpdate->setField('name', 'Administrators', 'eng-US'); |
| 4167 |
|
|
| 4168 |
|
// Start a transaction |
| 4169 |
|
$repository->beginTransaction(); |
| 4170 |
|
|
| 4171 |
|
try { |
| 4172 |
|
// Update the group name |
| 4173 |
|
$draft = $contentService->updateContent( |
| 4174 |
|
$draft->getVersionInfo(), |
| 4175 |
|
$contentUpdate |
| 4176 |
|
); |
| 4177 |
|
|
| 4178 |
|
// Publish updated version |
| 4179 |
|
$contentService->publishVersion($draft->getVersionInfo()); |
| 4180 |
|
|
| 4181 |
|
// Commit all changes. |
| 4182 |
|
$repository->commit(); |
| 4183 |
|
} catch (Exception $e) { |
| 4184 |
|
// Cleanup hanging transaction on error |
| 4185 |
|
$repository->rollback(); |
| 4186 |
|
throw $e; |
| 4187 |
|
} |
| 4188 |
|
|
| 4189 |
|
// Name is now "Administrators" |
| 4190 |
|
$name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US'); |
| 4191 |
|
/* END: Use Case */ |
| 4192 |
|
|
| 4193 |
|
$this->assertEquals('Administrators', $name); |
| 4194 |
|
} |
| 4195 |
|
|
| 4196 |
|
/** |
| 4197 |
|
* Test for the updateContentMetadata() method. |