|
@@ 4421-4465 (lines=45) @@
|
| 4418 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4419 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4420 |
|
*/ |
| 4421 |
|
public function testUpdateContentMetadataInTransactionWithRollback() |
| 4422 |
|
{ |
| 4423 |
|
$repository = $this->getRepository(); |
| 4424 |
|
|
| 4425 |
|
$contentId = $this->generateId('object', 12); |
| 4426 |
|
/* BEGIN: Use Case */ |
| 4427 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4428 |
|
|
| 4429 |
|
// Get the content service |
| 4430 |
|
$contentService = $repository->getContentService(); |
| 4431 |
|
|
| 4432 |
|
// Load a ContentInfo object |
| 4433 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4434 |
|
|
| 4435 |
|
// Store remoteId for later testing |
| 4436 |
|
$remoteId = $contentInfo->remoteId; |
| 4437 |
|
|
| 4438 |
|
// Start a transaction |
| 4439 |
|
$repository->beginTransaction(); |
| 4440 |
|
|
| 4441 |
|
try { |
| 4442 |
|
// Get metadata update struct and change remoteId |
| 4443 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4444 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4445 |
|
|
| 4446 |
|
// Update the metadata of the published content object |
| 4447 |
|
$contentService->updateContentMetadata( |
| 4448 |
|
$contentInfo, |
| 4449 |
|
$metadataUpdate |
| 4450 |
|
); |
| 4451 |
|
} catch (Exception $e) { |
| 4452 |
|
// Cleanup hanging transaction on error |
| 4453 |
|
$repository->rollback(); |
| 4454 |
|
throw $e; |
| 4455 |
|
} |
| 4456 |
|
|
| 4457 |
|
// Rollback all changes. |
| 4458 |
|
$repository->rollback(); |
| 4459 |
|
|
| 4460 |
|
// Load current remoteId |
| 4461 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4462 |
|
/* END: Use Case */ |
| 4463 |
|
|
| 4464 |
|
$this->assertEquals($remoteId, $remoteIdReloaded); |
| 4465 |
|
} |
| 4466 |
|
|
| 4467 |
|
/** |
| 4468 |
|
* Test for the updateContentMetadata() method. |
|
@@ 4474-4518 (lines=45) @@
|
| 4471 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
| 4472 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
| 4473 |
|
*/ |
| 4474 |
|
public function testUpdateContentMetadataInTransactionWithCommit() |
| 4475 |
|
{ |
| 4476 |
|
$repository = $this->getRepository(); |
| 4477 |
|
|
| 4478 |
|
$contentId = $this->generateId('object', 12); |
| 4479 |
|
/* BEGIN: Use Case */ |
| 4480 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4481 |
|
|
| 4482 |
|
// Get the content service |
| 4483 |
|
$contentService = $repository->getContentService(); |
| 4484 |
|
|
| 4485 |
|
// Load a ContentInfo object |
| 4486 |
|
$contentInfo = $contentService->loadContentInfo($contentId); |
| 4487 |
|
|
| 4488 |
|
// Store remoteId for later testing |
| 4489 |
|
$remoteId = $contentInfo->remoteId; |
| 4490 |
|
|
| 4491 |
|
// Start a transaction |
| 4492 |
|
$repository->beginTransaction(); |
| 4493 |
|
|
| 4494 |
|
try { |
| 4495 |
|
// Get metadata update struct and change remoteId |
| 4496 |
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
| 4497 |
|
$metadataUpdate->remoteId = md5(microtime(true)); |
| 4498 |
|
|
| 4499 |
|
// Update the metadata of the published content object |
| 4500 |
|
$contentService->updateContentMetadata( |
| 4501 |
|
$contentInfo, |
| 4502 |
|
$metadataUpdate |
| 4503 |
|
); |
| 4504 |
|
|
| 4505 |
|
// Commit all changes. |
| 4506 |
|
$repository->commit(); |
| 4507 |
|
} catch (Exception $e) { |
| 4508 |
|
// Cleanup hanging transaction on error |
| 4509 |
|
$repository->rollback(); |
| 4510 |
|
throw $e; |
| 4511 |
|
} |
| 4512 |
|
|
| 4513 |
|
// Load current remoteId |
| 4514 |
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
| 4515 |
|
/* END: Use Case */ |
| 4516 |
|
|
| 4517 |
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
| 4518 |
|
} |
| 4519 |
|
|
| 4520 |
|
/** |
| 4521 |
|
* Test for the deleteVersion() method. |