|
@@ 34-69 (lines=36) @@
|
| 31 |
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
| 32 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
| 33 |
|
*/ |
| 34 |
|
public function testCreateContentThrowsUnauthorizedException() |
| 35 |
|
{ |
| 36 |
|
if ($this->isVersion4()) { |
| 37 |
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
$repository = $this->getRepository(); |
| 41 |
|
|
| 42 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 43 |
|
/* BEGIN: Use Case */ |
| 44 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 45 |
|
// demo installation |
| 46 |
|
// Load the user service |
| 47 |
|
$userService = $repository->getUserService(); |
| 48 |
|
|
| 49 |
|
// Set anonymous user |
| 50 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 51 |
|
|
| 52 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 53 |
|
|
| 54 |
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
| 55 |
|
|
| 56 |
|
$contentService = $repository->getContentService(); |
| 57 |
|
|
| 58 |
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
| 59 |
|
$contentCreate->setField('name', 'Awesome Sindelfingen forum'); |
| 60 |
|
|
| 61 |
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
| 62 |
|
$contentCreate->alwaysAvailable = true; |
| 63 |
|
|
| 64 |
|
$this->expectException(UnauthorizedException::class); |
| 65 |
|
$this->expectExceptionMessageRegExp('/\'create\' \'content\'/'); |
| 66 |
|
|
| 67 |
|
$contentService->createContent($contentCreate); |
| 68 |
|
/* END: Use Case */ |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
|
* Test for the createContent() method. |
|
@@ 1004-1039 (lines=36) @@
|
| 1001 |
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
| 1002 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
| 1003 |
|
*/ |
| 1004 |
|
public function testUpdateContentThrowsUnauthorizedException() |
| 1005 |
|
{ |
| 1006 |
|
$repository = $this->getRepository(); |
| 1007 |
|
$contentService = $repository->getContentService(); |
| 1008 |
|
|
| 1009 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1010 |
|
/* BEGIN: Use Case */ |
| 1011 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1012 |
|
// demo installation |
| 1013 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1014 |
|
// demo installation |
| 1015 |
|
$draftVersion2 = $this->createContentDraftVersion2(); |
| 1016 |
|
|
| 1017 |
|
// Get VersionInfo instance |
| 1018 |
|
$versionInfo = $draftVersion2->getVersionInfo(); |
| 1019 |
|
|
| 1020 |
|
// Load the user service |
| 1021 |
|
$userService = $repository->getUserService(); |
| 1022 |
|
|
| 1023 |
|
// Set anonymous user |
| 1024 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1025 |
|
|
| 1026 |
|
// Create an update struct and modify some fields |
| 1027 |
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
| 1028 |
|
$contentUpdate->setField('name', 'An awesome² story about ezp.'); |
| 1029 |
|
$contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
| 1030 |
|
|
| 1031 |
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
| 1032 |
|
|
| 1033 |
|
$this->expectException(UnauthorizedException::class); |
| 1034 |
|
/* TODO - the `content/edit` policy should be probably needed */ |
| 1035 |
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
| 1036 |
|
|
| 1037 |
|
$contentService->updateContent($versionInfo, $contentUpdate); |
| 1038 |
|
/* END: Use Case */ |
| 1039 |
|
} |
| 1040 |
|
|
| 1041 |
|
/** |
| 1042 |
|
* Test for the publishVersion() method. |