You are here

class SessionLimitSessionTestCase in Session Limit 8

Same name in this branch
  1. 8 tests/session_limit.test \SessionLimitSessionTestCase
  2. 8 tests/SessionLimitSessionTestCase.php \Drupal\session_limit\SessionLimitSessionTestCase
Same name and namespace in other branches
  1. 6.2 tests/session_limit.test \SessionLimitSessionTestCase
  2. 7.2 tests/session_limit.test \SessionLimitSessionTestCase
  3. 2.x tests/session_limit.test \SessionLimitSessionTestCase

Tests the multiple session test functionality.

Hierarchy

Expanded class hierarchy of SessionLimitSessionTestCase

File

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

View source
class SessionLimitSessionTestCase extends SessionLimitBaseTestCase {

  /**
   * getInfo() returns properties that are displayed in the test selection form.
   */
  public static function getInfo() {
    return array(
      'name' => 'Session Limit MutiSession Tests',
      'description' => 'Ensure the multi session tests for SimpleTest work as expected',
      'group' => 'Session Limit',
    );
  }

  /**
   * setUp() performs any pre-requisite tasks that need to happen.
   */
  public function setUp() {

    // Enable any modules required for the test.
    parent::setUp('session_limit');
  }

  /**
   * Test session stash and restore.
   *
   * Drupal Simpletest has no native ability to test over multiple sessions.
   * The session_limit tests add this functionality. This first test checks
   * that multiple sessions are working in SimpleTest by logging in as two
   * different users simultaneously via two cUrl sessions.
   */
  public function testSessionStashAndRestore() {

    // Create and log in our privileged user.
    $user1 = $this
      ->drupalCreateUser(array(
      'access content',
    ));
    $user2 = $this
      ->drupalCreateUser(array(
      'access content',
    ));

    // Make sure that session_limit does not interfere with
    // this test of the tests.
    \Drupal::configFactory()
      ->getEditable('session_limit.settings')
      ->set('session_limit_behaviour', 0)
      ->save();
    \Drupal::configFactory()
      ->getEditable('session_limit.settings')
      ->set('session_limit_max', 100)
      ->save();

    // Login under session 1.
    $this
      ->drupalLogin($user1);
    $this
      ->drupalGet('user');
    $this
      ->assertText(t('Log out'), t('User is logged in under session 1.'));
    $this
      ->assertText($user1->name, t('User1 is logged in under session 1.'));

    // Backup session 1.
    $session_1 = $this
      ->stashSession();

    // Check session 2 is logged out.
    $this
      ->drupalGet('node');
    $this
      ->assertNoText(t('Log out'), t('Session 1 is shelved.'));

    // Login under session 2.
    $this
      ->drupalLogin($user2);
    $this
      ->drupalGet('user');
    $this
      ->assertText(t('Log out'), t('User is logged in under session 2.'));
    $this
      ->assertText($user2->name, t('User2 is logged in under session 2.'));

    // Backup session 2.
    $session_2 = $this
      ->stashSession();

    // Switch to session 1.
    $this
      ->restoreSession($session_1);

    // Check still logged in as session 1.
    $this
      ->drupalGet('user');
    $this
      ->assertText(t('Log out'), t('User is logged in under session 1.'));
    $this
      ->assertText($user1->name, t('User1 is logged in under session 1.'));

    // Switch to session 2.
    $this
      ->restoreSession($session_2);

    // Check still logged in as session 2.
    $this
      ->drupalGet('user');
    $this
      ->assertText(t('Log out'), t('User is logged in under session 2.'));
    $this
      ->assertText($user2->name, t('User2 is logged in under session 2.'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SessionLimitBaseTestCase::$curlHandles protected property A store references to different sessions.
SessionLimitBaseTestCase::$loggedInUsers protected property
SessionLimitBaseTestCase::assertSessionLogout public function Test that an individual user can have up to a specifed number of sessions.
SessionLimitBaseTestCase::assertSessionPrevent public function Test that new sessions cannot be created past a maximum.
SessionLimitBaseTestCase::closeAllSessions public function Close all stashed sessions and the current session.
SessionLimitBaseTestCase::drupalLoginExpectFail protected function Log in a user with the internal browser but expect this to fail.
SessionLimitBaseTestCase::restoreSession public function Restore a previously stashed session.
SessionLimitBaseTestCase::sessionLimitMakeRoles public function Session limit helper function to create 3 roles.
SessionLimitBaseTestCase::stashSession public function Initialise a new unique session.
SessionLimitSessionTestCase::getInfo public static function getInfo() returns properties that are displayed in the test selection form.
SessionLimitSessionTestCase::setUp public function setUp() performs any pre-requisite tasks that need to happen.
SessionLimitSessionTestCase::testSessionStashAndRestore public function Test session stash and restore.