| @@ 996-1030 (lines=35) @@ | ||
| 993 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
|
| 994 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 995 | */ |
|
| 996 | public function testUpdateContentThrowsUnauthorizedException() |
|
| 997 | { |
|
| 998 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 999 | ||
| 1000 | $repository = $this->getRepository(); |
|
| 1001 | $contentService = $repository->getContentService(); |
|
| 1002 | ||
| 1003 | $anonymousUserId = $this->generateId('user', 10); |
|
| 1004 | /* BEGIN: Use Case */ |
|
| 1005 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 1006 | // demo installation |
|
| 1007 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 1008 | // demo installation |
|
| 1009 | $draftVersion2 = $this->createContentDraftVersion2(); |
|
| 1010 | ||
| 1011 | // Get VersionInfo instance |
|
| 1012 | $versionInfo = $draftVersion2->getVersionInfo(); |
|
| 1013 | ||
| 1014 | // Load the user service |
|
| 1015 | $userService = $repository->getUserService(); |
|
| 1016 | ||
| 1017 | // Set anonymous user |
|
| 1018 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 1019 | ||
| 1020 | // Create an update struct and modify some fields |
|
| 1021 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 1022 | $contentUpdate->setField('name', 'An awesome² story about ezp.'); |
|
| 1023 | $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
|
| 1024 | ||
| 1025 | $contentUpdate->initialLanguageCode = 'eng-US'; |
|
| 1026 | ||
| 1027 | // This call will fail with a "UnauthorizedException" |
|
| 1028 | $contentService->updateContent($versionInfo, $contentUpdate); |
|
| 1029 | /* END: Use Case */ |
|
| 1030 | } |
|
| 1031 | ||
| 1032 | /** |
|
| 1033 | * Test for the publishVersion() method. |
|
| @@ 1746-1771 (lines=26) @@ | ||
| 1743 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
|
| 1744 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 1745 | */ |
|
| 1746 | public function testUpdateContentThrowsContentFieldValidationException() |
|
| 1747 | { |
|
| 1748 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class); |
|
| 1749 | ||
| 1750 | $repository = $this->getRepository(); |
|
| 1751 | ||
| 1752 | /* BEGIN: Use Case */ |
|
| 1753 | $contentTypeService = $repository->getContentTypeService(); |
|
| 1754 | $contentService = $repository->getContentService(); |
|
| 1755 | ||
| 1756 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 1757 | ||
| 1758 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 1759 | $contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
|
| 1760 | ||
| 1761 | $draft = $contentService->createContent($contentCreate); |
|
| 1762 | ||
| 1763 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 1764 | // Violates string length constraint |
|
| 1765 | $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US'); |
|
| 1766 | ||
| 1767 | // Throws ContentFieldValidationException because the string length |
|
| 1768 | // validation of the field "short_name" fails |
|
| 1769 | $contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
|
| 1770 | /* END: Use Case */ |
|
| 1771 | } |
|
| 1772 | ||
| 1773 | /** |
|
| 1774 | * Test for the updateContent() method. |
|