@@ -2101,6 +2101,39 @@ public function testAssignUserToUserGroup()
2101
2101
);
2102
2102
}
2103
2103
2104
+ /**
2105
+ * @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup
2106
+ */
2107
+ public function testAssignUserToGroupWithLocationsValidation (): void
2108
+ {
2109
+ $ repository = $ this ->getRepository ();
2110
+ $ userService = $ repository ->getUserService ();
2111
+ $ locationService = $ repository ->getLocationService ();
2112
+
2113
+ $ administratorGroupId = $ this ->generateId ('group ' , 12 );
2114
+
2115
+ $ user = $ this ->createUserVersion1 ();
2116
+
2117
+ $ group = $ userService ->loadUserGroup ($ administratorGroupId );
2118
+ $ groupLocation = $ locationService ->loadLocation ($ group ->contentInfo ->mainLocationId );
2119
+
2120
+ // Count number of child locations before assigning user to group
2121
+ $ count = $ locationService ->getLocationChildCount ($ groupLocation );
2122
+ $ expectedCount = $ count + 1 ;
2123
+
2124
+ $ userService ->assignUserToUserGroup (
2125
+ $ user ,
2126
+ $ group
2127
+ );
2128
+
2129
+ $ this ->refreshSearch ($ repository );
2130
+
2131
+ // Count number of child locations after assigning user to group
2132
+ $ actualCount = $ locationService ->getLocationChildCount ($ groupLocation );
2133
+
2134
+ self ::assertEquals ($ expectedCount , $ actualCount );
2135
+ }
2136
+
2104
2137
/**
2105
2138
* Test for the assignUserToUserGroup() method.
2106
2139
*
@@ -2224,6 +2257,48 @@ public function testUnAssignUserFromUserGroupThrowsBadStateArgumentException()
2224
2257
/* END: Use Case */
2225
2258
}
2226
2259
2260
+ /**
2261
+ * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup
2262
+ */
2263
+ public function testUnAssignUserToGroupWithLocationValidation (): void
2264
+ {
2265
+ $ repository = $ this ->getRepository ();
2266
+ $ userService = $ repository ->getUserService ();
2267
+ $ locationService = $ repository ->getLocationService ();
2268
+
2269
+ $ editorsGroupId = $ this ->generateId ('group ' , 13 );
2270
+ $ anonymousGroupId = $ this ->generateId ('group ' , 42 );
2271
+
2272
+ $ user = $ this ->createUserVersion1 ();
2273
+
2274
+ $ this ->refreshSearch ($ repository );
2275
+
2276
+ $ group = $ userService ->loadUserGroup ($ editorsGroupId );
2277
+ $ groupLocation = $ locationService ->loadLocation ($ group ->contentInfo ->mainLocationId );
2278
+
2279
+ // Count number of child locations before unassigning user from group
2280
+ $ count = $ locationService ->getLocationChildCount ($ groupLocation );
2281
+ $ expectedCount = $ count - 1 ;
2282
+
2283
+ // Assigning user to different group to avoid removing all groups from user
2284
+ $ userService ->assignUserToUserGroup (
2285
+ $ user ,
2286
+ $ userService ->loadUserGroup ($ anonymousGroupId )
2287
+ );
2288
+
2289
+ $ userService ->unAssignUserFromUserGroup (
2290
+ $ user ,
2291
+ $ userService ->loadUserGroup ($ editorsGroupId )
2292
+ );
2293
+
2294
+ $ this ->refreshSearch ($ repository );
2295
+
2296
+ // Count number of child locations after unassigning user from group
2297
+ $ actualCount = $ locationService ->getLocationChildCount ($ groupLocation );
2298
+
2299
+ self ::assertEquals ($ expectedCount , $ actualCount );
2300
+ }
2301
+
2227
2302
/**
2228
2303
* Test that multi-language logic for the loadUserGroup method respects prioritized language list.
2229
2304
*
0 commit comments