RavenTest.php in Raven: Sentry Integration 8.2
File
tests/src/Functional/RavenTest.php
View source
<?php
namespace Drupal\Tests\raven\Functional;
use Drupal\Component\Serialization\Json;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class RavenTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'raven',
'raven_test',
];
public function testRavenConfigAndHooks() {
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/development/logging');
$config['raven[php][client_key]'] = 'https://user:password@sentry.test/123456';
$config['raven[php][fatal_error_handler]'] = 1;
foreach (range(1, 8) as $level) {
$config["raven[php][log_levels][{$level}]"] = '1';
}
$this
->submitForm($config, $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('X-Logged', 'Logged');
$this
->assertSession()
->responseHeaderEquals('X-Not-Logged', NULL);
$this
->assertSession()
->responseHeaderEquals('X-Stacktrace-File', drupal_get_path('module', 'raven_test') . '/raven_test.module');
$cookies = Json::decode($this
->getSession()
->getResponseHeader('X-Logged-Cookies'));
$this
->assertSame('********', end($cookies));
$memory_limit = mt_rand(16000000, 17999999);
$url = $admin_user
->toUrl()
->setOption('query', [
'memory_limit' => $memory_limit,
]);
$this
->assertEquals($memory_limit . '00', $this
->drupalGet($url));
$this
->drupalGet('admin/config/development/logging');
$config = [
'raven[php][ignored_channels]' => "X-Logged\r\n",
];
$this
->submitForm($config, $this
->t('Save configuration'));
$this
->assertSession()
->responseHeaderEquals('X-Logged', NULL);
unserialize(serialize($this->container
->get('logger.raven')))->client
->captureException(new \Exception('This is a test.'));
}
}