| @@ 926-958 (lines=33) @@ | ||
| 923 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 924 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 925 | */ |
|
| 926 | public function testUpdateContentThrowsUnauthorizedException() |
|
| 927 | { |
|
| 928 | $repository = $this->getRepository(); |
|
| 929 | $contentService = $repository->getContentService(); |
|
| 930 | ||
| 931 | $anonymousUserId = $this->generateId('user', 10); |
|
| 932 | /* BEGIN: Use Case */ |
|
| 933 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 934 | // demo installation |
|
| 935 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 936 | // demo installation |
|
| 937 | $draftVersion2 = $this->createContentDraftVersion2(); |
|
| 938 | ||
| 939 | // Get VersionInfo instance |
|
| 940 | $versionInfo = $draftVersion2->getVersionInfo(); |
|
| 941 | ||
| 942 | // Load the user service |
|
| 943 | $userService = $repository->getUserService(); |
|
| 944 | ||
| 945 | // Set anonymous user |
|
| 946 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 947 | ||
| 948 | // Create an update struct and modify some fields |
|
| 949 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 950 | $contentUpdate->setField('name', 'An awesome² story about ezp.'); |
|
| 951 | $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
|
| 952 | ||
| 953 | $contentUpdate->initialLanguageCode = 'eng-US'; |
|
| 954 | ||
| 955 | // This call will fail with a "UnauthorizedException" |
|
| 956 | $contentService->updateContent($versionInfo, $contentUpdate); |
|
| 957 | /* END: Use Case */ |
|
| 958 | } |
|
| 959 | ||
| 960 | /** |
|
| 961 | * Test for the publishVersion() method. |
|
| @@ 1639-1662 (lines=24) @@ | ||
| 1636 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
|
| 1637 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 1638 | */ |
|
| 1639 | public function testUpdateContentThrowsContentFieldValidationException() |
|
| 1640 | { |
|
| 1641 | $repository = $this->getRepository(); |
|
| 1642 | ||
| 1643 | /* BEGIN: Use Case */ |
|
| 1644 | $contentTypeService = $repository->getContentTypeService(); |
|
| 1645 | $contentService = $repository->getContentService(); |
|
| 1646 | ||
| 1647 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 1648 | ||
| 1649 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 1650 | $contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
|
| 1651 | ||
| 1652 | $draft = $contentService->createContent($contentCreate); |
|
| 1653 | ||
| 1654 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 1655 | // Violates string length constraint |
|
| 1656 | $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US'); |
|
| 1657 | ||
| 1658 | // Throws ContentFieldValidationException because the string length |
|
| 1659 | // validation of the field "short_name" fails |
|
| 1660 | $contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
|
| 1661 | /* END: Use Case */ |
|
| 1662 | } |
|
| 1663 | ||
| 1664 | /** |
|
| 1665 | * Test for the updateContent() method. |
|