diff --git a/core/modules/dblog/src/Tests/DbLogTest.php b/core/modules/dblog/src/Tests/DbLogTest.php index d737831..f28f941 100644 --- a/core/modules/dblog/src/Tests/DbLogTest.php +++ b/core/modules/dblog/src/Tests/DbLogTest.php @@ -7,11 +7,9 @@ namespace Drupal\dblog\Tests; -use Drupal\Component\Utility\String; use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; use Drupal\Core\Logger\RfcLogLevel; -use Drupal\Core\Url; use Drupal\dblog\Controller\DbLogController; use Drupal\simpletest\WebTestBase; @@ -84,6 +82,38 @@ function testDbLog() { } /** + * Test individual log event page. + */ + 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); + $wid = db_query('SELECT MAX(wid) FROM {watchdog}')->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 severity. + $this->assertText('Notice', 'The severity was properly displayed on the detail page.'); + } + + /** * Verifies setting of the database log row limit. * * @param int $row_limit @@ -198,21 +228,7 @@ private function verifyReports($response = 200) { $this->assertResponse($response); if ($response == 200) { $this->assertText(t('Details'), 'DBLog event node was displayed'); - - // Verify the links appear correctly. - $links = db_select('watchdog', 'w') - ->fields('w', array('location', 'referer')) - ->condition('w.wid', $wid) - ->execute() - ->fetchAssoc(); - - // The urls need to be escaped as they are in DbLogController. - // Note that ::assertLinkByHref() wasn't used here since the original regression involved broken urls that passed - // since that method uses a contains rather than strict-matching. - $this->assertRaw('href="' . String::checkPlain((string) Url::fromUri($links['referer'])) . '"'); - $this->assertRaw('href="' . String::checkPlain((string) Url::fromUri($links['location'])) . '"'); } - } /**