eZ\Publish\Core\Repository\Tests\Service\Integration\UserBase::testAssignUserToUserGroup PHP Method

testAssignUserToUserGroup() public method

Test assigning a user group to user.
    public function testAssignUserToUserGroup()
    {
        $userService = $this->repository->getUserService();
        $locationService = $this->repository->getLocationService();
        $user = $userService->loadUser(14);
        $userGroup = $userService->loadUserGroup(42);
        $userService->assignUserToUserGroup($user, $userGroup);
        $userLocations = $locationService->loadLocations($user->getVersionInfo()->getContentInfo());
        if (!is_array($userLocations) || empty($userLocations)) {
            self::fail('Failed assigning user to user group');
        }
        $hasAddedLocation = false;
        foreach ($userLocations as $location) {
            if ($location->parentLocationId == $userGroup->getVersionInfo()->getContentInfo()->mainLocationId) {
                $hasAddedLocation = true;
                break;
            }
        }
        if (!$hasAddedLocation) {
            self::fail('Failed assigning user to user group');
        }
    }