|
@@ 4104-4140 (lines=37) @@
|
| 4101 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
| 4102 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4103 |
|
*/ |
| 4104 |
|
public function testCreateContentDraftInTransactionWithCommit() |
| 4105 |
|
{ |
| 4106 |
|
$repository = $this->getRepository(); |
| 4107 |
|
|
| 4108 |
|
$contentId = $this->generateId('object', 12); |
| 4109 |
|
/* BEGIN: Use Case */ |
| 4110 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4111 |
|
|
| 4112 |
|
// Load the user group content object |
| 4113 |
|
$content = $this->contentService->loadContent($contentId); |
| 4114 |
|
|
| 4115 |
|
// Start a new transaction |
| 4116 |
|
$repository->beginTransaction(); |
| 4117 |
|
|
| 4118 |
|
try { |
| 4119 |
|
// Create a new draft |
| 4120 |
|
$drafted = $this->contentService->createContentDraft($content->contentInfo); |
| 4121 |
|
|
| 4122 |
|
// Store version number for later reuse |
| 4123 |
|
$versionNo = $drafted->versionInfo->versionNo; |
| 4124 |
|
|
| 4125 |
|
// Commit all changes |
| 4126 |
|
$repository->commit(); |
| 4127 |
|
} catch (Exception $e) { |
| 4128 |
|
// Cleanup hanging transaction on error |
| 4129 |
|
$repository->rollback(); |
| 4130 |
|
throw $e; |
| 4131 |
|
} |
| 4132 |
|
|
| 4133 |
|
$content = $this->contentService->loadContent($contentId, null, $versionNo); |
| 4134 |
|
/* END: Use Case */ |
| 4135 |
|
|
| 4136 |
|
$this->assertEquals( |
| 4137 |
|
$versionNo, |
| 4138 |
|
$content->getVersionInfo()->versionNo |
| 4139 |
|
); |
| 4140 |
|
} |
| 4141 |
|
|
| 4142 |
|
/** |
| 4143 |
|
* Test for the publishVersion() method. |
|
@@ 4149-4189 (lines=41) @@
|
| 4146 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4147 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 4148 |
|
*/ |
| 4149 |
|
public function testPublishVersionInTransactionWithRollback() |
| 4150 |
|
{ |
| 4151 |
|
$repository = $this->getRepository(); |
| 4152 |
|
|
| 4153 |
|
$contentId = $this->generateId('object', 12); |
| 4154 |
|
/* BEGIN: Use Case */ |
| 4155 |
|
// $contentId is the ID of the "Administrator users" user group |
| 4156 |
|
|
| 4157 |
|
// Load the user group content object |
| 4158 |
|
$content = $this->contentService->loadContent($contentId); |
| 4159 |
|
|
| 4160 |
|
// Start a new transaction |
| 4161 |
|
$repository->beginTransaction(); |
| 4162 |
|
|
| 4163 |
|
try { |
| 4164 |
|
$draftVersion = $this->contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
| 4165 |
|
|
| 4166 |
|
// Publish a new version |
| 4167 |
|
$content = $this->contentService->publishVersion($draftVersion); |
| 4168 |
|
|
| 4169 |
|
// Store version number for later reuse |
| 4170 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4171 |
|
} catch (Exception $e) { |
| 4172 |
|
// Cleanup hanging transaction on error |
| 4173 |
|
$repository->rollback(); |
| 4174 |
|
throw $e; |
| 4175 |
|
} |
| 4176 |
|
|
| 4177 |
|
// Rollback |
| 4178 |
|
$repository->rollback(); |
| 4179 |
|
|
| 4180 |
|
try { |
| 4181 |
|
// This call will fail with a "NotFoundException" |
| 4182 |
|
$this->contentService->loadContent($contentId, null, $versionNo); |
| 4183 |
|
} catch (NotFoundException $e) { |
| 4184 |
|
return; |
| 4185 |
|
} |
| 4186 |
|
/* END: Use Case */ |
| 4187 |
|
|
| 4188 |
|
$this->fail('Can still load content draft after rollback'); |
| 4189 |
|
} |
| 4190 |
|
|
| 4191 |
|
/** |
| 4192 |
|
* Test for the publishVersion() method. |
|
@@ 4198-4234 (lines=37) @@
|
| 4195 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 4196 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
| 4197 |
|
*/ |
| 4198 |
|
public function testPublishVersionInTransactionWithCommit() |
| 4199 |
|
{ |
| 4200 |
|
$repository = $this->getRepository(); |
| 4201 |
|
|
| 4202 |
|
/* BEGIN: Use Case */ |
| 4203 |
|
// ID of the "Administrator users" user group |
| 4204 |
|
$contentId = 12; |
| 4205 |
|
|
| 4206 |
|
// Load the user group content object |
| 4207 |
|
$template = $this->contentService->loadContent($contentId); |
| 4208 |
|
|
| 4209 |
|
// Start a new transaction |
| 4210 |
|
$repository->beginTransaction(); |
| 4211 |
|
|
| 4212 |
|
try { |
| 4213 |
|
// Publish a new version |
| 4214 |
|
$content = $this->contentService->publishVersion( |
| 4215 |
|
$this->contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
| 4216 |
|
); |
| 4217 |
|
|
| 4218 |
|
// Store version number for later reuse |
| 4219 |
|
$versionNo = $content->versionInfo->versionNo; |
| 4220 |
|
|
| 4221 |
|
// Commit all changes |
| 4222 |
|
$repository->commit(); |
| 4223 |
|
} catch (Exception $e) { |
| 4224 |
|
// Cleanup hanging transaction on error |
| 4225 |
|
$repository->rollback(); |
| 4226 |
|
throw $e; |
| 4227 |
|
} |
| 4228 |
|
|
| 4229 |
|
// Load current version info |
| 4230 |
|
$versionInfo = $this->contentService->loadVersionInfo($content->contentInfo); |
| 4231 |
|
/* END: Use Case */ |
| 4232 |
|
|
| 4233 |
|
$this->assertEquals($versionNo, $versionInfo->versionNo); |
| 4234 |
|
} |
| 4235 |
|
|
| 4236 |
|
/** |
| 4237 |
|
* Test for the updateContent() method. |