| @@ 1920-2017 (lines=98) @@ | ||
| 1917 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
|
| 1918 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 1919 | */ |
|
| 1920 | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1921 | { |
|
| 1922 | $repository = $this->getRepository(); |
|
| 1923 | $roleService = $repository->getRoleService(); |
|
| 1924 | ||
| 1925 | /* BEGIN: Use Case */ |
|
| 1926 | $user = $this->createUserVersion1(); |
|
| 1927 | ||
| 1928 | // Load the existing "Anonymous" role |
|
| 1929 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 1930 | ||
| 1931 | // Assign the "Anonymous" role to the newly created user |
|
| 1932 | $roleService->assignRoleToUser( |
|
| 1933 | $role, |
|
| 1934 | $user, |
|
| 1935 | new SubtreeLimitation( |
|
| 1936 | array( |
|
| 1937 | 'limitationValues' => array('/1/43/'), |
|
| 1938 | ) |
|
| 1939 | ) |
|
| 1940 | ); |
|
| 1941 | ||
| 1942 | // The assignments array will contain the new role<->user assignment |
|
| 1943 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1944 | /* END: Use Case */ |
|
| 1945 | ||
| 1946 | // Members + Partners + Anonymous + Example User |
|
| 1947 | $this->assertEquals(4, count($roleAssignments)); |
|
| 1948 | ||
| 1949 | // Get the role limitation |
|
| 1950 | $roleLimitation = null; |
|
| 1951 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1952 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1953 | if ($roleLimitation) { |
|
| 1954 | $this->assertInstanceOf( |
|
| 1955 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1956 | $roleAssignment |
|
| 1957 | ); |
|
| 1958 | break; |
|
| 1959 | } |
|
| 1960 | } |
|
| 1961 | ||
| 1962 | $this->assertEquals( |
|
| 1963 | new SubtreeLimitation( |
|
| 1964 | array( |
|
| 1965 | 'limitationValues' => array('/1/43/'), |
|
| 1966 | ) |
|
| 1967 | ), |
|
| 1968 | $roleLimitation |
|
| 1969 | ); |
|
| 1970 | ||
| 1971 | // Test again to see values being merged |
|
| 1972 | $roleService->assignRoleToUser( |
|
| 1973 | $role, |
|
| 1974 | $user, |
|
| 1975 | new SubtreeLimitation( |
|
| 1976 | array( |
|
| 1977 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 1978 | ) |
|
| 1979 | ) |
|
| 1980 | ); |
|
| 1981 | ||
| 1982 | // The assignments array will contain the new role<->user assignment |
|
| 1983 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1984 | ||
| 1985 | // Members + Partners + Anonymous + Example User |
|
| 1986 | $this->assertEquals(5, count($roleAssignments)); |
|
| 1987 | ||
| 1988 | // Get the role limitation |
|
| 1989 | $roleLimitations = []; |
|
| 1990 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1991 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1992 | if ($roleLimitation) { |
|
| 1993 | $this->assertInstanceOf( |
|
| 1994 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 1995 | $roleAssignment |
|
| 1996 | ); |
|
| 1997 | $roleLimitations[] = $roleLimitation; |
|
| 1998 | } |
|
| 1999 | } |
|
| 2000 | array_multisort($roleLimitations); |
|
| 2001 | ||
| 2002 | $this->assertEquals( |
|
| 2003 | [ |
|
| 2004 | new SubtreeLimitation( |
|
| 2005 | array( |
|
| 2006 | 'limitationValues' => array('/1/2/'), |
|
| 2007 | ) |
|
| 2008 | ), |
|
| 2009 | new SubtreeLimitation( |
|
| 2010 | array( |
|
| 2011 | 'limitationValues' => array('/1/43/'), |
|
| 2012 | ) |
|
| 2013 | ), |
|
| 2014 | ], |
|
| 2015 | $roleLimitations |
|
| 2016 | ); |
|
| 2017 | } |
|
| 2018 | ||
| 2019 | /** |
|
| 2020 | * Test for the assignRoleToUser() method. |
|
| @@ 2335-2428 (lines=94) @@ | ||
| 2332 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
|
| 2333 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2334 | */ |
|
| 2335 | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2336 | { |
|
| 2337 | $repository = $this->getRepository(); |
|
| 2338 | $roleService = $repository->getRoleService(); |
|
| 2339 | ||
| 2340 | /* BEGIN: Use Case */ |
|
| 2341 | $userGroup = $this->createUserGroupVersion1(); |
|
| 2342 | ||
| 2343 | // Load the existing "Anonymous" role |
|
| 2344 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2345 | ||
| 2346 | // Assign the "Anonymous" role to the newly created user group |
|
| 2347 | $roleService->assignRoleToUserGroup( |
|
| 2348 | $role, |
|
| 2349 | $userGroup, |
|
| 2350 | new SubtreeLimitation( |
|
| 2351 | array( |
|
| 2352 | 'limitationValues' => array('/1/43/'), |
|
| 2353 | ) |
|
| 2354 | ) |
|
| 2355 | ); |
|
| 2356 | ||
| 2357 | // The assignments array will contain the new role<->group assignment |
|
| 2358 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2359 | /* END: Use Case */ |
|
| 2360 | ||
| 2361 | // Members + Partners + Anonymous + Example Group |
|
| 2362 | $this->assertEquals(4, count($roleAssignments)); |
|
| 2363 | ||
| 2364 | // Get the role limitation |
|
| 2365 | $roleLimitation = null; |
|
| 2366 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2367 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2368 | if ($roleLimitation) { |
|
| 2369 | break; |
|
| 2370 | } |
|
| 2371 | } |
|
| 2372 | ||
| 2373 | $this->assertEquals( |
|
| 2374 | new SubtreeLimitation( |
|
| 2375 | array( |
|
| 2376 | 'limitationValues' => array('/1/43/'), |
|
| 2377 | ) |
|
| 2378 | ), |
|
| 2379 | $roleLimitation |
|
| 2380 | ); |
|
| 2381 | ||
| 2382 | // Test again to see values being merged |
|
| 2383 | $roleService->assignRoleToUserGroup( |
|
| 2384 | $role, |
|
| 2385 | $userGroup, |
|
| 2386 | new SubtreeLimitation( |
|
| 2387 | array( |
|
| 2388 | 'limitationValues' => array('/1/43/', '/1/2/'), |
|
| 2389 | ) |
|
| 2390 | ) |
|
| 2391 | ); |
|
| 2392 | ||
| 2393 | // The assignments array will contain the new role<->user assignment |
|
| 2394 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2395 | ||
| 2396 | // Members + Partners + Anonymous + Example User |
|
| 2397 | $this->assertEquals(5, count($roleAssignments)); |
|
| 2398 | ||
| 2399 | // Get the role limitation |
|
| 2400 | $roleLimitations = []; |
|
| 2401 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2402 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2403 | if ($roleLimitation) { |
|
| 2404 | $this->assertInstanceOf( |
|
| 2405 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
|
| 2406 | $roleAssignment |
|
| 2407 | ); |
|
| 2408 | $roleLimitations[] = $roleLimitation; |
|
| 2409 | } |
|
| 2410 | } |
|
| 2411 | array_multisort($roleLimitations); |
|
| 2412 | ||
| 2413 | $this->assertEquals( |
|
| 2414 | [ |
|
| 2415 | new SubtreeLimitation( |
|
| 2416 | array( |
|
| 2417 | 'limitationValues' => array('/1/2/'), |
|
| 2418 | ) |
|
| 2419 | ), |
|
| 2420 | new SubtreeLimitation( |
|
| 2421 | array( |
|
| 2422 | 'limitationValues' => array('/1/43/'), |
|
| 2423 | ) |
|
| 2424 | ), |
|
| 2425 | ], |
|
| 2426 | $roleLimitations |
|
| 2427 | ); |
|
| 2428 | } |
|
| 2429 | ||
| 2430 | /** |
|
| 2431 | * Test for the assignRoleToUserGroup() method. |
|