@@ -187,6 +187,48 @@ public function testUnassignUserFromGroups() {
187187 $ this ->invokePrivate ($ this ->ownGroupManager , 'handleUserUnassignedFromGroups ' , [$ user , ['groupA ' ]]);
188188 }
189189
190+ public function testUnassignUserFromGroupsWithKeepEmpytGroups () {
191+ $ this ->getGroupManager ();
192+ // set general-keep_groups to 1 and assert it was read
193+ $ this ->config
194+ ->expects ($ this ->exactly (1 ))
195+ ->method ('getAppValue ' )
196+ ->with ('user_saml ' , 'general-keep_groups ' , '0 ' )
197+ ->willReturn ('1 ' );
198+ // create user and group mock
199+ $ user = $ this ->createMock (IUser::class);
200+ $ groupA = $ this ->createMock (IGroup::class);
201+ $ groupA ->method ('getBackendNames ' )
202+ ->willReturn (['Database ' , 'user_saml ' ]);
203+ $ this ->groupManager
204+ ->method ('get ' )
205+ ->with ('groupA ' )
206+ ->willReturn ($ groupA );
207+ $ user ->expects ($ this ->once ())
208+ ->method ('getUID ' )
209+ ->willReturn ('uid ' );
210+ $ groupA ->expects ($ this ->exactly (1 ))
211+ ->method ('getGID ' )
212+ ->willReturn ('gid ' );
213+ // assert membership gets removed
214+ $ this ->ownGroupBackend
215+ ->expects ($ this ->once ())
216+ ->method ('removeFromGroup ' );
217+ // assert no remaining group memberships
218+ $ this ->ownGroupBackend
219+ ->expects ($ this ->once ())
220+ ->method ('countUsersInGroup ' )
221+ ->willReturn (0 );
222+ // assert group is not deleted
223+ $ this ->ownGroupBackend
224+ ->expects ($ this ->never ())
225+ ->method ('deleteGroup ' );
226+ $ this ->eventDispatcher ->expects ($ this ->exactly (0 ))
227+ ->method ('dispatchTyped ' );
228+
229+ $ this ->invokePrivate ($ this ->ownGroupManager , 'handleUserUnassignedFromGroups ' , [$ user , ['groupA ' ]]);
230+ }
231+
190232 public function testAssignUserToGroups () {
191233 $ this ->getGroupManager (['hasSamlBackend ' , 'createGroupInBackend ' ]);
192234 $ user = $ this ->createMock (IUser::class);
0 commit comments