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