| @@ 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. |
|
| @@ 1732-1755 (lines=24) @@ | ||
| 1729 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
|
| 1730 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 1731 | */ |
|
| 1732 | public function testUpdateContentThrowsContentFieldValidationException() |
|
| 1733 | { |
|
| 1734 | $repository = $this->getRepository(); |
|
| 1735 | ||
| 1736 | /* BEGIN: Use Case */ |
|
| 1737 | $contentTypeService = $repository->getContentTypeService(); |
|
| 1738 | $contentService = $repository->getContentService(); |
|
| 1739 | ||
| 1740 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 1741 | ||
| 1742 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 1743 | $contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
|
| 1744 | ||
| 1745 | $draft = $contentService->createContent($contentCreate); |
|
| 1746 | ||
| 1747 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 1748 | // Violates string length constraint |
|
| 1749 | $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US'); |
|
| 1750 | ||
| 1751 | // Throws ContentFieldValidationException because the string length |
|
| 1752 | // validation of the field "short_name" fails |
|
| 1753 | $contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
|
| 1754 | /* END: Use Case */ |
|
| 1755 | } |
|
| 1756 | ||
| 1757 | /** |
|
| 1758 | * Test for the updateContent() method. |
|