|
@@ 4236-4275 (lines=40) @@
|
| 4233 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
| 4234 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4235 |
|
*/ |
| 4236 |
|
public function testCreateContentDraftInTransactionWithCommit() |
| 4237 |
|
{ |
| 4238 |
|
$repository = $this->getRepository(); |
| 4239 |
|
|
| 4240 |
|
$contentId = $this->generateId('object', 12); |
| 4241 |
|
/* BEGIN: Use Case */ |
| 4242 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4243 |
|
|
| 4244 |
|
// Get the content service |
| 4245 |
|
$contentService = $repository->getContentService(); |
| 4246 |
|
|
| 4247 |
|
// Load the user group content object |
| 4248 |
|
$content = $contentService->loadContent($contentId); |
| 4249 |
|
|
| 4250 |
|
// Start a new transaction |
| 4251 |
|
$repository->beginTransaction(); |
| 4252 |
|
|
| 4253 |
|
try { |
| 4254 |
|
// Create a new draft |
| 4255 |
|
$drafted = $contentService->createContentDraft($content->contentInfo); |
| 4256 |
|
|
| 4257 |
|
// Store version number for later reuse |
| 4258 |
|
$versionNo = $drafted->versionInfo->versionNo; |
| 4259 |
|
|
| 4260 |
|
// Commit all changes |
| 4261 |
|
$repository->commit(); |
| 4262 |
|
} catch (Exception $e) { |
| 4263 |
|
// Cleanup hanging transaction on error |
| 4264 |
|
$repository->rollback(); |
| 4265 |
|
throw $e; |
| 4266 |
|
} |
| 4267 |
|
|
| 4268 |
|
$content = $contentService->loadContent($contentId, null, $versionNo); |
| 4269 |
|
/* END: Use Case */ |
| 4270 |
|
|
| 4271 |
|
$this->assertEquals( |
| 4272 |
|
$versionNo, |
| 4273 |
|
$content->getVersionInfo()->versionNo |
| 4274 |
|
); |
| 4275 |
|
} |
| 4276 |
|
|
| 4277 |
|
/** |
| 4278 |
|
* Test for the publishVersion() method. |
|
@@ 4284-4327 (lines=44) @@
|
| 4281 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4282 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4283 |
|
*/ |
| 4284 |
|
public function testPublishVersionInTransactionWithRollback() |
| 4285 |
|
{ |
| 4286 |
|
$repository = $this->getRepository(); |
| 4287 |
|
|
| 4288 |
|
$contentId = $this->generateId('object', 12); |
| 4289 |
|
/* BEGIN: Use Case */ |
| 4290 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4291 |
|
|
| 4292 |
|
// Get the content service |
| 4293 |
|
$contentService = $repository->getContentService(); |
| 4294 |
|
|
| 4295 |
|
// Load the user group content object |
| 4296 |
|
$content = $contentService->loadContent($contentId); |
| 4297 |
|
|
| 4298 |
|
// Start a new transaction |
| 4299 |
|
$repository->beginTransaction(); |
| 4300 |
|
|
| 4301 |
|
try { |
| 4302 |
|
$draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
| 4303 |
|
|
| 4304 |
|
// Publish a new version |
| 4305 |
|
$content = $contentService->publishVersion($draftVersion); |
| 4306 |
|
|
| 4307 |
|
// Store version number for later reuse |
| 4308 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4309 |
|
} catch (Exception $e) { |
| 4310 |
|
// Cleanup hanging transaction on error |
| 4311 |
|
$repository->rollback(); |
| 4312 |
|
throw $e; |
| 4313 |
|
} |
| 4314 |
|
|
| 4315 |
|
// Rollback |
| 4316 |
|
$repository->rollback(); |
| 4317 |
|
|
| 4318 |
|
try { |
| 4319 |
|
// This call will fail with a "NotFoundException" |
| 4320 |
|
$contentService->loadContent($contentId, null, $versionNo); |
| 4321 |
|
} catch (NotFoundException $e) { |
| 4322 |
|
return; |
| 4323 |
|
} |
| 4324 |
|
/* END: Use Case */ |
| 4325 |
|
|
| 4326 |
|
$this->fail('Can still load content draft after rollback'); |
| 4327 |
|
} |
| 4328 |
|
|
| 4329 |
|
/** |
| 4330 |
|
* Test for the publishVersion() method. |
|
@@ 4336-4375 (lines=40) @@
|
| 4333 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4334 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
| 4335 |
|
*/ |
| 4336 |
|
public function testPublishVersionInTransactionWithCommit() |
| 4337 |
|
{ |
| 4338 |
|
$repository = $this->getRepository(); |
| 4339 |
|
|
| 4340 |
|
/* BEGIN: Use Case */ |
| 4341 |
|
// ID of the "Administrator users" user group |
| 4342 |
|
$contentId = 12; |
| 4343 |
|
|
| 4344 |
|
// Get the content service |
| 4345 |
|
$contentService = $repository->getContentService(); |
| 4346 |
|
|
| 4347 |
|
// Load the user group content object |
| 4348 |
|
$template = $contentService->loadContent($contentId); |
| 4349 |
|
|
| 4350 |
|
// Start a new transaction |
| 4351 |
|
$repository->beginTransaction(); |
| 4352 |
|
|
| 4353 |
|
try { |
| 4354 |
|
// Publish a new version |
| 4355 |
|
$content = $contentService->publishVersion( |
| 4356 |
|
$contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
| 4357 |
|
); |
| 4358 |
|
|
| 4359 |
|
// Store version number for later reuse |
| 4360 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4361 |
|
|
| 4362 |
|
// Commit all changes |
| 4363 |
|
$repository->commit(); |
| 4364 |
|
} catch (Exception $e) { |
| 4365 |
|
// Cleanup hanging transaction on error |
| 4366 |
|
$repository->rollback(); |
| 4367 |
|
throw $e; |
| 4368 |
|
} |
| 4369 |
|
|
| 4370 |
|
// Load current version info |
| 4371 |
|
$versionInfo = $contentService->loadVersionInfo($content->contentInfo); |
| 4372 |
|
/* END: Use Case */ |
| 4373 |
|
|
| 4374 |
|
$this->assertEquals($versionNo, $versionInfo->versionNo); |
| 4375 |
|
} |
| 4376 |
|
|
| 4377 |
|
/** |
| 4378 |
|
* Test for the updateContent() method. |