function DbLogTest::testLogEventPage

Same name in other branches
  1. 9 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()
  2. 10 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()
  3. 11.x core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()

Test individual log event page.

File

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

Class

DbLogTest
Generate events and verify dblog entries; verify user access to log reports based on permissions.

Namespace

Drupal\Tests\dblog\Functional

Code

public function testLogEventPage() {
    // Login the admin user.
    $this->drupalLogin($this->adminUser);
    // Since referrer and location links vary by how the tests are run, inject
    // fake log data to test these.
    $context = [
        'request_uri' => 'http://example.com?dblog=1',
        'referer' => 'http://example.org?dblog=2',
        'uid' => 0,
        'channel' => 'testing',
        'link' => 'foo/bar',
        'ip' => '0.0.1.0',
        'timestamp' => REQUEST_TIME,
    ];
    \Drupal::service('logger.dblog')->log(RfcLogLevel::NOTICE, 'Test message', $context);
    $query = Database::getConnection()->select('watchdog');
    $query->addExpression('MAX(wid)');
    $wid = $query->execute()
        ->fetchField();
    // Verify the links appear correctly.
    $this->drupalGet('admin/reports/dblog/event/' . $wid);
    $this->assertLinkByHref($context['request_uri']);
    $this->assertLinkByHref($context['referer']);
    // Verify hostname.
    $this->assertRaw($context['ip'], 'Found hostname on the detail page.');
    // Verify location.
    $this->assertRaw($context['request_uri'], 'Found location on the detail page.');
    // Verify severity.
    $this->assertText('Notice', 'The severity was properly displayed on the detail page.');
}

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