public function DbLogTest::testLogEventPage in Drupal 9
Same name and namespace in other branches
- 8 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 109
Class
- DbLogTest
- Generate events and verify dblog entries; verify user access to log reports 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');
}