Complex classes like ContentServiceTest 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 ContentServiceTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class ContentServiceTest extends BaseContentServiceTest |
||
| 43 | { |
||
| 44 | private const ADMINISTRATORS_USER_GROUP_NAME = 'Administrators'; |
||
| 45 | private const ADMINISTRATORS_USER_GROUP_ID = 12; |
||
| 46 | private const ADMINISTRATORS_USER_GROUP_LOCATION_ID = 13; |
||
| 47 | |||
| 48 | private const WRITERS_USER_GROUP_NAME = 'Writers'; |
||
| 49 | |||
| 50 | private const MEMBERS_USER_GROUP_ID = 11; |
||
| 51 | |||
| 52 | private const MEDIA_CONTENT_ID = 41; |
||
| 53 | |||
| 54 | private const MEDIA_REMOTE_ID = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 55 | private const DEMO_DESIGN_REMOTE_ID = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 56 | |||
| 57 | private const FORUM_IDENTIFIER = 'forum'; |
||
| 58 | |||
| 59 | private const ENG_US = 'eng-US'; |
||
| 60 | private const GER_DE = 'ger-DE'; |
||
| 61 | private const ENG_GB = 'eng-GB'; |
||
| 62 | |||
| 63 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
| 64 | private $permissionResolver; |
||
| 65 | |||
| 66 | /** @var \eZ\Publish\API\Repository\ContentService */ |
||
| 67 | private $contentService; |
||
| 68 | |||
| 69 | /** @var \eZ\Publish\API\Repository\LocationService */ |
||
| 70 | private $locationService; |
||
| 71 | |||
| 72 | public function setUp(): void |
||
| 73 | { |
||
| 74 | parent::setUp(); |
||
| 75 | |||
| 76 | $repository = $this->getRepository(); |
||
| 77 | $this->permissionResolver = $repository->getPermissionResolver(); |
||
| 78 | $this->contentService = $repository->getContentService(); |
||
| 79 | $this->locationService = $repository->getLocationService(); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Test for the newContentCreateStruct() method. |
||
| 84 | * |
||
| 85 | * @see \eZ\Publish\API\Repository\ContentService::newContentCreateStruct() |
||
| 86 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
||
| 87 | * @group user |
||
| 88 | * @group field-type |
||
| 89 | */ |
||
| 90 | public function testNewContentCreateStruct() |
||
| 91 | { |
||
| 92 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 93 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 94 | |||
| 95 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 96 | |||
| 97 | $this->assertInstanceOf(ContentCreateStruct::class, $contentCreate); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Test for the createContent() method. |
||
| 102 | * |
||
| 103 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 104 | * |
||
| 105 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 106 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
||
| 107 | * @group user |
||
| 108 | * @group field-type |
||
| 109 | */ |
||
| 110 | public function testCreateContent() |
||
| 111 | { |
||
| 112 | if ($this->isVersion4()) { |
||
| 113 | $this->markTestSkipped('This test requires eZ Publish 5'); |
||
| 114 | } |
||
| 115 | |||
| 116 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 117 | |||
| 118 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 119 | |||
| 120 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 121 | $contentCreate->setField('name', 'My awesome forum'); |
||
| 122 | |||
| 123 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 124 | $contentCreate->alwaysAvailable = true; |
||
| 125 | |||
| 126 | $content = $this->contentService->createContent($contentCreate); |
||
| 127 | |||
| 128 | $this->assertInstanceOf(Content::class, $content); |
||
| 129 | |||
| 130 | return $content; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Test for the createContent() method. |
||
| 135 | * |
||
| 136 | * Tests made for issue #EZP-20955 where Anonymous user is granted access to create content |
||
| 137 | * and should have access to do that. |
||
| 138 | * |
||
| 139 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 140 | * |
||
| 141 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 142 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
||
| 143 | * @group user |
||
| 144 | * @group field-type |
||
| 145 | */ |
||
| 146 | public function testCreateContentAndPublishWithPrivilegedAnonymousUser() |
||
| 147 | { |
||
| 148 | if ($this->isVersion4()) { |
||
| 149 | $this->markTestSkipped('This test requires eZ Publish 5'); |
||
| 150 | } |
||
| 151 | |||
| 152 | $anonymousUserId = $this->generateId('user', 10); |
||
| 153 | |||
| 154 | $repository = $this->getRepository(); |
||
| 155 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 156 | $roleService = $repository->getRoleService(); |
||
| 157 | |||
| 158 | // Give Anonymous user role additional rights |
||
| 159 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
||
| 160 | $roleDraft = $roleService->createRoleDraft($role); |
||
| 161 | $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create'); |
||
| 162 | $policyCreateStruct->addLimitation(new SectionLimitation(['limitationValues' => [1]])); |
||
| 163 | $policyCreateStruct->addLimitation(new LocationLimitation(['limitationValues' => [2]])); |
||
| 164 | $policyCreateStruct->addLimitation(new ContentTypeLimitation(['limitationValues' => [1]])); |
||
| 165 | $roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
||
| 166 | |||
| 167 | $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'publish'); |
||
| 168 | $policyCreateStruct->addLimitation(new SectionLimitation(['limitationValues' => [1]])); |
||
| 169 | $policyCreateStruct->addLimitation(new LocationLimitation(['limitationValues' => [2]])); |
||
| 170 | $policyCreateStruct->addLimitation(new ContentTypeLimitation(['limitationValues' => [1]])); |
||
| 171 | $roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
||
| 172 | $roleService->publishRoleDraft($roleDraft); |
||
| 173 | |||
| 174 | // Set Anonymous user as current |
||
| 175 | $repository->getPermissionResolver()->setCurrentUserReference($repository->getUserService()->loadUser($anonymousUserId)); |
||
| 176 | |||
| 177 | // Create a new content object: |
||
| 178 | $contentCreate = $this->contentService->newContentCreateStruct( |
||
| 179 | $contentTypeService->loadContentTypeByIdentifier('folder'), |
||
| 180 | self::ENG_GB |
||
| 181 | ); |
||
| 182 | |||
| 183 | $contentCreate->setField('name', 'Folder 1'); |
||
| 184 | |||
| 185 | $content = $this->contentService->createContent( |
||
| 186 | $contentCreate, |
||
| 187 | [$this->locationService->newLocationCreateStruct(2)] |
||
| 188 | ); |
||
| 189 | |||
| 190 | $this->contentService->publishVersion( |
||
| 191 | $content->getVersionInfo() |
||
| 192 | ); |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Test for the createContent() method. |
||
| 197 | * |
||
| 198 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 199 | * |
||
| 200 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 201 | * |
||
| 202 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 203 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 204 | */ |
||
| 205 | public function testCreateContentSetsContentInfo($content) |
||
| 206 | { |
||
| 207 | $this->assertInstanceOf(ContentInfo::class, $content->contentInfo); |
||
| 208 | |||
| 209 | return $content; |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Test for the createContent() method. |
||
| 214 | * |
||
| 215 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 216 | * |
||
| 217 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 218 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsContentInfo |
||
| 219 | */ |
||
| 220 | public function testCreateContentSetsExpectedContentInfo($content) |
||
| 221 | { |
||
| 222 | $this->assertEquals( |
||
| 223 | [ |
||
| 224 | $content->id, |
||
| 225 | 28, // id of content type "forum" |
||
| 226 | true, |
||
| 227 | 1, |
||
| 228 | 'abcdef0123456789abcdef0123456789', |
||
| 229 | self::ENG_US, |
||
| 230 | $this->getRepository()->getCurrentUser()->id, |
||
|
|
|||
| 231 | false, |
||
| 232 | null, |
||
| 233 | // Main Location id for unpublished Content should be null |
||
| 234 | null, |
||
| 235 | ], |
||
| 236 | [ |
||
| 237 | $content->contentInfo->id, |
||
| 238 | $content->contentInfo->contentTypeId, |
||
| 239 | $content->contentInfo->alwaysAvailable, |
||
| 240 | $content->contentInfo->currentVersionNo, |
||
| 241 | $content->contentInfo->remoteId, |
||
| 242 | $content->contentInfo->mainLanguageCode, |
||
| 243 | $content->contentInfo->ownerId, |
||
| 244 | $content->contentInfo->published, |
||
| 245 | $content->contentInfo->publishedDate, |
||
| 246 | $content->contentInfo->mainLocationId, |
||
| 247 | ] |
||
| 248 | ); |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Test for the createContent() method. |
||
| 253 | * |
||
| 254 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 255 | * |
||
| 256 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 257 | * |
||
| 258 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 259 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 260 | */ |
||
| 261 | public function testCreateContentSetsVersionInfo($content) |
||
| 262 | { |
||
| 263 | $this->assertInstanceOf(VersionInfo::class, $content->getVersionInfo()); |
||
| 264 | |||
| 265 | return $content; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Test for the createContent() method. |
||
| 270 | * |
||
| 271 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 272 | * |
||
| 273 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 274 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsVersionInfo |
||
| 275 | */ |
||
| 276 | public function testCreateContentSetsExpectedVersionInfo($content) |
||
| 277 | { |
||
| 278 | $this->assertEquals( |
||
| 279 | [ |
||
| 280 | 'status' => VersionInfo::STATUS_DRAFT, |
||
| 281 | 'versionNo' => 1, |
||
| 282 | 'creatorId' => $this->getRepository()->getCurrentUser()->id, |
||
| 283 | 'initialLanguageCode' => self::ENG_US, |
||
| 284 | ], |
||
| 285 | [ |
||
| 286 | 'status' => $content->getVersionInfo()->status, |
||
| 287 | 'versionNo' => $content->getVersionInfo()->versionNo, |
||
| 288 | 'creatorId' => $content->getVersionInfo()->creatorId, |
||
| 289 | 'initialLanguageCode' => $content->getVersionInfo()->initialLanguageCode, |
||
| 290 | ] |
||
| 291 | ); |
||
| 292 | $this->assertTrue($content->getVersionInfo()->isDraft()); |
||
| 293 | $this->assertFalse($content->getVersionInfo()->isPublished()); |
||
| 294 | $this->assertFalse($content->getVersionInfo()->isArchived()); |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Test for the createContent() method. |
||
| 299 | * |
||
| 300 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 301 | * |
||
| 302 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 303 | * @depends testCreateContent |
||
| 304 | */ |
||
| 305 | public function testCreateContentSetsExpectedContentType($content) |
||
| 306 | { |
||
| 307 | $contentType = $content->getContentType(); |
||
| 308 | |||
| 309 | $this->assertEquals( |
||
| 310 | [ |
||
| 311 | $contentType->id, |
||
| 312 | // Won't match as it's set to true in createContentDraftVersion1() |
||
| 313 | //$contentType->defaultAlwaysAvailable, |
||
| 314 | //$contentType->defaultSortField, |
||
| 315 | //$contentType->defaultSortOrder, |
||
| 316 | ], |
||
| 317 | [ |
||
| 318 | $content->contentInfo->contentTypeId, |
||
| 319 | //$content->contentInfo->alwaysAvailable, |
||
| 320 | //$location->sortField, |
||
| 321 | //$location->sortOrder, |
||
| 322 | ] |
||
| 323 | ); |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Test for the createContent() method. |
||
| 328 | * |
||
| 329 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 330 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 331 | */ |
||
| 332 | public function testCreateContentThrowsInvalidArgumentException() |
||
| 333 | { |
||
| 334 | if ($this->isVersion4()) { |
||
| 335 | $this->markTestSkipped('This test requires eZ Publish 5'); |
||
| 336 | } |
||
| 337 | |||
| 338 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 339 | |||
| 340 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 341 | |||
| 342 | $contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 343 | $contentCreate1->setField('name', 'An awesome Sidelfingen forum'); |
||
| 344 | |||
| 345 | $contentCreate1->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 346 | $contentCreate1->alwaysAvailable = true; |
||
| 347 | |||
| 348 | $draft = $this->contentService->createContent($contentCreate1); |
||
| 349 | $this->contentService->publishVersion($draft->versionInfo); |
||
| 350 | |||
| 351 | $contentCreate2 = $this->contentService->newContentCreateStruct($contentType, self::ENG_GB); |
||
| 352 | $contentCreate2->setField('name', 'An awesome Bielefeld forum'); |
||
| 353 | |||
| 354 | $contentCreate2->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 355 | $contentCreate2->alwaysAvailable = false; |
||
| 356 | |||
| 357 | $this->expectException(APIInvalidArgumentException::class); |
||
| 358 | $this->contentService->createContent($contentCreate2); |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Test for the createContent() method. |
||
| 363 | * |
||
| 364 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 365 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 366 | */ |
||
| 367 | public function testCreateContentThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
||
| 368 | { |
||
| 369 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 370 | |||
| 371 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 372 | |||
| 373 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 374 | // The name field does only accept strings and null as its values |
||
| 375 | $contentCreate->setField('name', new \stdClass()); |
||
| 376 | |||
| 377 | $this->expectException(APIInvalidArgumentException::class); |
||
| 378 | $this->contentService->createContent($contentCreate); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Test for the createContent() method. |
||
| 383 | * |
||
| 384 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 385 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 386 | */ |
||
| 387 | public function testCreateContentThrowsContentFieldValidationException() |
||
| 388 | { |
||
| 389 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 390 | |||
| 391 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
||
| 392 | |||
| 393 | $contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 394 | $contentCreate1->setField('name', 'An awesome Sidelfingen folder'); |
||
| 395 | // Violates string length constraint |
||
| 396 | $contentCreate1->setField('short_name', str_repeat('a', 200)); |
||
| 397 | |||
| 398 | $this->expectException(ContentFieldValidationException::class); |
||
| 399 | |||
| 400 | // Throws ContentFieldValidationException, since short_name does not pass validation of the string length validator |
||
| 401 | $this->contentService->createContent($contentCreate1); |
||
| 402 | } |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Test for the createContent() method. |
||
| 406 | * |
||
| 407 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 408 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 409 | */ |
||
| 410 | public function testCreateContentRequiredFieldMissing() |
||
| 411 | { |
||
| 412 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 413 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 414 | |||
| 415 | $contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 416 | // Required field "name" is not set |
||
| 417 | |||
| 418 | $this->expectException(ContentFieldValidationException::class); |
||
| 419 | |||
| 420 | // Throws a ContentFieldValidationException, since a required field is missing |
||
| 421 | $this->contentService->createContent($contentCreate1); |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Test for the createContent() method. |
||
| 426 | * |
||
| 427 | * NOTE: We have bidirectional dependencies between the ContentService and |
||
| 428 | * the LocationService, so that we cannot use PHPUnit's test dependencies |
||
| 429 | * here. |
||
| 430 | * |
||
| 431 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 432 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
| 433 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId |
||
| 434 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 435 | * @group user |
||
| 436 | */ |
||
| 437 | public function testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately() |
||
| 438 | { |
||
| 439 | $this->createContentDraftVersion1(); |
||
| 440 | |||
| 441 | $this->expectException(NotFoundException::class); |
||
| 442 | |||
| 443 | // The location will not have been created, yet, so this throws an exception |
||
| 444 | $this->locationService->loadLocationByRemoteId('0123456789abcdef0123456789abcdef'); |
||
| 445 | } |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Test for the createContent() method. |
||
| 449 | * |
||
| 450 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 451 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 452 | */ |
||
| 453 | public function testCreateContentThrowsInvalidArgumentExceptionWithLocationCreateParameter() |
||
| 454 | { |
||
| 455 | $parentLocationId = $this->generateId('location', 56); |
||
| 456 | // $parentLocationId is a valid location ID |
||
| 457 | |||
| 458 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 459 | |||
| 460 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 461 | |||
| 462 | // Configure new locations |
||
| 463 | $locationCreate1 = $this->locationService->newLocationCreateStruct($parentLocationId); |
||
| 464 | |||
| 465 | $locationCreate1->priority = 23; |
||
| 466 | $locationCreate1->hidden = true; |
||
| 467 | $locationCreate1->remoteId = '0123456789abcdef0123456789aaaaaa'; |
||
| 468 | $locationCreate1->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 469 | $locationCreate1->sortOrder = Location::SORT_ORDER_DESC; |
||
| 470 | |||
| 471 | $locationCreate2 = $this->locationService->newLocationCreateStruct($parentLocationId); |
||
| 472 | |||
| 473 | $locationCreate2->priority = 42; |
||
| 474 | $locationCreate2->hidden = true; |
||
| 475 | $locationCreate2->remoteId = '0123456789abcdef0123456789bbbbbb'; |
||
| 476 | $locationCreate2->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 477 | $locationCreate2->sortOrder = Location::SORT_ORDER_DESC; |
||
| 478 | |||
| 479 | // Configure new content object |
||
| 480 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 481 | |||
| 482 | $contentCreate->setField('name', 'A awesome Sindelfingen forum'); |
||
| 483 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 484 | $contentCreate->alwaysAvailable = true; |
||
| 485 | |||
| 486 | // Create new content object under the specified location |
||
| 487 | $draft = $this->contentService->createContent( |
||
| 488 | $contentCreate, |
||
| 489 | [$locationCreate1] |
||
| 490 | ); |
||
| 491 | $this->contentService->publishVersion($draft->versionInfo); |
||
| 492 | |||
| 493 | $this->expectException(APIInvalidArgumentException::class); |
||
| 494 | // Content remoteId already exists, |
||
| 495 | $this->contentService->createContent( |
||
| 496 | $contentCreate, |
||
| 497 | [$locationCreate2] |
||
| 498 | ); |
||
| 499 | } |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Test for the loadContentInfo() method. |
||
| 503 | * |
||
| 504 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
||
| 505 | * @group user |
||
| 506 | */ |
||
| 507 | public function testLoadContentInfo() |
||
| 508 | { |
||
| 509 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 510 | |||
| 511 | // Load the ContentInfo for "Media" folder |
||
| 512 | $contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
||
| 513 | |||
| 514 | $this->assertInstanceOf(ContentInfo::class, $contentInfo); |
||
| 515 | |||
| 516 | return $contentInfo; |
||
| 517 | } |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Test for the returned value of the loadContentInfo() method. |
||
| 521 | * |
||
| 522 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 523 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfo |
||
| 524 | * |
||
| 525 | * @param ContentInfo $contentInfo |
||
| 526 | */ |
||
| 527 | public function testLoadContentInfoSetsExpectedContentInfo(ContentInfo $contentInfo) |
||
| 528 | { |
||
| 529 | $this->assertPropertiesCorrectUnsorted( |
||
| 530 | $this->getExpectedMediaContentInfoProperties(), |
||
| 531 | $contentInfo |
||
| 532 | ); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Test for the loadContentInfo() method. |
||
| 537 | * |
||
| 538 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
||
| 539 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 540 | */ |
||
| 541 | public function testLoadContentInfoThrowsNotFoundException() |
||
| 542 | { |
||
| 543 | $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
||
| 544 | |||
| 545 | |||
| 546 | $this->expectException(NotFoundException::class); |
||
| 547 | |||
| 548 | // This call will fail with a NotFoundException |
||
| 549 | $this->contentService->loadContentInfo($nonExistentContentId); |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Test for the loadContentInfoList() method. |
||
| 554 | * |
||
| 555 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
||
| 556 | */ |
||
| 557 | public function testLoadContentInfoList() |
||
| 558 | { |
||
| 559 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 560 | $list = $this->contentService->loadContentInfoList([$mediaFolderId]); |
||
| 561 | |||
| 562 | $this->assertCount(1, $list); |
||
| 563 | $this->assertEquals([$mediaFolderId], array_keys($list), 'Array key was not content id'); |
||
| 564 | $this->assertInstanceOf( |
||
| 565 | ContentInfo::class, |
||
| 566 | $list[$mediaFolderId] |
||
| 567 | ); |
||
| 568 | } |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Test for the loadContentInfoList() method. |
||
| 572 | * |
||
| 573 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
||
| 574 | * @depends testLoadContentInfoList |
||
| 575 | */ |
||
| 576 | public function testLoadContentInfoListSkipsNotFoundItems() |
||
| 577 | { |
||
| 578 | $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
||
| 579 | $list = $this->contentService->loadContentInfoList([$nonExistentContentId]); |
||
| 580 | |||
| 581 | $this->assertCount(0, $list); |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Test for the loadContentInfoByRemoteId() method. |
||
| 586 | * |
||
| 587 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
||
| 588 | */ |
||
| 589 | public function testLoadContentInfoByRemoteId() |
||
| 590 | { |
||
| 591 | // Load the ContentInfo for "Media" folder |
||
| 592 | $contentInfo = $this->contentService->loadContentInfoByRemoteId('faaeb9be3bd98ed09f606fc16d144eca'); |
||
| 593 | |||
| 594 | $this->assertInstanceOf(ContentInfo::class, $contentInfo); |
||
| 595 | |||
| 596 | return $contentInfo; |
||
| 597 | } |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Test for the returned value of the loadContentInfoByRemoteId() method. |
||
| 601 | * |
||
| 602 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
||
| 603 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId |
||
| 604 | * |
||
| 605 | * @param ContentInfo $contentInfo |
||
| 606 | */ |
||
| 607 | public function testLoadContentInfoByRemoteIdSetsExpectedContentInfo(ContentInfo $contentInfo) |
||
| 608 | { |
||
| 609 | $this->assertPropertiesCorrectUnsorted( |
||
| 610 | [ |
||
| 611 | 'id' => 10, |
||
| 612 | 'contentTypeId' => 4, |
||
| 613 | 'name' => 'Anonymous User', |
||
| 614 | 'sectionId' => 2, |
||
| 615 | 'currentVersionNo' => 2, |
||
| 616 | 'published' => true, |
||
| 617 | 'ownerId' => 14, |
||
| 618 | 'modificationDate' => $this->createDateTime(1072180405), |
||
| 619 | 'publishedDate' => $this->createDateTime(1033920665), |
||
| 620 | 'alwaysAvailable' => 1, |
||
| 621 | 'remoteId' => 'faaeb9be3bd98ed09f606fc16d144eca', |
||
| 622 | 'mainLanguageCode' => self::ENG_US, |
||
| 623 | 'mainLocationId' => 45, |
||
| 624 | ], |
||
| 625 | $contentInfo |
||
| 626 | ); |
||
| 627 | } |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Test for the loadContentInfoByRemoteId() method. |
||
| 631 | * |
||
| 632 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
||
| 633 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
||
| 634 | */ |
||
| 635 | public function testLoadContentInfoByRemoteIdThrowsNotFoundException() |
||
| 636 | { |
||
| 637 | $this->expectException(NotFoundException::class); |
||
| 638 | |||
| 639 | $this->contentService->loadContentInfoByRemoteId('abcdefghijklmnopqrstuvwxyz0123456789'); |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Test for the loadVersionInfo() method. |
||
| 644 | * |
||
| 645 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
||
| 646 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 647 | * @group user |
||
| 648 | */ |
||
| 649 | public function testLoadVersionInfo() |
||
| 650 | { |
||
| 651 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 652 | // $mediaFolderId contains the ID of the "Media" folder |
||
| 653 | |||
| 654 | // Load the ContentInfo for "Media" folder |
||
| 655 | $contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
||
| 656 | |||
| 657 | // Now load the current version info of the "Media" folder |
||
| 658 | $versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
||
| 659 | |||
| 660 | $this->assertInstanceOf( |
||
| 661 | VersionInfo::class, |
||
| 662 | $versionInfo |
||
| 663 | ); |
||
| 664 | } |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Test for the loadVersionInfoById() method. |
||
| 668 | * |
||
| 669 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
||
| 670 | */ |
||
| 671 | public function testLoadVersionInfoById() |
||
| 672 | { |
||
| 673 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 674 | // $mediaFolderId contains the ID of the "Media" folder |
||
| 675 | |||
| 676 | // Load the VersionInfo for "Media" folder |
||
| 677 | $versionInfo = $this->contentService->loadVersionInfoById($mediaFolderId); |
||
| 678 | |||
| 679 | $this->assertInstanceOf( |
||
| 680 | VersionInfo::class, |
||
| 681 | $versionInfo |
||
| 682 | ); |
||
| 683 | |||
| 684 | return $versionInfo; |
||
| 685 | } |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Test for the returned value of the loadVersionInfoById() method. |
||
| 689 | * |
||
| 690 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
||
| 691 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 692 | * |
||
| 693 | * @param VersionInfo $versionInfo |
||
| 694 | */ |
||
| 695 | public function testLoadVersionInfoByIdSetsExpectedVersionInfo(VersionInfo $versionInfo) |
||
| 696 | { |
||
| 697 | $this->assertPropertiesCorrect( |
||
| 698 | [ |
||
| 699 | 'names' => [ |
||
| 700 | self::ENG_US => 'Media', |
||
| 701 | ], |
||
| 702 | 'contentInfo' => new ContentInfo($this->getExpectedMediaContentInfoProperties()), |
||
| 703 | 'id' => 472, |
||
| 704 | 'versionNo' => 1, |
||
| 705 | 'modificationDate' => $this->createDateTime(1060695457), |
||
| 706 | 'creatorId' => 14, |
||
| 707 | 'creationDate' => $this->createDateTime(1060695450), |
||
| 708 | 'status' => VersionInfo::STATUS_PUBLISHED, |
||
| 709 | 'initialLanguageCode' => self::ENG_US, |
||
| 710 | 'languageCodes' => [ |
||
| 711 | self::ENG_US, |
||
| 712 | ], |
||
| 713 | ], |
||
| 714 | $versionInfo |
||
| 715 | ); |
||
| 716 | $this->assertTrue($versionInfo->isPublished()); |
||
| 717 | $this->assertFalse($versionInfo->isDraft()); |
||
| 718 | $this->assertFalse($versionInfo->isArchived()); |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Test for the loadVersionInfoById() method. |
||
| 723 | * |
||
| 724 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
||
| 725 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
||
| 726 | */ |
||
| 727 | public function testLoadVersionInfoByIdThrowsNotFoundException() |
||
| 728 | { |
||
| 729 | $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
||
| 730 | |||
| 731 | $this->expectException(NotFoundException::class); |
||
| 732 | |||
| 733 | $this->contentService->loadVersionInfoById($nonExistentContentId); |
||
| 734 | } |
||
| 735 | |||
| 736 | /** |
||
| 737 | * Test for the loadContentByContentInfo() method. |
||
| 738 | * |
||
| 739 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
||
| 740 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 741 | */ |
||
| 742 | public function testLoadContentByContentInfo() |
||
| 743 | { |
||
| 744 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 745 | // $mediaFolderId contains the ID of the "Media" folder |
||
| 746 | |||
| 747 | // Load the ContentInfo for "Media" folder |
||
| 748 | $contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
||
| 749 | |||
| 750 | // Now load the current content version for the info instance |
||
| 751 | $content = $this->contentService->loadContentByContentInfo($contentInfo); |
||
| 752 | |||
| 753 | $this->assertInstanceOf( |
||
| 754 | Content::class, |
||
| 755 | $content |
||
| 756 | ); |
||
| 757 | } |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Test for the loadContentByVersionInfo() method. |
||
| 761 | * |
||
| 762 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
||
| 763 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 764 | */ |
||
| 765 | public function testLoadContentByVersionInfo() |
||
| 766 | { |
||
| 767 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 768 | // $mediaFolderId contains the ID of the "Media" folder |
||
| 769 | |||
| 770 | // Load the ContentInfo for "Media" folder |
||
| 771 | $contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
||
| 772 | |||
| 773 | // Load the current VersionInfo |
||
| 774 | $versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
||
| 775 | |||
| 776 | // Now load the current content version for the info instance |
||
| 777 | $content = $this->contentService->loadContentByVersionInfo($versionInfo); |
||
| 778 | |||
| 779 | $this->assertInstanceOf( |
||
| 780 | Content::class, |
||
| 781 | $content |
||
| 782 | ); |
||
| 783 | } |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Test for the loadContent() method. |
||
| 787 | * |
||
| 788 | * @see \eZ\Publish\API\Repository\ContentService::loadContent() |
||
| 789 | * @group user |
||
| 790 | * @group field-type |
||
| 791 | */ |
||
| 792 | public function testLoadContent() |
||
| 793 | { |
||
| 794 | $mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
||
| 795 | // $mediaFolderId contains the ID of the "Media" folder |
||
| 796 | |||
| 797 | // Load the Content for "Media" folder, any language and current version |
||
| 798 | $content = $this->contentService->loadContent($mediaFolderId); |
||
| 799 | |||
| 800 | $this->assertInstanceOf( |
||
| 801 | Content::class, |
||
| 802 | $content |
||
| 803 | ); |
||
| 804 | } |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Test for the loadContent() method. |
||
| 808 | * |
||
| 809 | * @see \eZ\Publish\API\Repository\ContentService::loadContent() |
||
| 810 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 811 | */ |
||
| 812 | public function testLoadContentThrowsNotFoundException() |
||
| 813 | { |
||
| 814 | $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
||
| 815 | |||
| 816 | $this->expectException(NotFoundException::class); |
||
| 817 | |||
| 818 | $this->contentService->loadContent($nonExistentContentId); |
||
| 819 | } |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Data provider for testLoadContentByRemoteId(). |
||
| 823 | * |
||
| 824 | * @return array |
||
| 825 | */ |
||
| 826 | public function contentRemoteIdVersionLanguageProvider() |
||
| 827 | { |
||
| 828 | return [ |
||
| 829 | ['f5c88a2209584891056f987fd965b0ba', null, null], |
||
| 830 | ['f5c88a2209584891056f987fd965b0ba', [self::ENG_US], null], |
||
| 831 | ['f5c88a2209584891056f987fd965b0ba', null, 1], |
||
| 832 | ['f5c88a2209584891056f987fd965b0ba', [self::ENG_US], 1], |
||
| 833 | [self::MEDIA_REMOTE_ID, null, null], |
||
| 834 | [self::MEDIA_REMOTE_ID, [self::ENG_US], null], |
||
| 835 | [self::MEDIA_REMOTE_ID, null, 1], |
||
| 836 | [self::MEDIA_REMOTE_ID, [self::ENG_US], 1], |
||
| 837 | ]; |
||
| 838 | } |
||
| 839 | |||
| 840 | /** |
||
| 841 | * Test for the loadContentByRemoteId() method. |
||
| 842 | * |
||
| 843 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId |
||
| 844 | * @dataProvider contentRemoteIdVersionLanguageProvider |
||
| 845 | * |
||
| 846 | * @param string $remoteId |
||
| 847 | * @param array|null $languages |
||
| 848 | * @param int $versionNo |
||
| 849 | */ |
||
| 850 | public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 851 | { |
||
| 852 | $content = $this->contentService->loadContentByRemoteId($remoteId, $languages, $versionNo); |
||
| 853 | |||
| 854 | $this->assertInstanceOf( |
||
| 855 | Content::class, |
||
| 856 | $content |
||
| 857 | ); |
||
| 858 | |||
| 859 | $this->assertEquals($remoteId, $content->contentInfo->remoteId); |
||
| 860 | if ($languages !== null) { |
||
| 861 | $this->assertEquals($languages, $content->getVersionInfo()->languageCodes); |
||
| 862 | } |
||
| 863 | $this->assertEquals($versionNo ?: 1, $content->getVersionInfo()->versionNo); |
||
| 864 | } |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Test for the loadContentByRemoteId() method. |
||
| 868 | * |
||
| 869 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId() |
||
| 870 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
||
| 871 | */ |
||
| 872 | public function testLoadContentByRemoteIdThrowsNotFoundException() |
||
| 873 | { |
||
| 874 | $this->expectException(NotFoundException::class); |
||
| 875 | |||
| 876 | // This call will fail with a "NotFoundException", because no content object exists for the given remoteId |
||
| 877 | $this->contentService->loadContentByRemoteId('a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3'); |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Test for the publishVersion() method. |
||
| 882 | * |
||
| 883 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 884 | * |
||
| 885 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 886 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 887 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 888 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 889 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 890 | * @group user |
||
| 891 | * @group field-type |
||
| 892 | */ |
||
| 893 | public function testPublishVersion() |
||
| 894 | { |
||
| 895 | $time = time(); |
||
| 896 | $content = $this->createContentVersion1(); |
||
| 897 | |||
| 898 | $this->assertInstanceOf(Content::class, $content); |
||
| 899 | $this->assertTrue($content->contentInfo->published); |
||
| 900 | $this->assertEquals(VersionInfo::STATUS_PUBLISHED, $content->versionInfo->status); |
||
| 901 | $this->assertGreaterThanOrEqual($time, $content->contentInfo->publishedDate->getTimestamp()); |
||
| 902 | $this->assertGreaterThanOrEqual($time, $content->contentInfo->modificationDate->getTimestamp()); |
||
| 903 | $this->assertTrue($content->versionInfo->isPublished()); |
||
| 904 | $this->assertFalse($content->versionInfo->isDraft()); |
||
| 905 | $this->assertFalse($content->versionInfo->isArchived()); |
||
| 906 | |||
| 907 | return $content; |
||
| 908 | } |
||
| 909 | |||
| 910 | /** |
||
| 911 | * Test for the publishVersion() method. |
||
| 912 | * |
||
| 913 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 914 | * |
||
| 915 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 916 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 917 | */ |
||
| 918 | public function testPublishVersionSetsExpectedContentInfo($content) |
||
| 919 | { |
||
| 920 | $this->assertEquals( |
||
| 921 | [ |
||
| 922 | $content->id, |
||
| 923 | true, |
||
| 924 | 1, |
||
| 925 | 'abcdef0123456789abcdef0123456789', |
||
| 926 | self::ENG_US, |
||
| 927 | $this->getRepository()->getCurrentUser()->id, |
||
| 928 | true, |
||
| 929 | ], |
||
| 930 | [ |
||
| 931 | $content->contentInfo->id, |
||
| 932 | $content->contentInfo->alwaysAvailable, |
||
| 933 | $content->contentInfo->currentVersionNo, |
||
| 934 | $content->contentInfo->remoteId, |
||
| 935 | $content->contentInfo->mainLanguageCode, |
||
| 936 | $content->contentInfo->ownerId, |
||
| 937 | $content->contentInfo->published, |
||
| 938 | ] |
||
| 939 | ); |
||
| 940 | |||
| 941 | $this->assertNotNull($content->contentInfo->mainLocationId); |
||
| 942 | $date = new \DateTime('1984/01/01'); |
||
| 943 | $this->assertGreaterThan( |
||
| 944 | $date->getTimestamp(), |
||
| 945 | $content->contentInfo->publishedDate->getTimestamp() |
||
| 946 | ); |
||
| 947 | } |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Test for the publishVersion() method. |
||
| 951 | * |
||
| 952 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 953 | * |
||
| 954 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 955 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 956 | */ |
||
| 957 | public function testPublishVersionSetsExpectedVersionInfo($content) |
||
| 958 | { |
||
| 959 | $this->assertEquals( |
||
| 960 | [ |
||
| 961 | $this->getRepository()->getCurrentUser()->id, |
||
| 962 | self::ENG_US, |
||
| 963 | VersionInfo::STATUS_PUBLISHED, |
||
| 964 | 1, |
||
| 965 | ], |
||
| 966 | [ |
||
| 967 | $content->getVersionInfo()->creatorId, |
||
| 968 | $content->getVersionInfo()->initialLanguageCode, |
||
| 969 | $content->getVersionInfo()->status, |
||
| 970 | $content->getVersionInfo()->versionNo, |
||
| 971 | ] |
||
| 972 | ); |
||
| 973 | |||
| 974 | $date = new \DateTime('1984/01/01'); |
||
| 975 | $this->assertGreaterThan( |
||
| 976 | $date->getTimestamp(), |
||
| 977 | $content->getVersionInfo()->modificationDate->getTimestamp() |
||
| 978 | ); |
||
| 979 | |||
| 980 | $this->assertNotNull($content->getVersionInfo()->modificationDate); |
||
| 981 | $this->assertTrue($content->getVersionInfo()->isPublished()); |
||
| 982 | $this->assertFalse($content->getVersionInfo()->isDraft()); |
||
| 983 | $this->assertFalse($content->getVersionInfo()->isArchived()); |
||
| 984 | } |
||
| 985 | |||
| 986 | /** |
||
| 987 | * Test for the publishVersion() method. |
||
| 988 | * |
||
| 989 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 990 | * |
||
| 991 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 992 | * @depends testPublishVersion |
||
| 993 | */ |
||
| 994 | public function testPublishVersionSetsExpectedContentType($content) |
||
| 995 | { |
||
| 996 | $contentType = $content->getContentType(); |
||
| 997 | |||
| 998 | $this->assertEquals( |
||
| 999 | [ |
||
| 1000 | $contentType->id, |
||
| 1001 | // won't be a match as it's set to true in createContentDraftVersion1() |
||
| 1002 | //$contentType->defaultAlwaysAvailable, |
||
| 1003 | //$contentType->defaultSortField, |
||
| 1004 | //$contentType->defaultSortOrder, |
||
| 1005 | ], |
||
| 1006 | [ |
||
| 1007 | $content->contentInfo->contentTypeId, |
||
| 1008 | //$content->contentInfo->alwaysAvailable, |
||
| 1009 | //$location->sortField, |
||
| 1010 | //$location->sortOrder, |
||
| 1011 | ] |
||
| 1012 | ); |
||
| 1013 | } |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Test for the publishVersion() method. |
||
| 1017 | * |
||
| 1018 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1019 | * |
||
| 1020 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1021 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 1022 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1023 | */ |
||
| 1024 | public function testPublishVersionCreatesLocationsDefinedOnCreate() |
||
| 1025 | { |
||
| 1026 | $content = $this->createContentVersion1(); |
||
| 1027 | |||
| 1028 | $location = $this->locationService->loadLocationByRemoteId( |
||
| 1029 | '0123456789abcdef0123456789abcdef' |
||
| 1030 | ); |
||
| 1031 | |||
| 1032 | $this->assertEquals( |
||
| 1033 | $location->getContentInfo(), |
||
| 1034 | $content->getVersionInfo()->getContentInfo() |
||
| 1035 | ); |
||
| 1036 | |||
| 1037 | return [$content, $location]; |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * Test for the publishVersion() method. |
||
| 1042 | * |
||
| 1043 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1044 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionCreatesLocationsDefinedOnCreate |
||
| 1045 | */ |
||
| 1046 | public function testCreateContentWithLocationCreateParameterCreatesExpectedLocation(array $testData) |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Test for the publishVersion() method. |
||
| 1075 | * |
||
| 1076 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1077 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1078 | */ |
||
| 1079 | public function testPublishVersionThrowsBadStateException() |
||
| 1080 | { |
||
| 1081 | $draft = $this->createContentDraftVersion1(); |
||
| 1082 | |||
| 1083 | // Publish the content draft |
||
| 1084 | $this->contentService->publishVersion($draft->getVersionInfo()); |
||
| 1085 | |||
| 1086 | $this->expectException(BadStateException::class); |
||
| 1087 | |||
| 1088 | // This call will fail with a "BadStateException", because the version is already published. |
||
| 1089 | $this->contentService->publishVersion($draft->getVersionInfo()); |
||
| 1090 | } |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Test that publishVersion() does not affect publishedDate (assuming previous version exists). |
||
| 1094 | * |
||
| 1095 | * @covers \eZ\Publish\API\Repository\ContentService::publishVersion |
||
| 1096 | */ |
||
| 1097 | public function testPublishVersionDoesNotChangePublishedDate() |
||
| 1098 | { |
||
| 1099 | $publishedContent = $this->createContentVersion1(); |
||
| 1100 | |||
| 1101 | // force timestamps to differ |
||
| 1102 | sleep(1); |
||
| 1103 | |||
| 1104 | $contentDraft = $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 1105 | $contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1106 | $contentUpdateStruct->setField('name', 'New name'); |
||
| 1107 | $contentDraft = $this->contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct); |
||
| 1108 | $republishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
||
| 1109 | |||
| 1110 | $this->assertEquals( |
||
| 1111 | $publishedContent->contentInfo->publishedDate->getTimestamp(), |
||
| 1112 | $republishedContent->contentInfo->publishedDate->getTimestamp() |
||
| 1113 | ); |
||
| 1114 | $this->assertGreaterThan( |
||
| 1115 | $publishedContent->contentInfo->modificationDate->getTimestamp(), |
||
| 1116 | $republishedContent->contentInfo->modificationDate->getTimestamp() |
||
| 1117 | ); |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Test for the createContentDraft() method. |
||
| 1122 | * |
||
| 1123 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1124 | * |
||
| 1125 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1126 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1127 | * @group user |
||
| 1128 | */ |
||
| 1129 | public function testCreateContentDraft() |
||
| 1130 | { |
||
| 1131 | $content = $this->createContentVersion1(); |
||
| 1132 | |||
| 1133 | // Now we create a new draft from the published content |
||
| 1134 | $draftedContent = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1135 | |||
| 1136 | $this->assertInstanceOf( |
||
| 1137 | Content::class, |
||
| 1138 | $draftedContent |
||
| 1139 | ); |
||
| 1140 | |||
| 1141 | return $draftedContent; |
||
| 1142 | } |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * Test for the createContentDraft() method. |
||
| 1146 | * |
||
| 1147 | * Test that editor has access to edit own draft. |
||
| 1148 | * Note: Editors have access to version_read, which is needed to load content drafts. |
||
| 1149 | * |
||
| 1150 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1151 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1152 | * @group user |
||
| 1153 | */ |
||
| 1154 | public function testCreateContentDraftAndLoadAccess() |
||
| 1155 | { |
||
| 1156 | $user = $this->createUserVersion1(); |
||
| 1157 | |||
| 1158 | // Set new editor as user |
||
| 1159 | $this->permissionResolver->setCurrentUserReference($user); |
||
| 1160 | |||
| 1161 | // Create draft |
||
| 1162 | $draft = $this->createContentDraftVersion1(2, 'folder'); |
||
| 1163 | |||
| 1164 | // Try to load the draft |
||
| 1165 | $loadedDraft = $this->contentService->loadContent($draft->id); |
||
| 1166 | |||
| 1167 | $this->assertEquals($draft->id, $loadedDraft->id); |
||
| 1168 | } |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Test for the createContentDraft() method. |
||
| 1172 | * |
||
| 1173 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1174 | * |
||
| 1175 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1176 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1177 | */ |
||
| 1178 | public function testCreateContentDraftSetsExpectedProperties($draft) |
||
| 1179 | { |
||
| 1180 | $this->assertEquals( |
||
| 1181 | [ |
||
| 1182 | 'fieldCount' => 2, |
||
| 1183 | 'relationCount' => 0, |
||
| 1184 | ], |
||
| 1185 | [ |
||
| 1186 | 'fieldCount' => count($draft->getFields()), |
||
| 1187 | 'relationCount' => count($this->getRepository()->getContentService()->loadRelations($draft->getVersionInfo())), |
||
| 1188 | ] |
||
| 1189 | ); |
||
| 1190 | } |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Test for the createContentDraft() method. |
||
| 1194 | * |
||
| 1195 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1196 | * |
||
| 1197 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1198 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1199 | */ |
||
| 1200 | public function testCreateContentDraftSetsContentInfo($draft) |
||
| 1201 | { |
||
| 1202 | $contentInfo = $draft->contentInfo; |
||
| 1203 | |||
| 1204 | $this->assertEquals( |
||
| 1205 | [ |
||
| 1206 | $draft->id, |
||
| 1207 | true, |
||
| 1208 | 1, |
||
| 1209 | self::ENG_US, |
||
| 1210 | $this->getRepository()->getCurrentUser()->id, |
||
| 1211 | 'abcdef0123456789abcdef0123456789', |
||
| 1212 | 1, |
||
| 1213 | ], |
||
| 1214 | [ |
||
| 1215 | $contentInfo->id, |
||
| 1216 | $contentInfo->alwaysAvailable, |
||
| 1217 | $contentInfo->currentVersionNo, |
||
| 1218 | $contentInfo->mainLanguageCode, |
||
| 1219 | $contentInfo->ownerId, |
||
| 1220 | $contentInfo->remoteId, |
||
| 1221 | $contentInfo->sectionId, |
||
| 1222 | ] |
||
| 1223 | ); |
||
| 1224 | } |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Test for the createContentDraft() method. |
||
| 1228 | * |
||
| 1229 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1230 | * |
||
| 1231 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1232 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1233 | */ |
||
| 1234 | public function testCreateContentDraftSetsVersionInfo($draft) |
||
| 1235 | { |
||
| 1236 | $versionInfo = $draft->getVersionInfo(); |
||
| 1237 | |||
| 1238 | $this->assertEquals( |
||
| 1239 | [ |
||
| 1240 | 'creatorId' => $this->getRepository()->getCurrentUser()->id, |
||
| 1241 | 'initialLanguageCode' => self::ENG_US, |
||
| 1242 | 'languageCodes' => [0 => self::ENG_US], |
||
| 1243 | 'status' => VersionInfo::STATUS_DRAFT, |
||
| 1244 | 'versionNo' => 2, |
||
| 1245 | ], |
||
| 1246 | [ |
||
| 1247 | 'creatorId' => $versionInfo->creatorId, |
||
| 1248 | 'initialLanguageCode' => $versionInfo->initialLanguageCode, |
||
| 1249 | 'languageCodes' => $versionInfo->languageCodes, |
||
| 1250 | 'status' => $versionInfo->status, |
||
| 1251 | 'versionNo' => $versionInfo->versionNo, |
||
| 1252 | ] |
||
| 1253 | ); |
||
| 1254 | $this->assertTrue($versionInfo->isDraft()); |
||
| 1255 | $this->assertFalse($versionInfo->isPublished()); |
||
| 1256 | $this->assertFalse($versionInfo->isArchived()); |
||
| 1257 | } |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Test for the createContentDraft() method. |
||
| 1261 | * |
||
| 1262 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1263 | * |
||
| 1264 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1265 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1266 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 1267 | */ |
||
| 1268 | public function testCreateContentDraftLoadVersionInfoStillLoadsPublishedVersion($draft) |
||
| 1269 | { |
||
| 1270 | $content = $this->createContentVersion1(); |
||
| 1271 | |||
| 1272 | // Now we create a new draft from the published content |
||
| 1273 | $this->contentService->createContentDraft($content->contentInfo); |
||
| 1274 | |||
| 1275 | // This call will still load the published version |
||
| 1276 | $versionInfoPublished = $this->contentService->loadVersionInfo($content->contentInfo); |
||
| 1277 | |||
| 1278 | $this->assertEquals(1, $versionInfoPublished->versionNo); |
||
| 1279 | } |
||
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Test for the createContentDraft() method. |
||
| 1283 | * |
||
| 1284 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1285 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 1286 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1287 | */ |
||
| 1288 | public function testCreateContentDraftLoadContentStillLoadsPublishedVersion() |
||
| 1289 | { |
||
| 1290 | $content = $this->createContentVersion1(); |
||
| 1291 | |||
| 1292 | // Now we create a new draft from the published content |
||
| 1293 | $this->contentService->createContentDraft($content->contentInfo); |
||
| 1294 | |||
| 1295 | // This call will still load the published content version |
||
| 1296 | $contentPublished = $this->contentService->loadContent($content->id); |
||
| 1297 | |||
| 1298 | $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
||
| 1299 | } |
||
| 1300 | |||
| 1301 | /** |
||
| 1302 | * Test for the createContentDraft() method. |
||
| 1303 | * |
||
| 1304 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1305 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
||
| 1306 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1307 | */ |
||
| 1308 | public function testCreateContentDraftLoadContentByRemoteIdStillLoadsPublishedVersion() |
||
| 1309 | { |
||
| 1310 | $content = $this->createContentVersion1(); |
||
| 1311 | |||
| 1312 | // Now we create a new draft from the published content |
||
| 1313 | $this->contentService->createContentDraft($content->contentInfo); |
||
| 1314 | |||
| 1315 | // This call will still load the published content version |
||
| 1316 | $contentPublished = $this->contentService->loadContentByRemoteId('abcdef0123456789abcdef0123456789'); |
||
| 1317 | |||
| 1318 | $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
||
| 1319 | } |
||
| 1320 | |||
| 1321 | /** |
||
| 1322 | * Test for the createContentDraft() method. |
||
| 1323 | * |
||
| 1324 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1325 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 1326 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1327 | */ |
||
| 1328 | public function testCreateContentDraftLoadContentByContentInfoStillLoadsPublishedVersion() |
||
| 1329 | { |
||
| 1330 | $content = $this->createContentVersion1(); |
||
| 1331 | |||
| 1332 | // Now we create a new draft from the published content |
||
| 1333 | $this->contentService->createContentDraft($content->contentInfo); |
||
| 1334 | |||
| 1335 | // This call will still load the published content version |
||
| 1336 | $contentPublished = $this->contentService->loadContentByContentInfo($content->contentInfo); |
||
| 1337 | |||
| 1338 | $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Test for the newContentUpdateStruct() method. |
||
| 1343 | * |
||
| 1344 | * @covers \eZ\Publish\API\Repository\ContentService::newContentUpdateStruct |
||
| 1345 | * @group user |
||
| 1346 | */ |
||
| 1347 | public function testNewContentUpdateStruct() |
||
| 1348 | { |
||
| 1349 | $updateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1350 | |||
| 1351 | $this->assertInstanceOf( |
||
| 1352 | ContentUpdateStruct::class, |
||
| 1353 | $updateStruct |
||
| 1354 | ); |
||
| 1355 | |||
| 1356 | $this->assertPropertiesCorrect( |
||
| 1357 | [ |
||
| 1358 | 'initialLanguageCode' => null, |
||
| 1359 | 'fields' => [], |
||
| 1360 | ], |
||
| 1361 | $updateStruct |
||
| 1362 | ); |
||
| 1363 | } |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Test for the updateContent() method. |
||
| 1367 | * |
||
| 1368 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1369 | * |
||
| 1370 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1371 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
||
| 1372 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1373 | * @group user |
||
| 1374 | * @group field-type |
||
| 1375 | */ |
||
| 1376 | public function testUpdateContent() |
||
| 1377 | { |
||
| 1378 | $draftVersion2 = $this->createUpdatedDraftVersion2(); |
||
| 1379 | |||
| 1380 | $this->assertInstanceOf( |
||
| 1381 | Content::class, |
||
| 1382 | $draftVersion2 |
||
| 1383 | ); |
||
| 1384 | |||
| 1385 | $this->assertEquals( |
||
| 1386 | $this->generateId('user', 10), |
||
| 1387 | $draftVersion2->versionInfo->creatorId, |
||
| 1388 | 'creatorId is not properly set on new Version' |
||
| 1389 | ); |
||
| 1390 | |||
| 1391 | return $draftVersion2; |
||
| 1392 | } |
||
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Test for the updateContent_WithDifferentUser() method. |
||
| 1396 | * |
||
| 1397 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1398 | * |
||
| 1399 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1400 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
||
| 1401 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1402 | * @group user |
||
| 1403 | * @group field-type |
||
| 1404 | */ |
||
| 1405 | public function testUpdateContentWithDifferentUser() |
||
| 1406 | { |
||
| 1407 | $arrayWithDraftVersion2 = $this->createUpdatedDraftVersion2NotAdmin(); |
||
| 1408 | |||
| 1409 | $this->assertInstanceOf( |
||
| 1410 | Content::class, |
||
| 1411 | $arrayWithDraftVersion2[0] |
||
| 1412 | ); |
||
| 1413 | |||
| 1414 | $this->assertEquals( |
||
| 1415 | $this->generateId('user', $arrayWithDraftVersion2[1]), |
||
| 1416 | $arrayWithDraftVersion2[0]->versionInfo->creatorId, |
||
| 1417 | 'creatorId is not properly set on new Version' |
||
| 1418 | ); |
||
| 1419 | |||
| 1420 | return $arrayWithDraftVersion2[0]; |
||
| 1421 | } |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Test for the updateContent() method. |
||
| 1425 | * |
||
| 1426 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1427 | * |
||
| 1428 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1429 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1430 | */ |
||
| 1431 | public function testUpdateContentSetsExpectedFields($content) |
||
| 1432 | { |
||
| 1433 | $actual = $this->normalizeFields($content->getFields()); |
||
| 1434 | |||
| 1435 | $expected = [ |
||
| 1436 | new Field( |
||
| 1437 | [ |
||
| 1438 | 'id' => 0, |
||
| 1439 | 'value' => true, |
||
| 1440 | 'languageCode' => self::ENG_GB, |
||
| 1441 | 'fieldDefIdentifier' => 'description', |
||
| 1442 | 'fieldTypeIdentifier' => 'ezrichtext', |
||
| 1443 | ] |
||
| 1444 | ), |
||
| 1445 | new Field( |
||
| 1446 | [ |
||
| 1447 | 'id' => 0, |
||
| 1448 | 'value' => true, |
||
| 1449 | 'languageCode' => self::ENG_US, |
||
| 1450 | 'fieldDefIdentifier' => 'description', |
||
| 1451 | 'fieldTypeIdentifier' => 'ezrichtext', |
||
| 1452 | ] |
||
| 1453 | ), |
||
| 1454 | new Field( |
||
| 1455 | [ |
||
| 1456 | 'id' => 0, |
||
| 1457 | 'value' => true, |
||
| 1458 | 'languageCode' => self::ENG_GB, |
||
| 1459 | 'fieldDefIdentifier' => 'name', |
||
| 1460 | 'fieldTypeIdentifier' => 'ezstring', |
||
| 1461 | ] |
||
| 1462 | ), |
||
| 1463 | new Field( |
||
| 1464 | [ |
||
| 1465 | 'id' => 0, |
||
| 1466 | 'value' => true, |
||
| 1467 | 'languageCode' => self::ENG_US, |
||
| 1468 | 'fieldDefIdentifier' => 'name', |
||
| 1469 | 'fieldTypeIdentifier' => 'ezstring', |
||
| 1470 | ] |
||
| 1471 | ), |
||
| 1472 | ]; |
||
| 1473 | |||
| 1474 | $this->assertEquals($expected, $actual); |
||
| 1475 | } |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Test for the updateContent() method. |
||
| 1479 | * |
||
| 1480 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1481 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1482 | */ |
||
| 1483 | public function testUpdateContentThrowsBadStateException() |
||
| 1484 | { |
||
| 1485 | $content = $this->createContentVersion1(); |
||
| 1486 | |||
| 1487 | // Now create an update struct and modify some fields |
||
| 1488 | $contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1489 | $contentUpdateStruct->setField('title', 'An awesome² story about ezp.'); |
||
| 1490 | $contentUpdateStruct->setField('title', 'An awesome²³ story about ezp.', self::ENG_GB); |
||
| 1491 | |||
| 1492 | $contentUpdateStruct->initialLanguageCode = self::ENG_US; |
||
| 1493 | |||
| 1494 | $this->expectException(BadStateException::class); |
||
| 1495 | |||
| 1496 | // This call will fail with a "BadStateException", because $publishedContent is not a draft. |
||
| 1497 | $this->contentService->updateContent( |
||
| 1498 | $content->getVersionInfo(), |
||
| 1499 | $contentUpdateStruct |
||
| 1500 | ); |
||
| 1501 | } |
||
| 1502 | |||
| 1503 | /** |
||
| 1504 | * Test for the updateContent() method. |
||
| 1505 | * |
||
| 1506 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1507 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1508 | */ |
||
| 1509 | public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept() |
||
| 1510 | { |
||
| 1511 | $draft = $this->createContentDraftVersion1(); |
||
| 1512 | |||
| 1513 | // Now create an update struct and modify some fields |
||
| 1514 | $contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1515 | // The name field does not accept a stdClass object as its input |
||
| 1516 | $contentUpdateStruct->setField('name', new \stdClass(), self::ENG_US); |
||
| 1517 | |||
| 1518 | $this->expectException(APIInvalidArgumentException::class); |
||
| 1519 | // is not accepted |
||
| 1520 | $this->contentService->updateContent( |
||
| 1521 | $draft->getVersionInfo(), |
||
| 1522 | $contentUpdateStruct |
||
| 1523 | ); |
||
| 1524 | } |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Test for the updateContent() method. |
||
| 1528 | * |
||
| 1529 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1530 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1531 | */ |
||
| 1532 | public function testUpdateContentWhenMandatoryFieldIsEmpty() |
||
| 1533 | { |
||
| 1534 | $draft = $this->createContentDraftVersion1(); |
||
| 1535 | |||
| 1536 | // Now create an update struct and set a mandatory field to null |
||
| 1537 | $contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1538 | $contentUpdateStruct->setField('name', null); |
||
| 1539 | |||
| 1540 | // Don't set this, then the above call without languageCode will fail |
||
| 1541 | $contentUpdateStruct->initialLanguageCode = self::ENG_US; |
||
| 1542 | |||
| 1543 | $this->expectException(ContentFieldValidationException::class); |
||
| 1544 | |||
| 1545 | // This call will fail with a "ContentFieldValidationException", because the mandatory "name" field is empty. |
||
| 1546 | $this->contentService->updateContent( |
||
| 1547 | $draft->getVersionInfo(), |
||
| 1548 | $contentUpdateStruct |
||
| 1549 | ); |
||
| 1550 | } |
||
| 1551 | |||
| 1552 | /** |
||
| 1553 | * Test for the updateContent() method. |
||
| 1554 | * |
||
| 1555 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1556 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1557 | */ |
||
| 1558 | public function testUpdateContentThrowsContentFieldValidationException() |
||
| 1559 | { |
||
| 1560 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 1561 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
||
| 1562 | |||
| 1563 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 1564 | $contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
||
| 1565 | |||
| 1566 | $draft = $this->contentService->createContent($contentCreate); |
||
| 1567 | |||
| 1568 | $contentUpdate = $this->contentService->newContentUpdateStruct(); |
||
| 1569 | // Violates string length constraint |
||
| 1570 | $contentUpdate->setField('short_name', str_repeat('a', 200), self::ENG_US); |
||
| 1571 | |||
| 1572 | $this->expectException(ContentFieldValidationException::class); |
||
| 1573 | |||
| 1574 | // Throws ContentFieldValidationException because the string length validation of the field "short_name" fails |
||
| 1575 | $this->contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
||
| 1576 | } |
||
| 1577 | |||
| 1578 | /** |
||
| 1579 | * Test for the updateContent() method. |
||
| 1580 | * |
||
| 1581 | * @covers \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1582 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1583 | */ |
||
| 1584 | public function testUpdateContentValidatorIgnoresRequiredFieldsOfNotUpdatedLanguages() |
||
| 1585 | { |
||
| 1586 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 1587 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
||
| 1588 | |||
| 1589 | // Create multilangual content |
||
| 1590 | $contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 1591 | $contentCreate->setField('name', 'An awesome Sidelfingen folder', self::ENG_US); |
||
| 1592 | $contentCreate->setField('name', 'An awesome Sidelfingen folder', self::ENG_GB); |
||
| 1593 | |||
| 1594 | $contentDraft = $this->contentService->createContent($contentCreate); |
||
| 1595 | |||
| 1596 | // 2. Update content type definition |
||
| 1597 | $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType); |
||
| 1598 | |||
| 1599 | $fieldDefinition = $contentType->getFieldDefinition('description'); |
||
| 1600 | $fieldDefinitionUpdate = $contentTypeService->newFieldDefinitionUpdateStruct(); |
||
| 1601 | $fieldDefinitionUpdate->identifier = 'description'; |
||
| 1602 | $fieldDefinitionUpdate->isRequired = true; |
||
| 1603 | |||
| 1604 | $contentTypeService->updateFieldDefinition( |
||
| 1605 | $contentTypeDraft, |
||
| 1606 | $fieldDefinition, |
||
| 1607 | $fieldDefinitionUpdate |
||
| 1608 | ); |
||
| 1609 | $contentTypeService->publishContentTypeDraft($contentTypeDraft); |
||
| 1610 | |||
| 1611 | // 3. Update only eng-US translation |
||
| 1612 | $description = new DOMDocument(); |
||
| 1613 | $description->loadXML(<<<XML |
||
| 1614 | <?xml version="1.0" encoding="UTF-8"?> |
||
| 1615 | <section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"> |
||
| 1616 | <para>Lorem ipsum dolor</para> |
||
| 1617 | </section> |
||
| 1618 | XML |
||
| 1619 | ); |
||
| 1620 | |||
| 1621 | $contentUpdate = $this->contentService->newContentUpdateStruct(); |
||
| 1622 | $contentUpdate->setField('name', 'An awesome Sidelfingen folder (updated)', self::ENG_US); |
||
| 1623 | $contentUpdate->setField('description', $description); |
||
| 1624 | |||
| 1625 | $this->contentService->updateContent($contentDraft->getVersionInfo(), $contentUpdate); |
||
| 1626 | } |
||
| 1627 | |||
| 1628 | /** |
||
| 1629 | * Test for the updateContent() method. |
||
| 1630 | * |
||
| 1631 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1632 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1633 | */ |
||
| 1634 | public function testUpdateContentWithNotUpdatingMandatoryField() |
||
| 1635 | { |
||
| 1636 | $draft = $this->createContentDraftVersion1(); |
||
| 1637 | |||
| 1638 | // Now create an update struct which does not overwrite mandatory |
||
| 1639 | // fields |
||
| 1640 | $contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
||
| 1641 | $contentUpdateStruct->setField( |
||
| 1642 | 'description', |
||
| 1643 | '<?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0"/>' |
||
| 1644 | ); |
||
| 1645 | |||
| 1646 | // Don't set this, then the above call without languageCode will fail |
||
| 1647 | $contentUpdateStruct->initialLanguageCode = self::ENG_US; |
||
| 1648 | |||
| 1649 | // This will only update the "description" field in the "eng-US" language |
||
| 1650 | $updatedDraft = $this->contentService->updateContent( |
||
| 1651 | $draft->getVersionInfo(), |
||
| 1652 | $contentUpdateStruct |
||
| 1653 | ); |
||
| 1654 | |||
| 1655 | foreach ($updatedDraft->getFields() as $field) { |
||
| 1656 | if ($field->languageCode === self::ENG_US && $field->fieldDefIdentifier === 'name' && $field->value !== null) { |
||
| 1657 | // Found field |
||
| 1658 | return; |
||
| 1659 | } |
||
| 1660 | } |
||
| 1661 | $this->fail( |
||
| 1662 | 'Field with identifier "name" in language "eng-US" could not be found or has empty value.' |
||
| 1663 | ); |
||
| 1664 | } |
||
| 1665 | |||
| 1666 | /** |
||
| 1667 | * Test for the createContentDraft() method. |
||
| 1668 | * |
||
| 1669 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
||
| 1670 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1671 | */ |
||
| 1672 | public function testCreateContentDraftWithSecondParameter() |
||
| 1673 | { |
||
| 1674 | $contentVersion2 = $this->createContentVersion2(); |
||
| 1675 | |||
| 1676 | // Now we create a new draft from the initial version |
||
| 1677 | $draftedContentReloaded = $this->contentService->createContentDraft( |
||
| 1678 | $contentVersion2->contentInfo, |
||
| 1679 | $contentVersion2->getVersionInfo() |
||
| 1680 | ); |
||
| 1681 | |||
| 1682 | $this->assertEquals(3, $draftedContentReloaded->getVersionInfo()->versionNo); |
||
| 1683 | } |
||
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Test for the createContentDraft() method with third parameter. |
||
| 1687 | * |
||
| 1688 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1689 | */ |
||
| 1690 | public function testCreateContentDraftWithThirdParameter() |
||
| 1691 | { |
||
| 1692 | $content = $this->contentService->loadContent(4); |
||
| 1693 | $user = $this->createUserVersion1(); |
||
| 1694 | |||
| 1695 | $draftContent = $this->contentService->createContentDraft( |
||
| 1696 | $content->contentInfo, |
||
| 1697 | $content->getVersionInfo(), |
||
| 1698 | $user |
||
| 1699 | ); |
||
| 1700 | |||
| 1701 | $this->assertInstanceOf( |
||
| 1702 | Content::class, |
||
| 1703 | $draftContent |
||
| 1704 | ); |
||
| 1705 | } |
||
| 1706 | |||
| 1707 | /** |
||
| 1708 | * Test for the publishVersion() method. |
||
| 1709 | * |
||
| 1710 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1711 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1712 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1713 | */ |
||
| 1714 | public function testPublishVersionFromContentDraft() |
||
| 1715 | { |
||
| 1716 | $contentVersion2 = $this->createContentVersion2(); |
||
| 1717 | |||
| 1718 | $versionInfo = $this->contentService->loadVersionInfo($contentVersion2->contentInfo); |
||
| 1719 | |||
| 1720 | $this->assertEquals( |
||
| 1721 | [ |
||
| 1722 | 'status' => VersionInfo::STATUS_PUBLISHED, |
||
| 1723 | 'versionNo' => 2, |
||
| 1724 | ], |
||
| 1725 | [ |
||
| 1726 | 'status' => $versionInfo->status, |
||
| 1727 | 'versionNo' => $versionInfo->versionNo, |
||
| 1728 | ] |
||
| 1729 | ); |
||
| 1730 | $this->assertTrue($versionInfo->isPublished()); |
||
| 1731 | $this->assertFalse($versionInfo->isDraft()); |
||
| 1732 | $this->assertFalse($versionInfo->isArchived()); |
||
| 1733 | } |
||
| 1734 | |||
| 1735 | /** |
||
| 1736 | * Test for the publishVersion() method. |
||
| 1737 | * |
||
| 1738 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1739 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1740 | */ |
||
| 1741 | public function testPublishVersionFromContentDraftArchivesOldVersion() |
||
| 1742 | { |
||
| 1743 | $contentVersion2 = $this->createContentVersion2(); |
||
| 1744 | |||
| 1745 | $versionInfo = $this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1); |
||
| 1746 | |||
| 1747 | $this->assertEquals( |
||
| 1748 | [ |
||
| 1749 | 'status' => VersionInfo::STATUS_ARCHIVED, |
||
| 1750 | 'versionNo' => 1, |
||
| 1751 | ], |
||
| 1752 | [ |
||
| 1753 | 'status' => $versionInfo->status, |
||
| 1754 | 'versionNo' => $versionInfo->versionNo, |
||
| 1755 | ] |
||
| 1756 | ); |
||
| 1757 | $this->assertTrue($versionInfo->isArchived()); |
||
| 1758 | $this->assertFalse($versionInfo->isDraft()); |
||
| 1759 | $this->assertFalse($versionInfo->isPublished()); |
||
| 1760 | } |
||
| 1761 | |||
| 1762 | /** |
||
| 1763 | * Test for the publishVersion() method. |
||
| 1764 | * |
||
| 1765 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1766 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1767 | */ |
||
| 1768 | public function testPublishVersionFromContentDraftUpdatesContentInfoCurrentVersion() |
||
| 1769 | { |
||
| 1770 | $contentVersion2 = $this->createContentVersion2(); |
||
| 1771 | |||
| 1772 | $this->assertEquals(2, $contentVersion2->contentInfo->currentVersionNo); |
||
| 1773 | } |
||
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Test for the publishVersion() method. |
||
| 1777 | * |
||
| 1778 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1779 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1780 | */ |
||
| 1781 | public function testPublishVersionFromOldContentDraftArchivesNewerVersionNo() |
||
| 1782 | { |
||
| 1783 | $content = $this->createContentVersion1(); |
||
| 1784 | |||
| 1785 | // Create a new draft with versionNo = 2 |
||
| 1786 | $draftedContentVersion2 = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1787 | |||
| 1788 | // Create another new draft with versionNo = 3 |
||
| 1789 | $draftedContentVersion3 = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1790 | |||
| 1791 | // Publish draft with versionNo = 3 |
||
| 1792 | $this->contentService->publishVersion($draftedContentVersion3->getVersionInfo()); |
||
| 1793 | |||
| 1794 | // Publish the first draft with versionNo = 2 |
||
| 1795 | // currentVersionNo is now 2, versionNo 3 will be archived |
||
| 1796 | $publishedDraft = $this->contentService->publishVersion($draftedContentVersion2->getVersionInfo()); |
||
| 1797 | |||
| 1798 | $this->assertEquals(2, $publishedDraft->contentInfo->currentVersionNo); |
||
| 1799 | } |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * Test for the publishVersion() method, and that it creates limited archives. |
||
| 1803 | * |
||
| 1804 | * @todo Adapt this when per content type archive limited is added on repository Content Type model. |
||
| 1805 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1806 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1807 | */ |
||
| 1808 | public function testPublishVersionNotCreatingUnlimitedArchives() |
||
| 1809 | { |
||
| 1810 | $content = $this->createContentVersion1(); |
||
| 1811 | |||
| 1812 | // load first to make sure list gets updated also (cache) |
||
| 1813 | $versionInfoList = $this->contentService->loadVersions($content->contentInfo); |
||
| 1814 | $this->assertEquals(1, count($versionInfoList)); |
||
| 1815 | $this->assertEquals(1, $versionInfoList[0]->versionNo); |
||
| 1816 | |||
| 1817 | // Create a new draft with versionNo = 2 |
||
| 1818 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1819 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1820 | |||
| 1821 | // Create a new draft with versionNo = 3 |
||
| 1822 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1823 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1824 | |||
| 1825 | // Create a new draft with versionNo = 4 |
||
| 1826 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1827 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1828 | |||
| 1829 | // Create a new draft with versionNo = 5 |
||
| 1830 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1831 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1832 | |||
| 1833 | // Create a new draft with versionNo = 6 |
||
| 1834 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1835 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1836 | |||
| 1837 | // Create a new draft with versionNo = 7 |
||
| 1838 | $draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
||
| 1839 | $this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
||
| 1840 | |||
| 1841 | $versionInfoList = $this->contentService->loadVersions($content->contentInfo); |
||
| 1842 | |||
| 1843 | $this->assertEquals(6, count($versionInfoList)); |
||
| 1844 | $this->assertEquals(2, $versionInfoList[0]->versionNo); |
||
| 1845 | $this->assertEquals(7, $versionInfoList[5]->versionNo); |
||
| 1846 | |||
| 1847 | $this->assertEquals( |
||
| 1848 | [ |
||
| 1849 | VersionInfo::STATUS_ARCHIVED, |
||
| 1850 | VersionInfo::STATUS_ARCHIVED, |
||
| 1851 | VersionInfo::STATUS_ARCHIVED, |
||
| 1852 | VersionInfo::STATUS_ARCHIVED, |
||
| 1853 | VersionInfo::STATUS_ARCHIVED, |
||
| 1854 | VersionInfo::STATUS_PUBLISHED, |
||
| 1855 | ], |
||
| 1856 | [ |
||
| 1857 | $versionInfoList[0]->status, |
||
| 1858 | $versionInfoList[1]->status, |
||
| 1859 | $versionInfoList[2]->status, |
||
| 1860 | $versionInfoList[3]->status, |
||
| 1861 | $versionInfoList[4]->status, |
||
| 1862 | $versionInfoList[5]->status, |
||
| 1863 | ] |
||
| 1864 | ); |
||
| 1865 | } |
||
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Test for the newContentMetadataUpdateStruct() method. |
||
| 1869 | * |
||
| 1870 | * @covers \eZ\Publish\API\Repository\ContentService::newContentMetadataUpdateStruct |
||
| 1871 | * @group user |
||
| 1872 | */ |
||
| 1873 | public function testNewContentMetadataUpdateStruct() |
||
| 1874 | { |
||
| 1875 | // Creates a new metadata update struct |
||
| 1876 | $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
||
| 1877 | |||
| 1878 | foreach ($metadataUpdate as $propertyName => $propertyValue) { |
||
| 1879 | $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
||
| 1880 | } |
||
| 1881 | |||
| 1882 | $metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
||
| 1883 | $metadataUpdate->mainLanguageCode = self::ENG_GB; |
||
| 1884 | $metadataUpdate->alwaysAvailable = false; |
||
| 1885 | |||
| 1886 | $this->assertInstanceOf( |
||
| 1887 | ContentMetadataUpdateStruct::class, |
||
| 1888 | $metadataUpdate |
||
| 1889 | ); |
||
| 1890 | } |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * Test for the updateContentMetadata() method. |
||
| 1894 | * |
||
| 1895 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1896 | * |
||
| 1897 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1898 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1899 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentMetadataUpdateStruct |
||
| 1900 | * @group user |
||
| 1901 | */ |
||
| 1902 | public function testUpdateContentMetadata() |
||
| 1903 | { |
||
| 1904 | $content = $this->createContentVersion1(); |
||
| 1905 | |||
| 1906 | // Creates a metadata update struct |
||
| 1907 | $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
||
| 1908 | |||
| 1909 | $metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
||
| 1910 | $metadataUpdate->mainLanguageCode = self::ENG_GB; |
||
| 1911 | $metadataUpdate->alwaysAvailable = false; |
||
| 1912 | $metadataUpdate->publishedDate = $this->createDateTime(441759600); // 1984/01/01 |
||
| 1913 | $metadataUpdate->modificationDate = $this->createDateTime(441759600); // 1984/01/01 |
||
| 1914 | |||
| 1915 | // Update the metadata of the published content object |
||
| 1916 | $content = $this->contentService->updateContentMetadata( |
||
| 1917 | $content->contentInfo, |
||
| 1918 | $metadataUpdate |
||
| 1919 | ); |
||
| 1920 | |||
| 1921 | $this->assertInstanceOf( |
||
| 1922 | Content::class, |
||
| 1923 | $content |
||
| 1924 | ); |
||
| 1925 | |||
| 1926 | return $content; |
||
| 1927 | } |
||
| 1928 | |||
| 1929 | /** |
||
| 1930 | * Test for the updateContentMetadata() method. |
||
| 1931 | * |
||
| 1932 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1933 | * |
||
| 1934 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1935 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 1936 | */ |
||
| 1937 | public function testUpdateContentMetadataSetsExpectedProperties($content) |
||
| 1938 | { |
||
| 1939 | $contentInfo = $content->contentInfo; |
||
| 1940 | |||
| 1941 | $this->assertEquals( |
||
| 1942 | [ |
||
| 1943 | 'remoteId' => 'aaaabbbbccccddddeeeeffff11112222', |
||
| 1944 | 'sectionId' => $this->generateId('section', 1), |
||
| 1945 | 'alwaysAvailable' => false, |
||
| 1946 | 'currentVersionNo' => 1, |
||
| 1947 | 'mainLanguageCode' => self::ENG_GB, |
||
| 1948 | 'modificationDate' => $this->createDateTime(441759600), |
||
| 1949 | 'ownerId' => $this->getRepository()->getCurrentUser()->id, |
||
| 1950 | 'published' => true, |
||
| 1951 | 'publishedDate' => $this->createDateTime(441759600), |
||
| 1952 | ], |
||
| 1953 | [ |
||
| 1954 | 'remoteId' => $contentInfo->remoteId, |
||
| 1955 | 'sectionId' => $contentInfo->sectionId, |
||
| 1956 | 'alwaysAvailable' => $contentInfo->alwaysAvailable, |
||
| 1957 | 'currentVersionNo' => $contentInfo->currentVersionNo, |
||
| 1958 | 'mainLanguageCode' => $contentInfo->mainLanguageCode, |
||
| 1959 | 'modificationDate' => $contentInfo->modificationDate, |
||
| 1960 | 'ownerId' => $contentInfo->ownerId, |
||
| 1961 | 'published' => $contentInfo->published, |
||
| 1962 | 'publishedDate' => $contentInfo->publishedDate, |
||
| 1963 | ] |
||
| 1964 | ); |
||
| 1965 | } |
||
| 1966 | |||
| 1967 | /** |
||
| 1968 | * Test for the updateContentMetadata() method. |
||
| 1969 | * |
||
| 1970 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1971 | * |
||
| 1972 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1973 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 1974 | */ |
||
| 1975 | public function testUpdateContentMetadataNotUpdatesContentVersion($content) |
||
| 1976 | { |
||
| 1977 | $this->assertEquals(1, $content->getVersionInfo()->versionNo); |
||
| 1978 | } |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Test for the updateContentMetadata() method. |
||
| 1982 | * |
||
| 1983 | * @covers \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1984 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 1985 | */ |
||
| 1986 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnDuplicateRemoteId() |
||
| 1987 | { |
||
| 1988 | $content = $this->createContentVersion1(); |
||
| 1989 | |||
| 1990 | // Creates a metadata update struct |
||
| 1991 | $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
||
| 1992 | $metadataUpdate->remoteId = self::MEDIA_REMOTE_ID; |
||
| 1993 | |||
| 1994 | $this->expectException(APIInvalidArgumentException::class); |
||
| 1995 | // specified remoteId is already used by the "Media" page. |
||
| 1996 | $this->contentService->updateContentMetadata( |
||
| 1997 | $content->contentInfo, |
||
| 1998 | $metadataUpdate |
||
| 1999 | ); |
||
| 2000 | } |
||
| 2001 | |||
| 2002 | /** |
||
| 2003 | * Test for the updateContentMetadata() method. |
||
| 2004 | * |
||
| 2005 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 2006 | */ |
||
| 2007 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnNoMetadataPropertiesSet() |
||
| 2008 | { |
||
| 2009 | $contentInfo = $this->contentService->loadContentInfo(4); |
||
| 2010 | $contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); |
||
| 2011 | |||
| 2012 | $this->expectException(APIInvalidArgumentException::class); |
||
| 2013 | $this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 2014 | } |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * Test for the deleteContent() method. |
||
| 2018 | * |
||
| 2019 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 2020 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2021 | */ |
||
| 2022 | public function testDeleteContent() |
||
| 2023 | { |
||
| 2024 | $contentVersion2 = $this->createContentVersion2(); |
||
| 2025 | |||
| 2026 | // Load the locations for this content object |
||
| 2027 | $locations = $this->locationService->loadLocations($contentVersion2->contentInfo); |
||
| 2028 | |||
| 2029 | // This will delete the content, all versions and the associated locations |
||
| 2030 | $this->contentService->deleteContent($contentVersion2->contentInfo); |
||
| 2031 | |||
| 2032 | $this->expectException(NotFoundException::class); |
||
| 2033 | |||
| 2034 | $this->expectException(NotFoundException::class); |
||
| 2035 | |||
| 2036 | foreach ($locations as $location) { |
||
| 2037 | $this->locationService->loadLocation($location->id); |
||
| 2038 | } |
||
| 2039 | } |
||
| 2040 | |||
| 2041 | /** |
||
| 2042 | * Test for the deleteContent() method. |
||
| 2043 | * |
||
| 2044 | * Test for issue EZP-21057: |
||
| 2045 | * "contentService: Unable to delete a content with an empty file attribute" |
||
| 2046 | * |
||
| 2047 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 2048 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2049 | */ |
||
| 2050 | public function testDeleteContentWithEmptyBinaryField() |
||
| 2051 | { |
||
| 2052 | $contentVersion = $this->createContentVersion1EmptyBinaryField(); |
||
| 2053 | |||
| 2054 | // Load the locations for this content object |
||
| 2055 | $locations = $this->locationService->loadLocations($contentVersion->contentInfo); |
||
| 2056 | |||
| 2057 | // This will delete the content, all versions and the associated locations |
||
| 2058 | $this->contentService->deleteContent($contentVersion->contentInfo); |
||
| 2059 | |||
| 2060 | $this->expectException(NotFoundException::class); |
||
| 2061 | |||
| 2062 | $this->expectException(NotFoundException::class); |
||
| 2063 | |||
| 2064 | foreach ($locations as $location) { |
||
| 2065 | $this->locationService->loadLocation($location->id); |
||
| 2066 | } |
||
| 2067 | } |
||
| 2068 | |||
| 2069 | public function testCountContentDraftsReturnsZeroByDefault(): void |
||
| 2070 | { |
||
| 2071 | $this->assertSame(0, $this->contentService->countContentDrafts()); |
||
| 2072 | $this->assertSame(0, $this->contentService->countContentDrafts()); |
||
| 2073 | } |
||
| 2074 | |||
| 2075 | public function testCountContentDrafts(): void |
||
| 2076 | { |
||
| 2077 | // Create 5 drafts |
||
| 2078 | $this->createContentDrafts(5); |
||
| 2079 | |||
| 2080 | $this->assertSame(5, $this->contentService->countContentDrafts()); |
||
| 2081 | } |
||
| 2082 | |||
| 2083 | public function testCountContentDraftsForUsers(): void |
||
| 2084 | { |
||
| 2085 | $newUser = $this->createUserWithPolicies( |
||
| 2086 | 'new_user', |
||
| 2087 | [ |
||
| 2088 | ['module' => 'content', 'function' => 'create'], |
||
| 2089 | ['module' => 'content', 'function' => 'read'], |
||
| 2090 | ['module' => 'content', 'function' => 'publish'], |
||
| 2091 | ['module' => 'content', 'function' => 'edit'], |
||
| 2092 | ] |
||
| 2093 | ); |
||
| 2094 | |||
| 2095 | $previousUser = $this->permissionResolver->getCurrentUserReference(); |
||
| 2096 | |||
| 2097 | // Set new editor as user |
||
| 2098 | $this->permissionResolver->setCurrentUserReference($newUser); |
||
| 2099 | |||
| 2100 | // Create a content draft as newUser |
||
| 2101 | $publishedContent = $this->createContentVersion1(); |
||
| 2102 | $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2103 | |||
| 2104 | // Reset to previous current user |
||
| 2105 | $this->permissionResolver->setCurrentUserReference($previousUser); |
||
| 2106 | |||
| 2107 | // Now $contentDrafts for the previous current user and the new user |
||
| 2108 | $newUserDrafts = $this->contentService->countContentDrafts($newUser); |
||
| 2109 | $previousUserDrafts = $this->contentService->countContentDrafts(); |
||
| 2110 | |||
| 2111 | $this->assertSame(1, $newUserDrafts); |
||
| 2112 | $this->assertSame(0, $previousUserDrafts); |
||
| 2113 | } |
||
| 2114 | |||
| 2115 | /** |
||
| 2116 | * Test for the loadContentDrafts() method. |
||
| 2117 | * |
||
| 2118 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2119 | */ |
||
| 2120 | public function testLoadContentDraftsReturnsEmptyArrayByDefault() |
||
| 2121 | { |
||
| 2122 | $contentDrafts = $this->contentService->loadContentDrafts(); |
||
| 2123 | |||
| 2124 | $this->assertSame([], $contentDrafts); |
||
| 2125 | } |
||
| 2126 | |||
| 2127 | /** |
||
| 2128 | * Test for the loadContentDrafts() method. |
||
| 2129 | * |
||
| 2130 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2131 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 2132 | */ |
||
| 2133 | public function testLoadContentDrafts() |
||
| 2134 | { |
||
| 2135 | // "Media" content object |
||
| 2136 | $mediaContentInfo = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
||
| 2137 | |||
| 2138 | // "eZ Publish Demo Design ..." content object |
||
| 2139 | $demoDesignContentInfo = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
||
| 2140 | |||
| 2141 | // Create some drafts |
||
| 2142 | $this->contentService->createContentDraft($mediaContentInfo); |
||
| 2143 | $this->contentService->createContentDraft($demoDesignContentInfo); |
||
| 2144 | |||
| 2145 | // Now $contentDrafts should contain two drafted versions |
||
| 2146 | $draftedVersions = $this->contentService->loadContentDrafts(); |
||
| 2147 | |||
| 2148 | $actual = [ |
||
| 2149 | $draftedVersions[0]->status, |
||
| 2150 | $draftedVersions[0]->getContentInfo()->remoteId, |
||
| 2151 | $draftedVersions[1]->status, |
||
| 2152 | $draftedVersions[1]->getContentInfo()->remoteId, |
||
| 2153 | ]; |
||
| 2154 | sort($actual, SORT_STRING); |
||
| 2155 | |||
| 2156 | $this->assertEquals( |
||
| 2157 | [ |
||
| 2158 | VersionInfo::STATUS_DRAFT, |
||
| 2159 | VersionInfo::STATUS_DRAFT, |
||
| 2160 | self::DEMO_DESIGN_REMOTE_ID, |
||
| 2161 | self::MEDIA_REMOTE_ID, |
||
| 2162 | ], |
||
| 2163 | $actual |
||
| 2164 | ); |
||
| 2165 | } |
||
| 2166 | |||
| 2167 | /** |
||
| 2168 | * Test for the loadContentDrafts() method. |
||
| 2169 | * |
||
| 2170 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
||
| 2171 | */ |
||
| 2172 | public function testLoadContentDraftsWithFirstParameter() |
||
| 2173 | { |
||
| 2174 | $user = $this->createUserVersion1(); |
||
| 2175 | |||
| 2176 | // Get current user |
||
| 2177 | $oldCurrentUser = $this->permissionResolver->getCurrentUserReference(); |
||
| 2178 | |||
| 2179 | // Set new editor as user |
||
| 2180 | $this->permissionResolver->setCurrentUserReference($user); |
||
| 2181 | |||
| 2182 | // "Media" content object |
||
| 2183 | $mediaContentInfo = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
||
| 2184 | |||
| 2185 | // Create a content draft |
||
| 2186 | $this->contentService->createContentDraft($mediaContentInfo); |
||
| 2187 | |||
| 2188 | // Reset to previous current user |
||
| 2189 | $this->permissionResolver->setCurrentUserReference($oldCurrentUser); |
||
| 2190 | |||
| 2191 | // Now $contentDrafts for the previous current user and the new user |
||
| 2192 | $newCurrentUserDrafts = $this->contentService->loadContentDrafts($user); |
||
| 2193 | $oldCurrentUserDrafts = $this->contentService->loadContentDrafts(); |
||
| 2194 | |||
| 2195 | $this->assertSame([], $oldCurrentUserDrafts); |
||
| 2196 | |||
| 2197 | $this->assertEquals( |
||
| 2198 | [ |
||
| 2199 | VersionInfo::STATUS_DRAFT, |
||
| 2200 | self::MEDIA_REMOTE_ID, |
||
| 2201 | ], |
||
| 2202 | [ |
||
| 2203 | $newCurrentUserDrafts[0]->status, |
||
| 2204 | $newCurrentUserDrafts[0]->getContentInfo()->remoteId, |
||
| 2205 | ] |
||
| 2206 | ); |
||
| 2207 | $this->assertTrue($newCurrentUserDrafts[0]->isDraft()); |
||
| 2208 | $this->assertFalse($newCurrentUserDrafts[0]->isArchived()); |
||
| 2209 | $this->assertFalse($newCurrentUserDrafts[0]->isPublished()); |
||
| 2210 | } |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Test for the loadContentDraftList() method. |
||
| 2214 | * |
||
| 2215 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2216 | */ |
||
| 2217 | public function testLoadContentDraftListWithPaginationParameters() |
||
| 2218 | { |
||
| 2219 | // Create some drafts |
||
| 2220 | $publishedContent = $this->createContentVersion1(); |
||
| 2221 | $draftContentA = $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2222 | $draftContentB = $this->contentService->createContentDraft($draftContentA->contentInfo); |
||
| 2223 | $draftContentC = $this->contentService->createContentDraft($draftContentB->contentInfo); |
||
| 2224 | $draftContentD = $this->contentService->createContentDraft($draftContentC->contentInfo); |
||
| 2225 | $draftContentE = $this->contentService->createContentDraft($draftContentD->contentInfo); |
||
| 2226 | |||
| 2227 | $draftsOnPage1 = $this->contentService->loadContentDraftList(null, 0, 2); |
||
| 2228 | $draftsOnPage2 = $this->contentService->loadContentDraftList(null, 2, 2); |
||
| 2229 | |||
| 2230 | $this->assertSame(5, $draftsOnPage1->totalCount); |
||
| 2231 | $this->assertSame(5, $draftsOnPage2->totalCount); |
||
| 2232 | $this->assertEquals($draftContentE->getVersionInfo(), $draftsOnPage1->items[0]->getVersionInfo()); |
||
| 2233 | $this->assertEquals($draftContentD->getVersionInfo(), $draftsOnPage1->items[1]->getVersionInfo()); |
||
| 2234 | $this->assertEquals($draftContentC->getVersionInfo(), $draftsOnPage2->items[0]->getVersionInfo()); |
||
| 2235 | $this->assertEquals($draftContentB->getVersionInfo(), $draftsOnPage2->items[1]->getVersionInfo()); |
||
| 2236 | } |
||
| 2237 | |||
| 2238 | /** |
||
| 2239 | * Test for the loadContentDraftList() method. |
||
| 2240 | * |
||
| 2241 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
||
| 2242 | */ |
||
| 2243 | public function testLoadContentDraftListWithForUserWithLimitation() |
||
| 2244 | { |
||
| 2245 | $oldUser = $this->permissionResolver->getCurrentUserReference(); |
||
| 2246 | |||
| 2247 | $parentContent = $this->createFolder(['eng-US' => 'parentFolder'], 2); |
||
| 2248 | $content = $this->createFolder(['eng-US' => 'parentFolder'], $parentContent->contentInfo->mainLocationId); |
||
| 2249 | |||
| 2250 | // User has limitation to read versions only for `$content`, not for `$parentContent` |
||
| 2251 | $newUser = $this->createUserWithVersionreadLimitations([$content->contentInfo->mainLocationId]); |
||
| 2252 | |||
| 2253 | $this->permissionResolver->setCurrentUserReference($newUser); |
||
| 2254 | |||
| 2255 | $contentDraftUnauthorized = $this->contentService->createContentDraft($parentContent->contentInfo); |
||
| 2256 | $contentDraftA = $this->contentService->createContentDraft($content->contentInfo); |
||
| 2257 | $contentDraftB = $this->contentService->createContentDraft($content->contentInfo); |
||
| 2258 | |||
| 2259 | $newUserDraftList = $this->contentService->loadContentDraftList($newUser, 0); |
||
| 2260 | $this->assertSame(3, $newUserDraftList->totalCount); |
||
| 2261 | $this->assertEquals($contentDraftB->getVersionInfo(), $newUserDraftList->items[0]->getVersionInfo()); |
||
| 2262 | $this->assertEquals($contentDraftA->getVersionInfo(), $newUserDraftList->items[1]->getVersionInfo()); |
||
| 2263 | $this->assertEquals( |
||
| 2264 | new UnauthorizedContentDraftListItem('content', 'versionread', ['contentId' => $contentDraftUnauthorized->id]), |
||
| 2265 | $newUserDraftList->items[2] |
||
| 2266 | ); |
||
| 2267 | |||
| 2268 | // Reset to previous user |
||
| 2269 | $this->permissionResolver->setCurrentUserReference($oldUser); |
||
| 2270 | |||
| 2271 | $oldUserDraftList = $this->contentService->loadContentDraftList(); |
||
| 2272 | |||
| 2273 | $this->assertSame(0, $oldUserDraftList->totalCount); |
||
| 2274 | $this->assertSame([], $oldUserDraftList->items); |
||
| 2275 | } |
||
| 2276 | |||
| 2277 | /** |
||
| 2278 | * Test for the loadContentDraftList() method. |
||
| 2279 | * |
||
| 2280 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2281 | */ |
||
| 2282 | public function testLoadAllContentDrafts() |
||
| 2283 | { |
||
| 2284 | // Create more drafts then default pagination limit |
||
| 2285 | $this->createContentDrafts(12); |
||
| 2286 | |||
| 2287 | $this->assertCount(12, $this->contentService->loadContentDraftList()); |
||
| 2288 | } |
||
| 2289 | |||
| 2290 | /** |
||
| 2291 | * Test for the loadVersionInfo() method. |
||
| 2292 | * |
||
| 2293 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
||
| 2294 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2295 | */ |
||
| 2296 | public function testLoadVersionInfoWithSecondParameter() |
||
| 2297 | { |
||
| 2298 | $publishedContent = $this->createContentVersion1(); |
||
| 2299 | |||
| 2300 | $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2301 | |||
| 2302 | // Will return the VersionInfo of the $draftContent |
||
| 2303 | $versionInfo = $this->contentService->loadVersionInfoById($publishedContent->id, 2); |
||
| 2304 | |||
| 2305 | $this->assertEquals(2, $versionInfo->versionNo); |
||
| 2306 | |||
| 2307 | // Check that ContentInfo contained in VersionInfo has correct main Location id set |
||
| 2308 | $this->assertEquals( |
||
| 2309 | $publishedContent->getVersionInfo()->getContentInfo()->mainLocationId, |
||
| 2310 | $versionInfo->getContentInfo()->mainLocationId |
||
| 2311 | ); |
||
| 2312 | } |
||
| 2313 | |||
| 2314 | /** |
||
| 2315 | * Test for the loadVersionInfo() method. |
||
| 2316 | * |
||
| 2317 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
||
| 2318 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
||
| 2319 | */ |
||
| 2320 | public function testLoadVersionInfoThrowsNotFoundExceptionWithSecondParameter() |
||
| 2321 | { |
||
| 2322 | $draft = $this->createContentDraftVersion1(); |
||
| 2323 | |||
| 2324 | $this->expectException(NotFoundException::class); |
||
| 2325 | |||
| 2326 | // This call will fail with a "NotFoundException", because not versionNo 2 exists for this content object. |
||
| 2327 | $this->contentService->loadVersionInfo($draft->contentInfo, 2); |
||
| 2328 | } |
||
| 2329 | |||
| 2330 | /** |
||
| 2331 | * Test for the loadVersionInfoById() method. |
||
| 2332 | * |
||
| 2333 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
||
| 2334 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
||
| 2335 | */ |
||
| 2336 | public function testLoadVersionInfoByIdWithSecondParameter() |
||
| 2337 | { |
||
| 2338 | $publishedContent = $this->createContentVersion1(); |
||
| 2339 | |||
| 2340 | $draftContent = $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2341 | |||
| 2342 | // Will return the VersionInfo of the $draftContent |
||
| 2343 | $versionInfo = $this->contentService->loadVersionInfoById($publishedContent->id, 2); |
||
| 2344 | |||
| 2345 | $this->assertEquals(2, $versionInfo->versionNo); |
||
| 2346 | |||
| 2347 | // Check that ContentInfo contained in VersionInfo has correct main Location id set |
||
| 2348 | $this->assertEquals( |
||
| 2349 | $publishedContent->getVersionInfo()->getContentInfo()->mainLocationId, |
||
| 2350 | $versionInfo->getContentInfo()->mainLocationId |
||
| 2351 | ); |
||
| 2352 | |||
| 2353 | return [ |
||
| 2354 | 'versionInfo' => $versionInfo, |
||
| 2355 | 'draftContent' => $draftContent, |
||
| 2356 | ]; |
||
| 2357 | } |
||
| 2358 | |||
| 2359 | /** |
||
| 2360 | * Test for the returned value of the loadVersionInfoById() method. |
||
| 2361 | * |
||
| 2362 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter |
||
| 2363 | * @covers \eZ\Publish\API\Repository\ContentService::loadVersionInfoById |
||
| 2364 | * |
||
| 2365 | * @param array $data |
||
| 2366 | */ |
||
| 2367 | public function testLoadVersionInfoByIdWithSecondParameterSetsExpectedVersionInfo(array $data) |
||
| 2368 | { |
||
| 2369 | /** @var VersionInfo $versionInfo */ |
||
| 2370 | $versionInfo = $data['versionInfo']; |
||
| 2371 | /** @var \eZ\Publish\API\Repository\Values\Content\Content $draftContent */ |
||
| 2372 | $draftContent = $data['draftContent']; |
||
| 2373 | |||
| 2374 | $this->assertPropertiesCorrect( |
||
| 2375 | [ |
||
| 2376 | 'names' => [ |
||
| 2377 | self::ENG_US => 'An awesome forum', |
||
| 2378 | ], |
||
| 2379 | 'contentInfo' => new ContentInfo([ |
||
| 2380 | 'id' => $draftContent->contentInfo->id, |
||
| 2381 | 'contentTypeId' => 28, |
||
| 2382 | 'name' => 'An awesome forum', |
||
| 2383 | 'sectionId' => 1, |
||
| 2384 | 'currentVersionNo' => 1, |
||
| 2385 | 'published' => true, |
||
| 2386 | 'ownerId' => 14, |
||
| 2387 | // this Content Object is created at the test runtime |
||
| 2388 | 'modificationDate' => $versionInfo->contentInfo->modificationDate, |
||
| 2389 | 'publishedDate' => $versionInfo->contentInfo->publishedDate, |
||
| 2390 | 'alwaysAvailable' => 1, |
||
| 2391 | 'remoteId' => 'abcdef0123456789abcdef0123456789', |
||
| 2392 | 'mainLanguageCode' => self::ENG_US, |
||
| 2393 | 'mainLocationId' => $draftContent->contentInfo->mainLocationId, |
||
| 2394 | 'status' => ContentInfo::STATUS_PUBLISHED, |
||
| 2395 | ]), |
||
| 2396 | 'id' => $draftContent->versionInfo->id, |
||
| 2397 | 'versionNo' => 2, |
||
| 2398 | 'creatorId' => 14, |
||
| 2399 | 'status' => 0, |
||
| 2400 | 'initialLanguageCode' => self::ENG_US, |
||
| 2401 | 'languageCodes' => [ |
||
| 2402 | self::ENG_US, |
||
| 2403 | ], |
||
| 2404 | ], |
||
| 2405 | $versionInfo |
||
| 2406 | ); |
||
| 2407 | } |
||
| 2408 | |||
| 2409 | /** |
||
| 2410 | * Test for the loadVersionInfoById() method. |
||
| 2411 | * |
||
| 2412 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
||
| 2413 | */ |
||
| 2414 | public function testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParameter() |
||
| 2415 | { |
||
| 2416 | $content = $this->createContentVersion1(); |
||
| 2417 | |||
| 2418 | $this->expectException(NotFoundException::class); |
||
| 2419 | |||
| 2420 | // This call will fail with a "NotFoundException", because not versionNo 2 exists for this content object. |
||
| 2421 | $this->contentService->loadVersionInfoById($content->id, 2); |
||
| 2422 | } |
||
| 2423 | |||
| 2424 | /** |
||
| 2425 | * Test for the loadContentByVersionInfo() method. |
||
| 2426 | * |
||
| 2427 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages) |
||
| 2428 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2429 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
||
| 2430 | */ |
||
| 2431 | public function testLoadContentByVersionInfoWithSecondParameter() |
||
| 2432 | { |
||
| 2433 | $sectionId = $this->generateId('section', 1); |
||
| 2434 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 2435 | |||
| 2436 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 2437 | |||
| 2438 | $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 2439 | |||
| 2440 | $contentCreateStruct->setField('name', 'Sindelfingen forum²'); |
||
| 2441 | |||
| 2442 | $contentCreateStruct->setField('name', 'Sindelfingen forum²³', self::ENG_GB); |
||
| 2443 | |||
| 2444 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 2445 | // $sectionId contains the ID of section 1 |
||
| 2446 | $contentCreateStruct->sectionId = $sectionId; |
||
| 2447 | $contentCreateStruct->alwaysAvailable = true; |
||
| 2448 | |||
| 2449 | // Create a new content draft |
||
| 2450 | $content = $this->contentService->createContent($contentCreateStruct); |
||
| 2451 | |||
| 2452 | // Now publish this draft |
||
| 2453 | $publishedContent = $this->contentService->publishVersion($content->getVersionInfo()); |
||
| 2454 | |||
| 2455 | // Will return a content instance with fields in "eng-US" |
||
| 2456 | $reloadedContent = $this->contentService->loadContentByVersionInfo( |
||
| 2457 | $publishedContent->getVersionInfo(), |
||
| 2458 | [ |
||
| 2459 | self::ENG_GB, |
||
| 2460 | ], |
||
| 2461 | false |
||
| 2462 | ); |
||
| 2463 | |||
| 2464 | $actual = []; |
||
| 2465 | foreach ($reloadedContent->getFields() as $field) { |
||
| 2466 | $actual[] = new Field( |
||
| 2467 | [ |
||
| 2468 | 'id' => 0, |
||
| 2469 | 'value' => $field->value !== null, // Actual value tested by FieldType integration tests |
||
| 2470 | 'languageCode' => $field->languageCode, |
||
| 2471 | 'fieldDefIdentifier' => $field->fieldDefIdentifier, |
||
| 2472 | ] |
||
| 2473 | ); |
||
| 2474 | } |
||
| 2475 | usort( |
||
| 2476 | $actual, |
||
| 2477 | function ($field1, $field2) { |
||
| 2478 | if (0 === ($return = strcasecmp($field1->fieldDefIdentifier, $field2->fieldDefIdentifier))) { |
||
| 2479 | return strcasecmp($field1->languageCode, $field2->languageCode); |
||
| 2480 | } |
||
| 2481 | |||
| 2482 | return $return; |
||
| 2483 | } |
||
| 2484 | ); |
||
| 2485 | |||
| 2486 | $expected = [ |
||
| 2487 | new Field( |
||
| 2488 | [ |
||
| 2489 | 'id' => 0, |
||
| 2490 | 'value' => true, |
||
| 2491 | 'languageCode' => self::ENG_GB, |
||
| 2492 | 'fieldDefIdentifier' => 'description', |
||
| 2493 | ] |
||
| 2494 | ), |
||
| 2495 | new Field( |
||
| 2496 | [ |
||
| 2497 | 'id' => 0, |
||
| 2498 | 'value' => true, |
||
| 2499 | 'languageCode' => self::ENG_GB, |
||
| 2500 | 'fieldDefIdentifier' => 'name', |
||
| 2501 | ] |
||
| 2502 | ), |
||
| 2503 | ]; |
||
| 2504 | |||
| 2505 | $this->assertEquals($expected, $actual); |
||
| 2506 | } |
||
| 2507 | |||
| 2508 | /** |
||
| 2509 | * Test for the loadContentByContentInfo() method. |
||
| 2510 | * |
||
| 2511 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages) |
||
| 2512 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 2513 | */ |
||
| 2514 | public function testLoadContentByContentInfoWithLanguageParameters() |
||
| 2515 | { |
||
| 2516 | $sectionId = $this->generateId('section', 1); |
||
| 2517 | $contentTypeService = $this->getRepository()->getContentTypeService(); |
||
| 2518 | |||
| 2519 | $contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
||
| 2520 | |||
| 2521 | $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
||
| 2522 | |||
| 2523 | $contentCreateStruct->setField('name', 'Sindelfingen forum²'); |
||
| 2524 | |||
| 2525 | $contentCreateStruct->setField('name', 'Sindelfingen forum²³', self::ENG_GB); |
||
| 2526 | |||
| 2527 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 2528 | // $sectionId contains the ID of section 1 |
||
| 2529 | $contentCreateStruct->sectionId = $sectionId; |
||
| 2530 | $contentCreateStruct->alwaysAvailable = true; |
||
| 2531 | |||
| 2532 | // Create a new content draft |
||
| 2533 | $content = $this->contentService->createContent($contentCreateStruct); |
||
| 2534 | |||
| 2535 | // Now publish this draft |
||
| 2536 | $publishedContent = $this->contentService->publishVersion($content->getVersionInfo()); |
||
| 2537 | |||
| 2538 | // Will return a content instance with fields in "eng-US" |
||
| 2539 | $reloadedContent = $this->contentService->loadContentByContentInfo( |
||
| 2540 | $publishedContent->contentInfo, |
||
| 2541 | [ |
||
| 2542 | self::ENG_US, |
||
| 2543 | ], |
||
| 2544 | null, |
||
| 2545 | false |
||
| 2546 | ); |
||
| 2547 | |||
| 2548 | $actual = $this->normalizeFields($reloadedContent->getFields()); |
||
| 2549 | |||
| 2550 | $expected = [ |
||
| 2551 | new Field( |
||
| 2552 | [ |
||
| 2553 | 'id' => 0, |
||
| 2554 | 'value' => true, |
||
| 2555 | 'languageCode' => self::ENG_US, |
||
| 2556 | 'fieldDefIdentifier' => 'description', |
||
| 2557 | 'fieldTypeIdentifier' => 'ezrichtext', |
||
| 2558 | ] |
||
| 2559 | ), |
||
| 2560 | new Field( |
||
| 2561 | [ |
||
| 2562 | 'id' => 0, |
||
| 2563 | 'value' => true, |
||
| 2564 | 'languageCode' => self::ENG_US, |
||
| 2565 | 'fieldDefIdentifier' => 'name', |
||
| 2566 | 'fieldTypeIdentifier' => 'ezstring', |
||
| 2567 | ] |
||
| 2568 | ), |
||
| 2569 | ]; |
||
| 2570 | |||
| 2571 | $this->assertEquals($expected, $actual); |
||
| 2572 | |||
| 2573 | // Will return a content instance with fields in "eng-GB" (versions prior to 6.0.0-beta9 returned "eng-US" also) |
||
| 2574 | $reloadedContent = $this->contentService->loadContentByContentInfo( |
||
| 2575 | $publishedContent->contentInfo, |
||
| 2576 | [ |
||
| 2577 | self::ENG_GB, |
||
| 2578 | ], |
||
| 2579 | null, |
||
| 2580 | true |
||
| 2581 | ); |
||
| 2582 | |||
| 2583 | $actual = $this->normalizeFields($reloadedContent->getFields()); |
||
| 2584 | |||
| 2585 | $expected = [ |
||
| 2586 | new Field( |
||
| 2587 | [ |
||
| 2588 | 'id' => 0, |
||
| 2589 | 'value' => true, |
||
| 2590 | 'languageCode' => self::ENG_GB, |
||
| 2591 | 'fieldDefIdentifier' => 'description', |
||
| 2592 | 'fieldTypeIdentifier' => 'ezrichtext', |
||
| 2593 | ] |
||
| 2594 | ), |
||
| 2595 | new Field( |
||
| 2596 | [ |
||
| 2597 | 'id' => 0, |
||
| 2598 | 'value' => true, |
||
| 2599 | 'languageCode' => self::ENG_GB, |
||
| 2600 | 'fieldDefIdentifier' => 'name', |
||
| 2601 | 'fieldTypeIdentifier' => 'ezstring', |
||
| 2602 | ] |
||
| 2603 | ), |
||
| 2604 | ]; |
||
| 2605 | |||
| 2606 | $this->assertEquals($expected, $actual); |
||
| 2607 | |||
| 2608 | // Will return a content instance with fields in main language "eng-US", as "fre-FR" does not exists |
||
| 2609 | $reloadedContent = $this->contentService->loadContentByContentInfo( |
||
| 2610 | $publishedContent->contentInfo, |
||
| 2611 | [ |
||
| 2612 | 'fre-FR', |
||
| 2613 | ], |
||
| 2614 | null, |
||
| 2615 | true |
||
| 2616 | ); |
||
| 2617 | |||
| 2618 | $actual = $this->normalizeFields($reloadedContent->getFields()); |
||
| 2619 | |||
| 2620 | $expected = [ |
||
| 2621 | new Field( |
||
| 2622 | [ |
||
| 2623 | 'id' => 0, |
||
| 2624 | 'value' => true, |
||
| 2625 | 'languageCode' => self::ENG_US, |
||
| 2626 | 'fieldDefIdentifier' => 'description', |
||
| 2627 | 'fieldTypeIdentifier' => 'ezrichtext', |
||
| 2628 | ] |
||
| 2629 | ), |
||
| 2630 | new Field( |
||
| 2631 | [ |
||
| 2632 | 'id' => 0, |
||
| 2633 | 'value' => true, |
||
| 2634 | 'languageCode' => self::ENG_US, |
||
| 2635 | 'fieldDefIdentifier' => 'name', |
||
| 2636 | 'fieldTypeIdentifier' => 'ezstring', |
||
| 2637 | ] |
||
| 2638 | ), |
||
| 2639 | ]; |
||
| 2640 | |||
| 2641 | $this->assertEquals($expected, $actual); |
||
| 2642 | } |
||
| 2643 | |||
| 2644 | /** |
||
| 2645 | * Test for the loadContentByContentInfo() method. |
||
| 2646 | * |
||
| 2647 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
||
| 2648 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 2649 | */ |
||
| 2650 | public function testLoadContentByContentInfoWithVersionNumberParameter() |
||
| 2651 | { |
||
| 2652 | $publishedContent = $this->createContentVersion1(); |
||
| 2653 | |||
| 2654 | $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2655 | |||
| 2656 | // This content instance is identical to $draftContent |
||
| 2657 | $draftContentReloaded = $this->contentService->loadContentByContentInfo( |
||
| 2658 | $publishedContent->contentInfo, |
||
| 2659 | null, |
||
| 2660 | 2 |
||
| 2661 | ); |
||
| 2662 | |||
| 2663 | $this->assertEquals( |
||
| 2664 | 2, |
||
| 2665 | $draftContentReloaded->getVersionInfo()->versionNo |
||
| 2666 | ); |
||
| 2667 | |||
| 2668 | // Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
||
| 2669 | $this->assertEquals( |
||
| 2670 | $publishedContent->versionInfo->contentInfo->mainLocationId, |
||
| 2671 | $draftContentReloaded->versionInfo->contentInfo->mainLocationId |
||
| 2672 | ); |
||
| 2673 | } |
||
| 2674 | |||
| 2675 | /** |
||
| 2676 | * Test for the loadContentByContentInfo() method. |
||
| 2677 | * |
||
| 2678 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
||
| 2679 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter |
||
| 2680 | */ |
||
| 2681 | public function testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNumberParameter() |
||
| 2682 | { |
||
| 2683 | $content = $this->createContentVersion1(); |
||
| 2684 | |||
| 2685 | $this->expectException(NotFoundException::class); |
||
| 2686 | |||
| 2687 | // This call will fail with a "NotFoundException", because no content with versionNo = 2 exists. |
||
| 2688 | $this->contentService->loadContentByContentInfo($content->contentInfo, null, 2); |
||
| 2689 | } |
||
| 2690 | |||
| 2691 | /** |
||
| 2692 | * Test for the loadContent() method. |
||
| 2693 | * |
||
| 2694 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages) |
||
| 2695 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2696 | */ |
||
| 2697 | public function testLoadContentWithSecondParameter() |
||
| 2698 | { |
||
| 2699 | $draft = $this->createMultipleLanguageDraftVersion1(); |
||
| 2700 | |||
| 2701 | // This draft contains those fields localized with "eng-GB" |
||
| 2702 | $draftLocalized = $this->contentService->loadContent($draft->id, [self::ENG_GB], null, false); |
||
| 2703 | |||
| 2704 | $this->assertLocaleFieldsEquals($draftLocalized->getFields(), self::ENG_GB); |
||
| 2705 | |||
| 2706 | return $draft; |
||
| 2707 | } |
||
| 2708 | |||
| 2709 | /** |
||
| 2710 | * Test for the loadContent() method using undefined translation. |
||
| 2711 | * |
||
| 2712 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter |
||
| 2713 | * |
||
| 2714 | * @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft |
||
| 2715 | */ |
||
| 2716 | public function testLoadContentWithSecondParameterThrowsNotFoundException(Content $contentDraft) |
||
| 2717 | { |
||
| 2718 | $this->expectException(NotFoundException::class); |
||
| 2719 | |||
| 2720 | $this->contentService->loadContent($contentDraft->id, [self::GER_DE], null, false); |
||
| 2721 | } |
||
| 2722 | |||
| 2723 | /** |
||
| 2724 | * Test for the loadContent() method. |
||
| 2725 | * |
||
| 2726 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
||
| 2727 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2728 | */ |
||
| 2729 | public function testLoadContentWithThirdParameter() |
||
| 2730 | { |
||
| 2731 | $publishedContent = $this->createContentVersion1(); |
||
| 2732 | |||
| 2733 | $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2734 | |||
| 2735 | // This content instance is identical to $draftContent |
||
| 2736 | $draftContentReloaded = $this->contentService->loadContent($publishedContent->id, null, 2); |
||
| 2737 | |||
| 2738 | $this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo); |
||
| 2739 | |||
| 2740 | // Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
||
| 2741 | $this->assertEquals( |
||
| 2742 | $publishedContent->versionInfo->contentInfo->mainLocationId, |
||
| 2743 | $draftContentReloaded->versionInfo->contentInfo->mainLocationId |
||
| 2744 | ); |
||
| 2745 | } |
||
| 2746 | |||
| 2747 | /** |
||
| 2748 | * Test for the loadContent() method. |
||
| 2749 | * |
||
| 2750 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
||
| 2751 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
||
| 2752 | */ |
||
| 2753 | public function testLoadContentThrowsNotFoundExceptionWithThirdParameter() |
||
| 2754 | { |
||
| 2755 | $content = $this->createContentVersion1(); |
||
| 2756 | |||
| 2757 | $this->expectException(NotFoundException::class); |
||
| 2758 | |||
| 2759 | // This call will fail with a "NotFoundException", because for this content object no versionNo=2 exists. |
||
| 2760 | $this->contentService->loadContent($content->id, null, 2); |
||
| 2761 | } |
||
| 2762 | |||
| 2763 | /** |
||
| 2764 | * Test for the loadContentByRemoteId() method. |
||
| 2765 | * |
||
| 2766 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages) |
||
| 2767 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2768 | */ |
||
| 2769 | public function testLoadContentByRemoteIdWithSecondParameter() |
||
| 2770 | { |
||
| 2771 | $draft = $this->createMultipleLanguageDraftVersion1(); |
||
| 2772 | |||
| 2773 | $this->contentService->publishVersion($draft->versionInfo); |
||
| 2774 | |||
| 2775 | // This draft contains those fields localized with "eng-GB" |
||
| 2776 | $draftLocalized = $this->contentService->loadContentByRemoteId( |
||
| 2777 | $draft->contentInfo->remoteId, |
||
| 2778 | [self::ENG_GB], |
||
| 2779 | null, |
||
| 2780 | false |
||
| 2781 | ); |
||
| 2782 | |||
| 2783 | $this->assertLocaleFieldsEquals($draftLocalized->getFields(), self::ENG_GB); |
||
| 2784 | } |
||
| 2785 | |||
| 2786 | /** |
||
| 2787 | * Test for the loadContentByRemoteId() method. |
||
| 2788 | * |
||
| 2789 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 2790 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2791 | */ |
||
| 2792 | public function testLoadContentByRemoteIdWithThirdParameter() |
||
| 2793 | { |
||
| 2794 | $publishedContent = $this->createContentVersion1(); |
||
| 2795 | |||
| 2796 | $this->contentService->createContentDraft($publishedContent->contentInfo); |
||
| 2797 | |||
| 2798 | // This content instance is identical to $draftContent |
||
| 2799 | $draftContentReloaded = $this->contentService->loadContentByRemoteId( |
||
| 2800 | $publishedContent->contentInfo->remoteId, |
||
| 2801 | null, |
||
| 2802 | 2 |
||
| 2803 | ); |
||
| 2804 | |||
| 2805 | $this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo); |
||
| 2806 | |||
| 2807 | // Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
||
| 2808 | $this->assertEquals( |
||
| 2809 | $publishedContent->versionInfo->contentInfo->mainLocationId, |
||
| 2810 | $draftContentReloaded->versionInfo->contentInfo->mainLocationId |
||
| 2811 | ); |
||
| 2812 | } |
||
| 2813 | |||
| 2814 | /** |
||
| 2815 | * Test for the loadContentByRemoteId() method. |
||
| 2816 | * |
||
| 2817 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 2818 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter |
||
| 2819 | */ |
||
| 2820 | public function testLoadContentByRemoteIdThrowsNotFoundExceptionWithThirdParameter() |
||
| 2821 | { |
||
| 2822 | $content = $this->createContentVersion1(); |
||
| 2823 | |||
| 2824 | $this->expectException(NotFoundException::class); |
||
| 2825 | |||
| 2826 | // This call will fail with a "NotFoundException", because for this content object no versionNo=2 exists. |
||
| 2827 | $this->contentService->loadContentByRemoteId( |
||
| 2828 | $content->contentInfo->remoteId, |
||
| 2829 | null, |
||
| 2830 | 2 |
||
| 2831 | ); |
||
| 2832 | } |
||
| 2833 | |||
| 2834 | /** |
||
| 2835 | * Test that retrieval of translated name field respects prioritized language list. |
||
| 2836 | * |
||
| 2837 | * @dataProvider getPrioritizedLanguageList |
||
| 2838 | * @param string[]|null $languageCodes |
||
| 2839 | */ |
||
| 2840 | public function testLoadContentWithPrioritizedLanguagesList($languageCodes) |
||
| 2841 | { |
||
| 2842 | $content = $this->createContentVersion2(); |
||
| 2843 | |||
| 2844 | $content = $this->contentService->loadContent($content->id, $languageCodes); |
||
| 2845 | |||
| 2846 | $expectedName = $content->getVersionInfo()->getName( |
||
| 2847 | isset($languageCodes[0]) ? $languageCodes[0] : null |
||
| 2848 | ); |
||
| 2849 | $nameValue = $content->getFieldValue('name'); |
||
| 2850 | /** @var \eZ\Publish\Core\FieldType\TextLine\Value $nameValue */ |
||
| 2851 | self::assertEquals($expectedName, $nameValue->text); |
||
| 2852 | self::assertEquals($expectedName, $content->getVersionInfo()->getName()); |
||
| 2853 | // Also check value on shortcut method on content |
||
| 2854 | self::assertEquals($expectedName, $content->getName()); |
||
| 2855 | } |
||
| 2856 | |||
| 2857 | /** |
||
| 2858 | * @return array |
||
| 2859 | */ |
||
| 2860 | public function getPrioritizedLanguageList() |
||
| 2861 | { |
||
| 2862 | return [ |
||
| 2863 | [[self::ENG_US]], |
||
| 2864 | [[self::ENG_GB]], |
||
| 2865 | [[self::ENG_GB, self::ENG_US]], |
||
| 2866 | [[self::ENG_US, self::ENG_GB]], |
||
| 2867 | ]; |
||
| 2868 | } |
||
| 2869 | |||
| 2870 | /** |
||
| 2871 | * Test for the deleteVersion() method. |
||
| 2872 | * |
||
| 2873 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2874 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2875 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2876 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2877 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 2878 | */ |
||
| 2879 | public function testDeleteVersion() |
||
| 2880 | { |
||
| 2881 | $content = $this->createContentVersion1(); |
||
| 2882 | |||
| 2883 | // Create new draft, because published or last version of the Content can't be deleted |
||
| 2884 | $draft = $this->contentService->createContentDraft( |
||
| 2885 | $content->getVersionInfo()->getContentInfo() |
||
| 2886 | ); |
||
| 2887 | |||
| 2888 | // Delete the previously created draft |
||
| 2889 | $this->contentService->deleteVersion($draft->getVersionInfo()); |
||
| 2890 | |||
| 2891 | $versions = $this->contentService->loadVersions($content->getVersionInfo()->getContentInfo()); |
||
| 2892 | |||
| 2893 | $this->assertCount(1, $versions); |
||
| 2894 | $this->assertEquals( |
||
| 2895 | $content->getVersionInfo()->id, |
||
| 2896 | $versions[0]->id |
||
| 2897 | ); |
||
| 2898 | } |
||
| 2899 | |||
| 2900 | /** |
||
| 2901 | * Test for the deleteVersion() method. |
||
| 2902 | * |
||
| 2903 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2904 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2905 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2906 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2907 | */ |
||
| 2908 | public function testDeleteVersionThrowsBadStateExceptionOnPublishedVersion() |
||
| 2909 | { |
||
| 2910 | $content = $this->createContentVersion1(); |
||
| 2911 | |||
| 2912 | $this->expectException(BadStateException::class); |
||
| 2913 | |||
| 2914 | // This call will fail with a "BadStateException", because the content version is currently published. |
||
| 2915 | $this->contentService->deleteVersion($content->getVersionInfo()); |
||
| 2916 | } |
||
| 2917 | |||
| 2918 | /** |
||
| 2919 | * Test for the deleteVersion() method. |
||
| 2920 | * |
||
| 2921 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2922 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2923 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2924 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2925 | */ |
||
| 2926 | public function testDeleteVersionWorksIfOnlyVersionIsDraft() |
||
| 2927 | { |
||
| 2928 | $draft = $this->createContentDraftVersion1(); |
||
| 2929 | |||
| 2930 | $this->contentService->deleteVersion($draft->getVersionInfo()); |
||
| 2931 | |||
| 2932 | $this->expectException(NotFoundException::class); |
||
| 2933 | |||
| 2934 | // This call will fail with a "NotFound", because we allow to delete content if remaining version is draft. |
||
| 2935 | // Can normally only happen if there where always only a draft to begin with, simplifies UI edit API usage. |
||
| 2936 | $this->contentService->loadContent($draft->id); |
||
| 2937 | } |
||
| 2938 | |||
| 2939 | /** |
||
| 2940 | * Test for the loadVersions() method. |
||
| 2941 | * |
||
| 2942 | * @see \eZ\Publish\API\Repository\ContentService::loadVersions() |
||
| 2943 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2944 | * |
||
| 2945 | * @return VersionInfo[] |
||
| 2946 | */ |
||
| 2947 | public function testLoadVersions() |
||
| 2948 | { |
||
| 2949 | $contentVersion2 = $this->createContentVersion2(); |
||
| 2950 | |||
| 2951 | // Load versions of this ContentInfo instance |
||
| 2952 | $versions = $this->contentService->loadVersions($contentVersion2->contentInfo); |
||
| 2953 | |||
| 2954 | $expectedVersionsOrder = [ |
||
| 2955 | $this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1), |
||
| 2956 | $this->contentService->loadVersionInfo($contentVersion2->contentInfo, 2), |
||
| 2957 | ]; |
||
| 2958 | |||
| 2959 | $this->assertEquals($expectedVersionsOrder, $versions); |
||
| 2960 | |||
| 2961 | return $versions; |
||
| 2962 | } |
||
| 2963 | |||
| 2964 | /** |
||
| 2965 | * Test for the loadVersions() method. |
||
| 2966 | * |
||
| 2967 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
||
| 2968 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 2969 | * |
||
| 2970 | * @param VersionInfo[] $versions |
||
| 2971 | */ |
||
| 2972 | public function testLoadVersionsSetsExpectedVersionInfo(array $versions) |
||
| 3015 | |||
| 3016 | /** |
||
| 3017 | * Test for the copyContent() method. |
||
| 3018 | * |
||
| 3019 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 3020 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 3021 | * @group field-type |
||
| 3022 | */ |
||
| 3023 | public function testCopyContent() |
||
| 3024 | { |
||
| 3025 | $parentLocationId = $this->generateId('location', 56); |
||
| 3026 | |||
| 3027 | $contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
||
| 3028 | |||
| 3029 | // Configure new target location |
||
| 3030 | $targetLocationCreate = $this->locationService->newLocationCreateStruct($parentLocationId); |
||
| 3031 | |||
| 3032 | $targetLocationCreate->priority = 42; |
||
| 3033 | $targetLocationCreate->hidden = true; |
||
| 3034 | $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
||
| 3035 | $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 3036 | $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
| 3037 | |||
| 3038 | // Copy content with all versions and drafts |
||
| 3039 | $contentCopied = $this->contentService->copyContent( |
||
| 3040 | $contentVersion2->contentInfo, |
||
| 3041 | $targetLocationCreate |
||
| 3042 | ); |
||
| 3043 | |||
| 3044 | $this->assertInstanceOf( |
||
| 3045 | Content::class, |
||
| 3046 | $contentCopied |
||
| 3047 | ); |
||
| 3048 | |||
| 3049 | $this->assertNotEquals( |
||
| 3050 | $contentVersion2->contentInfo->remoteId, |
||
| 3051 | $contentCopied->contentInfo->remoteId |
||
| 3052 | ); |
||
| 3053 | |||
| 3054 | $this->assertNotEquals( |
||
| 3055 | $contentVersion2->id, |
||
| 3056 | $contentCopied->id |
||
| 3057 | ); |
||
| 3058 | |||
| 3059 | $this->assertEquals( |
||
| 3060 | 2, |
||
| 3061 | count($this->contentService->loadVersions($contentCopied->contentInfo)) |
||
| 3062 | ); |
||
| 3063 | |||
| 3064 | $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo); |
||
| 3065 | |||
| 3066 | $this->assertAllFieldsEquals($contentCopied->getFields()); |
||
| 3067 | |||
| 3068 | $this->assertDefaultContentStates($contentCopied->contentInfo); |
||
| 3069 | |||
| 3070 | $this->assertNotNull( |
||
| 3071 | $contentCopied->contentInfo->mainLocationId, |
||
| 3072 | 'Expected main location to be set given we provided a LocationCreateStruct' |
||
| 3073 | ); |
||
| 3074 | } |
||
| 3075 | |||
| 3076 | /** |
||
| 3077 | * Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false |
||
| 3078 | * See settings/test/integration_legacy.yml for service override. |
||
| 3079 | * |
||
| 3080 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 3081 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 3082 | * @group field-type |
||
| 3083 | */ |
||
| 3084 | public function testCopyContentWithNewOwner() |
||
| 3085 | { |
||
| 3086 | $parentLocationId = $this->generateId('location', 56); |
||
| 3087 | |||
| 3088 | $userService = $this->getRepository()->getUserService(); |
||
| 3089 | |||
| 3090 | $newOwner = $this->createUser('new_owner', 'foo', 'bar'); |
||
| 3091 | /** @var \eZ\Publish\API\Repository\Values\Content\Content $contentVersion2 */ |
||
| 3092 | $contentVersion2 = $this->createContentDraftVersion1( |
||
| 3093 | $parentLocationId, |
||
| 3094 | self::FORUM_IDENTIFIER, |
||
| 3095 | 'name', |
||
| 3096 | $newOwner |
||
| 3097 | ); |
||
| 3098 | |||
| 3099 | // Configure new target location |
||
| 3100 | $targetLocationCreate = $this->locationService->newLocationCreateStruct($parentLocationId); |
||
| 3101 | |||
| 3102 | $targetLocationCreate->priority = 42; |
||
| 3103 | $targetLocationCreate->hidden = true; |
||
| 3104 | $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
||
| 3105 | $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 3106 | $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
| 3107 | |||
| 3108 | // Copy content with all versions and drafts |
||
| 3109 | $contentCopied = $this->contentService->copyContent( |
||
| 3110 | $contentVersion2->contentInfo, |
||
| 3111 | $targetLocationCreate |
||
| 3112 | ); |
||
| 3113 | |||
| 3114 | $this->assertEquals( |
||
| 3115 | $newOwner->id, |
||
| 3116 | $contentVersion2->contentInfo->ownerId |
||
| 3117 | ); |
||
| 3118 | $this->assertEquals( |
||
| 3119 | $userService->loadUserByLogin('admin')->getUserId(), |
||
| 3120 | $contentCopied->contentInfo->ownerId |
||
| 3123 | |||
| 3124 | /** |
||
| 3125 | * Test for the copyContent() method. |
||
| 3126 | * |
||
| 3127 | * @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo) |
||
| 3128 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 3129 | */ |
||
| 3130 | public function testCopyContentWithGivenVersion() |
||
| 3179 | |||
| 3180 | /** |
||
| 3181 | * Test for the addRelation() method. |
||
| 3182 | * |
||
| 3183 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 3184 | * |
||
| 3185 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3186 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 3187 | */ |
||
| 3188 | public function testAddRelation() |
||
| 3207 | |||
| 3208 | /** |
||
| 3209 | * Test for the addRelation() method. |
||
| 3210 | * |
||
| 3211 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3212 | * |
||
| 3213 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3214 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3215 | */ |
||
| 3216 | public function testAddRelationAddsRelationToContent($relations) |
||
| 3223 | |||
| 3224 | /** |
||
| 3225 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3226 | */ |
||
| 3227 | protected function assertExpectedRelations($relations) |
||
| 3244 | |||
| 3245 | /** |
||
| 3246 | * Test for the addRelation() method. |
||
| 3247 | * |
||
| 3248 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3249 | * |
||
| 3250 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3251 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3252 | */ |
||
| 3253 | public function testAddRelationSetsExpectedRelations($relations) |
||
| 3257 | |||
| 3258 | /** |
||
| 3259 | * Test for the createContentDraft() method. |
||
| 3260 | * |
||
| 3261 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 3262 | * |
||
| 3263 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 3264 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
||
| 3265 | */ |
||
| 3266 | public function testCreateContentDraftWithRelations() |
||
| 3282 | |||
| 3283 | /** |
||
| 3284 | * Test for the createContentDraft() method. |
||
| 3285 | * |
||
| 3286 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3287 | * |
||
| 3288 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 3289 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelations |
||
| 3290 | */ |
||
| 3291 | public function testCreateContentDraftWithRelationsCreatesRelations($relations) |
||
| 3300 | |||
| 3301 | /** |
||
| 3302 | * Test for the createContentDraft() method. |
||
| 3303 | * |
||
| 3304 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3305 | * |
||
| 3306 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelationsCreatesRelations |
||
| 3307 | */ |
||
| 3308 | public function testCreateContentDraftWithRelationsCreatesExpectedRelations($relations) |
||
| 3312 | |||
| 3313 | /** |
||
| 3314 | * Test for the addRelation() method. |
||
| 3315 | * |
||
| 3316 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3317 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3318 | */ |
||
| 3319 | public function testAddRelationThrowsBadStateException() |
||
| 3333 | |||
| 3334 | /** |
||
| 3335 | * Test for the loadRelations() method. |
||
| 3336 | * |
||
| 3337 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3338 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3339 | */ |
||
| 3340 | public function testLoadRelations() |
||
| 3394 | |||
| 3395 | /** |
||
| 3396 | * Test for the loadRelations() method. |
||
| 3397 | * |
||
| 3398 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3399 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3400 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3401 | */ |
||
| 3402 | public function testLoadRelationsSkipsArchivedContent() |
||
| 3449 | |||
| 3450 | /** |
||
| 3451 | * Test for the loadRelations() method. |
||
| 3452 | * |
||
| 3453 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3454 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3455 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3456 | */ |
||
| 3457 | public function testLoadRelationsSkipsDraftContent() |
||
| 3499 | |||
| 3500 | /** |
||
| 3501 | * Test for the loadReverseRelations() method. |
||
| 3502 | * |
||
| 3503 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3504 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3505 | */ |
||
| 3506 | public function testLoadReverseRelations() |
||
| 3580 | |||
| 3581 | /** |
||
| 3582 | * Test for the loadReverseRelations() method. |
||
| 3583 | * |
||
| 3584 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3585 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3586 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
||
| 3587 | */ |
||
| 3588 | public function testLoadReverseRelationsSkipsArchivedContent() |
||
| 3653 | |||
| 3654 | /** |
||
| 3655 | * Test for the loadReverseRelations() method. |
||
| 3656 | * |
||
| 3657 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3658 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3659 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
||
| 3660 | */ |
||
| 3661 | public function testLoadReverseRelationsSkipsDraftContent() |
||
| 3716 | |||
| 3717 | /** |
||
| 3718 | * Test for the deleteRelation() method. |
||
| 3719 | * |
||
| 3720 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3721 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3722 | */ |
||
| 3723 | public function testDeleteRelation() |
||
| 3742 | |||
| 3743 | /** |
||
| 3744 | * Test for the deleteRelation() method. |
||
| 3745 | * |
||
| 3746 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3747 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
||
| 3748 | */ |
||
| 3749 | public function testDeleteRelationThrowsBadStateException() |
||
| 3775 | |||
| 3776 | /** |
||
| 3777 | * Test for the deleteRelation() method. |
||
| 3778 | * |
||
| 3779 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3780 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
||
| 3781 | */ |
||
| 3782 | public function testDeleteRelationThrowsInvalidArgumentException() |
||
| 3796 | |||
| 3797 | /** |
||
| 3798 | * Test for the createContent() method. |
||
| 3799 | * |
||
| 3800 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 3801 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 3802 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 3803 | */ |
||
| 3804 | public function testCreateContentInTransactionWithRollback() |
||
| 3848 | |||
| 3849 | /** |
||
| 3850 | * Test for the createContent() method. |
||
| 3851 | * |
||
| 3852 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 3853 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 3854 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 3855 | */ |
||
| 3856 | public function testCreateContentInTransactionWithCommit() |
||
| 3895 | |||
| 3896 | /** |
||
| 3897 | * Test for the createContent() method. |
||
| 3898 | * |
||
| 3899 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 3900 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 3901 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
||
| 3902 | */ |
||
| 3903 | public function testCreateContentWithLocationCreateParameterInTransactionWithRollback() |
||
| 3932 | |||
| 3933 | /** |
||
| 3934 | * Test for the createContent() method. |
||
| 3935 | * |
||
| 3936 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 3937 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 3938 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
||
| 3939 | */ |
||
| 3940 | public function testCreateContentWithLocationCreateParameterInTransactionWithCommit() |
||
| 3965 | |||
| 3966 | /** |
||
| 3967 | * Test for the createContentDraft() method. |
||
| 3968 | * |
||
| 3969 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 3970 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 3971 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 3972 | */ |
||
| 3973 | public function testCreateContentDraftInTransactionWithRollback() |
||
| 4009 | |||
| 4010 | /** |
||
| 4011 | * Test for the createContentDraft() method. |
||
| 4012 | * |
||
| 4013 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 4014 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 4015 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4016 | */ |
||
| 4017 | public function testCreateContentDraftInTransactionWithCommit() |
||
| 4051 | |||
| 4052 | /** |
||
| 4053 | * Test for the publishVersion() method. |
||
| 4054 | * |
||
| 4055 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 4056 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 4057 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4058 | */ |
||
| 4059 | public function testPublishVersionInTransactionWithRollback() |
||
| 4097 | |||
| 4098 | /** |
||
| 4099 | * Test for the publishVersion() method. |
||
| 4100 | * |
||
| 4101 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 4102 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 4103 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 4104 | */ |
||
| 4105 | public function testPublishVersionInTransactionWithCommit() |
||
| 4137 | |||
| 4138 | /** |
||
| 4139 | * Test for the updateContent() method. |
||
| 4140 | * |
||
| 4141 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 4142 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 4143 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4144 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4145 | */ |
||
| 4146 | public function testUpdateContentInTransactionWithRollback() |
||
| 4187 | |||
| 4188 | /** |
||
| 4189 | * Test for the updateContent() method. |
||
| 4190 | * |
||
| 4191 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 4192 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 4193 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4194 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4195 | */ |
||
| 4196 | public function testUpdateContentInTransactionWithCommit() |
||
| 4237 | |||
| 4238 | /** |
||
| 4239 | * Test for the updateContentMetadata() method. |
||
| 4240 | * |
||
| 4241 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 4242 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 4243 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4244 | */ |
||
| 4245 | public function testUpdateContentMetadataInTransactionWithRollback() |
||
| 4284 | |||
| 4285 | /** |
||
| 4286 | * Test for the updateContentMetadata() method. |
||
| 4287 | * |
||
| 4288 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 4289 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 4290 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4291 | */ |
||
| 4292 | public function testUpdateContentMetadataInTransactionWithCommit() |
||
| 4331 | |||
| 4332 | /** |
||
| 4333 | * Test for the deleteVersion() method. |
||
| 4334 | * |
||
| 4335 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 4336 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 4337 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4338 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
||
| 4339 | */ |
||
| 4340 | public function testDeleteVersionInTransactionWithRollback() |
||
| 4370 | |||
| 4371 | /** |
||
| 4372 | * Test for the deleteVersion() method. |
||
| 4373 | * |
||
| 4374 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 4375 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 4376 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4377 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
||
| 4378 | */ |
||
| 4379 | public function testDeleteVersionInTransactionWithCommit() |
||
| 4409 | |||
| 4410 | /** |
||
| 4411 | * Test for the deleteContent() method. |
||
| 4412 | * |
||
| 4413 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 4414 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
||
| 4415 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4416 | */ |
||
| 4417 | public function testDeleteContentInTransactionWithRollback() |
||
| 4446 | |||
| 4447 | /** |
||
| 4448 | * Test for the deleteContent() method. |
||
| 4449 | * |
||
| 4450 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 4451 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
||
| 4452 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4453 | */ |
||
| 4454 | public function testDeleteContentInTransactionWithCommit() |
||
| 4487 | |||
| 4488 | /** |
||
| 4489 | * Test for the copyContent() method. |
||
| 4490 | * |
||
| 4491 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 4492 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 4493 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
| 4494 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
| 4495 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
| 4496 | */ |
||
| 4497 | public function testCopyContentInTransactionWithRollback() |
||
| 4537 | |||
| 4538 | /** |
||
| 4539 | * Test for the copyContent() method. |
||
| 4540 | * |
||
| 4541 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 4542 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 4543 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
| 4544 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
| 4545 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
| 4546 | */ |
||
| 4547 | public function testCopyContentInTransactionWithCommit() |
||
| 4587 | |||
| 4588 | public function testURLAliasesCreatedForNewContent() |
||
| 4618 | |||
| 4619 | public function testURLAliasesCreatedForUpdatedContent() |
||
| 4685 | |||
| 4686 | public function testCustomURLAliasesNotHistorizedOnUpdatedContent() |
||
| 4738 | |||
| 4739 | /** |
||
| 4740 | * Test to ensure that old versions are not affected by updates to newer |
||
| 4741 | * drafts. |
||
| 4742 | */ |
||
| 4743 | public function testUpdatingDraftDoesNotUpdateOldVersions() |
||
| 4755 | |||
| 4756 | /** |
||
| 4757 | * Test scenario with writer and publisher users. |
||
| 4758 | * Writer can only create content. Publisher can publish this content. |
||
| 4759 | */ |
||
| 4760 | public function testPublishWorkflow() |
||
| 4795 | |||
| 4796 | /** |
||
| 4797 | * Test publish / content policy is required to be able to publish content. |
||
| 4798 | */ |
||
| 4799 | public function testPublishContentWithoutPublishPolicyThrowsException() |
||
| 4819 | |||
| 4820 | /** |
||
| 4821 | * Test removal of the specific translation from all the Versions of a Content Object. |
||
| 4822 | * |
||
| 4823 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 4824 | */ |
||
| 4825 | public function testDeleteTranslation() |
||
| 4844 | |||
| 4845 | /** |
||
| 4846 | * Test deleting a Translation which is initial for some Version, updates initialLanguageCode |
||
| 4847 | * with mainLanguageCode (assuming they are different). |
||
| 4848 | */ |
||
| 4849 | public function testDeleteTranslationUpdatesInitialLanguageCodeVersion() |
||
| 4877 | |||
| 4878 | /** |
||
| 4879 | * Test removal of the specific translation properly updates languages of the URL alias. |
||
| 4880 | * |
||
| 4881 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 4882 | */ |
||
| 4883 | public function testDeleteTranslationUpdatesUrlAlias() |
||
| 4917 | |||
| 4918 | /** |
||
| 4919 | * Test removal of a main translation throws BadStateException. |
||
| 4920 | * |
||
| 4921 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 4922 | */ |
||
| 4923 | public function testDeleteTranslationMainLanguageThrowsBadStateException() |
||
| 4936 | |||
| 4937 | /** |
||
| 4938 | * Test removal of a Translation is possible when some archived Versions have only this Translation. |
||
| 4939 | * |
||
| 4940 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 4941 | */ |
||
| 4942 | public function testDeleteTranslationDeletesSingleTranslationVersions() |
||
| 4964 | |||
| 4965 | /** |
||
| 4966 | * Test removal of the translation by the user who is not allowed to delete a content |
||
| 4967 | * throws UnauthorizedException. |
||
| 4968 | * |
||
| 4969 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 4970 | */ |
||
| 4971 | public function testDeleteTranslationThrowsUnauthorizedException() |
||
| 4995 | |||
| 4996 | /** |
||
| 4997 | * Test removal of a non-existent translation throws InvalidArgumentException. |
||
| 4998 | * |
||
| 4999 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
||
| 5000 | */ |
||
| 5001 | public function testDeleteTranslationThrowsInvalidArgumentException() |
||
| 5011 | |||
| 5012 | /** |
||
| 5013 | * Test deleting a Translation from Draft. |
||
| 5014 | * |
||
| 5015 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5016 | */ |
||
| 5017 | public function testDeleteTranslationFromDraft() |
||
| 5029 | |||
| 5030 | /** |
||
| 5031 | * Get values for multilingual field. |
||
| 5032 | * |
||
| 5033 | * @return array |
||
| 5034 | */ |
||
| 5035 | public function providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing() |
||
| 5046 | |||
| 5047 | /** |
||
| 5048 | * Test deleting a Translation from Draft removes previously stored URL aliases for published Content. |
||
| 5049 | * |
||
| 5050 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5051 | * |
||
| 5052 | * @dataProvider providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing |
||
| 5053 | * |
||
| 5054 | * @param string[] $fieldValues translated field values |
||
| 5055 | * |
||
| 5056 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 5057 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 5058 | * @throws NotFoundException |
||
| 5059 | * @throws UnauthorizedException |
||
| 5060 | */ |
||
| 5061 | public function testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing(array $fieldValues) |
||
| 5118 | |||
| 5119 | /** |
||
| 5120 | * Test that URL aliases for deleted Translations are properly archived. |
||
| 5121 | */ |
||
| 5122 | public function testDeleteTranslationFromDraftArchivesUrlAliasOnPublishing() |
||
| 5175 | |||
| 5176 | /** |
||
| 5177 | * Test deleting a Translation from Draft which has single Translation throws BadStateException. |
||
| 5178 | * |
||
| 5179 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5180 | */ |
||
| 5181 | public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnSingleTranslation() |
||
| 5212 | |||
| 5213 | /** |
||
| 5214 | * Test deleting the Main Translation from Draft throws BadStateException. |
||
| 5215 | * |
||
| 5216 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5217 | */ |
||
| 5218 | public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnMainTranslation() |
||
| 5238 | |||
| 5239 | /** |
||
| 5240 | * Test deleting the Translation from Published Version throws BadStateException. |
||
| 5241 | * |
||
| 5242 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5243 | */ |
||
| 5244 | public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnPublishedVersion() |
||
| 5256 | |||
| 5257 | /** |
||
| 5258 | * Test deleting a Translation from Draft throws UnauthorizedException if user cannot edit Content. |
||
| 5259 | * |
||
| 5260 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5261 | */ |
||
| 5262 | public function testDeleteTranslationFromDraftThrowsUnauthorizedException() |
||
| 5288 | |||
| 5289 | /** |
||
| 5290 | * Test deleting a non-existent Translation from Draft throws InvalidArgumentException. |
||
| 5291 | * |
||
| 5292 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
||
| 5293 | */ |
||
| 5294 | public function testDeleteTranslationFromDraftThrowsInvalidArgumentException() |
||
| 5303 | |||
| 5304 | /** |
||
| 5305 | * Test loading list of Content items. |
||
| 5306 | */ |
||
| 5307 | public function testLoadContentListByContentInfo() |
||
| 5330 | |||
| 5331 | /** |
||
| 5332 | * Test loading content versions after removing exactly two drafts. |
||
| 5333 | * |
||
| 5334 | * @see https://jira.ez.no/browse/EZP-30271 |
||
| 5335 | * |
||
| 5336 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
||
| 5337 | */ |
||
| 5338 | public function testLoadVersionsAfterDeletingTwoDrafts() |
||
| 5365 | |||
| 5366 | /** |
||
| 5367 | * Tests loading list of content versions of status draft. |
||
| 5368 | */ |
||
| 5369 | public function testLoadVersionsOfStatusDraft() |
||
| 5381 | |||
| 5382 | /** |
||
| 5383 | * Tests loading list of content versions of status archived. |
||
| 5384 | */ |
||
| 5385 | public function testLoadVersionsOfStatusArchived() |
||
| 5399 | |||
| 5400 | /** |
||
| 5401 | * Asserts that all aliases defined in $expectedAliasProperties with the |
||
| 5402 | * given properties are available in $actualAliases and not more. |
||
| 5403 | * |
||
| 5404 | * @param array $expectedAliasProperties |
||
| 5405 | * @param array $actualAliases |
||
| 5406 | */ |
||
| 5407 | private function assertAliasesCorrect(array $expectedAliasProperties, array $actualAliases) |
||
| 5445 | |||
| 5446 | /** |
||
| 5447 | * Asserts that the given fields are equal to the default fields fixture. |
||
| 5448 | * |
||
| 5449 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5450 | */ |
||
| 5451 | private function assertAllFieldsEquals(array $fields) |
||
| 5458 | |||
| 5459 | /** |
||
| 5460 | * Asserts that the given fields are equal to a language filtered set of the |
||
| 5461 | * default fields fixture. |
||
| 5462 | * |
||
| 5463 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5464 | * @param string $languageCode |
||
| 5465 | */ |
||
| 5466 | private function assertLocaleFieldsEquals(array $fields, $languageCode) |
||
| 5480 | |||
| 5481 | /** |
||
| 5482 | * This method normalizes a set of fields and returns a normalized set. |
||
| 5483 | * |
||
| 5484 | * Normalization means it resets the storage specific field id to zero and |
||
| 5485 | * it sorts the field by their identifier and their language code. In |
||
| 5486 | * addition, the field value is removed, since this one depends on the |
||
| 5487 | * specific FieldType, which is tested in a dedicated integration test. |
||
| 5488 | * |
||
| 5489 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5490 | * |
||
| 5491 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 5492 | */ |
||
| 5493 | private function normalizeFields(array $fields) |
||
| 5520 | |||
| 5521 | /** |
||
| 5522 | * Asserts that given Content has default ContentStates. |
||
| 5523 | * |
||
| 5524 | * @param ContentInfo $contentInfo |
||
| 5525 | */ |
||
| 5526 | private function assertDefaultContentStates(ContentInfo $contentInfo) |
||
| 5544 | |||
| 5545 | /** |
||
| 5546 | * Assert that given Content has no references to a translation specified by the $languageCode. |
||
| 5547 | * |
||
| 5548 | * @param string $languageCode |
||
| 5549 | * @param int $contentId |
||
| 5550 | */ |
||
| 5551 | private function assertTranslationDoesNotExist($languageCode, $contentId) |
||
| 5570 | |||
| 5571 | /** |
||
| 5572 | * Returns the default fixture of fields used in most tests. |
||
| 5573 | * |
||
| 5574 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 5575 | */ |
||
| 5576 | private function createFieldsFixture() |
||
| 5617 | |||
| 5618 | /** |
||
| 5619 | * Gets expected property values for the "Media" ContentInfo ValueObject. |
||
| 5620 | * |
||
| 5621 | * @return array |
||
| 5622 | */ |
||
| 5623 | private function getExpectedMediaContentInfoProperties() |
||
| 5642 | |||
| 5643 | /** |
||
| 5644 | * @covers \eZ\Publish\API\Repository\ContentService::hideContent |
||
| 5645 | * |
||
| 5646 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 5647 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 5648 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 5649 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
| 5650 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 5651 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 5652 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 5653 | */ |
||
| 5654 | public function testHideContent(): void |
||
| 5688 | |||
| 5689 | /** |
||
| 5690 | * @covers \eZ\Publish\API\Repository\ContentService::revealContent |
||
| 5691 | * |
||
| 5692 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
| 5693 | * @throws NotFoundException |
||
| 5694 | * @throws UnauthorizedException |
||
| 5695 | */ |
||
| 5696 | public function testRevealContent() |
||
| 5743 | |||
| 5744 | /** |
||
| 5745 | * @depends testRevealContent |
||
| 5746 | */ |
||
| 5747 | public function testRevealContentWithHiddenParent() |
||
| 5801 | |||
| 5802 | /** |
||
| 5803 | * @depends testRevealContent |
||
| 5804 | */ |
||
| 5805 | public function testRevealContentWithHiddenChildren() |
||
| 5869 | |||
| 5870 | public function testHideContentWithParentLocation() |
||
| 5916 | |||
| 5917 | public function testChangeContentName() |
||
| 5938 | |||
| 5939 | public function testCopyTranslationsFromPublishedToDraft() |
||
| 6001 | |||
| 6002 | /** |
||
| 6003 | * Create structure of parent folders with Locations to be used for Content hide/reveal tests. |
||
| 6004 | * |
||
| 6005 | * @param int $parentLocationId |
||
| 6006 | * |
||
| 6007 | * @return \eZ\Publish\API\Repository\Values\Content\Location[] A list of Locations aimed to be parents |
||
| 6008 | * |
||
| 6009 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
| 6010 | * @throws NotFoundException |
||
| 6011 | * @throws UnauthorizedException |
||
| 6012 | */ |
||
| 6013 | private function createParentLocationsForHideReveal(int $parentLocationId): array |
||
| 6023 | |||
| 6024 | /** |
||
| 6025 | * Filter Locations list by hidden only. |
||
| 6026 | * |
||
| 6027 | * @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
||
| 6028 | * |
||
| 6029 | * @return array |
||
| 6030 | */ |
||
| 6031 | private function filterHiddenLocations(array $locations): array |
||
| 6042 | |||
| 6043 | public function testPublishVersionWithSelectedLanguages() |
||
| 6072 | |||
| 6073 | public function testCreateContentWithRomanianSpecialCharsInTitle() |
||
| 6084 | |||
| 6085 | /** |
||
| 6086 | * @param int $amountOfDrafts |
||
| 6087 | * |
||
| 6088 | * @throws UnauthorizedException |
||
| 6089 | */ |
||
| 6090 | private function createContentDrafts(int $amountOfDrafts): void |
||
| 6102 | |||
| 6103 | /** |
||
| 6104 | * @param array $limitationValues |
||
| 6105 | * |
||
| 6106 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
| 6107 | * |
||
| 6108 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
| 6109 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 6110 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 6111 | */ |
||
| 6112 | private function createUserWithVersionreadLimitations(array $limitationValues = [2]): User |
||
| 6128 | } |
||
| 6129 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.