|
@@ 33-66 (lines=34) @@
|
| 30 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 31 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
| 32 |
|
*/ |
| 33 |
|
public function testCreateContentThrowsUnauthorizedException() |
| 34 |
|
{ |
| 35 |
|
if ($this->isVersion4()) { |
| 36 |
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
$repository = $this->getRepository(); |
| 40 |
|
|
| 41 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 42 |
|
/* BEGIN: Use Case */ |
| 43 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 44 |
|
// demo installation |
| 45 |
|
// Load the user service |
| 46 |
|
$userService = $repository->getUserService(); |
| 47 |
|
|
| 48 |
|
// Set anonymous user |
| 49 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 50 |
|
|
| 51 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 52 |
|
|
| 53 |
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
| 54 |
|
|
| 55 |
|
$contentService = $repository->getContentService(); |
| 56 |
|
|
| 57 |
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
| 58 |
|
$contentCreate->setField('name', 'Awesome Sindelfingen forum'); |
| 59 |
|
|
| 60 |
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
| 61 |
|
$contentCreate->alwaysAvailable = true; |
| 62 |
|
|
| 63 |
|
// This call will fail with a "UnauthorizedException" |
| 64 |
|
$contentService->createContent($contentCreate); |
| 65 |
|
/* END: Use Case */ |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
/** |
| 69 |
|
* Test for the createContent() method. |
|
@@ 969-1001 (lines=33) @@
|
| 966 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
| 967 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
| 968 |
|
*/ |
| 969 |
|
public function testUpdateContentThrowsUnauthorizedException() |
| 970 |
|
{ |
| 971 |
|
$repository = $this->getRepository(); |
| 972 |
|
$contentService = $repository->getContentService(); |
| 973 |
|
|
| 974 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 975 |
|
/* BEGIN: Use Case */ |
| 976 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 977 |
|
// demo installation |
| 978 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 979 |
|
// demo installation |
| 980 |
|
$draftVersion2 = $this->createContentDraftVersion2(); |
| 981 |
|
|
| 982 |
|
// Get VersionInfo instance |
| 983 |
|
$versionInfo = $draftVersion2->getVersionInfo(); |
| 984 |
|
|
| 985 |
|
// Load the user service |
| 986 |
|
$userService = $repository->getUserService(); |
| 987 |
|
|
| 988 |
|
// Set anonymous user |
| 989 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 990 |
|
|
| 991 |
|
// Create an update struct and modify some fields |
| 992 |
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
| 993 |
|
$contentUpdate->setField('name', 'An awesome² story about ezp.'); |
| 994 |
|
$contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
| 995 |
|
|
| 996 |
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
| 997 |
|
|
| 998 |
|
// This call will fail with a "UnauthorizedException" |
| 999 |
|
$contentService->updateContent($versionInfo, $contentUpdate); |
| 1000 |
|
/* END: Use Case */ |
| 1001 |
|
} |
| 1002 |
|
|
| 1003 |
|
/** |
| 1004 |
|
* Test for the publishVersion() method. |