| @@ 1966-2063 (lines=98) @@ | ||
| 1963 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser($role, $user, $roleLimitation) |
|
| 1964 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 1965 | */ |
|
| 1966 | public function testAssignRoleToUserWithRoleLimitation() |
|
| 1967 | { |
|
| 1968 | $repository = $this->getRepository(); |
|
| 1969 | $roleService = $repository->getRoleService(); |
|
| 1970 | ||
| 1971 | /* BEGIN: Use Case */ |
|
| 1972 | $user = $this->createUserVersion1(); |
|
| 1973 | ||
| 1974 | // Load the existing "Anonymous" role |
|
| 1975 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 1976 | ||
| 1977 | // Assign the "Anonymous" role to the newly created user |
|
| 1978 | $roleService->assignRoleToUser( |
|
| 1979 | $role, |
|
| 1980 | $user, |
|
| 1981 | new SubtreeLimitation( |
|
| 1982 | [ |
|
| 1983 | 'limitationValues' => ['/1/43/'], |
|
| 1984 | ] |
|
| 1985 | ) |
|
| 1986 | ); |
|
| 1987 | ||
| 1988 | // The assignments array will contain the new role<->user assignment |
|
| 1989 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 1990 | /* END: Use Case */ |
|
| 1991 | ||
| 1992 | // Members + Partners + Anonymous + Example User |
|
| 1993 | $this->assertEquals(4, count($roleAssignments)); |
|
| 1994 | ||
| 1995 | // Get the role limitation |
|
| 1996 | $roleLimitation = null; |
|
| 1997 | foreach ($roleAssignments as $roleAssignment) { |
|
| 1998 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 1999 | if ($roleLimitation) { |
|
| 2000 | $this->assertInstanceOf( |
|
| 2001 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 2002 | $roleAssignment |
|
| 2003 | ); |
|
| 2004 | break; |
|
| 2005 | } |
|
| 2006 | } |
|
| 2007 | ||
| 2008 | $this->assertEquals( |
|
| 2009 | new SubtreeLimitation( |
|
| 2010 | [ |
|
| 2011 | 'limitationValues' => ['/1/43/'], |
|
| 2012 | ] |
|
| 2013 | ), |
|
| 2014 | $roleLimitation |
|
| 2015 | ); |
|
| 2016 | ||
| 2017 | // Test again to see values being merged |
|
| 2018 | $roleService->assignRoleToUser( |
|
| 2019 | $role, |
|
| 2020 | $user, |
|
| 2021 | new SubtreeLimitation( |
|
| 2022 | [ |
|
| 2023 | 'limitationValues' => ['/1/43/', '/1/2/'], |
|
| 2024 | ] |
|
| 2025 | ) |
|
| 2026 | ); |
|
| 2027 | ||
| 2028 | // The assignments array will contain the new role<->user assignment |
|
| 2029 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2030 | ||
| 2031 | // Members + Partners + Anonymous + Example User |
|
| 2032 | $this->assertEquals(5, count($roleAssignments)); |
|
| 2033 | ||
| 2034 | // Get the role limitation |
|
| 2035 | $roleLimitations = []; |
|
| 2036 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2037 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2038 | if ($roleLimitation) { |
|
| 2039 | $this->assertInstanceOf( |
|
| 2040 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
|
| 2041 | $roleAssignment |
|
| 2042 | ); |
|
| 2043 | $roleLimitations[] = $roleLimitation; |
|
| 2044 | } |
|
| 2045 | } |
|
| 2046 | array_multisort($roleLimitations); |
|
| 2047 | ||
| 2048 | $this->assertEquals( |
|
| 2049 | [ |
|
| 2050 | new SubtreeLimitation( |
|
| 2051 | [ |
|
| 2052 | 'limitationValues' => ['/1/2/'], |
|
| 2053 | ] |
|
| 2054 | ), |
|
| 2055 | new SubtreeLimitation( |
|
| 2056 | [ |
|
| 2057 | 'limitationValues' => ['/1/43/'], |
|
| 2058 | ] |
|
| 2059 | ), |
|
| 2060 | ], |
|
| 2061 | $roleLimitations |
|
| 2062 | ); |
|
| 2063 | } |
|
| 2064 | ||
| 2065 | /** |
|
| 2066 | * Test for the assignRoleToUser() method. |
|
| @@ 2416-2509 (lines=94) @@ | ||
| 2413 | * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup($role, $userGroup, $roleLimitation) |
|
| 2414 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2415 | */ |
|
| 2416 | public function testAssignRoleToUserGroupWithRoleLimitation() |
|
| 2417 | { |
|
| 2418 | $repository = $this->getRepository(); |
|
| 2419 | $roleService = $repository->getRoleService(); |
|
| 2420 | ||
| 2421 | /* BEGIN: Use Case */ |
|
| 2422 | $userGroup = $this->createUserGroupVersion1(); |
|
| 2423 | ||
| 2424 | // Load the existing "Anonymous" role |
|
| 2425 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2426 | ||
| 2427 | // Assign the "Anonymous" role to the newly created user group |
|
| 2428 | $roleService->assignRoleToUserGroup( |
|
| 2429 | $role, |
|
| 2430 | $userGroup, |
|
| 2431 | new SubtreeLimitation( |
|
| 2432 | [ |
|
| 2433 | 'limitationValues' => ['/1/43/'], |
|
| 2434 | ] |
|
| 2435 | ) |
|
| 2436 | ); |
|
| 2437 | ||
| 2438 | // The assignments array will contain the new role<->group assignment |
|
| 2439 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2440 | /* END: Use Case */ |
|
| 2441 | ||
| 2442 | // Members + Partners + Anonymous + Example Group |
|
| 2443 | $this->assertEquals(4, count($roleAssignments)); |
|
| 2444 | ||
| 2445 | // Get the role limitation |
|
| 2446 | $roleLimitation = null; |
|
| 2447 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2448 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2449 | if ($roleLimitation) { |
|
| 2450 | break; |
|
| 2451 | } |
|
| 2452 | } |
|
| 2453 | ||
| 2454 | $this->assertEquals( |
|
| 2455 | new SubtreeLimitation( |
|
| 2456 | [ |
|
| 2457 | 'limitationValues' => ['/1/43/'], |
|
| 2458 | ] |
|
| 2459 | ), |
|
| 2460 | $roleLimitation |
|
| 2461 | ); |
|
| 2462 | ||
| 2463 | // Test again to see values being merged |
|
| 2464 | $roleService->assignRoleToUserGroup( |
|
| 2465 | $role, |
|
| 2466 | $userGroup, |
|
| 2467 | new SubtreeLimitation( |
|
| 2468 | [ |
|
| 2469 | 'limitationValues' => ['/1/43/', '/1/2/'], |
|
| 2470 | ] |
|
| 2471 | ) |
|
| 2472 | ); |
|
| 2473 | ||
| 2474 | // The assignments array will contain the new role<->user assignment |
|
| 2475 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
| 2476 | ||
| 2477 | // Members + Partners + Anonymous + Example User |
|
| 2478 | $this->assertEquals(5, count($roleAssignments)); |
|
| 2479 | ||
| 2480 | // Get the role limitation |
|
| 2481 | $roleLimitations = []; |
|
| 2482 | foreach ($roleAssignments as $roleAssignment) { |
|
| 2483 | $roleLimitation = $roleAssignment->getRoleLimitation(); |
|
| 2484 | if ($roleLimitation) { |
|
| 2485 | $this->assertInstanceOf( |
|
| 2486 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
|
| 2487 | $roleAssignment |
|
| 2488 | ); |
|
| 2489 | $roleLimitations[] = $roleLimitation; |
|
| 2490 | } |
|
| 2491 | } |
|
| 2492 | array_multisort($roleLimitations); |
|
| 2493 | ||
| 2494 | $this->assertEquals( |
|
| 2495 | [ |
|
| 2496 | new SubtreeLimitation( |
|
| 2497 | [ |
|
| 2498 | 'limitationValues' => ['/1/2/'], |
|
| 2499 | ] |
|
| 2500 | ), |
|
| 2501 | new SubtreeLimitation( |
|
| 2502 | [ |
|
| 2503 | 'limitationValues' => ['/1/43/'], |
|
| 2504 | ] |
|
| 2505 | ), |
|
| 2506 | ], |
|
| 2507 | $roleLimitations |
|
| 2508 | ); |
|
| 2509 | } |
|
| 2510 | ||
| 2511 | /** |
|
| 2512 | * Test for the assignRoleToUserGroup() method. |
|