Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ContentBase often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentBase, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | abstract class ContentBase extends BaseServiceTest |
||
| 25 | { |
||
| 26 | protected $testContentType; |
||
| 27 | |||
| 28 | protected function getContentInfoExpectedValues() |
||
| 29 | { |
||
| 30 | // Legacy fixture content ID=4 values |
||
| 31 | return array( |
||
| 32 | 'id' => 4, |
||
| 33 | 'name' => 'Users', |
||
| 34 | 'sectionId' => 2, |
||
| 35 | 'currentVersionNo' => 1, |
||
| 36 | 'published' => true, |
||
| 37 | 'ownerId' => 14, |
||
| 38 | 'modificationDate' => $this->getDateTime(1033917596), |
||
| 39 | 'publishedDate' => $this->getDateTime(1033917596), |
||
| 40 | 'alwaysAvailable' => true, |
||
| 41 | 'remoteId' => 'f5c88a2209584891056f987fd965b0ba', |
||
| 42 | 'mainLanguageCode' => 'eng-US', |
||
| 43 | 'mainLocationId' => 5, |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param bool $draft |
||
| 49 | * |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | protected function getVersionInfoExpectedValues($draft = false) |
||
| 53 | { |
||
| 54 | // Legacy fixture content 4 current version (1) values |
||
| 55 | $values = array( |
||
| 56 | //"id" => 4, |
||
| 57 | 'versionNo' => 1, |
||
| 58 | 'modificationDate' => $this->getDateTime(0), |
||
| 59 | 'creatorId' => 14, |
||
| 60 | 'creationDate' => $this->getDateTime(0), |
||
| 61 | 'status' => VersionInfo::STATUS_PUBLISHED, |
||
| 62 | 'initialLanguageCode' => 'eng-US', |
||
| 63 | 'languageCodes' => array('eng-US'), |
||
| 64 | // Implementation properties |
||
| 65 | 'names' => array('eng-US' => 'Users'), |
||
| 66 | ); |
||
| 67 | |||
| 68 | if ($draft) { |
||
| 69 | //$values["id"] = 675; |
||
| 70 | $values['creatorId'] = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 71 | $values['versionNo'] = 2; |
||
| 72 | $values['status'] = VersionInfo::STATUS_DRAFT; |
||
| 73 | unset($values['modificationDate']); |
||
| 74 | unset($values['creationDate']); |
||
| 75 | } |
||
| 76 | |||
| 77 | return $values; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param array $languages |
||
| 82 | * |
||
| 83 | * @return mixed |
||
| 84 | */ |
||
| 85 | protected function getFieldValuesExpectedValues(array $languages = null) |
||
| 86 | { |
||
| 87 | // Legacy fixture content ID=4 field values |
||
| 88 | $fieldValues = array( |
||
| 89 | 'eng-US' => array( |
||
| 90 | 'name' => array('eng-US' => 'Users'), |
||
| 91 | 'description' => array('eng-US' => 'Main group'), |
||
| 92 | ), |
||
| 93 | ); |
||
| 94 | |||
| 95 | $returnArray = array(); |
||
| 96 | foreach ($fieldValues as $languageCode => $languageFieldValues) { |
||
| 97 | if (!empty($languages) && !in_array($languageCode, $languages)) { |
||
| 98 | continue; |
||
| 99 | } |
||
| 100 | $returnArray = array_merge_recursive($returnArray, $languageFieldValues); |
||
| 101 | } |
||
| 102 | |||
| 103 | return $returnArray; |
||
| 104 | } |
||
| 105 | |||
| 106 | protected function getExpectedContentType() |
||
| 107 | { |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Test for the loadContentInfo() method. |
||
| 112 | * |
||
| 113 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
||
| 114 | * |
||
| 115 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 116 | */ |
||
| 117 | public function testLoadContentInfo() |
||
| 118 | { |
||
| 119 | /* BEGIN: Use Case */ |
||
| 120 | $contentService = $this->repository->getContentService(); |
||
| 121 | |||
| 122 | $contentInfo = $contentService->loadContentInfo(4); |
||
| 123 | /* END: Use Case */ |
||
| 124 | |||
| 125 | $this->assertInstanceOf( |
||
| 126 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
||
| 127 | $contentInfo |
||
| 128 | ); |
||
| 129 | |||
| 130 | return $contentInfo; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Test for the loadContentInfo() method. |
||
| 135 | * |
||
| 136 | * @depends testLoadContentInfo |
||
| 137 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
||
| 138 | * |
||
| 139 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 140 | */ |
||
| 141 | public function testLoadContentInfoValues($contentInfo) |
||
| 142 | { |
||
| 143 | $this->assertPropertiesCorrect( |
||
| 144 | $this->getContentInfoExpectedValues(), |
||
| 145 | $contentInfo |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Test for the loadContentInfo() method. |
||
| 151 | * |
||
| 152 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
||
| 153 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 154 | */ |
||
| 155 | public function testLoadContentInfoThrowsNotFoundException() |
||
| 156 | { |
||
| 157 | /* BEGIN: Use Case */ |
||
| 158 | $contentService = $this->repository->getContentService(); |
||
| 159 | |||
| 160 | // Throws an exception because given contentId does not exist |
||
| 161 | $contentInfo = $contentService->loadContentInfo(APIBaseTest::DB_INT_MAX); |
||
|
|
|||
| 162 | /* END: Use Case */ |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Test for the loadContentInfo() method. |
||
| 167 | * |
||
| 168 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfo |
||
| 169 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 170 | */ |
||
| 171 | public function testLoadContentInfoThrowsUnauthorizedException() |
||
| 172 | { |
||
| 173 | // Set anonymous as current user |
||
| 174 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 175 | |||
| 176 | $this->repository->getContentService()->loadContentInfo(4); |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Test for the loadContentInfoByRemoteId() method. |
||
| 181 | * |
||
| 182 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
||
| 183 | * |
||
| 184 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 185 | */ |
||
| 186 | public function testLoadContentInfoByRemoteId() |
||
| 187 | { |
||
| 188 | /* BEGIN: Use Case */ |
||
| 189 | $contentService = $this->repository->getContentService(); |
||
| 190 | |||
| 191 | $contentInfo = $contentService->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
||
| 192 | /* END: Use Case */ |
||
| 193 | |||
| 194 | $this->assertInstanceOf( |
||
| 195 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
||
| 196 | $contentInfo |
||
| 197 | ); |
||
| 198 | |||
| 199 | return $contentInfo; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Test for the loadContentInfoByRemoteId() method. |
||
| 204 | * |
||
| 205 | * @depends testLoadContentInfoByRemoteId |
||
| 206 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
||
| 207 | * |
||
| 208 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 209 | */ |
||
| 210 | public function testLoadContentInfoByRemoteIdValues($contentInfo) |
||
| 211 | { |
||
| 212 | $this->assertPropertiesCorrect( |
||
| 213 | $this->getContentInfoExpectedValues(), |
||
| 214 | $contentInfo |
||
| 215 | ); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Test for the loadContentInfoByRemoteId() method. |
||
| 220 | * |
||
| 221 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
||
| 222 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 223 | */ |
||
| 224 | public function testLoadContentInfoByRemoteIdThrowsNotFoundException() |
||
| 225 | { |
||
| 226 | /* BEGIN: Use Case */ |
||
| 227 | $contentService = $this->repository->getContentService(); |
||
| 228 | |||
| 229 | // Throws an exception because remoteId does not exist |
||
| 230 | $contentInfo = $contentService->loadContentInfoByRemoteId('this-remote-id-does-not-exist'); |
||
| 231 | /* END: Use Case */ |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Test for the loadContentInfoByRemoteId() method. |
||
| 236 | * |
||
| 237 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentInfoByRemoteId |
||
| 238 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 239 | */ |
||
| 240 | public function testLoadContentInfoByRemoteIdThrowsUnauthorizedException() |
||
| 241 | { |
||
| 242 | // Set anonymous as current user |
||
| 243 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 244 | |||
| 245 | $this->repository->getContentService()->loadContentInfoByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Test for the loadVersionInfoById() method. |
||
| 250 | * |
||
| 251 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 252 | * |
||
| 253 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 254 | */ |
||
| 255 | View Code Duplication | public function testLoadVersionInfoById() |
|
| 256 | { |
||
| 257 | /* BEGIN: Use Case */ |
||
| 258 | $contentService = $this->repository->getContentService(); |
||
| 259 | |||
| 260 | $versionInfo = $contentService->loadVersionInfoById(4); |
||
| 261 | /* END: Use Case */ |
||
| 262 | |||
| 263 | $this->assertInstanceOf( |
||
| 264 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
||
| 265 | $versionInfo |
||
| 266 | ); |
||
| 267 | |||
| 268 | return $versionInfo; |
||
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Test for the loadVersionInfoById() method. |
||
| 273 | * |
||
| 274 | * @depends testLoadVersionInfoById |
||
| 275 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 276 | * |
||
| 277 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 278 | */ |
||
| 279 | public function testLoadVersionInfoByIdValues($versionInfo) |
||
| 280 | { |
||
| 281 | $this->assertPropertiesCorrect( |
||
| 282 | $this->getVersionInfoExpectedValues(), |
||
| 283 | $versionInfo |
||
| 284 | ); |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Test for the loadVersionInfoById() method. |
||
| 289 | * |
||
| 290 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 291 | * |
||
| 292 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 293 | */ |
||
| 294 | View Code Duplication | public function testLoadVersionInfoByIdWithSecondParameter() |
|
| 295 | { |
||
| 296 | /* BEGIN: Use Case */ |
||
| 297 | $contentService = $this->repository->getContentService(); |
||
| 298 | |||
| 299 | $versionInfo = $contentService->loadVersionInfoById(4, 1); |
||
| 300 | /* END: Use Case */ |
||
| 301 | |||
| 302 | $this->assertInstanceOf( |
||
| 303 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
||
| 304 | $versionInfo |
||
| 305 | ); |
||
| 306 | |||
| 307 | return $versionInfo; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Test for the loadVersionInfoById() method. |
||
| 312 | * |
||
| 313 | * @depends testLoadVersionInfoByIdWithSecondParameter |
||
| 314 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 315 | * |
||
| 316 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 317 | */ |
||
| 318 | public function testLoadVersionInfoByIdWithSecondParameterValues($versionInfo) |
||
| 319 | { |
||
| 320 | $this->assertPropertiesCorrect( |
||
| 321 | $this->getVersionInfoExpectedValues(), |
||
| 322 | $versionInfo |
||
| 323 | ); |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Test for the loadVersionInfoById() method. |
||
| 328 | * |
||
| 329 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 330 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 331 | */ |
||
| 332 | public function testLoadVersionInfoByIdThrowsNotFoundException() |
||
| 333 | { |
||
| 334 | /* BEGIN: Use Case */ |
||
| 335 | $contentService = $this->repository->getContentService(); |
||
| 336 | |||
| 337 | // Throws an exception because version with given number does not exists |
||
| 338 | $versionInfo = $contentService->loadVersionInfoById(4, APIBaseTest::DB_INT_MAX); |
||
| 339 | /* END: Use Case */ |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Test for the loadVersionInfoById() method. |
||
| 344 | * |
||
| 345 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 346 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 347 | */ |
||
| 348 | public function testLoadVersionInfoByIdThrowsUnauthorizedException() |
||
| 349 | { |
||
| 350 | // Set anonymous as current user |
||
| 351 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 352 | |||
| 353 | $this->repository->getContentService()->loadVersionInfoById(4); |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Data provider for testLoadContent(). |
||
| 358 | * |
||
| 359 | * @return array |
||
| 360 | */ |
||
| 361 | public function testLoadContentArgumentsProvider() |
||
| 362 | { |
||
| 363 | return array( |
||
| 364 | array(4, null, null), |
||
| 365 | array(4, array('eng-US'), null), |
||
| 366 | array(4, array('eng-US', 'fre-FR'), null), |
||
| 367 | array(4, null, 1), |
||
| 368 | array(4, array('eng-US', 'fre-FR', 'nor-NO', 'eng-DE'), 1), |
||
| 369 | array(4, array('eng-US'), 1), |
||
| 370 | ); |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Test for the loadContent() method. |
||
| 375 | * |
||
| 376 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 377 | * @dataProvider testLoadContentArgumentsProvider |
||
| 378 | * |
||
| 379 | * @param int $contentId |
||
| 380 | * @param array $languages |
||
| 381 | * @param int $versionNo |
||
| 382 | * |
||
| 383 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 384 | */ |
||
| 385 | View Code Duplication | public function testLoadContent($contentId, array $languages = null, $versionNo = null) |
|
| 386 | { |
||
| 387 | /* BEGIN: Use Case */ |
||
| 388 | $contentService = $this->repository->getContentService(); |
||
| 389 | |||
| 390 | $content = $contentService->loadContent($contentId, $languages, $versionNo); |
||
| 391 | /* END: Use Case */ |
||
| 392 | |||
| 393 | $this->assertInstanceOf( |
||
| 394 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 395 | $content |
||
| 396 | ); |
||
| 397 | |||
| 398 | $this->assertContentValues($content, $languages); |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 403 | * @param array $languages |
||
| 404 | * @param bool $draft |
||
| 405 | */ |
||
| 406 | protected function assertContentValues(APIContent $content, array $languages = null, $draft = false) |
||
| 407 | { |
||
| 408 | $versionInfoValues = $this->getVersionInfoExpectedValues($draft); |
||
| 409 | $contentInfoValues = $this->getContentInfoExpectedValues(); |
||
| 410 | $fieldValuesValues = $this->getFieldValuesExpectedValues($languages); |
||
| 411 | |||
| 412 | $this->assertPropertiesCorrect( |
||
| 413 | $versionInfoValues, |
||
| 414 | $content->getVersionInfo() |
||
| 415 | ); |
||
| 416 | |||
| 417 | $this->assertPropertiesCorrect( |
||
| 418 | $contentInfoValues, |
||
| 419 | $content->contentInfo |
||
| 420 | ); |
||
| 421 | |||
| 422 | $this->assertEquals( |
||
| 423 | $fieldValuesValues, |
||
| 424 | $content->fields |
||
| 425 | ); |
||
| 426 | |||
| 427 | // @todo assert relations |
||
| 428 | |||
| 429 | $this->assertEquals($content->id, $content->contentInfo->id); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Test for the loadContent() method. |
||
| 434 | * |
||
| 435 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 436 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 437 | */ |
||
| 438 | public function testLoadContentThrowsUnauthorizedException() |
||
| 439 | { |
||
| 440 | // Set anonymous as current user |
||
| 441 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 442 | |||
| 443 | $this->repository->getContentService()->loadContent(4); |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Test for the loadContent() method. |
||
| 448 | * |
||
| 449 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 450 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 451 | */ |
||
| 452 | View Code Duplication | public function testLoadContentWithVersionThrowsUnauthorizedException() |
|
| 453 | { |
||
| 454 | list($draft) = $this->createTestContent(); |
||
| 455 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 456 | |||
| 457 | $this->repository->getContentService()->loadContent( |
||
| 458 | $draft->id, |
||
| 459 | null, |
||
| 460 | $draft->versionInfo->versionNo |
||
| 461 | ); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Test for the loadContent() method. |
||
| 466 | * |
||
| 467 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 468 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 469 | */ |
||
| 470 | public function testLoadContentThrowsNotFoundExceptionContentNotFound() |
||
| 471 | { |
||
| 472 | /* BEGIN: Use Case */ |
||
| 473 | $contentService = $this->repository->getContentService(); |
||
| 474 | |||
| 475 | // Throws an exception because content with id APIBaseTest::DB_INT_MAX does not exist |
||
| 476 | $content = $contentService->loadContent(APIBaseTest::DB_INT_MAX); |
||
| 477 | /* END: Use Case */ |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Test for the loadContent() method. |
||
| 482 | * |
||
| 483 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 484 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 485 | */ |
||
| 486 | public function testLoadContentThrowsNotFoundExceptionVersionNotFound() |
||
| 487 | { |
||
| 488 | /* BEGIN: Use Case */ |
||
| 489 | $contentService = $this->repository->getContentService(); |
||
| 490 | |||
| 491 | // Throws an exception because version number APIBaseTest::DB_INT_MAX for content with id 4 does not exist |
||
| 492 | $content = $contentService->loadContent(4, null, APIBaseTest::DB_INT_MAX); |
||
| 493 | /* END: Use Case */ |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Test for the loadContent() method. |
||
| 498 | * |
||
| 499 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 500 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 501 | */ |
||
| 502 | public function testLoadContentThrowsNotFoundExceptionLanguageNotFound() |
||
| 503 | { |
||
| 504 | /* BEGIN: Use Case */ |
||
| 505 | $contentService = $this->repository->getContentService(); |
||
| 506 | |||
| 507 | // Throws an exception because content does not exists in "fre-FR" language |
||
| 508 | $content = $contentService->loadContent(4, array('fre-FR'), null, false); |
||
| 509 | /* END: Use Case */ |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Test for the loadContent() method. |
||
| 514 | * |
||
| 515 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContent |
||
| 516 | */ |
||
| 517 | public function testLoadContentThrowsNotFoundExceptionLanguageNotFoundVariation() |
||
| 518 | { |
||
| 519 | /* BEGIN: Use Case */ |
||
| 520 | $contentService = $this->repository->getContentService(); |
||
| 521 | |||
| 522 | // Content only exists in eng-US, so we should only have it in eng-US. |
||
| 523 | $content = $contentService->loadContent(4, array('eng-US', 'eng-GB')); |
||
| 524 | $this->assertInstanceOf( |
||
| 525 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 526 | $content |
||
| 527 | ); |
||
| 528 | $this->assertContentValues($content, array('eng-US')); |
||
| 529 | /* END: Use Case */ |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Data provider for testLoadContentByRemoteId(). |
||
| 534 | * |
||
| 535 | * @return array |
||
| 536 | */ |
||
| 537 | public function testLoadContentByRemoteIdArgumentsProvider() |
||
| 538 | { |
||
| 539 | return array( |
||
| 540 | array('f5c88a2209584891056f987fd965b0ba', null, null), |
||
| 541 | array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), null), |
||
| 542 | array('f5c88a2209584891056f987fd965b0ba', null, 1), |
||
| 543 | array('f5c88a2209584891056f987fd965b0ba', array('eng-US'), 1), |
||
| 544 | ); |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Test for the loadContentByRemoteId() method. |
||
| 549 | * |
||
| 550 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
||
| 551 | * @dataProvider testLoadContentByRemoteIdArgumentsProvider |
||
| 552 | * |
||
| 553 | * @param string $remoteId |
||
| 554 | * @param array|null $languages |
||
| 555 | * @param int $versionNo |
||
| 556 | * |
||
| 557 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 558 | */ |
||
| 559 | View Code Duplication | public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) |
|
| 560 | { |
||
| 561 | /* BEGIN: Use Case */ |
||
| 562 | $contentService = $this->repository->getContentService(); |
||
| 563 | |||
| 564 | $content = $contentService->loadContentByRemoteId($remoteId, $languages, $versionNo); |
||
| 565 | /* END: Use Case */ |
||
| 566 | |||
| 567 | $this->assertInstanceOf( |
||
| 568 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 569 | $content |
||
| 570 | ); |
||
| 571 | |||
| 572 | $this->assertContentValues($content, $languages); |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Test for the loadContentByRemoteId() method. |
||
| 577 | * |
||
| 578 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
||
| 579 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 580 | */ |
||
| 581 | public function testLoadContentByRemoteIdThrowsNotFoundException() |
||
| 582 | { |
||
| 583 | /* BEGIN: Use Case */ |
||
| 584 | $contentService = $this->repository->getContentService(); |
||
| 585 | |||
| 586 | // Throws an exception because given remoteId does not exist |
||
| 587 | $content = $contentService->loadContentByRemoteId('non-existent-remote-id'); |
||
| 588 | /* END: Use Case */ |
||
| 589 | } |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Test for the loadContentByRemoteId() method. |
||
| 593 | * |
||
| 594 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
||
| 595 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 596 | */ |
||
| 597 | public function testLoadContentByRemoteIdThrowsUnauthorizedException() |
||
| 598 | { |
||
| 599 | // Set anonymous as current user |
||
| 600 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 601 | |||
| 602 | $this->repository->getContentService()->loadContentByRemoteId('f5c88a2209584891056f987fd965b0ba'); |
||
| 603 | } |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Test for the loadContentByRemoteId() method. |
||
| 607 | * |
||
| 608 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByRemoteId |
||
| 609 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 610 | */ |
||
| 611 | public function testLoadContentByRemoteIdWithVersionThrowsUnauthorizedException() |
||
| 612 | { |
||
| 613 | $contentService = $this->repository->getContentService(); |
||
| 614 | |||
| 615 | $content = $contentService->loadContent(4); |
||
| 616 | $draft = $contentService->createContentDraft($content->contentInfo); |
||
| 617 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 618 | |||
| 619 | $contentService->loadContentByRemoteId( |
||
| 620 | $draft->contentInfo->remoteId, |
||
| 621 | null, |
||
| 622 | $draft->versionInfo->versionNo |
||
| 623 | ); |
||
| 624 | } |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Test for the newContentCreateStruct() method. |
||
| 628 | * |
||
| 629 | * @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct |
||
| 630 | * |
||
| 631 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 632 | */ |
||
| 633 | public function testNewContentCreateStruct() |
||
| 634 | { |
||
| 635 | /* BEGIN: Use Case */ |
||
| 636 | $contentService = $this->repository->getContentService(); |
||
| 637 | $contentTypeService = $this->repository->getContentTypeService(); |
||
| 638 | |||
| 639 | $folderContentType = $contentTypeService->loadContentType(1); |
||
| 640 | |||
| 641 | $contentCreateStruct = $contentService->newContentCreateStruct( |
||
| 642 | $folderContentType, |
||
| 643 | 'eng-GB' |
||
| 644 | ); |
||
| 645 | /* END: Use Case */ |
||
| 646 | |||
| 647 | $this->assertInstanceOf( |
||
| 648 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct', |
||
| 649 | $contentCreateStruct |
||
| 650 | ); |
||
| 651 | |||
| 652 | return array( |
||
| 653 | 'contentType' => $folderContentType, |
||
| 654 | 'contentCreateStruct' => $contentCreateStruct, |
||
| 655 | ); |
||
| 656 | } |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Test for the newContentCreateStruct() method. |
||
| 660 | * |
||
| 661 | * @depends testNewContentCreateStruct |
||
| 662 | * @covers \eZ\Publish\Core\Repository\ContentService::newContentCreateStruct |
||
| 663 | * |
||
| 664 | * @param array $data |
||
| 665 | */ |
||
| 666 | public function testNewContentCreateStructValues(array $data) |
||
| 667 | { |
||
| 668 | $contentType = $data['contentType']; |
||
| 669 | $contentCreateStruct = $data['contentCreateStruct']; |
||
| 670 | |||
| 671 | $expectedValues = array( |
||
| 672 | 'fields' => array(), |
||
| 673 | 'contentType' => $contentType, |
||
| 674 | 'sectionId' => null, |
||
| 675 | 'ownerId' => null, |
||
| 676 | 'alwaysAvailable' => null, |
||
| 677 | 'remoteId' => null, |
||
| 678 | 'mainLanguageCode' => 'eng-GB', |
||
| 679 | 'modificationDate' => null, |
||
| 680 | ); |
||
| 681 | |||
| 682 | $this->assertPropertiesCorrect( |
||
| 683 | $expectedValues, |
||
| 684 | $contentCreateStruct |
||
| 685 | ); |
||
| 686 | } |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Test for the createContent() method. |
||
| 690 | * |
||
| 691 | * @depends testNewContentCreateStruct |
||
| 692 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 693 | * |
||
| 694 | * @return array |
||
| 695 | */ |
||
| 696 | public function testCreateContent() |
||
| 697 | { |
||
| 698 | $time = time(); |
||
| 699 | $testContentType = $this->createTestContentType(); |
||
| 700 | |||
| 701 | /* BEGIN: Use Case */ |
||
| 702 | $contentService = $this->repository->getContentService(); |
||
| 703 | |||
| 704 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 705 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 706 | $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
||
| 707 | $contentCreate->sectionId = 1; |
||
| 708 | $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 709 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 710 | $contentCreate->alwaysAvailable = true; |
||
| 711 | |||
| 712 | $locationCreates = array( |
||
| 713 | new LocationCreateStruct( |
||
| 714 | array( |
||
| 715 | //priority = 0 |
||
| 716 | //hidden = false |
||
| 717 | 'remoteId' => 'db787a9143f57828dd4331573466a013', |
||
| 718 | //sortField = Location::SORT_FIELD_NAME |
||
| 719 | //sortOrder = Location::SORT_ORDER_ASC |
||
| 720 | 'parentLocationId' => 2, |
||
| 721 | ) |
||
| 722 | ), |
||
| 723 | new LocationCreateStruct( |
||
| 724 | array( |
||
| 725 | //priority = 0 |
||
| 726 | //hidden = false |
||
| 727 | 'remoteId' => 'a3dd7c1c9e04c89e446a70f647286e6b', |
||
| 728 | //sortField = Location::SORT_FIELD_NAME |
||
| 729 | //sortOrder = Location::SORT_ORDER_ASC |
||
| 730 | 'parentLocationId' => 5, |
||
| 731 | ) |
||
| 732 | ), |
||
| 733 | ); |
||
| 734 | |||
| 735 | $contentDraft = $contentService->createContent($contentCreate, $locationCreates); |
||
| 736 | /* END: Use Case */ |
||
| 737 | |||
| 738 | $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $contentDraft); |
||
| 739 | |||
| 740 | return array( |
||
| 741 | 'expected' => $contentCreate, |
||
| 742 | 'actual' => $contentDraft, |
||
| 743 | 'loadedActual' => $contentService->loadContent($contentDraft->id, null, 1), |
||
| 744 | 'contentType' => $testContentType, |
||
| 745 | 'time' => $time, |
||
| 746 | ); |
||
| 747 | } |
||
| 748 | |||
| 749 | /** |
||
| 750 | * Test for the createContent() method. |
||
| 751 | * |
||
| 752 | * @depends testCreateContent |
||
| 753 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 754 | * |
||
| 755 | * @param array $data |
||
| 756 | */ |
||
| 757 | public function testCreateContentStructValues(array $data) |
||
| 758 | { |
||
| 759 | $this->assertCreateContentStructValues($data); |
||
| 760 | } |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Test for the createContent() method. |
||
| 764 | * |
||
| 765 | * Because of the way ContentHandler::create() is implemented and tested in legacy storage it is also necessary to |
||
| 766 | * test loaded content object, not only the one returned by ContentService::createContent |
||
| 767 | * |
||
| 768 | * @depends testCreateContent |
||
| 769 | * @depends testLoadContent |
||
| 770 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 771 | * |
||
| 772 | * @param array $data |
||
| 773 | */ |
||
| 774 | public function testCreateContentStructValuesLoaded(array $data) |
||
| 775 | { |
||
| 776 | $data['actual'] = $data['loadedActual']; |
||
| 777 | |||
| 778 | $this->assertCreateContentStructValues($data); |
||
| 779 | } |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Test for the createContent() method. |
||
| 783 | * |
||
| 784 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 785 | * |
||
| 786 | * @param array $data |
||
| 787 | */ |
||
| 788 | protected function assertCreateContentStructValues(array $data) |
||
| 789 | { |
||
| 790 | $this->assertCreateContentStructValuesContentInfo($data); |
||
| 791 | $this->assertCreateContentStructValuesVersionInfo($data); |
||
| 792 | $this->assertCreateContentStructValuesRelations($data); |
||
| 793 | $this->assertCreateContentStructValuesFields($data); |
||
| 794 | } |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Asserts that ContentInfo is valid after Content creation. |
||
| 798 | * |
||
| 799 | * @param array $data |
||
| 800 | */ |
||
| 801 | protected function assertCreateContentStructValuesContentInfo(array $data) |
||
| 802 | { |
||
| 803 | /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
||
| 804 | $contentDraft = $data['actual']; |
||
| 805 | /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
||
| 806 | $contentCreate = $data['expected']; |
||
| 807 | |||
| 808 | $this->assertPropertiesCorrect( |
||
| 809 | array( |
||
| 810 | 'id' => $contentDraft->id, |
||
| 811 | 'name' => $contentCreate->fields[0]->value, |
||
| 812 | 'sectionId' => $contentCreate->sectionId, |
||
| 813 | 'currentVersionNo' => 1, |
||
| 814 | 'published' => false, |
||
| 815 | 'ownerId' => $contentCreate->ownerId, |
||
| 816 | 'modificationDate' => null, |
||
| 817 | 'publishedDate' => null, |
||
| 818 | 'alwaysAvailable' => $contentCreate->alwaysAvailable, |
||
| 819 | 'remoteId' => $contentCreate->remoteId, |
||
| 820 | 'mainLanguageCode' => $contentCreate->mainLanguageCode, |
||
| 821 | // @todo: should be null, InMemory skips creating node assignments and creates locations right away |
||
| 822 | //"mainLocationId" => null, |
||
| 823 | //"contentType" |
||
| 824 | ), |
||
| 825 | $contentDraft->versionInfo->contentInfo |
||
| 826 | ); |
||
| 827 | $this->assertNotNull($contentDraft->id); |
||
| 828 | $this->assertEquals( |
||
| 829 | $contentCreate->contentType->id, |
||
| 830 | $contentDraft->versionInfo->contentInfo->contentTypeId |
||
| 831 | ); |
||
| 832 | } |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Asserts that VersionInfo is valid after Content creation. |
||
| 836 | * |
||
| 837 | * @param array $data |
||
| 838 | */ |
||
| 839 | protected function assertCreateContentStructValuesVersionInfo(array $data) |
||
| 840 | { |
||
| 841 | /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
||
| 842 | $contentDraft = $data['actual']; |
||
| 843 | /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
||
| 844 | $contentCreate = $data['expected']; |
||
| 845 | $time = $data['time']; |
||
| 846 | |||
| 847 | $this->assertPropertiesCorrect( |
||
| 848 | array( |
||
| 849 | //"id" |
||
| 850 | 'versionNo' => 1, |
||
| 851 | //"creationDate" |
||
| 852 | //"modificationDate" |
||
| 853 | 'creatorId' => $contentCreate->ownerId, |
||
| 854 | 'status' => VersionInfo::STATUS_DRAFT, |
||
| 855 | 'initialLanguageCode' => $contentCreate->mainLanguageCode, |
||
| 856 | //"languageCodes" |
||
| 857 | 'names' => array( |
||
| 858 | 'eng-GB' => 'value for field definition with empty default value', |
||
| 859 | 'eng-US' => 'value for field definition with empty default value', |
||
| 860 | ), |
||
| 861 | ), |
||
| 862 | $contentDraft->versionInfo |
||
| 863 | ); |
||
| 864 | |||
| 865 | $languageCodes = $this->getLanguageCodesFromFields($contentCreate->fields, $contentCreate->mainLanguageCode); |
||
| 866 | |||
| 867 | $this->assertCount(count($languageCodes), $contentDraft->versionInfo->languageCodes); |
||
| 868 | foreach ($contentDraft->versionInfo->languageCodes as $languageCode) { |
||
| 869 | $this->assertTrue(in_array($languageCode, $languageCodes)); |
||
| 870 | } |
||
| 871 | $this->assertNotNull($contentDraft->versionInfo->id); |
||
| 872 | $this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->creationDate); |
||
| 873 | $this->assertGreaterThanOrEqual($this->getDateTime($time), $contentDraft->versionInfo->modificationDate); |
||
| 874 | } |
||
| 875 | |||
| 876 | /** |
||
| 877 | * @param array $data |
||
| 878 | */ |
||
| 879 | protected function assertCreateContentStructValuesRelations(array $data) |
||
| 880 | { |
||
| 881 | // @todo: relations not implemented yet |
||
| 882 | } |
||
| 883 | |||
| 884 | /** |
||
| 885 | * Asserts that fields are valid after Content creation. |
||
| 886 | * |
||
| 887 | * @param array $data |
||
| 888 | */ |
||
| 889 | protected function assertCreateContentStructValuesFields(array $data) |
||
| 890 | { |
||
| 891 | /** @var $contentDraft \eZ\Publish\API\Repository\Values\Content\Content */ |
||
| 892 | $contentDraft = $data['actual']; |
||
| 893 | /** @var $contentCreate \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */ |
||
| 894 | $contentCreate = $data['expected']; |
||
| 895 | /** @var $contentType \eZ\Publish\API\Repository\Values\ContentType\ContentType */ |
||
| 896 | $contentType = $data['contentType']; |
||
| 897 | |||
| 898 | $createdFields = $contentDraft->getFields(); |
||
| 899 | $createdInLanguageCodes = $this->getLanguageCodesFromFields( |
||
| 900 | $contentCreate->fields, |
||
| 901 | $contentCreate->mainLanguageCode |
||
| 902 | ); |
||
| 903 | |||
| 904 | $this->assertCount( |
||
| 905 | count($contentType->fieldDefinitions) * count($createdInLanguageCodes), |
||
| 906 | $createdFields, |
||
| 907 | 'Number of created fields does not match number of content type field definitions multiplied by number of languages the content is created in' |
||
| 908 | ); |
||
| 909 | |||
| 910 | // Check field values |
||
| 911 | $structFields = array(); |
||
| 912 | foreach ($contentCreate->fields as $field) { |
||
| 913 | $structFields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
| 914 | } |
||
| 915 | foreach ($contentType->fieldDefinitions as $fieldDefinition) { |
||
| 916 | $this->assertArrayHasKey( |
||
| 917 | $fieldDefinition->identifier, |
||
| 918 | $contentDraft->fields, |
||
| 919 | "Field values are missing for field definition '{$fieldDefinition->identifier}'" |
||
| 920 | ); |
||
| 921 | |||
| 922 | foreach ($createdInLanguageCodes as $languageCode) { |
||
| 923 | $this->assertArrayHasKey( |
||
| 924 | $languageCode, |
||
| 925 | $contentDraft->fields[$fieldDefinition->identifier], |
||
| 926 | "Field value is missing for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}'" |
||
| 927 | ); |
||
| 928 | |||
| 929 | // If field is not set in create struct, it should have default value |
||
| 930 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreate->mainLanguageCode; |
||
| 931 | if (isset($structFields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
| 932 | $this->assertEquals( |
||
| 933 | $structFields[$fieldDefinition->identifier][$valueLanguageCode]->value, |
||
| 934 | $contentDraft->fields[$fieldDefinition->identifier][$languageCode], |
||
| 935 | "Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to given struct field value" |
||
| 936 | ); |
||
| 937 | } else { |
||
| 938 | $this->assertEquals( |
||
| 939 | $fieldDefinition->defaultValue, |
||
| 940 | $contentDraft->fields[$fieldDefinition->identifier][$languageCode], |
||
| 941 | "Field value for field definition '{$fieldDefinition->identifier}' in language '{$languageCode}' is not equal to default value" |
||
| 942 | ); |
||
| 943 | } |
||
| 944 | } |
||
| 945 | } |
||
| 946 | } |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Gathers language codes from an array of fields. |
||
| 950 | * |
||
| 951 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 952 | * @param string $mainLanguageCode |
||
| 953 | * |
||
| 954 | * @return array an array of language code strings |
||
| 955 | */ |
||
| 956 | protected function getLanguageCodesFromFields(array $fields, $mainLanguageCode) |
||
| 957 | { |
||
| 958 | $languageCodes = array($mainLanguageCode); |
||
| 959 | foreach ($fields as $field) { |
||
| 960 | $languageCodes[] = $field->languageCode; |
||
| 961 | } |
||
| 962 | |||
| 963 | return array_unique($languageCodes); |
||
| 964 | } |
||
| 965 | |||
| 966 | /** |
||
| 967 | * Test for the createContent() method. |
||
| 968 | * |
||
| 969 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 970 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 971 | */ |
||
| 972 | public function testCreateContentThrowsUnauthorizedException() |
||
| 973 | { |
||
| 974 | $testContentType = $this->createTestContentType(); |
||
| 975 | $contentService = $this->repository->getContentService(); |
||
| 976 | |||
| 977 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 978 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 979 | $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
||
| 980 | $contentCreate->sectionId = 1; |
||
| 981 | $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 982 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 983 | $contentCreate->alwaysAvailable = true; |
||
| 984 | |||
| 985 | $locationCreates = array( |
||
| 986 | new LocationCreateStruct( |
||
| 987 | array( |
||
| 988 | 'remoteId' => 'db787a9143f57828dd4331573466a013', |
||
| 989 | 'parentLocationId' => 2, |
||
| 990 | ) |
||
| 991 | ), |
||
| 992 | ); |
||
| 993 | |||
| 994 | // Set anonymous as current user |
||
| 995 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 996 | |||
| 997 | $contentService->createContent($contentCreate, $locationCreates); |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Test for the createContent() method. |
||
| 1002 | * |
||
| 1003 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1004 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1005 | */ |
||
| 1006 | public function testCreateContentWithoutLocationsThrowsUnauthorizedException() |
||
| 1007 | { |
||
| 1008 | $testContentType = $this->createTestContentType(); |
||
| 1009 | $contentService = $this->repository->getContentService(); |
||
| 1010 | |||
| 1011 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1012 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 1013 | $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
||
| 1014 | $contentCreate->sectionId = 1; |
||
| 1015 | $contentCreate->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 1016 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 1017 | $contentCreate->alwaysAvailable = true; |
||
| 1018 | |||
| 1019 | // Set anonymous as current user |
||
| 1020 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 1021 | |||
| 1022 | $contentService->createContent($contentCreate, array()); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Test for the createContent() method. |
||
| 1027 | * |
||
| 1028 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1029 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1030 | */ |
||
| 1031 | public function testCreateContentThrowsInvalidArgumentException() |
||
| 1032 | { |
||
| 1033 | $testContentType = $this->createTestContentType(); |
||
| 1034 | |||
| 1035 | /* BEGIN: Use Case */ |
||
| 1036 | $contentService = $this->repository->getContentService(); |
||
| 1037 | |||
| 1038 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1039 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 1040 | $contentCreate->sectionId = 1; |
||
| 1041 | $contentCreate->ownerId = 14; |
||
| 1042 | $contentCreate->remoteId = 'f5c88a2209584891056f987fd965b0ba'; |
||
| 1043 | $contentCreate->alwaysAvailable = true; |
||
| 1044 | |||
| 1045 | // Throws an exception because remoteId "f5c88a2209584891056f987fd965b0ba" already exists |
||
| 1046 | $contentService->createContent($contentCreate); |
||
| 1047 | /* END: Use Case */ |
||
| 1048 | } |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Test for the createContent() method. |
||
| 1052 | * |
||
| 1053 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1054 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1055 | * |
||
| 1056 | * @return array |
||
| 1057 | */ |
||
| 1058 | View Code Duplication | public function testCreateContentThrowsContentValidationExceptionFieldDefinitionUnexisting() |
|
| 1059 | { |
||
| 1060 | $testContentType = $this->createTestContentType(); |
||
| 1061 | |||
| 1062 | /* BEGIN: Use Case */ |
||
| 1063 | $contentService = $this->repository->getContentService(); |
||
| 1064 | |||
| 1065 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1066 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 1067 | $contentCreate->setField('humpty_dumpty', 'no such field definition'); |
||
| 1068 | $contentCreate->sectionId = 1; |
||
| 1069 | $contentCreate->ownerId = 14; |
||
| 1070 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 1071 | $contentCreate->alwaysAvailable = true; |
||
| 1072 | |||
| 1073 | // Throws an exception because field definition with identifier "humpty_dumpty" does not exist |
||
| 1074 | $contentService->createContent($contentCreate); |
||
| 1075 | /* END: Use Case */ |
||
| 1076 | } |
||
| 1077 | |||
| 1078 | /** |
||
| 1079 | * Test for the createContent() method. |
||
| 1080 | * |
||
| 1081 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1082 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1083 | * |
||
| 1084 | * @return array |
||
| 1085 | */ |
||
| 1086 | View Code Duplication | public function testCreateContentThrowsContentValidationExceptionUntranslatableField() |
|
| 1087 | { |
||
| 1088 | $testContentType = $this->createTestContentType(); |
||
| 1089 | |||
| 1090 | /* BEGIN: Use Case */ |
||
| 1091 | $contentService = $this->repository->getContentService(); |
||
| 1092 | |||
| 1093 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1094 | $contentCreate->setField('test_required_empty', 'value for field definition with empty default value'); |
||
| 1095 | $contentCreate->setField('test_untranslatable', 'Bandersnatch', 'eng-US'); |
||
| 1096 | $contentCreate->sectionId = 1; |
||
| 1097 | $contentCreate->ownerId = 14; |
||
| 1098 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 1099 | $contentCreate->alwaysAvailable = true; |
||
| 1100 | |||
| 1101 | // Throws an exception because translation was given for a untranslatable field |
||
| 1102 | // Note that it is still permissible to set untranslatable field with main language |
||
| 1103 | $contentService->createContent($contentCreate); |
||
| 1104 | /* END: Use Case */ |
||
| 1105 | } |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Test for the createContent() method. |
||
| 1109 | * |
||
| 1110 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1111 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1112 | * |
||
| 1113 | * @return array |
||
| 1114 | */ |
||
| 1115 | public function testCreateContentThrowsContentValidationRequiredFieldDefaultValueEmpty() |
||
| 1116 | { |
||
| 1117 | $testContentType = $this->createTestContentType(); |
||
| 1118 | |||
| 1119 | /* BEGIN: Use Case */ |
||
| 1120 | $contentService = $this->repository->getContentService(); |
||
| 1121 | |||
| 1122 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1123 | $contentCreate->setField('test_translatable', 'Jabberwock'); |
||
| 1124 | $contentCreate->sectionId = 1; |
||
| 1125 | $contentCreate->ownerId = 14; |
||
| 1126 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 1127 | $contentCreate->alwaysAvailable = true; |
||
| 1128 | |||
| 1129 | // Throws an exception because required field is not set and its default value is empty |
||
| 1130 | $contentService->createContent($contentCreate); |
||
| 1131 | /* END: Use Case */ |
||
| 1132 | } |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Test for the createContent() method. |
||
| 1136 | * |
||
| 1137 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent |
||
| 1138 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 1139 | */ |
||
| 1140 | View Code Duplication | public function testCreateContentThrowsContentFieldValidationException() |
|
| 1141 | { |
||
| 1142 | $testContentType = $this->createTestContentType(); |
||
| 1143 | |||
| 1144 | /* BEGIN: Use Case */ |
||
| 1145 | $contentService = $this->repository->getContentService(); |
||
| 1146 | |||
| 1147 | $contentCreate = $contentService->newContentCreateStruct($testContentType, 'eng-GB'); |
||
| 1148 | $contentCreate->setField( |
||
| 1149 | 'test_required_empty', |
||
| 1150 | 'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' |
||
| 1151 | ); |
||
| 1152 | $contentCreate->setField('test_translatable', 'and thumbs opposable', 'eng-US'); |
||
| 1153 | $contentCreate->sectionId = 1; |
||
| 1154 | $contentCreate->ownerId = 14; |
||
| 1155 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 1156 | $contentCreate->alwaysAvailable = true; |
||
| 1157 | |||
| 1158 | // Throws an exception because "test_required_empty" field value is too long and fails |
||
| 1159 | // field definition's string length validator |
||
| 1160 | $contentService->createContent($contentCreate); |
||
| 1161 | /* END: Use Case */ |
||
| 1162 | } |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * Test for the newContentMetadataUpdateStruct() method. |
||
| 1166 | * |
||
| 1167 | * @covers \eZ\Publish\Core\Repository\ContentService::newContentMetadataUpdateStruct |
||
| 1168 | */ |
||
| 1169 | View Code Duplication | public function testNewContentMetadataUpdateStruct() |
|
| 1170 | { |
||
| 1171 | /* BEGIN: Use Case */ |
||
| 1172 | $contentService = $this->repository->getContentService(); |
||
| 1173 | |||
| 1174 | $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
||
| 1175 | /* END: Use Case */ |
||
| 1176 | |||
| 1177 | $this->assertInstanceOf( |
||
| 1178 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentMetadataUpdateStruct', |
||
| 1179 | $contentMetadataUpdateStruct |
||
| 1180 | ); |
||
| 1181 | |||
| 1182 | foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { |
||
| 1183 | $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
||
| 1184 | } |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Test for the updateContentMetadata() method. |
||
| 1189 | * |
||
| 1190 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 1191 | * @depends testNewContentMetadataUpdateStruct |
||
| 1192 | * |
||
| 1193 | * @return array |
||
| 1194 | */ |
||
| 1195 | public function testUpdateContentMetadata() |
||
| 1196 | { |
||
| 1197 | // Create one additional location for content to be set as main location |
||
| 1198 | $locationService = $this->repository->getLocationService(); |
||
| 1199 | $contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
||
| 1200 | $locationCreateStruct = $locationService->newLocationCreateStruct(44); |
||
| 1201 | $locationCreateStruct->remoteId = 'test-location-remote-id-1234'; |
||
| 1202 | $newLocation = $locationService->createLocation( |
||
| 1203 | $contentInfo, |
||
| 1204 | $locationCreateStruct |
||
| 1205 | ); |
||
| 1206 | $newSectionId = $this->repository->getContentService()->loadContentInfo( |
||
| 1207 | $locationService->loadLocation($newLocation->parentLocationId)->contentId |
||
| 1208 | )->sectionId; |
||
| 1209 | // Change content section to be different from new main location parent location content |
||
| 1210 | $sectionService = $this->repository->getSectionService(); |
||
| 1211 | $sectionService->assignSection( |
||
| 1212 | $contentInfo, |
||
| 1213 | $sectionService->loadSection($newSectionId === 1 ? $newSectionId + 1 : $newSectionId - 1) |
||
| 1214 | ); |
||
| 1215 | |||
| 1216 | /* BEGIN: Use Case */ |
||
| 1217 | $contentService = $this->repository->getContentService(); |
||
| 1218 | |||
| 1219 | $contentInfo = $contentService->loadContentInfo(12); |
||
| 1220 | |||
| 1221 | $newMainLocationId = $newLocation->id; |
||
| 1222 | $time = time(); |
||
| 1223 | $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
||
| 1224 | $contentMetadataUpdateStruct->ownerId = 10; |
||
| 1225 | $contentMetadataUpdateStruct->publishedDate = $this->getDateTime($time); |
||
| 1226 | $contentMetadataUpdateStruct->modificationDate = $this->getDateTime($time); |
||
| 1227 | $contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB'; |
||
| 1228 | $contentMetadataUpdateStruct->alwaysAvailable = false; |
||
| 1229 | $contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; |
||
| 1230 | $contentMetadataUpdateStruct->mainLocationId = $newMainLocationId; |
||
| 1231 | |||
| 1232 | $content = $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 1233 | /* END: Use Case */ |
||
| 1234 | |||
| 1235 | $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $content); |
||
| 1236 | |||
| 1237 | return array( |
||
| 1238 | 'expected' => $contentMetadataUpdateStruct, |
||
| 1239 | 'actual' => $content, |
||
| 1240 | 'newSectionId' => $newSectionId, |
||
| 1241 | ); |
||
| 1242 | } |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * Test for the updateContentMetadata() method. |
||
| 1246 | * |
||
| 1247 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 1248 | * @depends testUpdateContentMetadata |
||
| 1249 | * |
||
| 1250 | * @param array $data |
||
| 1251 | */ |
||
| 1252 | public function testUpdateContentMetadataStructValues(array $data) |
||
| 1253 | { |
||
| 1254 | /** @var $updateStruct \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct */ |
||
| 1255 | $updateStruct = $data['expected']; |
||
| 1256 | /** @var $content \eZ\Publish\API\Repository\Values\Content\Content */ |
||
| 1257 | $content = $data['actual']; |
||
| 1258 | |||
| 1259 | $this->assertPropertiesCorrect( |
||
| 1260 | array( |
||
| 1261 | 'ownerId' => $updateStruct->ownerId, |
||
| 1262 | // not changeable through MetadataUpdateStruct |
||
| 1263 | //"name" |
||
| 1264 | 'publishedDate' => $updateStruct->publishedDate, |
||
| 1265 | 'modificationDate' => $updateStruct->modificationDate, |
||
| 1266 | 'mainLanguageCode' => $updateStruct->mainLanguageCode, |
||
| 1267 | 'alwaysAvailable' => $updateStruct->alwaysAvailable, |
||
| 1268 | 'remoteId' => $updateStruct->remoteId, |
||
| 1269 | 'mainLocationId' => $updateStruct->mainLocationId, |
||
| 1270 | 'sectionId' => $data['newSectionId'], |
||
| 1271 | ), |
||
| 1272 | $content->contentInfo |
||
| 1273 | ); |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * Test for the updateContentMetadata() method. |
||
| 1278 | * |
||
| 1279 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 1280 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1281 | */ |
||
| 1282 | public function testUpdateContentMetadataThrowsUnauthorizedException() |
||
| 1283 | { |
||
| 1284 | $contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
||
| 1285 | $contentMetadataUpdateStruct = $this->repository->getContentService()->newContentMetadataUpdateStruct(); |
||
| 1286 | $contentMetadataUpdateStruct->remoteId = 'the-all-new-remoteid'; |
||
| 1287 | |||
| 1288 | // Set anonymous as current user |
||
| 1289 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 1290 | |||
| 1291 | $this->repository->getContentService()->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 1292 | } |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Test for the updateContentMetadata() method. |
||
| 1296 | * |
||
| 1297 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 1298 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1299 | * @depends testNewContentMetadataUpdateStruct |
||
| 1300 | */ |
||
| 1301 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionDuplicateRemoteId() |
||
| 1302 | { |
||
| 1303 | /* BEGIN: Use Case */ |
||
| 1304 | $contentService = $this->repository->getContentService(); |
||
| 1305 | $contentInfo = $contentService->loadContentInfo(4); |
||
| 1306 | $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
||
| 1307 | $contentMetadataUpdateStruct->remoteId = '9b47a45624b023b1a76c73b74d704acf'; |
||
| 1308 | |||
| 1309 | // Throws an exception because remoteId "9b47a45624b023b1a76c73b74d704acf" is already in use |
||
| 1310 | $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 1311 | /* END: Use Case */ |
||
| 1312 | } |
||
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Test for the updateContentMetadata() method. |
||
| 1316 | * |
||
| 1317 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 1318 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1319 | * @depends testNewContentMetadataUpdateStruct |
||
| 1320 | */ |
||
| 1321 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionNoMetadataPropertiesSet() |
||
| 1322 | { |
||
| 1323 | /* BEGIN: Use Case */ |
||
| 1324 | $contentService = $this->repository->getContentService(); |
||
| 1325 | $contentInfo = $contentService->loadContentInfo(4); |
||
| 1326 | $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); |
||
| 1327 | |||
| 1328 | // Throws an exception because no properties are set in $contentMetadataUpdateStruct |
||
| 1329 | $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 1330 | /* END: Use Case */ |
||
| 1331 | } |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * Test for the newContentUpdateStruct() method. |
||
| 1335 | * |
||
| 1336 | * @covers \eZ\Publish\Core\Repository\ContentService::newContentUpdateStruct |
||
| 1337 | */ |
||
| 1338 | View Code Duplication | public function testNewContentUpdateStruct() |
|
| 1339 | { |
||
| 1340 | /* BEGIN: Use Case */ |
||
| 1341 | $contentService = $this->repository->getContentService(); |
||
| 1342 | |||
| 1343 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1344 | /* END: Use Case */ |
||
| 1345 | |||
| 1346 | $this->assertInstanceOf( |
||
| 1347 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\ContentUpdateStruct', |
||
| 1348 | $contentUpdateStruct |
||
| 1349 | ); |
||
| 1350 | |||
| 1351 | $this->assertPropertiesCorrect( |
||
| 1352 | array( |
||
| 1353 | 'initialLanguageCode' => null, |
||
| 1354 | 'fields' => array(), |
||
| 1355 | ), |
||
| 1356 | $contentUpdateStruct |
||
| 1357 | ); |
||
| 1358 | } |
||
| 1359 | |||
| 1360 | /** |
||
| 1361 | * Test for the updateContent() method. |
||
| 1362 | * |
||
| 1363 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1364 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1365 | */ |
||
| 1366 | public function testUpdateContentThrowsUnauthorizedException() |
||
| 1367 | { |
||
| 1368 | list($content, $contentType) = $this->createTestContent(); |
||
| 1369 | |||
| 1370 | $contentUpdateStruct = $this->repository->getContentService()->newContentUpdateStruct(); |
||
| 1371 | $contentUpdateStruct->initialLanguageCode = 'eng-US'; |
||
| 1372 | $contentUpdateStruct->setField('test_required_empty', 'new value for test_required_empty'); |
||
| 1373 | |||
| 1374 | // Set anonymous as current user |
||
| 1375 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 1376 | |||
| 1377 | $this->repository->getContentService()->updateContent( |
||
| 1378 | $content->versionInfo, |
||
| 1379 | $contentUpdateStruct |
||
| 1380 | ); |
||
| 1381 | } |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Test for the updateContent() method. |
||
| 1385 | * |
||
| 1386 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1387 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1388 | */ |
||
| 1389 | public function testUpdateContentThrowsBadStateException() |
||
| 1390 | { |
||
| 1391 | /* BEGIN: Use Case */ |
||
| 1392 | $contentService = $this->repository->getContentService(); |
||
| 1393 | |||
| 1394 | $versionInfo = $contentService->loadVersionInfoById(4); |
||
| 1395 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1396 | |||
| 1397 | // Throws an exception because version is not a draft |
||
| 1398 | $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
||
| 1399 | /* END: Use Case */ |
||
| 1400 | } |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Test for the updateContent() method. |
||
| 1404 | * |
||
| 1405 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1406 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 1407 | */ |
||
| 1408 | View Code Duplication | public function testUpdateContentThrowsContentFieldValidationException() |
|
| 1409 | { |
||
| 1410 | list($content, $contentType) = $this->createTestContent(); |
||
| 1411 | |||
| 1412 | /* BEGIN: Use Case */ |
||
| 1413 | $contentService = $this->repository->getContentService(); |
||
| 1414 | |||
| 1415 | $versionInfo = $contentService->loadVersionInfoById( |
||
| 1416 | $content->id, |
||
| 1417 | $content->getVersionInfo()->versionNo |
||
| 1418 | ); |
||
| 1419 | |||
| 1420 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1421 | $contentUpdateStruct->initialLanguageCode = 'eng-US'; |
||
| 1422 | $contentUpdateStruct->setField( |
||
| 1423 | 'test_required_empty', |
||
| 1424 | 'a string that is too long and will not validate 12345678901234567890123456789012345678901234567890' |
||
| 1425 | ); |
||
| 1426 | |||
| 1427 | // Throws an exception because "test_required_empty" field value is too long and fails |
||
| 1428 | // field definition's string length validator |
||
| 1429 | $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
||
| 1430 | /* END: Use Case */ |
||
| 1431 | } |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Test for the updateContent() method. |
||
| 1435 | * |
||
| 1436 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1437 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1438 | */ |
||
| 1439 | View Code Duplication | public function testUpdateContentThrowsContentValidationExceptionRequiredFieldEmpty() |
|
| 1440 | { |
||
| 1441 | list($content, $contentType) = $this->createTestContent(); |
||
| 1442 | |||
| 1443 | /* BEGIN: Use Case */ |
||
| 1444 | $contentService = $this->repository->getContentService(); |
||
| 1445 | |||
| 1446 | $versionInfo = $contentService->loadVersionInfoById( |
||
| 1447 | $content->id, |
||
| 1448 | $content->getVersionInfo()->versionNo |
||
| 1449 | ); |
||
| 1450 | |||
| 1451 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1452 | $contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
||
| 1453 | $contentUpdateStruct->setField('test_required_empty', ''); |
||
| 1454 | |||
| 1455 | // Throws an exception because required field is being updated with empty value |
||
| 1456 | $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
||
| 1457 | /* END: Use Case */ |
||
| 1458 | } |
||
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Test for the updateContent() method. |
||
| 1462 | * |
||
| 1463 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1464 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1465 | */ |
||
| 1466 | View Code Duplication | public function testUpdateContentThrowsContentValidationExceptionFieldDefinitionNonexistent() |
|
| 1467 | { |
||
| 1468 | list($content, $contentType) = $this->createTestContent(); |
||
| 1469 | |||
| 1470 | /* BEGIN: Use Case */ |
||
| 1471 | $contentService = $this->repository->getContentService(); |
||
| 1472 | |||
| 1473 | $versionInfo = $contentService->loadVersionInfoById( |
||
| 1474 | $content->id, |
||
| 1475 | $content->getVersionInfo()->versionNo |
||
| 1476 | ); |
||
| 1477 | |||
| 1478 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1479 | $contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
||
| 1480 | $contentUpdateStruct->setField('nonexistent_field_definition_identifier', 'eng-GB'); |
||
| 1481 | |||
| 1482 | // Throws an exception because field definition with identifier "nonexistent_field_definition_identifier" |
||
| 1483 | // does not exist in content draft content type |
||
| 1484 | $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
||
| 1485 | /* END: Use Case */ |
||
| 1486 | } |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Test for the updateContent() method. |
||
| 1490 | * |
||
| 1491 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
||
| 1492 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1493 | * |
||
| 1494 | * @return array |
||
| 1495 | */ |
||
| 1496 | View Code Duplication | public function testUpdateContentThrowsContentValidationExceptionUntranslatableField() |
|
| 1497 | { |
||
| 1498 | list($content, $contentType) = $this->createTestContent(); |
||
| 1499 | |||
| 1500 | /* BEGIN: Use Case */ |
||
| 1501 | $contentService = $this->repository->getContentService(); |
||
| 1502 | |||
| 1503 | $versionInfo = $contentService->loadVersionInfoById( |
||
| 1504 | $content->id, |
||
| 1505 | $content->getVersionInfo()->versionNo |
||
| 1506 | ); |
||
| 1507 | |||
| 1508 | $contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
| 1509 | $contentUpdateStruct->initialLanguageCode = 'eng-GB'; |
||
| 1510 | $contentUpdateStruct->setField('test_untranslatable', 'Jabberwock', 'eng-US'); |
||
| 1511 | |||
| 1512 | // Throws an exception because translation was given for a untranslatable field |
||
| 1513 | // Note that it is still permissible to set untranslatable field with main language |
||
| 1514 | $updatedContent = $contentService->updateContent($versionInfo, $contentUpdateStruct); |
||
| 1515 | /* END: Use Case */ |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | /** |
||
| 1519 | * Test for the publishVersion() method. |
||
| 1520 | * |
||
| 1521 | * @depends testCreateContent |
||
| 1522 | * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
||
| 1523 | */ |
||
| 1524 | public function testPublishVersion() |
||
| 1525 | { |
||
| 1526 | $time = time(); |
||
| 1527 | list($draftContent, $contentType) = $this->createTestContent(); |
||
| 1528 | |||
| 1529 | /* BEGIN: Use Case */ |
||
| 1530 | $contentService = $this->repository->getContentService(); |
||
| 1531 | |||
| 1532 | $versionInfo = $contentService->loadVersionInfoById( |
||
| 1533 | $draftContent->id, |
||
| 1534 | $draftContent->getVersionInfo()->versionNo |
||
| 1535 | ); |
||
| 1536 | |||
| 1537 | $publishedContent = $contentService->publishVersion($versionInfo); |
||
| 1538 | /* END: Use Case */ |
||
| 1539 | |||
| 1540 | $this->assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $publishedContent); |
||
| 1541 | $this->assertTrue($publishedContent->contentInfo->published); |
||
| 1542 | $this->assertEquals(VersionInfo::STATUS_PUBLISHED, $publishedContent->versionInfo->status); |
||
| 1543 | $this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->publishedDate->getTimestamp()); |
||
| 1544 | $this->assertGreaterThanOrEqual($time, $publishedContent->contentInfo->modificationDate->getTimestamp()); |
||
| 1545 | } |
||
| 1546 | |||
| 1547 | public function testPublishVersionDoesNotChangePublishedDate() |
||
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Test for the publishVersion() method. |
||
| 1582 | * |
||
| 1583 | * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
||
| 1584 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1585 | */ |
||
| 1586 | public function testPublishVersionThrowsBadStateException() |
||
| 1587 | { |
||
| 1588 | /* BEGIN: Use Case */ |
||
| 1589 | $contentService = $this->repository->getContentService(); |
||
| 1590 | |||
| 1591 | $versionInfo = $contentService->loadVersionInfoById(4); |
||
| 1592 | |||
| 1593 | // Throws an exception because version is already published |
||
| 1594 | $publishedContent = $contentService->publishVersion($versionInfo); |
||
| 1595 | /* END: Use Case */ |
||
| 1596 | } |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Test for the publishVersion() method. |
||
| 1600 | * |
||
| 1601 | * @covers \eZ\Publish\Core\Repository\ContentService::publishVersion |
||
| 1602 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1603 | */ |
||
| 1604 | View Code Duplication | public function testPublishVersionThrowsUnauthorizedException() |
|
| 1605 | { |
||
| 1606 | list($draftContent, $contentType) = $this->createTestContent(); |
||
| 1607 | |||
| 1608 | // Set anonymous as current user |
||
| 1609 | $this->repository->setCurrentUser($this->getStubbedUser(10)); |
||
| 1610 | |||
| 1611 | $this->repository->getContentService()->publishVersion($draftContent->versionInfo); |
||
| 1612 | } |
||
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Test for the createContentDraft() method. |
||
| 1616 | * |
||
| 1617 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1618 | * |
||
| 1619 | * @return array |
||
| 1620 | */ |
||
| 1621 | View Code Duplication | public function testCreateContentDraft() |
|
| 1622 | { |
||
| 1623 | $time = time(); |
||
| 1624 | |||
| 1625 | /* BEGIN: Use Case */ |
||
| 1626 | $contentService = $this->repository->getContentService(); |
||
| 1627 | |||
| 1628 | $contentInfo = $contentService->loadContentInfo(4); |
||
| 1629 | |||
| 1630 | $draftContent = $contentService->createContentDraft($contentInfo); |
||
| 1631 | /* END: Use Case */ |
||
| 1632 | |||
| 1633 | $this->assertInstanceOf( |
||
| 1634 | 'eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 1635 | $draftContent |
||
| 1636 | ); |
||
| 1637 | |||
| 1638 | return array( |
||
| 1639 | 'draftContent' => $draftContent, |
||
| 1640 | 'time' => $time, |
||
| 1641 | ); |
||
| 1642 | } |
||
| 1643 | |||
| 1644 | /** |
||
| 1645 | * @param array $data |
||
| 1646 | */ |
||
| 1647 | protected function assertDraftContentValues(array $data) |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * Test for the createContentDraft() method. |
||
| 1666 | * |
||
| 1667 | * @depends testCreateContentDraft |
||
| 1668 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1669 | * |
||
| 1670 | * @param array $data |
||
| 1671 | */ |
||
| 1672 | public function testCreateContentDraftValues(array $data) |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Test for the createContentDraft() method. |
||
| 1679 | * |
||
| 1680 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1681 | * |
||
| 1682 | * @return array |
||
| 1683 | */ |
||
| 1684 | View Code Duplication | public function testCreateContentDraftWithSecondArgument() |
|
| 1708 | |||
| 1709 | /** |
||
| 1710 | * Test for the createContentDraft() method. |
||
| 1711 | * |
||
| 1712 | * @depends testCreateContentDraftWithSecondArgument |
||
| 1713 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1714 | * |
||
| 1715 | * @param array $data |
||
| 1716 | */ |
||
| 1717 | public function testCreateContentDraftWithSecondArgumentValues(array $data) |
||
| 1721 | |||
| 1722 | /** |
||
| 1723 | * Test for the createContentDraft() method. |
||
| 1724 | * |
||
| 1725 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1726 | * |
||
| 1727 | * @return array |
||
| 1728 | */ |
||
| 1729 | public function testCreateContentDraftWithThirdArgument() |
||
| 1754 | |||
| 1755 | /** |
||
| 1756 | * Test for the createContentDraft() method. |
||
| 1757 | * |
||
| 1758 | * @depends testCreateContentDraftWithThirdArgument |
||
| 1759 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1760 | * |
||
| 1761 | * @param array $data |
||
| 1762 | */ |
||
| 1763 | public function testCreateContentDraftWithThirdArgumentValues(array $data) |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * Test for the createContentDraft() method. |
||
| 1770 | * |
||
| 1771 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1772 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1773 | */ |
||
| 1774 | View Code Duplication | public function testCreateContentDraftThrowsBadStateException() |
|
| 1787 | |||
| 1788 | /** |
||
| 1789 | * Test for the createContentDraft() method. |
||
| 1790 | * |
||
| 1791 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1792 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1793 | */ |
||
| 1794 | View Code Duplication | public function testCreateContentDraftThrowsUnauthorizedException() |
|
| 1805 | |||
| 1806 | /** |
||
| 1807 | * Test for the loadContentDrafts() method. |
||
| 1808 | * |
||
| 1809 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
||
| 1810 | */ |
||
| 1811 | public function testLoadContentDrafts() |
||
| 1857 | |||
| 1858 | /** |
||
| 1859 | * Test for the loadContentDrafts() method. |
||
| 1860 | * |
||
| 1861 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
||
| 1862 | */ |
||
| 1863 | public function testLoadContentDraftsWithFirstArgument() |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Test for the loadContentDrafts() method. |
||
| 1869 | * |
||
| 1870 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentDrafts |
||
| 1871 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1872 | */ |
||
| 1873 | public function testLoadContentDraftsThrowsUnauthorizedException() |
||
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Test for the loadVersions() method. |
||
| 1884 | * |
||
| 1885 | * @depends testLoadContentInfo |
||
| 1886 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 1887 | * |
||
| 1888 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] |
||
| 1889 | */ |
||
| 1890 | public function testLoadVersions() |
||
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Test for the loadVersions() method. |
||
| 1904 | * |
||
| 1905 | * @depends testLoadVersions |
||
| 1906 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 1907 | * |
||
| 1908 | * @param array $versions |
||
| 1909 | */ |
||
| 1910 | public function testLoadVersionsValues(array $versions) |
||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Test for the loadVersions() method. |
||
| 1922 | * |
||
| 1923 | * @depends testLoadContentInfo |
||
| 1924 | * @depends testCreateContentDraft |
||
| 1925 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 1926 | * |
||
| 1927 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] |
||
| 1928 | */ |
||
| 1929 | View Code Duplication | public function testLoadVersionsMultiple() |
|
| 1947 | |||
| 1948 | /** |
||
| 1949 | * Test for the loadVersions() method. |
||
| 1950 | * |
||
| 1951 | * @depends testLoadVersionsMultiple |
||
| 1952 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 1953 | * |
||
| 1954 | * @param array $data |
||
| 1955 | */ |
||
| 1956 | public function testLoadVersionsMultipleValues(array $data) |
||
| 1981 | |||
| 1982 | /** |
||
| 1983 | * Test for the loadVersions() method. |
||
| 1984 | * |
||
| 1985 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 1986 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1987 | */ |
||
| 1988 | View Code Duplication | public function testLoadVersionsThrowsUnauthorizedException() |
|
| 1999 | |||
| 2000 | /** |
||
| 2001 | * Test for the deleteVersion() method. |
||
| 2002 | * |
||
| 2003 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
||
| 2004 | */ |
||
| 2005 | public function testDeleteVersion() |
||
| 2029 | |||
| 2030 | /** |
||
| 2031 | * Test for the deleteVersion() method. |
||
| 2032 | * |
||
| 2033 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
||
| 2034 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 2035 | */ |
||
| 2036 | public function testDeleteVersionThrowsBadStateException() |
||
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Test for the deleteVersion() method. |
||
| 2050 | * |
||
| 2051 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
||
| 2052 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2053 | */ |
||
| 2054 | View Code Duplication | public function testDeleteVersionThrowsUnauthorizedException() |
|
| 2068 | |||
| 2069 | /** |
||
| 2070 | * Test for the copyContent() method. |
||
| 2071 | * |
||
| 2072 | * @dep_ends testCreate |
||
| 2073 | * @dep_ends testLoadContentInfo |
||
| 2074 | * @dep_ends testLoadVersionInfoById |
||
| 2075 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
||
| 2076 | */ |
||
| 2077 | public function testCopyContentSingleVersion() |
||
| 2109 | |||
| 2110 | /** |
||
| 2111 | * Test for the copyContent() method. |
||
| 2112 | * |
||
| 2113 | * @dep_ends testLoadVersions |
||
| 2114 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
||
| 2115 | */ |
||
| 2116 | public function testCopyContentAllVersions() |
||
| 2171 | |||
| 2172 | /** |
||
| 2173 | * Asserts that $copiedContent is valid copy of $originalContent. |
||
| 2174 | * |
||
| 2175 | * @param \eZ\Publish\API\Repository\Values\Content\Content $originalContent |
||
| 2176 | * @param \eZ\Publish\API\Repository\Values\Content\Content $copiedContent |
||
| 2177 | */ |
||
| 2178 | protected function assertCopyContentValues(APIContent $originalContent, APIContent $copiedContent) |
||
| 2244 | |||
| 2245 | /** |
||
| 2246 | * Test for the copyContent() method. |
||
| 2247 | * |
||
| 2248 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent |
||
| 2249 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2250 | */ |
||
| 2251 | View Code Duplication | public function testCopyContentThrowsUnauthorizedException() |
|
| 2264 | |||
| 2265 | /** |
||
| 2266 | * Test for the newTranslationInfo() method. |
||
| 2267 | * |
||
| 2268 | * @covers \eZ\Publish\Core\Repository\ContentService::newTranslationInfo |
||
| 2269 | */ |
||
| 2270 | View Code Duplication | public function testNewTranslationInfo() |
|
| 2287 | |||
| 2288 | /** |
||
| 2289 | * Test for the newTranslationValues() method. |
||
| 2290 | * |
||
| 2291 | * @covers \eZ\Publish\Core\Repository\ContentService::newTranslationValues |
||
| 2292 | */ |
||
| 2293 | View Code Duplication | public function testNewTranslationValues() |
|
| 2310 | |||
| 2311 | /** |
||
| 2312 | * Test for the loadRelations() method. |
||
| 2313 | * |
||
| 2314 | * @covers \eZ\Publish\Core\Repository\ContentService::loadRelations |
||
| 2315 | * @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
||
| 2316 | */ |
||
| 2317 | View Code Duplication | public function testLoadRelations() |
|
| 2333 | |||
| 2334 | protected function assertRelations($relations, $sourceContentInfo, $destinationContentInfo) |
||
| 2345 | |||
| 2346 | /** |
||
| 2347 | * Test for the loadRelations() method. |
||
| 2348 | * |
||
| 2349 | * @covers \eZ\Publish\Core\Repository\ContentService::loadRelations |
||
| 2350 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2351 | */ |
||
| 2352 | View Code Duplication | public function testLoadRelationsThrowsUnauthorizedException() |
|
| 2369 | |||
| 2370 | /** |
||
| 2371 | * Test for the loadReverseRelations() method. |
||
| 2372 | * |
||
| 2373 | * @covers \eZ\Publish\Core\Repository\ContentService::loadReverseRelations |
||
| 2374 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2375 | */ |
||
| 2376 | public function testLoadReverseRelationsThrowsUnauthorizedException() |
||
| 2393 | |||
| 2394 | /** |
||
| 2395 | * Test for the addRelation() method. |
||
| 2396 | * |
||
| 2397 | * @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
||
| 2398 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2399 | */ |
||
| 2400 | public function testAddRelationThrowsUnauthorizedException() |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Test for the addRelation() method. |
||
| 2418 | * |
||
| 2419 | * @covers \eZ\Publish\Core\Repository\ContentService::addRelation |
||
| 2420 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 2421 | */ |
||
| 2422 | View Code Duplication | public function testAddRelationThrowsBadStateException() |
|
| 2435 | |||
| 2436 | /** |
||
| 2437 | * Test for the deleteRelation() method. |
||
| 2438 | * |
||
| 2439 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
||
| 2440 | */ |
||
| 2441 | View Code Duplication | public function testDeleteRelation() |
|
| 2462 | |||
| 2463 | /** |
||
| 2464 | * Test for the deleteRelation() method. |
||
| 2465 | * |
||
| 2466 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
||
| 2467 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 2468 | */ |
||
| 2469 | View Code Duplication | public function testDeleteRelationThrowsUnauthorizedException() |
|
| 2489 | |||
| 2490 | /** |
||
| 2491 | * Test for the deleteRelation() method. |
||
| 2492 | * |
||
| 2493 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
||
| 2494 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 2495 | */ |
||
| 2496 | View Code Duplication | public function testDeleteRelationThrowsBadStateException() |
|
| 2515 | |||
| 2516 | /** |
||
| 2517 | * Test for the deleteRelation() method. |
||
| 2518 | * |
||
| 2519 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteRelation |
||
| 2520 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2521 | */ |
||
| 2522 | public function testDeleteRelationThrowsInvalidArgumentException() |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Creates and returns content draft used in testing. |
||
| 2537 | * |
||
| 2538 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 2539 | */ |
||
| 2540 | protected function createTestContent() |
||
| 2581 | |||
| 2582 | /** |
||
| 2583 | * Returns ContentType used in testing. |
||
| 2584 | * |
||
| 2585 | * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
||
| 2586 | */ |
||
| 2587 | protected function createTestContentType() |
||
| 2675 | } |
||
| 2676 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.