| @@ 1898-1995 (lines=98) @@ | ||
| 1895 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
|
| 1896 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 1897 | */ |
|
| 1898 | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1899 | { |
|
| 1900 | $repository = $this->getRepository(); |
|
| 1901 | $roleService = $repository->getRoleService(); |
|
| 1902 | ||
| 1903 | /* BEGIN: Use Case */ |
|
| 1904 | $user = $this->createUserVersion1(); |
|
| 1905 | ||
| 1906 | // Load the existing "Anonymous" role |
|
| 1907 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 1908 | ||
| 1909 | // Assign the "Anonymous" role to the newly created user |
|
| 1910 | $roleService->assignRoleToUser( |
|
| 1911 | $role, |
|
| 1912 | $user, |
|
| 1913 | new SubtreeLimitation( |
|
| 1914 | array( |
|
| 1915 | 'limitationValues' => array('/1/43/'), |
|
| 1916 | ) |
|
| 1917 | ) |
|
| 1918 | ); |
|
| 1919 | ||
| 1920 | // The assignments array will contain the new role<->user assignment |
|
| 1921 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1922 | /* END: Use Case */ |
|
| 1923 | ||
| 1924 | // Members + Partners + Anonymous + Example User |
|
| 1925 | $this->assertEquals(4, count($roleAssignments)); |
|
| 1926 | ||
| 1927 | // Get the role limitation |
|
| 1928 | $roleLimitation = null; |
|
| 1929 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1930 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1931 | if ($roleLimitation) { |
|
| 1932 | $this->assertInstanceOf( |
|
| 1933 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1934 | $roleAssignment |
|
| 1935 | ); |
|
| 1936 | break; |
|
| 1937 | } |
|
| 1938 | } |
|
| 1939 | ||
| 1940 | $this->assertEquals( |
|
| 1941 | new SubtreeLimitation( |
|
| 1942 | array( |
|
| 1943 | 'limitationValues' => array('/1/43/'), |
|
| 1944 | ) |
|
| 1945 | ), |
|
| 1946 | $roleLimitation |
|
| 1947 | ); |
|
| 1948 | ||
| 1949 | // Test again to see values being merged |
|
| 1950 | $roleService->assignRoleToUser( |
|
| 1951 | $role, |
|
| 1952 | $user, |
|
| 1953 | new SubtreeLimitation( |
|
| 1954 | array( |
|
| 1955 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 1956 | ) |
|
| 1957 | ) |
|
| 1958 | ); |
|
| 1959 | ||
| 1960 | // The assignments array will contain the new role<->user assignment |
|
| 1961 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1962 | ||
| 1963 | // Members + Partners + Anonymous + Example User |
|
| 1964 | $this->assertEquals(5, count($roleAssignments)); |
|
| 1965 | ||
| 1966 | // Get the role limitation |
|
| 1967 | $roleLimitations = []; |
|
| 1968 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1969 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1970 | if ($roleLimitation) { |
|
| 1971 | $this->assertInstanceOf( |
|
| 1972 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1973 | $roleAssignment |
|
| 1974 | ); |
|
| 1975 | $roleLimitations[] = $roleLimitation; |
|
| 1976 | } |
|
| 1977 | } |
|
| 1978 | array_multisort($roleLimitations); |
|
| 1979 | ||
| 1980 | $this->assertEquals( |
|
| 1981 | [ |
|
| 1982 | new SubtreeLimitation( |
|
| 1983 | array( |
|
| 1984 | 'limitationValues' => array('/1/2/'), |
|
| 1985 | ) |
|
| 1986 | ), |
|
| 1987 | new SubtreeLimitation( |
|
| 1988 | array( |
|
| 1989 | 'limitationValues' => array('/1/43/'), |
|
| 1990 | ) |
|
| 1991 | ), |
|
| 1992 | ], |
|
| 1993 | $roleLimitations |
|
| 1994 | ); |
|
| 1995 | } |
|
| 1996 | ||
| 1997 | /** |
|
| 1998 | * Test for the assignRoleToUser() method. |
|
| @@ 2313-2406 (lines=94) @@ | ||
| 2310 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
|
| 2311 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2312 | */ |
|
| 2313 | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2314 | { |
|
| 2315 | $repository = $this->getRepository(); |
|
| 2316 | $roleService = $repository->getRoleService(); |
|
| 2317 | ||
| 2318 | /* BEGIN: Use Case */ |
|
| 2319 | $userGroup = $this->createUserGroupVersion1(); |
|
| 2320 | ||
| 2321 | // Load the existing "Anonymous" role |
|
| 2322 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2323 | ||
| 2324 | // Assign the "Anonymous" role to the newly created user group |
|
| 2325 | $roleService->assignRoleToUserGroup( |
|
| 2326 | $role, |
|
| 2327 | $userGroup, |
|
| 2328 | new SubtreeLimitation( |
|
| 2329 | array( |
|
| 2330 | 'limitationValues' => array('/1/43/'), |
|
| 2331 | ) |
|
| 2332 | ) |
|
| 2333 | ); |
|
| 2334 | ||
| 2335 | // The assignments array will contain the new role<->group assignment |
|
| 2336 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2337 | /* END: Use Case */ |
|
| 2338 | ||
| 2339 | // Members + Partners + Anonymous + Example Group |
|
| 2340 | $this->assertEquals(4, count($roleAssignments)); |
|
| 2341 | ||
| 2342 | // Get the role limitation |
|
| 2343 | $roleLimitation = null; |
|
| 2344 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2345 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2346 | if ($roleLimitation) { |
|
| 2347 | break; |
|
| 2348 | } |
|
| 2349 | } |
|
| 2350 | ||
| 2351 | $this->assertEquals( |
|
| 2352 | new SubtreeLimitation( |
|
| 2353 | array( |
|
| 2354 | 'limitationValues' => array('/1/43/'), |
|
| 2355 | ) |
|
| 2356 | ), |
|
| 2357 | $roleLimitation |
|
| 2358 | ); |
|
| 2359 | ||
| 2360 | // Test again to see values being merged |
|
| 2361 | $roleService->assignRoleToUserGroup( |
|
| 2362 | $role, |
|
| 2363 | $userGroup, |
|
| 2364 | new SubtreeLimitation( |
|
| 2365 | array( |
|
| 2366 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 2367 | ) |
|
| 2368 | ) |
|
| 2369 | ); |
|
| 2370 | ||
| 2371 | // The assignments array will contain the new role<->user assignment |
|
| 2372 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2373 | ||
| 2374 | // Members + Partners + Anonymous + Example User |
|
| 2375 | $this->assertEquals(5, count($roleAssignments)); |
|
| 2376 | ||
| 2377 | // Get the role limitation |
|
| 2378 | $roleLimitations = []; |
|
| 2379 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2380 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2381 | if ($roleLimitation) { |
|
| 2382 | $this->assertInstanceOf( |
|
| 2383 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
|
| 2384 | $roleAssignment |
|
| 2385 | ); |
|
| 2386 | $roleLimitations[] = $roleLimitation; |
|
| 2387 | } |
|
| 2388 | } |
|
| 2389 | array_multisort($roleLimitations); |
|
| 2390 | ||
| 2391 | $this->assertEquals( |
|
| 2392 | [ |
|
| 2393 | new SubtreeLimitation( |
|
| 2394 | array( |
|
| 2395 | 'limitationValues' => array('/1/2/'), |
|
| 2396 | ) |
|
| 2397 | ), |
|
| 2398 | new SubtreeLimitation( |
|
| 2399 | array( |
|
| 2400 | 'limitationValues' => array('/1/43/'), |
|
| 2401 | ) |
|
| 2402 | ), |
|
| 2403 | ], |
|
| 2404 | $roleLimitations |
|
| 2405 | ); |
|
| 2406 | } |
|
| 2407 | ||
| 2408 | /** |
|
| 2409 | * Test for the assignRoleToUserGroup() method. |
|