View source
<?php
namespace Drupal\Tests\devel\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
class DevelErrorHandlerTest extends BrowserTestBase {
public static $modules = [
'devel',
];
public function testErrorHandler() {
$messages_selector = 'div.messages--warning';
$expected_notice = new FormattableMarkup('%type: @message in %function (line ', [
'%type' => 'Notice',
'@message' => 'Undefined variable: undefined',
'%function' => 'Drupal\\devel\\Form\\SettingsForm->demonstrateErrorHandlers()',
]);
$expected_warning = new FormattableMarkup('%type: @message in %function (line ', [
'%type' => 'Warning',
'@message' => 'Division by zero',
'%function' => 'Drupal\\devel\\Form\\SettingsForm->demonstrateErrorHandlers()',
]);
$config = $this
->config('system.logging');
$config
->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)
->save();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access devel information',
]);
$this
->drupalLogin($admin_user);
$error_handlers = \Drupal::config('devel.settings')
->get('error_handlers');
$this
->assertEquals($error_handlers, [
DEVEL_ERROR_HANDLER_STANDARD => DEVEL_ERROR_HANDLER_STANDARD,
]);
$this
->drupalGet('admin/config/development/devel');
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_STANDARD);
$edit = [
'error_handlers[]' => DEVEL_ERROR_HANDLER_NONE,
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$error_handlers = \Drupal::config('devel.settings')
->get('error_handlers');
$this
->assertEquals($error_handlers, [
DEVEL_ERROR_HANDLER_NONE => DEVEL_ERROR_HANDLER_NONE,
]);
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_NONE);
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseNotContains($expected_notice);
$this
->assertSession()
->responseNotContains($expected_warning);
$this
->assertSession()
->elementNotExists('css', $messages_selector);
$edit = [
'error_handlers[]' => DEVEL_ERROR_HANDLER_BACKTRACE_KINT,
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$error_handlers = \Drupal::config('devel.settings')
->get('error_handlers');
$this
->assertEquals($error_handlers, [
DEVEL_ERROR_HANDLER_BACKTRACE_KINT => DEVEL_ERROR_HANDLER_BACKTRACE_KINT,
]);
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_BACKTRACE_KINT);
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementNotExists('css', $messages_selector);
$edit = [
'error_handlers[]' => DEVEL_ERROR_HANDLER_BACKTRACE_DPM,
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$error_handlers = \Drupal::config('devel.settings')
->get('error_handlers');
$this
->assertEquals($error_handlers, [
DEVEL_ERROR_HANDLER_BACKTRACE_DPM => DEVEL_ERROR_HANDLER_BACKTRACE_DPM,
]);
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_BACKTRACE_DPM);
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($expected_notice);
$this
->assertSession()
->responseContains($expected_warning);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_notice);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_warning);
$edit = [
'error_handlers[]' => [
DEVEL_ERROR_HANDLER_BACKTRACE_KINT => DEVEL_ERROR_HANDLER_BACKTRACE_KINT,
DEVEL_ERROR_HANDLER_BACKTRACE_DPM => DEVEL_ERROR_HANDLER_BACKTRACE_DPM,
],
];
$this
->drupalPostForm('admin/config/development/devel', $edit, t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$error_handlers = \Drupal::config('devel.settings')
->get('error_handlers');
$this
->assertEquals($error_handlers, [
DEVEL_ERROR_HANDLER_BACKTRACE_KINT => DEVEL_ERROR_HANDLER_BACKTRACE_KINT,
DEVEL_ERROR_HANDLER_BACKTRACE_DPM => DEVEL_ERROR_HANDLER_BACKTRACE_DPM,
]);
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_BACKTRACE_KINT);
$this
->assertOptionSelected('edit-error-handlers', DEVEL_ERROR_HANDLER_BACKTRACE_DPM);
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($expected_notice);
$this
->assertSession()
->responseContains($expected_warning);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_notice);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_warning);
$config
->set('error_level', ERROR_REPORTING_DISPLAY_ALL)
->save();
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($expected_notice);
$this
->assertSession()
->responseContains($expected_warning);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_notice);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_warning);
$config
->set('error_level', ERROR_REPORTING_DISPLAY_SOME)
->save();
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseContains($expected_notice);
$this
->assertSession()
->responseContains($expected_warning);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_notice);
$this
->assertSession()
->elementContains('css', $messages_selector, $expected_warning);
$config
->set('error_level', ERROR_REPORTING_HIDE)
->save();
$this
->clickLink('notice+warning');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseNotContains($expected_notice);
$this
->assertSession()
->responseNotContains($expected_warning);
$this
->assertSession()
->elementNotExists('css', $messages_selector);
}
}