|
@@ 4244-4287 (lines=44) @@
|
| 4241 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4242 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4243 |
|
*/ |
| 4244 |
|
public function testUpdateContentInTransactionWithRollback() |
| 4245 |
|
{ |
| 4246 |
|
$repository = $this->getRepository(); |
| 4247 |
|
|
| 4248 |
|
$contentId = $this->generateId('object', 12); |
| 4249 |
|
/* BEGIN: Use Case */ |
| 4250 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4251 |
|
|
| 4252 |
|
// Create a new user group draft |
| 4253 |
|
$draft = $this->contentService->createContentDraft( |
| 4254 |
|
$this->contentService->loadContentInfo($contentId) |
| 4255 |
|
); |
| 4256 |
|
|
| 4257 |
|
// Get an update struct and change the group name |
| 4258 |
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
| 4259 |
|
$contentUpdate->setField('name', 'Administrators', 'eng-US'); |
| 4260 |
|
|
| 4261 |
|
// Start a transaction |
| 4262 |
|
$repository->beginTransaction(); |
| 4263 |
|
|
| 4264 |
|
try { |
| 4265 |
|
// Update the group name |
| 4266 |
|
$draft = $this->contentService->updateContent( |
| 4267 |
|
$draft->getVersionInfo(), |
| 4268 |
|
$contentUpdate |
| 4269 |
|
); |
| 4270 |
|
|
| 4271 |
|
// Publish updated version |
| 4272 |
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
| 4273 |
|
} catch (Exception $e) { |
| 4274 |
|
// Cleanup hanging transaction on error |
| 4275 |
|
$repository->rollback(); |
| 4276 |
|
throw $e; |
| 4277 |
|
} |
| 4278 |
|
|
| 4279 |
|
// Rollback all changes. |
| 4280 |
|
$repository->rollback(); |
| 4281 |
|
|
| 4282 |
|
// Name will still be "Administrator users" |
| 4283 |
|
$name = $this->contentService->loadContent($contentId)->getFieldValue('name'); |
| 4284 |
|
/* END: Use Case */ |
| 4285 |
|
|
| 4286 |
|
$this->assertEquals('Administrator users', $name); |
| 4287 |
|
} |
| 4288 |
|
|
| 4289 |
|
/** |
| 4290 |
|
* Test for the updateContent() method. |
|
@@ 4297-4340 (lines=44) @@
|
| 4294 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4295 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4296 |
|
*/ |
| 4297 |
|
public function testUpdateContentInTransactionWithCommit() |
| 4298 |
|
{ |
| 4299 |
|
$repository = $this->getRepository(); |
| 4300 |
|
|
| 4301 |
|
$contentId = $this->generateId('object', 12); |
| 4302 |
|
/* BEGIN: Use Case */ |
| 4303 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4304 |
|
|
| 4305 |
|
// Create a new user group draft |
| 4306 |
|
$draft = $this->contentService->createContentDraft( |
| 4307 |
|
$this->contentService->loadContentInfo($contentId) |
| 4308 |
|
); |
| 4309 |
|
|
| 4310 |
|
// Get an update struct and change the group name |
| 4311 |
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
| 4312 |
|
$contentUpdate->setField('name', 'Administrators', 'eng-US'); |
| 4313 |
|
|
| 4314 |
|
// Start a transaction |
| 4315 |
|
$repository->beginTransaction(); |
| 4316 |
|
|
| 4317 |
|
try { |
| 4318 |
|
// Update the group name |
| 4319 |
|
$draft = $this->contentService->updateContent( |
| 4320 |
|
$draft->getVersionInfo(), |
| 4321 |
|
$contentUpdate |
| 4322 |
|
); |
| 4323 |
|
|
| 4324 |
|
// Publish updated version |
| 4325 |
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
| 4326 |
|
|
| 4327 |
|
// Commit all changes. |
| 4328 |
|
$repository->commit(); |
| 4329 |
|
} catch (Exception $e) { |
| 4330 |
|
// Cleanup hanging transaction on error |
| 4331 |
|
$repository->rollback(); |
| 4332 |
|
throw $e; |
| 4333 |
|
} |
| 4334 |
|
|
| 4335 |
|
// Name is now "Administrators" |
| 4336 |
|
$name = $this->contentService->loadContent($contentId)->getFieldValue('name', 'eng-US'); |
| 4337 |
|
/* END: Use Case */ |
| 4338 |
|
|
| 4339 |
|
$this->assertEquals('Administrators', $name); |
| 4340 |
|
} |
| 4341 |
|
|
| 4342 |
|
/** |
| 4343 |
|
* Test for the updateContentMetadata() method. |