function ViewsIntegrationTest::testMessages
Same name in other branches
- 9 core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::testMessages()
- 8.9.x core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::testMessages()
- 10 core/modules/dblog/tests/src/Kernel/Views/ViewsIntegrationTest.php \Drupal\Tests\dblog\Kernel\Views\ViewsIntegrationTest::testMessages()
Tests the messages escaping functionality.
File
-
core/
modules/ dblog/ tests/ src/ Kernel/ Views/ ViewsIntegrationTest.php, line 53
Class
- ViewsIntegrationTest
- Tests the views integration of dblog module.
Namespace
Drupal\Tests\dblog\Kernel\ViewsCode
public function testMessages() : void {
// Remove the watchdog entries added by the potential batch process.
$this->container
->get('database')
->truncate('watchdog')
->execute();
$entries = $this->createLogEntries();
$view = Views::getView('test_dblog');
$this->executeView($view);
$view->initStyle();
foreach ($entries as $index => $entry) {
if (!isset($entry['variables'])) {
continue;
}
$message_vars = $entry['variables'];
unset($message_vars['link']);
$this->assertEquals(new FormattableMarkup($entry['message'], $message_vars), $view->style_plugin
->getField($index, 'message'));
$link_field = $view->style_plugin
->getField($index, 'link');
// The 3rd entry contains some unsafe markup that needs to get filtered.
if ($index == 2) {
// Make sure that unsafe link differs from the rendered link, so we know
// that some filtering actually happened. We use assertNotSame and cast
// values to strings since HTML tags are significant.
$this->assertNotSame((string) $entry['variables']['link'], (string) $link_field);
}
$this->assertSame(Xss::filterAdmin($entry['variables']['link']), (string) $link_field);
}
// Disable replacing variables and check that the tokens aren't replaced.
$view->destroy();
$view->storage
->invalidateCaches();
$view->initHandlers();
$this->executeView($view);
$view->initStyle();
$view->field['message']->options['replace_variables'] = FALSE;
foreach ($entries as $index => $entry) {
$this->assertEquals($entry['message'], $view->style_plugin
->getField($index, 'message'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.