@@ -2264,6 +2264,39 @@ public function testAssignUserToUserGroupThrowsInvalidArgumentException()
22642264 /* END: Use Case */
22652265 }
22662266
2267+ /**
2268+ * @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup
2269+ */
2270+ public function testAssignUserToGroupWithLocationsValidation (): void
2271+ {
2272+ $ repository = $ this ->getRepository ();
2273+ $ userService = $ repository ->getUserService ();
2274+ $ locationService = $ repository ->getLocationService ();
2275+
2276+ $ administratorGroupId = $ this ->generateId ('group ' , 12 );
2277+
2278+ $ user = $ this ->createUserVersion1 ();
2279+
2280+ $ group = $ userService ->loadUserGroup ($ administratorGroupId );
2281+ $ groupLocation = $ locationService ->loadLocation ($ group ->contentInfo ->mainLocationId );
2282+
2283+ // Count number of child locations before assigning user to group
2284+ $ count = $ locationService ->getLocationChildCount ($ groupLocation );
2285+ $ expectedCount = $ count + 1 ;
2286+
2287+ $ userService ->assignUserToUserGroup (
2288+ $ user ,
2289+ $ group
2290+ );
2291+
2292+ $ this ->refreshSearch ($ repository );
2293+
2294+ // Count number of child locations after assigning the user to a group
2295+ $ actualCount = $ locationService ->getLocationChildCount ($ groupLocation );
2296+
2297+ self ::assertEquals ($ expectedCount , $ actualCount );
2298+ }
2299+
22672300 /**
22682301 * Test for the unAssignUssrFromUserGroup() method.
22692302 *
@@ -2361,6 +2394,48 @@ public function testUnAssignUserFromUserGroupThrowsBadStateArgumentException()
23612394 /* END: Use Case */
23622395 }
23632396
2397+ /**
2398+ * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup
2399+ */
2400+ public function testUnAssignUserToGroupWithLocationValidation (): void
2401+ {
2402+ $ repository = $ this ->getRepository ();
2403+ $ userService = $ repository ->getUserService ();
2404+ $ locationService = $ repository ->getLocationService ();
2405+
2406+ $ editorsGroupId = $ this ->generateId ('group ' , 13 );
2407+ $ anonymousGroupId = $ this ->generateId ('group ' , 42 );
2408+
2409+ $ user = $ this ->createUserVersion1 ();
2410+
2411+ $ this ->refreshSearch ($ repository );
2412+
2413+ $ group = $ userService ->loadUserGroup ($ editorsGroupId );
2414+ $ groupLocation = $ locationService ->loadLocation ($ group ->contentInfo ->mainLocationId );
2415+
2416+ // Count number of child locations before unassigning the user from a group
2417+ $ count = $ locationService ->getLocationChildCount ($ groupLocation );
2418+ $ expectedCount = $ count - 1 ;
2419+
2420+ // Assigning user to a different group to avoid removing all groups from the user
2421+ $ userService ->assignUserToUserGroup (
2422+ $ user ,
2423+ $ userService ->loadUserGroup ($ anonymousGroupId )
2424+ );
2425+
2426+ $ userService ->unAssignUserFromUserGroup (
2427+ $ user ,
2428+ $ userService ->loadUserGroup ($ editorsGroupId )
2429+ );
2430+
2431+ $ this ->refreshSearch ($ repository );
2432+
2433+ // Count number of child locations after unassigning the user from a group
2434+ $ actualCount = $ locationService ->getLocationChildCount ($ groupLocation );
2435+
2436+ self ::assertEquals ($ expectedCount , $ actualCount );
2437+ }
2438+
23642439 /**
23652440 * Test that multi-language logic for the loadUserGroup method respects prioritized language list.
23662441 *
0 commit comments