|
@@ 216-243 (lines=28) @@
|
| 213 |
|
* @see \eZ\Publish\API\Repository\RoleService::createRoleDraft() |
| 214 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewRoleCreateStruct |
| 215 |
|
*/ |
| 216 |
|
public function testCreateRoleDraft() |
| 217 |
|
{ |
| 218 |
|
$repository = $this->getRepository(); |
| 219 |
|
|
| 220 |
|
/* BEGIN: Use Case */ |
| 221 |
|
|
| 222 |
|
$roleService = $repository->getRoleService(); |
| 223 |
|
$roleCreate = $roleService->newRoleCreateStruct('roleName'); |
| 224 |
|
|
| 225 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 226 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 227 |
|
|
| 228 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 229 |
|
$roleService->addPolicyByRoleDraft( |
| 230 |
|
$roleDraft, |
| 231 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 232 |
|
); |
| 233 |
|
$roleService->publishRoleDraft($roleDraft); |
| 234 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 235 |
|
$newRoleDraft = $roleService->createRoleDraft($role); |
| 236 |
|
|
| 237 |
|
/* END: Use Case */ |
| 238 |
|
|
| 239 |
|
$this->assertInstanceOf( |
| 240 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\RoleDraft', |
| 241 |
|
$newRoleDraft |
| 242 |
|
); |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
/** |
| 246 |
|
* Test for the createRole() method. |
|
@@ 277-302 (lines=26) @@
|
| 274 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 275 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
| 276 |
|
*/ |
| 277 |
|
public function testCreateRoleDraftThrowsInvalidArgumentException() |
| 278 |
|
{ |
| 279 |
|
$repository = $this->getRepository(); |
| 280 |
|
|
| 281 |
|
/* BEGIN: Use Case */ |
| 282 |
|
|
| 283 |
|
$roleService = $repository->getRoleService(); |
| 284 |
|
$roleCreate = $roleService->newRoleCreateStruct('Editor'); |
| 285 |
|
|
| 286 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 287 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 288 |
|
|
| 289 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 290 |
|
$roleService->addPolicyByRoleDraft( |
| 291 |
|
$roleDraft, |
| 292 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 293 |
|
); |
| 294 |
|
$roleService->publishRoleDraft($roleDraft); |
| 295 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 296 |
|
$roleService->createRoleDraft($role); // First role draft |
| 297 |
|
|
| 298 |
|
// This call will fail with an InvalidArgumentException, because there is already a draft |
| 299 |
|
$roleService->createRoleDraft($role); |
| 300 |
|
|
| 301 |
|
/* END: Use Case */ |
| 302 |
|
} |
| 303 |
|
|
| 304 |
|
/** |
| 305 |
|
* Test for the createRole() method. |
|
@@ 791-816 (lines=26) @@
|
| 788 |
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
| 789 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdateRole |
| 790 |
|
*/ |
| 791 |
|
public function testUpdateRoleThrowsInvalidArgumentException() |
| 792 |
|
{ |
| 793 |
|
$repository = $this->getRepository(); |
| 794 |
|
|
| 795 |
|
/* BEGIN: Use Case */ |
| 796 |
|
$roleService = $repository->getRoleService(); |
| 797 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 798 |
|
|
| 799 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 800 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 801 |
|
|
| 802 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 803 |
|
$roleService->addPolicyByRoleDraft( |
| 804 |
|
$roleDraft, |
| 805 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 806 |
|
); |
| 807 |
|
$roleService->publishRoleDraft($roleDraft); |
| 808 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 809 |
|
|
| 810 |
|
$roleUpdate = $roleService->newRoleUpdateStruct(); |
| 811 |
|
$roleUpdate->identifier = 'Editor'; |
| 812 |
|
|
| 813 |
|
// This call will fail with an InvalidArgumentException, because Editor is a predefined role |
| 814 |
|
$roleService->updateRole($role, $roleUpdate); |
| 815 |
|
/* END: Use Case */ |
| 816 |
|
} |
| 817 |
|
|
| 818 |
|
/** |
| 819 |
|
* Test for the updateRoleDraft() method. |
|
@@ 853-876 (lines=24) @@
|
| 850 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
| 851 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoles |
| 852 |
|
*/ |
| 853 |
|
public function testDeleteRole() |
| 854 |
|
{ |
| 855 |
|
$repository = $this->getRepository(); |
| 856 |
|
|
| 857 |
|
/* BEGIN: Use Case */ |
| 858 |
|
$roleService = $repository->getRoleService(); |
| 859 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 860 |
|
|
| 861 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 862 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 863 |
|
|
| 864 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 865 |
|
$roleService->addPolicyByRoleDraft( |
| 866 |
|
$roleDraft, |
| 867 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 868 |
|
); |
| 869 |
|
$roleService->publishRoleDraft($roleDraft); |
| 870 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 871 |
|
|
| 872 |
|
$roleService->deleteRole($role); |
| 873 |
|
/* END: Use Case */ |
| 874 |
|
|
| 875 |
|
$this->assertEquals(5, count($roleService->loadRoles())); |
| 876 |
|
} |
| 877 |
|
|
| 878 |
|
/** |
| 879 |
|
* Test for the deleteRoleDraft() method. |
|
@@ 1724-1755 (lines=32) @@
|
| 1721 |
|
* @see \eZ\Publish\API\Repository\RoleService::removePolicyByRoleDraft() |
| 1722 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
| 1723 |
|
*/ |
| 1724 |
|
public function testRemovePolicyByRoleDraft() |
| 1725 |
|
{ |
| 1726 |
|
$repository = $this->getRepository(); |
| 1727 |
|
|
| 1728 |
|
/* BEGIN: Use Case */ |
| 1729 |
|
$roleService = $repository->getRoleService(); |
| 1730 |
|
|
| 1731 |
|
// Instantiate a new role create |
| 1732 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 1733 |
|
|
| 1734 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 1735 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 1736 |
|
|
| 1737 |
|
// Create a new role with two policies |
| 1738 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 1739 |
|
$roleService->addPolicyByRoleDraft( |
| 1740 |
|
$roleDraft, |
| 1741 |
|
$roleService->newPolicyCreateStruct('content', 'create') |
| 1742 |
|
); |
| 1743 |
|
$roleService->addPolicyByRoleDraft( |
| 1744 |
|
$roleDraft, |
| 1745 |
|
$roleService->newPolicyCreateStruct('content', 'delete') |
| 1746 |
|
); |
| 1747 |
|
|
| 1748 |
|
// Delete all policies from the new role |
| 1749 |
|
foreach ($roleDraft->getPolicies() as $policy) { |
| 1750 |
|
$roleDraft = $roleService->removePolicyByRoleDraft($roleDraft, $policy); |
| 1751 |
|
} |
| 1752 |
|
/* END: Use Case */ |
| 1753 |
|
|
| 1754 |
|
$this->assertSame(array(), $roleDraft->getPolicies()); |
| 1755 |
|
} |
| 1756 |
|
|
| 1757 |
|
/** |
| 1758 |
|
* Test for the deletePolicy() method. |
|
@@ 2863-2892 (lines=30) @@
|
| 2860 |
|
* @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft() |
| 2861 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
| 2862 |
|
*/ |
| 2863 |
|
public function testPublishRoleDraft() |
| 2864 |
|
{ |
| 2865 |
|
$repository = $this->getRepository(); |
| 2866 |
|
|
| 2867 |
|
/* BEGIN: Use Case */ |
| 2868 |
|
$roleService = $repository->getRoleService(); |
| 2869 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 2870 |
|
|
| 2871 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2872 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2873 |
|
|
| 2874 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2875 |
|
|
| 2876 |
|
$roleDraft = $roleService->addPolicyByRoleDraft( |
| 2877 |
|
$roleDraft, |
| 2878 |
|
$roleService->newPolicyCreateStruct('content', 'delete') |
| 2879 |
|
); |
| 2880 |
|
$roleDraft = $roleService->addPolicyByRoleDraft( |
| 2881 |
|
$roleDraft, |
| 2882 |
|
$roleService->newPolicyCreateStruct('content', 'create') |
| 2883 |
|
); |
| 2884 |
|
|
| 2885 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2886 |
|
/* END: Use Case */ |
| 2887 |
|
|
| 2888 |
|
$this->assertInstanceOf( |
| 2889 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\Role', |
| 2890 |
|
$roleService->loadRoleByIdentifier($roleCreate->identifier) |
| 2891 |
|
); |
| 2892 |
|
} |
| 2893 |
|
|
| 2894 |
|
/** |
| 2895 |
|
* Test for the publishRoleDraft() method. |