| @@ 1719-1816 (lines=98) @@ | ||
| 1716 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
|
| 1717 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 1718 | */ |
|
| 1719 | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1720 | { |
|
| 1721 | $repository = $this->getRepository(); |
|
| 1722 | $roleService = $repository->getRoleService(); |
|
| 1723 | ||
| 1724 | /* BEGIN: Use Case */ |
|
| 1725 | $user = $this->createUserVersion1(); |
|
| 1726 | ||
| 1727 | // Load the existing "Anonymous" role |
|
| 1728 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 1729 | ||
| 1730 | // Assign the "Anonymous" role to the newly created user |
|
| 1731 | $roleService->assignRoleToUser( |
|
| 1732 | $role, |
|
| 1733 | $user, |
|
| 1734 | new SubtreeLimitation( |
|
| 1735 | [ |
|
| 1736 | 'limitationValues' => ['/1/43/'], |
|
| 1737 | ] |
|
| 1738 | ) |
|
| 1739 | ); |
|
| 1740 | ||
| 1741 | // The assignments array will contain the new role<->user assignment |
|
| 1742 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1743 | /* END: Use Case */ |
|
| 1744 | ||
| 1745 | // Members + Partners + Anonymous + Example User |
|
| 1746 | $this->assertCount(4, $roleAssignments); |
|
| 1747 | ||
| 1748 | // Get the role limitation |
|
| 1749 | $roleLimitation = null; |
|
| 1750 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1751 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1752 | if ($roleLimitation) { |
|
| 1753 | $this->assertInstanceOf( |
|
| 1754 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1755 | $roleAssignment |
|
| 1756 | ); |
|
| 1757 | break; |
|
| 1758 | } |
|
| 1759 | } |
|
| 1760 | ||
| 1761 | $this->assertEquals( |
|
| 1762 | new SubtreeLimitation( |
|
| 1763 | [ |
|
| 1764 | 'limitationValues' => ['/1/43/'], |
|
| 1765 | ] |
|
| 1766 | ), |
|
| 1767 | $roleLimitation |
|
| 1768 | ); |
|
| 1769 | ||
| 1770 | // Test again to see values being merged |
|
| 1771 | $roleService->assignRoleToUser( |
|
| 1772 | $role, |
|
| 1773 | $user, |
|
| 1774 | new SubtreeLimitation( |
|
| 1775 | [ |
|
| 1776 | 'limitationValues' => ['/1/43/', '/1/2/'], |
|
| 1777 | ] |
|
| 1778 | ) |
|
| 1779 | ); |
|
| 1780 | ||
| 1781 | // The assignments array will contain the new role<->user assignment |
|
| 1782 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1783 | ||
| 1784 | // Members + Partners + Anonymous + Example User |
|
| 1785 | $this->assertCount(5, $roleAssignments); |
|
| 1786 | ||
| 1787 | // Get the role limitation |
|
| 1788 | $roleLimitations = []; |
|
| 1789 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1790 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1791 | if ($roleLimitation) { |
|
| 1792 | $this->assertInstanceOf( |
|
| 1793 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1794 | $roleAssignment |
|
| 1795 | ); |
|
| 1796 | $roleLimitations[] = $roleLimitation; |
|
| 1797 | } |
|
| 1798 | } |
|
| 1799 | array_multisort($roleLimitations); |
|
| 1800 | ||
| 1801 | $this->assertEquals( |
|
| 1802 | [ |
|
| 1803 | new SubtreeLimitation( |
|
| 1804 | [ |
|
| 1805 | 'limitationValues' => ['/1/2/'], |
|
| 1806 | ] |
|
| 1807 | ), |
|
| 1808 | new SubtreeLimitation( |
|
| 1809 | [ |
|
| 1810 | 'limitationValues' => ['/1/43/'], |
|
| 1811 | ] |
|
| 1812 | ), |
|
| 1813 | ], |
|
| 1814 | $roleLimitations |
|
| 1815 | ); |
|
| 1816 | } |
|
| 1817 | ||
| 1818 | /** |
|
| 1819 | * Test for the assignRoleToUser() method. |
|
| @@ 2163-2256 (lines=94) @@ | ||
| 2160 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
|
| 2161 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2162 | */ |
|
| 2163 | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2164 | { |
|
| 2165 | $repository = $this->getRepository(); |
|
| 2166 | $roleService = $repository->getRoleService(); |
|
| 2167 | ||
| 2168 | /* BEGIN: Use Case */ |
|
| 2169 | $userGroup = $this->createUserGroupVersion1(); |
|
| 2170 | ||
| 2171 | // Load the existing "Anonymous" role |
|
| 2172 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2173 | ||
| 2174 | // Assign the "Anonymous" role to the newly created user group |
|
| 2175 | $roleService->assignRoleToUserGroup( |
|
| 2176 | $role, |
|
| 2177 | $userGroup, |
|
| 2178 | new SubtreeLimitation( |
|
| 2179 | [ |
|
| 2180 | 'limitationValues' => ['/1/43/'], |
|
| 2181 | ] |
|
| 2182 | ) |
|
| 2183 | ); |
|
| 2184 | ||
| 2185 | // The assignments array will contain the new role<->group assignment |
|
| 2186 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2187 | /* END: Use Case */ |
|
| 2188 | ||
| 2189 | // Members + Partners + Anonymous + Example Group |
|
| 2190 | $this->assertCount(4, $roleAssignments); |
|
| 2191 | ||
| 2192 | // Get the role limitation |
|
| 2193 | $roleLimitation = null; |
|
| 2194 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2195 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2196 | if ($roleLimitation) { |
|
| 2197 | break; |
|
| 2198 | } |
|
| 2199 | } |
|
| 2200 | ||
| 2201 | $this->assertEquals( |
|
| 2202 | new SubtreeLimitation( |
|
| 2203 | [ |
|
| 2204 | 'limitationValues' => ['/1/43/'], |
|
| 2205 | ] |
|
| 2206 | ), |
|
| 2207 | $roleLimitation |
|
| 2208 | ); |
|
| 2209 | ||
| 2210 | // Test again to see values being merged |
|
| 2211 | $roleService->assignRoleToUserGroup( |
|
| 2212 | $role, |
|
| 2213 | $userGroup, |
|
| 2214 | new SubtreeLimitation( |
|
| 2215 | [ |
|
| 2216 | 'limitationValues' => ['/1/43/', '/1/2/'], |
|
| 2217 | ] |
|
| 2218 | ) |
|
| 2219 | ); |
|
| 2220 | ||
| 2221 | // The assignments array will contain the new role<->user assignment |
|
| 2222 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2223 | ||
| 2224 | // Members + Partners + Anonymous + Example User |
|
| 2225 | $this->assertCount(5, $roleAssignments); |
|
| 2226 | ||
| 2227 | // Get the role limitation |
|
| 2228 | $roleLimitations = []; |
|
| 2229 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2230 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2231 | if ($roleLimitation) { |
|
| 2232 | $this->assertInstanceOf( |
|
| 2233 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
|
| 2234 | $roleAssignment |
|
| 2235 | ); |
|
| 2236 | $roleLimitations[] = $roleLimitation; |
|
| 2237 | } |
|
| 2238 | } |
|
| 2239 | array_multisort($roleLimitations); |
|
| 2240 | ||
| 2241 | $this->assertEquals( |
|
| 2242 | [ |
|
| 2243 | new SubtreeLimitation( |
|
| 2244 | [ |
|
| 2245 | 'limitationValues' => ['/1/2/'], |
|
| 2246 | ] |
|
| 2247 | ), |
|
| 2248 | new SubtreeLimitation( |
|
| 2249 | [ |
|
| 2250 | 'limitationValues' => ['/1/43/'], |
|
| 2251 | ] |
|
| 2252 | ), |
|
| 2253 | ], |
|
| 2254 | $roleLimitations |
|
| 2255 | ); |
|
| 2256 | } |
|
| 2257 | ||
| 2258 | /** |
|
| 2259 | * Test for the assignRoleToUserGroup() method. |
|