| @@ 31-64 (lines=34) @@ | ||
| 28 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 29 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
|
| 30 | */ |
|
| 31 | public function testCreateContentThrowsUnauthorizedException() |
|
| 32 | { |
|
| 33 | if ($this->isVersion4()) { |
|
| 34 | $this->markTestSkipped('This test requires eZ Publish 5'); |
|
| 35 | } |
|
| 36 | ||
| 37 | $repository = $this->getRepository(); |
|
| 38 | ||
| 39 | $anonymousUserId = $this->generateId('user', 10); |
|
| 40 | /* BEGIN: Use Case */ |
|
| 41 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 42 | // demo installation |
|
| 43 | // Load the user service |
|
| 44 | $userService = $repository->getUserService(); |
|
| 45 | ||
| 46 | // Set anonymous user |
|
| 47 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 48 | ||
| 49 | $contentTypeService = $repository->getContentTypeService(); |
|
| 50 | ||
| 51 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
|
| 52 | ||
| 53 | $contentService = $repository->getContentService(); |
|
| 54 | ||
| 55 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 56 | $contentCreate->setField('name', 'Awesome Sindelfingen forum'); |
|
| 57 | ||
| 58 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 59 | $contentCreate->alwaysAvailable = true; |
|
| 60 | ||
| 61 | // This call will fail with a "UnauthorizedException" |
|
| 62 | $contentService->createContent($contentCreate); |
|
| 63 | /* END: Use Case */ |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * Test for the createContent() method. |
|
| @@ 926-959 (lines=34) @@ | ||
| 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 | $anonymousUserId = $this->generateId('user', 10); |
|
| 933 | /* BEGIN: Use Case */ |
|
| 934 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 935 | // demo installation |
|
| 936 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 937 | // demo installation |
|
| 938 | $draftVersion2 = $this->createContentDraftVersion2(); |
|
| 939 | ||
| 940 | // Get VersionInfo instance |
|
| 941 | $versionInfo = $draftVersion2->getVersionInfo(); |
|
| 942 | ||
| 943 | // Load the user service |
|
| 944 | $userService = $repository->getUserService(); |
|
| 945 | ||
| 946 | // Set anonymous user |
|
| 947 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 948 | ||
| 949 | // Create an update struct and modify some fields |
|
| 950 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 951 | $contentUpdate->setField('name', 'An awesome² story about ezp.'); |
|
| 952 | $contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
|
| 953 | ||
| 954 | $contentUpdate->initialLanguageCode = 'eng-US'; |
|
| 955 | ||
| 956 | // This call will fail with a "UnauthorizedException" |
|
| 957 | $contentService->updateContent($versionInfo, $contentUpdate); |
|
| 958 | /* END: Use Case */ |
|
| 959 | } |
|
| 960 | ||
| 961 | /** |
|
| 962 | * Test for the publishVersion() method. |
|
| @@ 1456-1479 (lines=24) @@ | ||
| 1453 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
|
| 1454 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
| 1455 | */ |
|
| 1456 | public function testUpdateContentThrowsContentFieldValidationException() |
|
| 1457 | { |
|
| 1458 | $repository = $this->getRepository(); |
|
| 1459 | ||
| 1460 | /* BEGIN: Use Case */ |
|
| 1461 | $contentTypeService = $repository->getContentTypeService(); |
|
| 1462 | $contentService = $repository->getContentService(); |
|
| 1463 | ||
| 1464 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 1465 | ||
| 1466 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 1467 | $contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
|
| 1468 | ||
| 1469 | $draft = $contentService->createContent($contentCreate); |
|
| 1470 | ||
| 1471 | $contentUpdate = $contentService->newContentUpdateStruct(); |
|
| 1472 | // Violates string length constraint |
|
| 1473 | $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US'); |
|
| 1474 | ||
| 1475 | // Throws ContentFieldValidationException because the string length |
|
| 1476 | // validation of the field "short_name" fails |
|
| 1477 | $contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
|
| 1478 | /* END: Use Case */ |
|
| 1479 | } |
|
| 1480 | ||
| 1481 | /** |
|
| 1482 | * Test for the updateContent() method. |
|