|
@@ 4356-4391 (lines=36) @@
|
| 4353 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4354 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
| 4355 |
|
*/ |
| 4356 |
|
public function testDeleteVersionInTransactionWithRollback() |
| 4357 |
|
{ |
| 4358 |
|
$repository = $this->getRepository(); |
| 4359 |
|
|
| 4360 |
|
$contentId = $this->generateId('object', 12); |
| 4361 |
|
/* BEGIN: Use Case */ |
| 4362 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4363 |
|
|
| 4364 |
|
// Get the content service |
| 4365 |
|
$contentService = $repository->getContentService(); |
| 4366 |
|
|
| 4367 |
|
// Start a new transaction |
| 4368 |
|
$repository->beginTransaction(); |
| 4369 |
|
|
| 4370 |
|
try { |
| 4371 |
|
// Create a new draft |
| 4372 |
|
$draft = $contentService->createContentDraft( |
| 4373 |
|
$contentService->loadContentInfo($contentId) |
| 4374 |
|
); |
| 4375 |
|
|
| 4376 |
|
$contentService->deleteVersion($draft->getVersionInfo()); |
| 4377 |
|
} catch (Exception $e) { |
| 4378 |
|
// Cleanup hanging transaction on error |
| 4379 |
|
$repository->rollback(); |
| 4380 |
|
throw $e; |
| 4381 |
|
} |
| 4382 |
|
|
| 4383 |
|
// Rollback all changes. |
| 4384 |
|
$repository->rollback(); |
| 4385 |
|
|
| 4386 |
|
// This array will be empty |
| 4387 |
|
$drafts = $contentService->loadContentDrafts(); |
| 4388 |
|
/* END: Use Case */ |
| 4389 |
|
|
| 4390 |
|
$this->assertSame([], $drafts); |
| 4391 |
|
} |
| 4392 |
|
|
| 4393 |
|
/** |
| 4394 |
|
* Test for the deleteVersion() method. |
|
@@ 4401-4436 (lines=36) @@
|
| 4398 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4399 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
| 4400 |
|
*/ |
| 4401 |
|
public function testDeleteVersionInTransactionWithCommit() |
| 4402 |
|
{ |
| 4403 |
|
$repository = $this->getRepository(); |
| 4404 |
|
|
| 4405 |
|
$contentId = $this->generateId('object', 12); |
| 4406 |
|
/* BEGIN: Use Case */ |
| 4407 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4408 |
|
|
| 4409 |
|
// Get the content service |
| 4410 |
|
$contentService = $repository->getContentService(); |
| 4411 |
|
|
| 4412 |
|
// Start a new transaction |
| 4413 |
|
$repository->beginTransaction(); |
| 4414 |
|
|
| 4415 |
|
try { |
| 4416 |
|
// Create a new draft |
| 4417 |
|
$draft = $contentService->createContentDraft( |
| 4418 |
|
$contentService->loadContentInfo($contentId) |
| 4419 |
|
); |
| 4420 |
|
|
| 4421 |
|
$contentService->deleteVersion($draft->getVersionInfo()); |
| 4422 |
|
|
| 4423 |
|
// Commit all changes. |
| 4424 |
|
$repository->commit(); |
| 4425 |
|
} catch (Exception $e) { |
| 4426 |
|
// Cleanup hanging transaction on error |
| 4427 |
|
$repository->rollback(); |
| 4428 |
|
throw $e; |
| 4429 |
|
} |
| 4430 |
|
|
| 4431 |
|
// This array will contain no element |
| 4432 |
|
$drafts = $contentService->loadContentDrafts(); |
| 4433 |
|
/* END: Use Case */ |
| 4434 |
|
|
| 4435 |
|
$this->assertSame([], $drafts); |
| 4436 |
|
} |
| 4437 |
|
|
| 4438 |
|
/** |
| 4439 |
|
* Test for the deleteContent() method. |
|
@@ 4445-4480 (lines=36) @@
|
| 4442 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
| 4443 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4444 |
|
*/ |
| 4445 |
|
public function testDeleteContentInTransactionWithRollback() |
| 4446 |
|
{ |
| 4447 |
|
$repository = $this->getRepository(); |
| 4448 |
|
|
| 4449 |
|
$contentId = $this->generateId('object', 11); |
| 4450 |
|
/* BEGIN: Use Case */ |
| 4451 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4452 |
|
// demo installation |
| 4453 |
|
|
| 4454 |
|
// Get content service |
| 4455 |
|
$contentService = $repository->getContentService(); |
| 4456 |
|
|
| 4457 |
|
// Load a ContentInfo instance |
| 4458 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4459 |
|
|
| 4460 |
|
// Start a new transaction |
| 4461 |
|
$repository->beginTransaction(); |
| 4462 |
|
|
| 4463 |
|
try { |
| 4464 |
|
// Delete content object |
| 4465 |
|
$contentService->deleteContent($contentInfo); |
| 4466 |
|
} catch (Exception $e) { |
| 4467 |
|
// Cleanup hanging transaction on error |
| 4468 |
|
$repository->rollback(); |
| 4469 |
|
throw $e; |
| 4470 |
|
} |
| 4471 |
|
|
| 4472 |
|
// Rollback all changes |
| 4473 |
|
$repository->rollback(); |
| 4474 |
|
|
| 4475 |
|
// This call will return the original content object |
| 4476 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4477 |
|
/* END: Use Case */ |
| 4478 |
|
|
| 4479 |
|
$this->assertEquals($contentId, $contentInfo->id); |
| 4480 |
|
} |
| 4481 |
|
|
| 4482 |
|
/** |
| 4483 |
|
* Test for the deleteContent() method. |