You are here

public function RavenTest::testRavenConfigAndHooks in Raven: Sentry Integration 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/RavenTest.php \Drupal\Tests\raven\Functional\RavenTest::testRavenConfigAndHooks()

Tests Raven module configuration UI and hooks.

File

tests/src/Functional/RavenTest.php, line 32

Class

RavenTest
Tests Raven module.

Namespace

Drupal\Tests\raven\Functional

Code

public function testRavenConfigAndHooks() {
  $admin_user = $this
    ->drupalCreateUser([
    'administer site configuration',
  ]);
  $this
    ->drupalLogin($admin_user);
  $config['raven[php][client_key]'] = 'https://user@sentry.test/123456';
  $config['raven[php][fatal_error_handler]'] = 1;
  foreach (range(1, 8) as $level) {
    $config["raven[php][log_levels][{$level}]"] = '1';
  }
  $this
    ->drupalGet('admin/config/development/logging');
  $this
    ->submitForm($config, $this
    ->t('Save configuration'));
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Logged', 'Logged');
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Not-Logged', NULL);

  // @todo Temporary work-around to support Drupal 9.2 and lower.
  $path = $this->container
    ->has('extension.path.resolver') ? $this->container
    ->get('extension.path.resolver')
    ->getPath('module', 'raven_test') : drupal_get_path('module', 'raven_test');
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Stacktrace-File', "/{$path}/raven_test.module");

  // Test fatal error handling.
  $memory_limit = mt_rand(16000000, 17999999);
  $url = $admin_user
    ->toUrl()
    ->setOption('query', [
    'memory_limit' => $memory_limit,
  ]);

  // Output should be the memory limit and 0 pending events/requests.
  $this
    ->assertEquals($memory_limit, $this
    ->drupalGet($url));

  // Test ignored channels.
  $config = [
    'raven[php][ignored_channels]' => "X-Logged\r\n",
  ];
  $this
    ->drupalGet('admin/config/development/logging');
  $this
    ->submitForm($config, $this
    ->t('Save configuration'));
  $this
    ->assertSession()
    ->responseHeaderEquals('X-Logged', NULL);

  // Test client functionality after logger is serialized and unserialized.
  unserialize(serialize($this->container
    ->get('logger.raven')));
  \Sentry\captureException(new \Exception('This is a test.'));
}