function DbLogTest::test403LogEventPage

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

Tests that a 403 event is logged with the exception triggering it.

File

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

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 test403LogEventPage() {
    $assert_session = $this->assertSession();
    $uri = 'admin/reports';
    $this->drupalLogin($this->webUser);
    $this->drupalGet($uri);
    $assert_session->statusCodeEquals(403);
    $this->drupalLogin($this->adminUser);
    $query = Database::getConnection()->select('watchdog')
        ->condition('type', 'access denied');
    $query->addExpression('MAX(wid)');
    $wid = $query->execute()
        ->fetchField();
    $this->drupalGet('admin/reports/dblog/event/' . $wid);
    $table = $this->xpath("//table[@class='dblog-event']");
    $this->assertCount(1, $table);
    // Verify type, severity and location.
    $type = $table[0]->findAll('xpath', "//tr/th[contains(text(), 'Type')]/../td");
    $this->assertCount(1, $type);
    $this->assertEquals('access denied', $type[0]->getText());
    $severity = $table[0]->findAll('xpath', "//tr/th[contains(text(), 'Severity')]/../td");
    $this->assertCount(1, $severity);
    $this->assertEquals('Warning', $severity[0]->getText());
    $location = $table[0]->findAll('xpath', "//tr/th[contains(text(), 'Location')]/../td/a");
    $this->assertCount(1, $location);
    $href = $location[0]->getAttribute('href');
    $this->assertEquals($this->baseUrl . '/' . $uri, $href);
    // Verify message.
    $message = $table[0]->findAll('xpath', "//tr/th[contains(text(), 'Message')]/../td");
    $this->assertCount(1, $message);
    $regex = "@Path: .+admin/reports\\. Drupal\\\\Core\\\\Http\\\\Exception\\\\CacheableAccessDeniedHttpException: The 'access site reports' permission is required\\. in Drupal\\\\Core\\\\Routing\\\\AccessAwareRouter->checkAccess\\(\\) \\(line \\d+ of .+/core/lib/Drupal/Core/Routing/AccessAwareRouter\\.php\\)\\.@";
    $this->assertRegExp($regex, $message[0]->getText());
}

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