|
@@ 4205-4244 (lines=40) @@
|
| 4202 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
| 4203 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4204 |
|
*/ |
| 4205 |
|
public function testCreateContentDraftInTransactionWithCommit() |
| 4206 |
|
{ |
| 4207 |
|
$repository = $this->getRepository(); |
| 4208 |
|
|
| 4209 |
|
$contentId = $this->generateId('object', 12); |
| 4210 |
|
/* BEGIN: Use Case */ |
| 4211 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4212 |
|
|
| 4213 |
|
// Get the content service |
| 4214 |
|
$contentService = $repository->getContentService(); |
| 4215 |
|
|
| 4216 |
|
// Load the user group content object |
| 4217 |
|
$content = $contentService->loadContent($contentId); |
| 4218 |
|
|
| 4219 |
|
// Start a new transaction |
| 4220 |
|
$repository->beginTransaction(); |
| 4221 |
|
|
| 4222 |
|
try { |
| 4223 |
|
// Create a new draft |
| 4224 |
|
$drafted = $contentService->createContentDraft($content->contentInfo); |
| 4225 |
|
|
| 4226 |
|
// Store version number for later reuse |
| 4227 |
|
$versionNo = $drafted->versionInfo->versionNo; |
| 4228 |
|
|
| 4229 |
|
// Commit all changes |
| 4230 |
|
$repository->commit(); |
| 4231 |
|
} catch (Exception $e) { |
| 4232 |
|
// Cleanup hanging transaction on error |
| 4233 |
|
$repository->rollback(); |
| 4234 |
|
throw $e; |
| 4235 |
|
} |
| 4236 |
|
|
| 4237 |
|
$content = $contentService->loadContent($contentId, null, $versionNo); |
| 4238 |
|
/* END: Use Case */ |
| 4239 |
|
|
| 4240 |
|
$this->assertEquals( |
| 4241 |
|
$versionNo, |
| 4242 |
|
$content->getVersionInfo()->versionNo |
| 4243 |
|
); |
| 4244 |
|
} |
| 4245 |
|
|
| 4246 |
|
/** |
| 4247 |
|
* Test for the publishVersion() method. |
|
@@ 4253-4296 (lines=44) @@
|
| 4250 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4251 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4252 |
|
*/ |
| 4253 |
|
public function testPublishVersionInTransactionWithRollback() |
| 4254 |
|
{ |
| 4255 |
|
$repository = $this->getRepository(); |
| 4256 |
|
|
| 4257 |
|
$contentId = $this->generateId('object', 12); |
| 4258 |
|
/* BEGIN: Use Case */ |
| 4259 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4260 |
|
|
| 4261 |
|
// Get the content service |
| 4262 |
|
$contentService = $repository->getContentService(); |
| 4263 |
|
|
| 4264 |
|
// Load the user group content object |
| 4265 |
|
$content = $contentService->loadContent($contentId); |
| 4266 |
|
|
| 4267 |
|
// Start a new transaction |
| 4268 |
|
$repository->beginTransaction(); |
| 4269 |
|
|
| 4270 |
|
try { |
| 4271 |
|
$draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
| 4272 |
|
|
| 4273 |
|
// Publish a new version |
| 4274 |
|
$content = $contentService->publishVersion($draftVersion); |
| 4275 |
|
|
| 4276 |
|
// Store version number for later reuse |
| 4277 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4278 |
|
} catch (Exception $e) { |
| 4279 |
|
// Cleanup hanging transaction on error |
| 4280 |
|
$repository->rollback(); |
| 4281 |
|
throw $e; |
| 4282 |
|
} |
| 4283 |
|
|
| 4284 |
|
// Rollback |
| 4285 |
|
$repository->rollback(); |
| 4286 |
|
|
| 4287 |
|
try { |
| 4288 |
|
// This call will fail with a "NotFoundException" |
| 4289 |
|
$contentService->loadContent($contentId, null, $versionNo); |
| 4290 |
|
} catch (NotFoundException $e) { |
| 4291 |
|
return; |
| 4292 |
|
} |
| 4293 |
|
/* END: Use Case */ |
| 4294 |
|
|
| 4295 |
|
$this->fail('Can still load content draft after rollback'); |
| 4296 |
|
} |
| 4297 |
|
|
| 4298 |
|
/** |
| 4299 |
|
* Test for the publishVersion() method. |
|
@@ 4305-4344 (lines=40) @@
|
| 4302 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4303 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
| 4304 |
|
*/ |
| 4305 |
|
public function testPublishVersionInTransactionWithCommit() |
| 4306 |
|
{ |
| 4307 |
|
$repository = $this->getRepository(); |
| 4308 |
|
|
| 4309 |
|
/* BEGIN: Use Case */ |
| 4310 |
|
// ID of the "Administrator users" user group |
| 4311 |
|
$contentId = 12; |
| 4312 |
|
|
| 4313 |
|
// Get the content service |
| 4314 |
|
$contentService = $repository->getContentService(); |
| 4315 |
|
|
| 4316 |
|
// Load the user group content object |
| 4317 |
|
$template = $contentService->loadContent($contentId); |
| 4318 |
|
|
| 4319 |
|
// Start a new transaction |
| 4320 |
|
$repository->beginTransaction(); |
| 4321 |
|
|
| 4322 |
|
try { |
| 4323 |
|
// Publish a new version |
| 4324 |
|
$content = $contentService->publishVersion( |
| 4325 |
|
$contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
| 4326 |
|
); |
| 4327 |
|
|
| 4328 |
|
// Store version number for later reuse |
| 4329 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4330 |
|
|
| 4331 |
|
// Commit all changes |
| 4332 |
|
$repository->commit(); |
| 4333 |
|
} catch (Exception $e) { |
| 4334 |
|
// Cleanup hanging transaction on error |
| 4335 |
|
$repository->rollback(); |
| 4336 |
|
throw $e; |
| 4337 |
|
} |
| 4338 |
|
|
| 4339 |
|
// Load current version info |
| 4340 |
|
$versionInfo = $contentService->loadVersionInfo($content->contentInfo); |
| 4341 |
|
/* END: Use Case */ |
| 4342 |
|
|
| 4343 |
|
$this->assertEquals($versionNo, $versionInfo->versionNo); |
| 4344 |
|
} |
| 4345 |
|
|
| 4346 |
|
/** |
| 4347 |
|
* Test for the updateContent() method. |