You are here

public function ViewsIntegrationTest::testMessages in Drupal 8

Same name and namespace in other branches
  1. 9 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 51

Class

ViewsIntegrationTest
Tests the views integration of dblog module.

Namespace

Drupal\Tests\dblog\Kernel\Views

Code

public function testMessages() {

  // 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;
    }
    $this
      ->assertEqual($view->style_plugin
      ->getField($index, 'message'), new FormattableMarkup($entry['message'], $entry['variables']));
    $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.
      $this
        ->assertNotEqual($link_field, $entry['variables']['link']);
    }
    $this
      ->assertEqual($link_field, Xss::filterAdmin($entry['variables']['link']));
  }

  // 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
      ->assertEqual($view->style_plugin
      ->getField($index, 'message'), $entry['message']);
  }
}