|
@@ 1645-1678 (lines=34) @@
|
| 1642 |
|
* @see \eZ\Publish\API\Repository\RoleService::removePolicy() |
| 1643 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
| 1644 |
|
*/ |
| 1645 |
|
public function testRemovePolicy() |
| 1646 |
|
{ |
| 1647 |
|
$repository = $this->getRepository(); |
| 1648 |
|
|
| 1649 |
|
/* BEGIN: Use Case */ |
| 1650 |
|
$roleService = $repository->getRoleService(); |
| 1651 |
|
|
| 1652 |
|
// Instantiate a new role create |
| 1653 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 1654 |
|
|
| 1655 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 1656 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 1657 |
|
|
| 1658 |
|
// Create a new role with two policies |
| 1659 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 1660 |
|
$roleService->addPolicyByRoleDraft( |
| 1661 |
|
$roleDraft, |
| 1662 |
|
$roleService->newPolicyCreateStruct('content', 'create') |
| 1663 |
|
); |
| 1664 |
|
$roleService->addPolicyByRoleDraft( |
| 1665 |
|
$roleDraft, |
| 1666 |
|
$roleService->newPolicyCreateStruct('content', 'delete') |
| 1667 |
|
); |
| 1668 |
|
$roleService->publishRoleDraft($roleDraft); |
| 1669 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 1670 |
|
|
| 1671 |
|
// Delete all policies from the new role |
| 1672 |
|
foreach ($role->getPolicies() as $policy) { |
| 1673 |
|
$role = $roleService->removePolicy($role, $policy); |
| 1674 |
|
} |
| 1675 |
|
/* END: Use Case */ |
| 1676 |
|
|
| 1677 |
|
$this->assertSame(array(), $role->getPolicies()); |
| 1678 |
|
} |
| 1679 |
|
|
| 1680 |
|
/** |
| 1681 |
|
* Test for the removePolicyByRoleDraft() method. |
|
@@ 1726-1760 (lines=35) @@
|
| 1723 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRole |
| 1724 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicy |
| 1725 |
|
*/ |
| 1726 |
|
public function testDeletePolicy() |
| 1727 |
|
{ |
| 1728 |
|
$repository = $this->getRepository(); |
| 1729 |
|
|
| 1730 |
|
/* BEGIN: Use Case */ |
| 1731 |
|
$roleService = $repository->getRoleService(); |
| 1732 |
|
|
| 1733 |
|
// Instantiate a new role create |
| 1734 |
|
$roleCreate = $roleService->newRoleCreateStruct('newRole'); |
| 1735 |
|
|
| 1736 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 1737 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 1738 |
|
|
| 1739 |
|
// Create a new role with two policies |
| 1740 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 1741 |
|
$roleService->addPolicyByRoleDraft( |
| 1742 |
|
$roleDraft, |
| 1743 |
|
$roleService->newPolicyCreateStruct('content', 'create') |
| 1744 |
|
); |
| 1745 |
|
$roleService->addPolicyByRoleDraft( |
| 1746 |
|
$roleDraft, |
| 1747 |
|
$roleService->newPolicyCreateStruct('content', 'delete') |
| 1748 |
|
); |
| 1749 |
|
$roleService->publishRoleDraft($roleDraft); |
| 1750 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 1751 |
|
|
| 1752 |
|
// Delete all policies from the new role |
| 1753 |
|
foreach ($role->getPolicies() as $policy) { |
| 1754 |
|
$roleService->deletePolicy($policy); |
| 1755 |
|
} |
| 1756 |
|
/* END: Use Case */ |
| 1757 |
|
|
| 1758 |
|
$role = $roleService->loadRole($role->id); |
| 1759 |
|
$this->assertSame(array(), $role->getPolicies()); |
| 1760 |
|
} |
| 1761 |
|
|
| 1762 |
|
/** |
| 1763 |
|
* Test loading user/group role assignments. |