@@ 4385-4431 (lines=47) @@ | ||
4382 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
|
4383 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
4384 | */ |
|
4385 | public function testUpdateContentInTransactionWithRollback() |
|
4386 | { |
|
4387 | $repository = $this->getRepository(); |
|
4388 | ||
4389 | $contentId = $this->generateId('object', 12); |
|
4390 | /* BEGIN: Use Case */ |
|
4391 | // $contentId is the ID of the "Administrator users" user group |
|
4392 | ||
4393 | // Load content service |
|
4394 | $contentService = $repository->getContentService(); |
|
4395 | ||
4396 | // Create a new user group draft |
|
4397 | $draft = $contentService->createContentDraft( |
|
4398 | $contentService->loadContentInfo($contentId) |
|
4399 | ); |
|
4400 | ||
4401 | // Get an update struct and change the group name |
|
4402 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
4403 | $contentUpdate->setField('name', 'Administrators', 'eng-US'); |
|
4404 | ||
4405 | // Start a transaction |
|
4406 | $repository->beginTransaction(); |
|
4407 | ||
4408 | try { |
|
4409 | // Update the group name |
|
4410 | $draft = $contentService->updateContent( |
|
4411 | $draft->getVersionInfo(), |
|
4412 | $contentUpdate |
|
4413 | ); |
|
4414 | ||
4415 | // Publish updated version |
|
4416 | $contentService->publishVersion($draft->getVersionInfo()); |
|
4417 | } catch (Exception $e) { |
|
4418 | // Cleanup hanging transaction on error |
|
4419 | $repository->rollback(); |
|
4420 | throw $e; |
|
4421 | } |
|
4422 | ||
4423 | // Rollback all changes. |
|
4424 | $repository->rollback(); |
|
4425 | ||
4426 | // Name will still be "Administrator users" |
|
4427 | $name = $contentService->loadContent($contentId)->getFieldValue('name'); |
|
4428 | /* END: Use Case */ |
|
4429 | ||
4430 | $this->assertEquals('Administrator users', $name); |
|
4431 | } |
|
4432 | ||
4433 | /** |
|
4434 | * Test for the updateContent() method. |
|
@@ 4441-4487 (lines=47) @@ | ||
4438 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
|
4439 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
4440 | */ |
|
4441 | public function testUpdateContentInTransactionWithCommit() |
|
4442 | { |
|
4443 | $repository = $this->getRepository(); |
|
4444 | ||
4445 | $contentId = $this->generateId('object', 12); |
|
4446 | /* BEGIN: Use Case */ |
|
4447 | // $contentId is the ID of the "Administrator users" user group |
|
4448 | ||
4449 | // Load content service |
|
4450 | $contentService = $repository->getContentService(); |
|
4451 | ||
4452 | // Create a new user group draft |
|
4453 | $draft = $contentService->createContentDraft( |
|
4454 | $contentService->loadContentInfo($contentId) |
|
4455 | ); |
|
4456 | ||
4457 | // Get an update struct and change the group name |
|
4458 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
4459 | $contentUpdate->setField('name', 'Administrators', 'eng-US'); |
|
4460 | ||
4461 | // Start a transaction |
|
4462 | $repository->beginTransaction(); |
|
4463 | ||
4464 | try { |
|
4465 | // Update the group name |
|
4466 | $draft = $contentService->updateContent( |
|
4467 | $draft->getVersionInfo(), |
|
4468 | $contentUpdate |
|
4469 | ); |
|
4470 | ||
4471 | // Publish updated version |
|
4472 | $contentService->publishVersion($draft->getVersionInfo()); |
|
4473 | ||
4474 | // Commit all changes. |
|
4475 | $repository->commit(); |
|
4476 | } catch (Exception $e) { |
|
4477 | // Cleanup hanging transaction on error |
|
4478 | $repository->rollback(); |
|
4479 | throw $e; |
|
4480 | } |
|
4481 | ||
4482 | // Name is now "Administrators" |
|
4483 | $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US'); |
|
4484 | /* END: Use Case */ |
|
4485 | ||
4486 | $this->assertEquals('Administrators', $name); |
|
4487 | } |
|
4488 | ||
4489 | /** |
|
4490 | * Test for the updateContentMetadata() method. |