You are here

public function SessionLimitBaseTestCase::sessionLimitMakeRoles in Session Limit 6.2

Same name and namespace in other branches
  1. 8 tests/session_limit.test \SessionLimitBaseTestCase::sessionLimitMakeRoles()
  2. 7.2 tests/session_limit.test \SessionLimitBaseTestCase::sessionLimitMakeRoles()
  3. 2.x tests/session_limit.test \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/session_limit.test
Checks that the session limit is returned correctly by a role.
SessionLimitLogoutTestCase::testSessionLimitUser in tests/session_limit.test
Checks that the session limit is returned correctly by a user override.
SessionLimitLogoutTestCase::testSessionLimitUserMaxPrecedence in tests/session_limit.test
Check that user override takes precedence over default and role regardless of max.
SessionLimitPreventTestCase::testSessionLimitRoles in tests/session_limit.test
Checks that the session limit is returned correctly by a role.
SessionLimitPreventTestCase::testSessionLimitUser in tests/session_limit.test
Checks that the session limit is returned correctly by a user override.

... See full list

File

tests/session_limit.test, line 32
Simpletest tests for session_limit.

Class

SessionLimitBaseTestCase
Base test for session limits.

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',
  );
  foreach ($roles as $role) {
    $role->rid = $this
      ->drupalCreateRole(array(
      'access content',
    ), $role->name);
    if (!empty($user)) {
      db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $user->uid, $role->rid);
    }
  }
  $user = empty($user) ? NULL : user_load($user->uid);
  return $roles;
}