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