function DbLogTest::testLogEventPageWithMissingInfo

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

Tests individual log event page with missing log attributes.

In some cases few log attributes are missing. For example:

  • Missing referer: When request is made to a specific URL directly and error occurred. In this case there is no referer.
  • Incorrect location: When location attribute is incorrect uri which can not be used to generate a valid link.
1 call to DbLogTest::testLogEventPageWithMissingInfo()
DbLogTest::testDbLog in core/modules/dblog/tests/src/Functional/DbLogTest.php
Tests Database Logging module functionality through interfaces.

File

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

Class

DbLogTest
Verifies log entries and user access based on permissions.

Namespace

Drupal\Tests\dblog\Functional

Code

protected function testLogEventPageWithMissingInfo() : void {
  $this->drupalLogin($this->adminUser);
  $connection = Database::getConnection();
  // Test log event page with missing referer.
  $this->generateLogEntries(1, [
    'referer' => NULL,
  ]);
  $query = $connection->select('watchdog');
  $query->addExpression('MAX([wid])');
  $wid = $query->execute()
    ->fetchField();
  $this->drupalGet('admin/reports/dblog/event/' . $wid);
  // Verify table headers are present, even though the referrer is missing.
  $this->assertSession()
    ->pageTextContains('Referrer');
  // Verify severity.
  $this->assertSession()
    ->pageTextContains('Notice');
  // Test log event page with incorrect location.
  $request_uri = '/some/incorrect/url';
  $this->generateLogEntries(1, [
    'request_uri' => $request_uri,
  ]);
  $query = $connection->select('watchdog');
  $query->addExpression('MAX([wid])');
  $wid = $query->execute()
    ->fetchField();
  $this->drupalGet('admin/reports/dblog/event/' . $wid);
  // Verify table headers are present.
  $this->assertSession()
    ->pageTextContains('Location');
  // Verify severity.
  $this->assertSession()
    ->pageTextContains('Notice');
  // Verify location is available as plain text.
  $this->assertEquals($request_uri, $this->cssSelect('table.dblog-event > tbody > tr:nth-child(4) > td')[0]
    ->getHtml());
  $this->assertSession()
    ->linkNotExists($request_uri);
}

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