| @@ 624-648 (lines=25) @@ | ||
| 621 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
|
| 622 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 623 | */ |
|
| 624 | public function testCanUserWithLimitationYes() |
|
| 625 | { |
|
| 626 | $repository = $this->getRepository(); |
|
| 627 | ||
| 628 | $imagesFolderId = $this->generateId('object', 49); |
|
| 629 | ||
| 630 | /* BEGIN: Use Case */ |
|
| 631 | // $imagesFolderId contains the ID of the "Images" folder |
|
| 632 | ||
| 633 | $user = $this->createUserVersion1(); |
|
| 634 | ||
| 635 | // Set created user as current user |
|
| 636 | $repository->setCurrentUser($user); |
|
| 637 | ||
| 638 | $contentService = $repository->getContentService(); |
|
| 639 | ||
| 640 | // Performing an action having necessary permissions will succeed |
|
| 641 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
|
| 642 | ||
| 643 | // This call will return true |
|
| 644 | $canUser = $repository->canUser('content', 'read', $imagesFolder); |
|
| 645 | /* END: Use Case */ |
|
| 646 | ||
| 647 | $this->assertTrue($canUser); |
|
| 648 | } |
|
| 649 | ||
| 650 | /** |
|
| 651 | * Test for the canUser() method. |
|
| @@ 701-725 (lines=25) @@ | ||
| 698 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 699 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 700 | */ |
|
| 701 | public function testCanUserThrowsInvalidArgumentException() |
|
| 702 | { |
|
| 703 | $repository = $this->getRepository(); |
|
| 704 | ||
| 705 | $userGroupContentTypeId = $this->generateId('type', 3); |
|
| 706 | ||
| 707 | /* BEGIN: Use Case */ |
|
| 708 | // $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
|
| 709 | ||
| 710 | $user = $this->createUserVersion1(); |
|
| 711 | ||
| 712 | // Set created user as current user |
|
| 713 | $repository->setCurrentUser($user); |
|
| 714 | ||
| 715 | $contentTypeService = $repository->getContentTypeService(); |
|
| 716 | ||
| 717 | // Load the "UserGroup" ContentType |
|
| 718 | $userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
|
| 719 | ||
| 720 | // This call will throw "InvalidArgumentException" because $userGroupContentType |
|
| 721 | // is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
|
| 722 | // which can not be checked for user access |
|
| 723 | $canUser = $repository->canUser('content', 'create', $userGroupContentType); |
|
| 724 | /* END: Use Case */ |
|
| 725 | } |
|
| 726 | ||
| 727 | /** |
|
| 728 | * Test for the canUser() method. |
|
| @@ 971-999 (lines=29) @@ | ||
| 968 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 969 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 970 | */ |
|
| 971 | public function testCanUserWithTargetThrowsInvalidArgumentException() |
|
| 972 | { |
|
| 973 | $repository = $this->getRepository(); |
|
| 974 | ||
| 975 | $homeId = $this->generateId('object', 57); |
|
| 976 | ||
| 977 | /* BEGIN: Use Case */ |
|
| 978 | // $homeId contains the ID of the "Home" frontpage |
|
| 979 | ||
| 980 | $user = $this->createUserVersion1(); |
|
| 981 | ||
| 982 | // Set created user as current user |
|
| 983 | $repository->setCurrentUser($user); |
|
| 984 | ||
| 985 | $contentService = $repository->getContentService(); |
|
| 986 | ||
| 987 | // Load the ContentInfo for "Home" frontpage |
|
| 988 | $contentInfo = $contentService->loadContentInfo($homeId); |
|
| 989 | ||
| 990 | // This call will throw "InvalidArgumentException" because $targets argument must be an |
|
| 991 | // instance of \eZ\Publish\API\Repository\Values\ValueObject class or an array of the same |
|
| 992 | $canUser = $repository->canUser( |
|
| 993 | 'content', |
|
| 994 | 'remove', |
|
| 995 | $contentInfo, |
|
| 996 | new \stdClass() |
|
| 997 | ); |
|
| 998 | /* END: Use Case */ |
|
| 999 | } |
|
| 1000 | ||
| 1001 | /** |
|
| 1002 | * Test for the canUser() method. |
|
| @@ 347-373 (lines=27) @@ | ||
| 344 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
|
| 345 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 346 | */ |
|
| 347 | public function testCanUserWithLimitationYes() |
|
| 348 | { |
|
| 349 | $repository = $this->getRepository(); |
|
| 350 | ||
| 351 | $imagesFolderId = $this->generateId('object', 49); |
|
| 352 | ||
| 353 | /* BEGIN: Use Case */ |
|
| 354 | // $imagesFolderId contains the ID of the "Images" folder |
|
| 355 | ||
| 356 | $user = $this->createUserVersion1(); |
|
| 357 | ||
| 358 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 359 | ||
| 360 | // Set created user as current user reference |
|
| 361 | $permissionResolver->setCurrentUserReference($user); |
|
| 362 | ||
| 363 | $contentService = $repository->getContentService(); |
|
| 364 | ||
| 365 | // Performing an action having necessary permissions will succeed |
|
| 366 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
|
| 367 | ||
| 368 | // This call will return true |
|
| 369 | $canUser = $permissionResolver->canUser('content', 'read', $imagesFolder); |
|
| 370 | /* END: Use Case */ |
|
| 371 | ||
| 372 | $this->assertTrue($canUser); |
|
| 373 | } |
|
| 374 | ||
| 375 | /** |
|
| 376 | * Test for the canUser() method. |
|
| @@ 428-454 (lines=27) @@ | ||
| 425 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 426 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 427 | */ |
|
| 428 | public function testCanUserThrowsInvalidArgumentException() |
|
| 429 | { |
|
| 430 | $repository = $this->getRepository(); |
|
| 431 | ||
| 432 | $userGroupContentTypeId = $this->generateId('type', 3); |
|
| 433 | ||
| 434 | /* BEGIN: Use Case */ |
|
| 435 | // $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
|
| 436 | ||
| 437 | $user = $this->createUserVersion1(); |
|
| 438 | ||
| 439 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 440 | ||
| 441 | // Set created user as current user reference |
|
| 442 | $permissionResolver->setCurrentUserReference($user); |
|
| 443 | ||
| 444 | $contentTypeService = $repository->getContentTypeService(); |
|
| 445 | ||
| 446 | // Load the "UserGroup" ContentType |
|
| 447 | $userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
|
| 448 | ||
| 449 | // This call will throw "InvalidArgumentException" because $userGroupContentType |
|
| 450 | // is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
|
| 451 | // which can not be checked for user access |
|
| 452 | $canUser = $permissionResolver->canUser('content', 'create', $userGroupContentType); |
|
| 453 | /* END: Use Case */ |
|
| 454 | } |
|
| 455 | ||
| 456 | /** |
|
| 457 | * Test for the canUser() method. |
|