function DbLogTest::testMessageParsing

Same name and namespace in other branches
  1. 9 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testMessageParsing()
  2. 10 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testMessageParsing()

Test that twig errors are displayed correctly.

File

core/modules/dblog/tests/src/Functional/DbLogTest.php, line 283

Class

DbLogTest
Verifies log entries and user access based on permissions.

Namespace

Drupal\Tests\dblog\Functional

Code

public function testMessageParsing() : void {
    $this->drupalLogin($this->adminUser);
    // Log a common twig error with {{ }} and { } variables.
    \Drupal::service('logger.factory')->get("php")
        ->error('Incorrect parameter {{foo}} in path {path}: {value}', [
        'foo' => 'bar',
        'path' => '/baz',
        'value' => 'horse',
    ]);
    // View the log page to verify it's correct.
    $wid = \Drupal::database()->query('SELECT MAX(wid) FROM {watchdog}')
        ->fetchField();
    $this->drupalGet('admin/reports/dblog/event/' . $wid);
    $this->assertSession()
        ->responseContains('Incorrect parameter {bar} in path /baz: horse');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.