function DbLogTest::test403LogEventPage
Same name in other branches
- 9 core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::test403LogEventPage()
- 8.9.x core/modules/dblog/tests/src/Functional/DbLogTest.php \Drupal\Tests\dblog\Functional\DbLogTest::test403LogEventPage()
- 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.
1 call to DbLogTest::test403LogEventPage()
- 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 184
Class
- DbLogTest
- Verifies log entries and user access based on permissions.
Namespace
Drupal\Tests\dblog\FunctionalCode
protected function test403LogEventPage() : void {
$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->assertSession()
->elementExists('xpath', "//table[@class='dblog-event']");
// Verify type, severity and location.
$type = "//tr/th[contains(text(), 'Type')]/../td";
$this->assertSession()
->elementsCount('xpath', $type, 1, $table);
$this->assertEquals('access denied', $table->findAll('xpath', $type)[0]
->getText());
$severity = "//tr/th[contains(text(), 'Severity')]/../td";
$this->assertSession()
->elementsCount('xpath', $severity, 1, $table);
$this->assertEquals('Warning', $table->findAll('xpath', $severity)[0]
->getText());
$location = $table->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->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->assertMatchesRegularExpression($regex, $message[0]->getText());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.