You are here

public function SessionLimitBaseTestCase::sessionLimitMakeRoles in Session Limit 8

Same name in this branch
  1. 8 tests/session_limit.test \SessionLimitBaseTestCase::sessionLimitMakeRoles()
  2. 8 tests/SessionLimitBaseTestCase.php \Drupal\session_limit\SessionLimitBaseTestCase::sessionLimitMakeRoles()
Same name and namespace in other branches
  1. 2.x tests/SessionLimitBaseTestCase.php \Drupal\session_limit\SessionLimitBaseTestCase::sessionLimitMakeRoles()

Session limit helper function to create 3 roles.

Parameters

stdClass $user: (optional) If provided the user will be added to the three roles.

Return value

array An array of the three roles.

6 calls to SessionLimitBaseTestCase::sessionLimitMakeRoles()
SessionLimitLogoutTestCase::testSessionLimitRoles in tests/SessionLimitLogoutTestCase.php
Checks that the session limit is returned correctly by a role.
SessionLimitLogoutTestCase::testSessionLimitUser in tests/SessionLimitLogoutTestCase.php
Checks that the session limit is returned correctly by a user override.
SessionLimitLogoutTestCase::testSessionLimitUserMaxPrecedence in tests/SessionLimitLogoutTestCase.php
Check that user override takes precedence over default and role regardless of max.
SessionLimitPreventTestCase::testSessionLimitRoles in tests/SessionLimitPreventTestCase.php
Checks that the session limit is returned correctly by a role.
SessionLimitPreventTestCase::testSessionLimitUser in tests/SessionLimitPreventTestCase.php
Checks that the session limit is returned correctly by a user override.

... See full list

File

tests/SessionLimitBaseTestCase.php, line 28

Class

SessionLimitBaseTestCase
Base test for session limits.

Namespace

Drupal\session_limit

Code

public function sessionLimitMakeRoles($user = NULL) {

  // Create roles.
  $roles = array();
  $roles[] = (object) array(
    'name' => 'role1',
  );
  $roles[] = (object) array(
    'name' => 'role2',
  );
  $roles[] = (object) array(
    'name' => 'role3',
  );
  user_role_save($roles[0]);
  user_role_save($roles[1]);
  user_role_save($roles[2]);
  if (!empty($user)) {
    $user->roles[$roles[0]->rid] = $roles[0]->name;
    $user->roles[$roles[1]->rid] = $roles[1]->name;
    $user->roles[$roles[2]->rid] = $roles[2]->name;
    $user
      ->save();
  }
  return $roles;
}