You are here

raven.test in Raven: Sentry Integration 7.4

Same filename and directory in other branches
  1. 7 raven.test
  2. 7.2 raven.test
  3. 7.3 raven.test

Tests for Raven.module.

File

raven.test
View source
<?php

/**
 * @file
 * Tests for Raven.module.
 */
use Sentry\SentrySdk;

/**
 * Tests logging messages to the database.
 */
class RavenTestCase extends DrupalWebTestCase {

  /**
   * A user with some relevant administrative permissions.
   *
   * @var object
   */
  protected $adminUser;

  /**
   * A user without any permissions.
   *
   * @var object
   */
  protected $anyUser;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return [
      'name' => 'Raven',
      'description' => 'Tests for Raven Sentry module.',
      'group' => 'Raven',
    ];
  }

  /**
   * Enable modules and create users with specific permissions.
   */
  public function setUp() {
    $modules = [
      'composer_autoloader',
      'raven',
      'raven_test',
    ];
    parent::setUp($modules);
    $this
      ->ensureAutoloader();
    $this->adminUser = $this
      ->drupalCreateUser([
      'administer site configuration',
      'access administration pages',
      'access site reports',
    ]);
    $this->anyUser = $this
      ->drupalCreateUser([]);
  }

  /**
   * Ensures that the Composer autoloader is set up properly.
   */
  protected function ensureAutoloader() {

    // Test to see if one of the classes that the autoloader should know
    // about has been defined.
    if (!class_exists(SentrySdk::class)) {

      // This most likely means that we are running on DrupalCI, so set
      // up for that.
      variable_set('composer_autoloader', DRUPAL_ROOT . '/vendor/autoload.php');
    }
  }

  /**
   * Tests Raven module functionality.
   */
  public function testRaven() {
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet('admin/reports/status');
    $this
      ->drupalGet('admin/config/development/logging');
    $edit['raven_dsn'] = 'https://user@sentry.test/123456';
    $edit['raven_enabled'] = TRUE;
    $edit['raven_watchdog_levels[4]'] = 4;
    $edit['raven_watchdog_levels[6]'] = 6;
    $edit['raven_fatal_error_handler'] = TRUE;
    $this
      ->drupalPost(NULL, $edit, 'Save configuration');
    $this
      ->drupalLogout();
    $this
      ->drupalLogin($this->anyUser);
    $this
      ->assertNoText('Sentry PHP library cannot be loaded. Check status report for more details.');
    $this
      ->assertIdentical($this
      ->drupalGetHeader('X-Logged'), 'Logged');
    $this
      ->assertFalse($this
      ->drupalGetHeader('X-Not-Logged'));
    $this
      ->assertIdentical(realpath($this
      ->drupalGetHeader('X-Watchdog-File')), realpath(drupal_get_filename('module', 'raven_test')));
    $this
      ->assertIdentical(realpath($this
      ->drupalGetHeader('X-Watchdog-Exception-File')), realpath(drupal_get_filename('module', 'raven_test')));
    $this
      ->assertIdentical($this
      ->drupalGetHeader('X-Watchdog-Exception-Function'), 'raven_test_throw_exception');
    $memory_limit = mt_rand(8000000, 9999999);
    $this
      ->assertEqual($memory_limit, $this
      ->drupalGet('', [
      'query' => [
        'memory_limit' => $memory_limit,
      ],
    ]));
  }

}

Classes

Namesort descending Description
RavenTestCase Tests logging messages to the database.