public function testUnAssignUserFromUserGroup()
{
$userService = $this->repository->getUserService();
$locationService = $this->repository->getLocationService();
$user = $userService->loadUser(14);
$userGroup = $userService->loadUserGroup(12);
// first assign another user group as we can't remove all users groups
$userGroup = $userService->loadUserGroup(42);
$userService->assignUserToUserGroup($user, $userGroup);
// un-assign original group
$userService->unAssignUserFromUserGroup($user, $userGroup);
try {
$user = $userService->loadUser(14);
} catch (NotFoundException $e) {
// user was deleted because the group we assigned him from was his last location
return;
}
$userLocations = $locationService->loadLocations($user->getVersionInfo()->getContentInfo());
if (is_array($userLocations) && !empty($userLocations)) {
$hasRemovedLocation = false;
foreach ($userLocations as $location) {
if ($location->parentLocationId == $userGroup->getVersionInfo()->getContentInfo()->mainLocationId) {
$hasRemovedLocation = true;
break;
}
}
if ($hasRemovedLocation) {
self::fail('Failed removing a user from user group');
}
}
}