|
@@ 610-641 (lines=32) @@
|
| 607 |
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
| 608 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 609 |
|
*/ |
| 610 |
|
public function testLoadContentThrowsUnauthorizedExceptionOnDrafts() |
| 611 |
|
{ |
| 612 |
|
/** @var $repository \eZ\Publish\API\Repository\Repository */ |
| 613 |
|
$repository = $this->getRepository(); |
| 614 |
|
|
| 615 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 616 |
|
/* BEGIN: Use Case */ |
| 617 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 618 |
|
// demo installation |
| 619 |
|
$user = $this->createUserVersion1(); |
| 620 |
|
|
| 621 |
|
// Set new editor as a content owner |
| 622 |
|
$repository->setCurrentUser($user); |
| 623 |
|
|
| 624 |
|
// Create draft with this user |
| 625 |
|
$draft = $this->createContentDraftVersion1(2, 'folder'); |
| 626 |
|
|
| 627 |
|
// Load anonymous user |
| 628 |
|
$userService = $repository->getUserService(); |
| 629 |
|
$user = $userService->loadUser($anonymousUserId); |
| 630 |
|
$repository->setCurrentUser($user); |
| 631 |
|
|
| 632 |
|
// Try to load the draft with anonymous user to make sure access won't be allowed by throwing an exception |
| 633 |
|
$contentService = $repository->getContentService(); |
| 634 |
|
|
| 635 |
|
$this->expectException(UnauthorizedException::class); |
| 636 |
|
// content versionread policy is needed because it is a draft |
| 637 |
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
| 638 |
|
|
| 639 |
|
$contentService->loadContent($draft->id); |
| 640 |
|
/* END: Use Case */ |
| 641 |
|
} |
| 642 |
|
|
| 643 |
|
/** |
| 644 |
|
* Test for the ContentService::loadContent() method on an archive. |
|
@@ 903-930 (lines=28) @@
|
| 900 |
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
| 901 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
| 902 |
|
*/ |
| 903 |
|
public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
| 904 |
|
{ |
| 905 |
|
$repository = $this->getRepository(); |
| 906 |
|
|
| 907 |
|
$contentService = $repository->getContentService(); |
| 908 |
|
|
| 909 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 910 |
|
/* BEGIN: Use Case */ |
| 911 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 912 |
|
// demo installation |
| 913 |
|
$content = $this->createContentVersion1(); |
| 914 |
|
|
| 915 |
|
// Get ContentInfo and VersionInfo instances |
| 916 |
|
$contentInfo = $content->contentInfo; |
| 917 |
|
$versionInfo = $content->getVersionInfo(); |
| 918 |
|
|
| 919 |
|
// Load the user service |
| 920 |
|
$userService = $repository->getUserService(); |
| 921 |
|
|
| 922 |
|
// Set anonymous user |
| 923 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 924 |
|
|
| 925 |
|
$this->expectException(UnauthorizedException::class); |
| 926 |
|
$this->expectExceptionMessageRegExp('/\'edit\' \'content\'/'); |
| 927 |
|
|
| 928 |
|
$contentService->createContentDraft($contentInfo, $versionInfo); |
| 929 |
|
/* END: Use Case */ |
| 930 |
|
} |
| 931 |
|
|
| 932 |
|
/** |
| 933 |
|
* Test for the loadContentDrafts() method. |
|
@@ 968-996 (lines=29) @@
|
| 965 |
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
| 966 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
| 967 |
|
*/ |
| 968 |
|
public function testLoadContentDraftsThrowsUnauthorizedExceptionWithFirstParameter() |
| 969 |
|
{ |
| 970 |
|
$repository = $this->getRepository(); |
| 971 |
|
|
| 972 |
|
$administratorUserId = $this->generateId('user', 14); |
| 973 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 974 |
|
/* BEGIN: Use Case */ |
| 975 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 976 |
|
// demo installation |
| 977 |
|
// $administratorUserId is the ID of the "Administrator" user in a eZ |
| 978 |
|
// Publish demo installation. |
| 979 |
|
|
| 980 |
|
$contentService = $repository->getContentService(); |
| 981 |
|
|
| 982 |
|
// Load the user service |
| 983 |
|
$userService = $repository->getUserService(); |
| 984 |
|
|
| 985 |
|
// Load the "Administrator" user |
| 986 |
|
$administratorUser = $userService->loadUser($administratorUserId); |
| 987 |
|
|
| 988 |
|
// Set anonymous user |
| 989 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 990 |
|
|
| 991 |
|
$this->expectException(UnauthorizedException::class); |
| 992 |
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
| 993 |
|
|
| 994 |
|
$contentService->loadContentDrafts($administratorUser); |
| 995 |
|
/* END: Use Case */ |
| 996 |
|
} |
| 997 |
|
|
| 998 |
|
/** |
| 999 |
|
* Test for the updateContent() method. |
|
@@ 1334-1369 (lines=36) @@
|
| 1331 |
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
| 1332 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
| 1333 |
|
*/ |
| 1334 |
|
public function testAddRelationThrowsUnauthorizedException() |
| 1335 |
|
{ |
| 1336 |
|
$repository = $this->getRepository(); |
| 1337 |
|
|
| 1338 |
|
$contentService = $repository->getContentService(); |
| 1339 |
|
|
| 1340 |
|
$anonymousUserId = $this->generateId('user', 10); |
| 1341 |
|
/* BEGIN: Use Case */ |
| 1342 |
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
| 1343 |
|
// demo installation |
| 1344 |
|
// Remote id of the "Media" page of a eZ Publish demo installation. |
| 1345 |
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
| 1346 |
|
|
| 1347 |
|
$draft = $this->createContentDraftVersion1(); |
| 1348 |
|
|
| 1349 |
|
// Get the draft's version info |
| 1350 |
|
$versionInfo = $draft->getVersionInfo(); |
| 1351 |
|
|
| 1352 |
|
// Load other content object |
| 1353 |
|
$media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
| 1354 |
|
|
| 1355 |
|
// Load the user service |
| 1356 |
|
$userService = $repository->getUserService(); |
| 1357 |
|
|
| 1358 |
|
// Set anonymous user |
| 1359 |
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
| 1360 |
|
|
| 1361 |
|
$this->expectException(UnauthorizedException::class); |
| 1362 |
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
| 1363 |
|
|
| 1364 |
|
$contentService->addRelation( |
| 1365 |
|
$versionInfo, |
| 1366 |
|
$media |
| 1367 |
|
); |
| 1368 |
|
/* END: Use Case */ |
| 1369 |
|
} |
| 1370 |
|
|
| 1371 |
|
/** |
| 1372 |
|
* Test for the deleteRelation() method. |