You are here

public function SessionLimitPreventTestCase::testSessionLimitUserMaxPrecedence in Session Limit 7.2

Same name and namespace in other branches
  1. 8 tests/session_limit.test \SessionLimitPreventTestCase::testSessionLimitUserMaxPrecedence()
  2. 6.2 tests/session_limit.test \SessionLimitPreventTestCase::testSessionLimitUserMaxPrecedence()
  3. 2.x tests/session_limit.test \SessionLimitPreventTestCase::testSessionLimitUserMaxPrecedence()

Checks that a user session limit is always used in preference to all others.

File

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

Class

SessionLimitPreventTestCase
Session limit functionality when behaviour is to prevent login at limit.

Code

public function testSessionLimitUserMaxPrecedence() {

  // Create a test user.
  $user = $this
    ->drupalCreateUser();
  $roles = $this
    ->sessionLimitMakeRoles($user);

  // Add a personal session limit.
  user_save($user, array(
    'data' => array(
      'session_limit' => 1,
    ),
  ));

  // Set the session limits for the roles.
  variable_set('session_limit_rid_' . $roles[0]->rid, 3);
  variable_set('session_limit_rid_' . $roles[1]->rid, 4);
  variable_set('session_limit_rid_' . $roles[2]->rid, 5);

  // Set the default session limit.
  variable_set('session_limit_max', 2);

  // Check if the user has access to 1 session, the user specified max.
  $this
    ->assertSessionPrevent(1, $user);
}