| @@ 1867-1964 (lines=98) @@ | ||
| 1864 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
|
| 1865 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 1866 | */ |
|
| 1867 | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1868 | { |
|
| 1869 | $repository = $this->getRepository(); |
|
| 1870 | $roleService = $repository->getRoleService(); |
|
| 1871 | ||
| 1872 | /* BEGIN: Use Case */ |
|
| 1873 | $user = $this->createUserVersion1(); |
|
| 1874 | ||
| 1875 | // Load the existing "Anonymous" role |
|
| 1876 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 1877 | ||
| 1878 | // Assign the "Anonymous" role to the newly created user |
|
| 1879 | $roleService->assignRoleToUser( |
|
| 1880 | $role, |
|
| 1881 | $user, |
|
| 1882 | new SubtreeLimitation( |
|
| 1883 | array( |
|
| 1884 | 'limitationValues' => array('/1/43/'), |
|
| 1885 | ) |
|
| 1886 | ) |
|
| 1887 | ); |
|
| 1888 | ||
| 1889 | // The assignments array will contain the new role<->user assignment |
|
| 1890 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1891 | /* END: Use Case */ |
|
| 1892 | ||
| 1893 | // Members + Partners + Anonymous + Example User |
|
| 1894 | $this->assertEquals(4, count($roleAssignments)); |
|
| 1895 | ||
| 1896 | // Get the role limitation |
|
| 1897 | $roleLimitation = null; |
|
| 1898 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1899 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1900 | if ($roleLimitation) { |
|
| 1901 | $this->assertInstanceOf( |
|
| 1902 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1903 | $roleAssignment |
|
| 1904 | ); |
|
| 1905 | break; |
|
| 1906 | } |
|
| 1907 | } |
|
| 1908 | ||
| 1909 | $this->assertEquals( |
|
| 1910 | new SubtreeLimitation( |
|
| 1911 | array( |
|
| 1912 | 'limitationValues' => array('/1/43/'), |
|
| 1913 | ) |
|
| 1914 | ), |
|
| 1915 | $roleLimitation |
|
| 1916 | ); |
|
| 1917 | ||
| 1918 | // Test again to see values being merged |
|
| 1919 | $roleService->assignRoleToUser( |
|
| 1920 | $role, |
|
| 1921 | $user, |
|
| 1922 | new SubtreeLimitation( |
|
| 1923 | array( |
|
| 1924 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 1925 | ) |
|
| 1926 | ) |
|
| 1927 | ); |
|
| 1928 | ||
| 1929 | // The assignments array will contain the new role<->user assignment |
|
| 1930 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1931 | ||
| 1932 | // Members + Partners + Anonymous + Example User |
|
| 1933 | $this->assertEquals(5, count($roleAssignments)); |
|
| 1934 | ||
| 1935 | // Get the role limitation |
|
| 1936 | $roleLimitations = []; |
|
| 1937 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1938 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1939 | if ($roleLimitation) { |
|
| 1940 | $this->assertInstanceOf( |
|
| 1941 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1942 | $roleAssignment |
|
| 1943 | ); |
|
| 1944 | $roleLimitations[] = $roleLimitation; |
|
| 1945 | } |
|
| 1946 | } |
|
| 1947 | array_multisort($roleLimitations); |
|
| 1948 | ||
| 1949 | $this->assertEquals( |
|
| 1950 | [ |
|
| 1951 | new SubtreeLimitation( |
|
| 1952 | array( |
|
| 1953 | 'limitationValues' => array('/1/2/'), |
|
| 1954 | ) |
|
| 1955 | ), |
|
| 1956 | new SubtreeLimitation( |
|
| 1957 | array( |
|
| 1958 | 'limitationValues' => array('/1/43/'), |
|
| 1959 | ) |
|
| 1960 | ), |
|
| 1961 | ], |
|
| 1962 | $roleLimitations |
|
| 1963 | ); |
|
| 1964 | } |
|
| 1965 | ||
| 1966 | /** |
|
| 1967 | * Test for the assignRoleToUser() method. |
|
| @@ 2282-2375 (lines=94) @@ | ||
| 2279 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
|
| 2280 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2281 | */ |
|
| 2282 | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2283 | { |
|
| 2284 | $repository = $this->getRepository(); |
|
| 2285 | $roleService = $repository->getRoleService(); |
|
| 2286 | ||
| 2287 | /* BEGIN: Use Case */ |
|
| 2288 | $userGroup = $this->createUserGroupVersion1(); |
|
| 2289 | ||
| 2290 | // Load the existing "Anonymous" role |
|
| 2291 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2292 | ||
| 2293 | // Assign the "Anonymous" role to the newly created user group |
|
| 2294 | $roleService->assignRoleToUserGroup( |
|
| 2295 | $role, |
|
| 2296 | $userGroup, |
|
| 2297 | new SubtreeLimitation( |
|
| 2298 | array( |
|
| 2299 | 'limitationValues' => array('/1/43/'), |
|
| 2300 | ) |
|
| 2301 | ) |
|
| 2302 | ); |
|
| 2303 | ||
| 2304 | // The assignments array will contain the new role<->group assignment |
|
| 2305 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2306 | /* END: Use Case */ |
|
| 2307 | ||
| 2308 | // Members + Partners + Anonymous + Example Group |
|
| 2309 | $this->assertEquals(4, count($roleAssignments)); |
|
| 2310 | ||
| 2311 | // Get the role limitation |
|
| 2312 | $roleLimitation = null; |
|
| 2313 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2314 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2315 | if ($roleLimitation) { |
|
| 2316 | break; |
|
| 2317 | } |
|
| 2318 | } |
|
| 2319 | ||
| 2320 | $this->assertEquals( |
|
| 2321 | new SubtreeLimitation( |
|
| 2322 | array( |
|
| 2323 | 'limitationValues' => array('/1/43/'), |
|
| 2324 | ) |
|
| 2325 | ), |
|
| 2326 | $roleLimitation |
|
| 2327 | ); |
|
| 2328 | ||
| 2329 | // Test again to see values being merged |
|
| 2330 | $roleService->assignRoleToUserGroup( |
|
| 2331 | $role, |
|
| 2332 | $userGroup, |
|
| 2333 | new SubtreeLimitation( |
|
| 2334 | array( |
|
| 2335 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 2336 | ) |
|
| 2337 | ) |
|
| 2338 | ); |
|
| 2339 | ||
| 2340 | // The assignments array will contain the new role<->user assignment |
|
| 2341 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2342 | ||
| 2343 | // Members + Partners + Anonymous + Example User |
|
| 2344 | $this->assertEquals(5, count($roleAssignments)); |
|
| 2345 | ||
| 2346 | // Get the role limitation |
|
| 2347 | $roleLimitations = []; |
|
| 2348 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2349 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2350 | if ($roleLimitation) { |
|
| 2351 | $this->assertInstanceOf( |
|
| 2352 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
|
| 2353 | $roleAssignment |
|
| 2354 | ); |
|
| 2355 | $roleLimitations[] = $roleLimitation; |
|
| 2356 | } |
|
| 2357 | } |
|
| 2358 | array_multisort($roleLimitations); |
|
| 2359 | ||
| 2360 | $this->assertEquals( |
|
| 2361 | [ |
|
| 2362 | new SubtreeLimitation( |
|
| 2363 | array( |
|
| 2364 | 'limitationValues' => array('/1/2/'), |
|
| 2365 | ) |
|
| 2366 | ), |
|
| 2367 | new SubtreeLimitation( |
|
| 2368 | array( |
|
| 2369 | 'limitationValues' => array('/1/43/'), |
|
| 2370 | ) |
|
| 2371 | ), |
|
| 2372 | ], |
|
| 2373 | $roleLimitations |
|
| 2374 | ); |
|
| 2375 | } |
|
| 2376 | ||
| 2377 | /** |
|
| 2378 | * Test for the assignRoleToUserGroup() method. |
|