function DbLogTest::testLogEventPage
Same name in other branches
- 8.9.x core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()
- 10 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()
- 11.x core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::testLogEventPage()
Tests individual log event page.
File
-
core/
modules/ dblog/ tests/ src/ Functional/ DbLogTest.php, line 110
Class
- DbLogTest
- Verifies log entries and user access based on permissions.
Namespace
Drupal\Tests\dblog\FunctionalCode
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->assertSession()
->linkByHrefExists($context['request_uri']);
$this->assertSession()
->linkByHrefExists($context['referer']);
// Verify hostname.
$this->assertSession()
->pageTextContains($context['ip']);
// Verify location.
$this->assertSession()
->pageTextContains($context['request_uri']);
// Verify severity.
$this->assertSession()
->pageTextContains('Notice');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.