|
@@ 4496-4540 (lines=45) @@
|
| 4493 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4494 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4495 |
|
*/ |
| 4496 |
|
public function testUpdateContentMetadataInTransactionWithRollback() |
| 4497 |
|
{ |
| 4498 |
|
$repository = $this->getRepository(); |
| 4499 |
|
|
| 4500 |
|
$contentId = $this->generateId('object', 12); |
| 4501 |
|
/* BEGIN: Use Case */ |
| 4502 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4503 |
|
|
| 4504 |
|
// Get the content service |
| 4505 |
|
$contentService = $repository->getContentService(); |
| 4506 |
|
|
| 4507 |
|
// Load a ContentInfo object |
| 4508 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4509 |
|
|
| 4510 |
|
// Store remoteId for later testing |
| 4511 |
|
$remoteId = $contentInfo->remoteId; |
| 4512 |
|
|
| 4513 |
|
// Start a transaction |
| 4514 |
|
$repository->beginTransaction(); |
| 4515 |
|
|
| 4516 |
|
try { |
| 4517 |
|
// Get metadata update struct and change remoteId |
| 4518 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4519 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4520 |
|
|
| 4521 |
|
// Update the metadata of the published content object |
| 4522 |
|
$contentService->updateContentMetadata( |
| 4523 |
|
$contentInfo, |
| 4524 |
|
$metadataUpdate |
| 4525 |
|
); |
| 4526 |
|
} catch (Exception $e) { |
| 4527 |
|
// Cleanup hanging transaction on error |
| 4528 |
|
$repository->rollback(); |
| 4529 |
|
throw $e; |
| 4530 |
|
} |
| 4531 |
|
|
| 4532 |
|
// Rollback all changes. |
| 4533 |
|
$repository->rollback(); |
| 4534 |
|
|
| 4535 |
|
// Load current remoteId |
| 4536 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4537 |
|
/* END: Use Case */ |
| 4538 |
|
|
| 4539 |
|
$this->assertEquals($remoteId, $remoteIdReloaded); |
| 4540 |
|
} |
| 4541 |
|
|
| 4542 |
|
/** |
| 4543 |
|
* Test for the updateContentMetadata() method. |
|
@@ 4549-4593 (lines=45) @@
|
| 4546 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4547 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4548 |
|
*/ |
| 4549 |
|
public function testUpdateContentMetadataInTransactionWithCommit() |
| 4550 |
|
{ |
| 4551 |
|
$repository = $this->getRepository(); |
| 4552 |
|
|
| 4553 |
|
$contentId = $this->generateId('object', 12); |
| 4554 |
|
/* BEGIN: Use Case */ |
| 4555 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4556 |
|
|
| 4557 |
|
// Get the content service |
| 4558 |
|
$contentService = $repository->getContentService(); |
| 4559 |
|
|
| 4560 |
|
// Load a ContentInfo object |
| 4561 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4562 |
|
|
| 4563 |
|
// Store remoteId for later testing |
| 4564 |
|
$remoteId = $contentInfo->remoteId; |
| 4565 |
|
|
| 4566 |
|
// Start a transaction |
| 4567 |
|
$repository->beginTransaction(); |
| 4568 |
|
|
| 4569 |
|
try { |
| 4570 |
|
// Get metadata update struct and change remoteId |
| 4571 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4572 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4573 |
|
|
| 4574 |
|
// Update the metadata of the published content object |
| 4575 |
|
$contentService->updateContentMetadata( |
| 4576 |
|
$contentInfo, |
| 4577 |
|
$metadataUpdate |
| 4578 |
|
); |
| 4579 |
|
|
| 4580 |
|
// Commit all changes. |
| 4581 |
|
$repository->commit(); |
| 4582 |
|
} catch (Exception $e) { |
| 4583 |
|
// Cleanup hanging transaction on error |
| 4584 |
|
$repository->rollback(); |
| 4585 |
|
throw $e; |
| 4586 |
|
} |
| 4587 |
|
|
| 4588 |
|
// Load current remoteId |
| 4589 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4590 |
|
/* END: Use Case */ |
| 4591 |
|
|
| 4592 |
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
| 4593 |
|
} |
| 4594 |
|
|
| 4595 |
|
/** |
| 4596 |
|
* Test for the deleteVersion() method. |