|
@@ 607-631 (lines=25) @@
|
| 604 |
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
| 605 |
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
| 606 |
|
*/ |
| 607 |
|
public function testCanUserWithLimitationYes() |
| 608 |
|
{ |
| 609 |
|
$repository = $this->getRepository(); |
| 610 |
|
|
| 611 |
|
$imagesFolderId = $this->generateId('object', 49); |
| 612 |
|
|
| 613 |
|
/* BEGIN: Use Case */ |
| 614 |
|
// $imagesFolderId contains the ID of the "Images" folder |
| 615 |
|
|
| 616 |
|
$user = $this->createUserVersion1(); |
| 617 |
|
|
| 618 |
|
// Set created user as current user |
| 619 |
|
$repository->setCurrentUser($user); |
| 620 |
|
|
| 621 |
|
$contentService = $repository->getContentService(); |
| 622 |
|
|
| 623 |
|
// Performing an action having necessary permissions will succeed |
| 624 |
|
$imagesFolder = $contentService->loadContent($imagesFolderId); |
| 625 |
|
|
| 626 |
|
// This call will return true |
| 627 |
|
$canUser = $repository->canUser('content', 'read', $imagesFolder); |
| 628 |
|
/* END: Use Case */ |
| 629 |
|
|
| 630 |
|
$this->assertTrue($canUser); |
| 631 |
|
} |
| 632 |
|
|
| 633 |
|
/** |
| 634 |
|
* Test for the canUser() method. |
|
@@ 684-708 (lines=25) @@
|
| 681 |
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
| 682 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 683 |
|
*/ |
| 684 |
|
public function testCanUserThrowsInvalidArgumentException() |
| 685 |
|
{ |
| 686 |
|
$repository = $this->getRepository(); |
| 687 |
|
|
| 688 |
|
$userGroupContentTypeId = $this->generateId('type', 3); |
| 689 |
|
|
| 690 |
|
/* BEGIN: Use Case */ |
| 691 |
|
// $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
| 692 |
|
|
| 693 |
|
$user = $this->createUserVersion1(); |
| 694 |
|
|
| 695 |
|
// Set created user as current user |
| 696 |
|
$repository->setCurrentUser($user); |
| 697 |
|
|
| 698 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 699 |
|
|
| 700 |
|
// Load the "UserGroup" ContentType |
| 701 |
|
$userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
| 702 |
|
|
| 703 |
|
// This call will throw "InvalidArgumentException" because $userGroupContentType |
| 704 |
|
// is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
| 705 |
|
// which can not be checked for user access |
| 706 |
|
$canUser = $repository->canUser('content', 'create', $userGroupContentType); |
| 707 |
|
/* END: Use Case */ |
| 708 |
|
} |
| 709 |
|
|
| 710 |
|
/** |
| 711 |
|
* Test for the canUser() method. |
|
@@ 954-982 (lines=29) @@
|
| 951 |
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
| 952 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 953 |
|
*/ |
| 954 |
|
public function testCanUserWithTargetThrowsInvalidArgumentException() |
| 955 |
|
{ |
| 956 |
|
$repository = $this->getRepository(); |
| 957 |
|
|
| 958 |
|
$homeId = $this->generateId('object', 57); |
| 959 |
|
|
| 960 |
|
/* BEGIN: Use Case */ |
| 961 |
|
// $homeId contains the ID of the "Home" frontpage |
| 962 |
|
|
| 963 |
|
$user = $this->createUserVersion1(); |
| 964 |
|
|
| 965 |
|
// Set created user as current user |
| 966 |
|
$repository->setCurrentUser($user); |
| 967 |
|
|
| 968 |
|
$contentService = $repository->getContentService(); |
| 969 |
|
|
| 970 |
|
// Load the ContentInfo for "Home" frontpage |
| 971 |
|
$contentInfo = $contentService->loadContentInfo($homeId); |
| 972 |
|
|
| 973 |
|
// This call will throw "InvalidArgumentException" because $targets argument must be an |
| 974 |
|
// instance of \eZ\Publish\API\Repository\Values\ValueObject class or an array of the same |
| 975 |
|
$canUser = $repository->canUser( |
| 976 |
|
'content', |
| 977 |
|
'remove', |
| 978 |
|
$contentInfo, |
| 979 |
|
new \stdClass() |
| 980 |
|
); |
| 981 |
|
/* END: Use Case */ |
| 982 |
|
} |
| 983 |
|
|
| 984 |
|
/** |
| 985 |
|
* Test for the canUser() method. |