You are here

mongodb_session.test in MongoDB 7

Contains \MongoDBSessionTestCase and \MongoDBSessionHttpsTestCase.

These tests cases cover the MongoDB session implementation.

File

mongodb_session/mongodb_session.test
View source
<?php

/**
 * @file
 * Contains \MongoDBSessionTestCase and \MongoDBSessionHttpsTestCase.
 *
 * These tests cases cover the MongoDB session implementation.
 */

/**
 * Override for SessionTestCase.
 *
 * Enable the MongoDB session module that is required to catch changes
 * made to users.
 */

// phpcs:ignore
class MongoDBSessionTestCase extends SessionTestCase {

  /**
   * {@inheritDoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Session tests',
      'description' => 'Drupal session handling tests.',
      'group' => 'MongoDB',
    );
  }

  /**
   * {@inheritDoc}
   */
  public function setUp() {

    // Skip SessionTestCase::setUp() and call the DrupalWebTestCase directly.
    // Yes, this is valid. Ugly, but valid.
    DrupalWebTestCase::setUp('mongodb_session', 'mongodb', 'session_test');
  }

}

/**
 * Override for SessionHttpsTestCase.
 */

// phpcs:ignore
class MongoDBSessionHttpsTestCase extends SessionHttpsTestCase {

  /**
   * {@inheritDoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Session https handling (MongoDB)',
      'description' => 'Ensure that when running under https two session cookies are generated.',
      'group' => 'MongoDB',
    );
  }

  /**
   * {@inheritDoc}
   */
  public function setUp() {
    parent::setUp('mongodb_session', 'mongodb');
    $this->collection = mongodb_collection(variable_get('mongodb_session', 'session'));
  }

  /**
   * Test that there exists a session with two specific session IDs.
   *
   * @param string $sid
   *   The insecure session ID to search for.
   * @param string $ssid
   *   The secure session ID to search for.
   * @param string $assertion_text
   *   The text to display when we perform the assertion.
   *
   * @return bool
   *   The result of assertTrue() that there's a session in the system that
   *   has the given insecure and secure session IDs.
   */
  protected function assertSessionIds($sid, $ssid, $assertion_text) {
    return $this
      ->assertTrue($this->collection
      ->findOne(array(
      'sid' => $sid,
      'ssid' => $ssid,
    ), array(
      'sid',
    )), $assertion_text);
  }

}