private function ControllerTest::verifyReports in MongoDB 8.2
Verify the logged-in user has the desired access to the log report.
Parameters
int $statusCode: HTTP status code.
Throws
\Behat\Mink\Exception\ExpectationException
\Behat\Mink\Exception\ResponseTextException
The first of the assertions would really belong in a functional test for the mongodb module. But until it gets a functional test, keeping it here saves some test running time over having one more functional test in mongodb module just for this.
1 call to ControllerTest::verifyReports()
- ControllerTest::testLoggerReportsAccess in modules/
mongodb_watchdog/ tests/ src/ Functional/ ControllerTest.php - The access and contents of the admin/reports/mongodb/watchdog[/*] pages.
File
- modules/
mongodb_watchdog/ tests/ src/ Functional/ ControllerTest.php, line 392
Class
- ControllerTest
- Test the MongoDB report controllers.
Namespace
Drupal\Tests\mongodb_watchdog\FunctionalCode
private function verifyReports($statusCode = Response::HTTP_OK) {
// View MongoDB help page.
$this
->drupalGet('/admin/help');
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
if ($statusCode == Response::HTTP_OK) {
$session
->pageTextContains('MongoDB');
}
$this
->drupalGet('/admin/help/mongodb');
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
if ($statusCode == Response::HTTP_OK) {
// DBLog help was displayed.
$session
->pageTextContains('implements a generic interface');
}
// View MongoDB watchdog overview report.
$this
->drupalGet(static::PATH_OVERVIEW);
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
if ($statusCode == Response::HTTP_OK) {
// MongoDB watchdog report was displayed.
$expectedTexts = [
'Recent log messages in MongoDB',
'Filter log messages',
'Type',
'Severity',
'Latest',
'Severity',
'Message',
'Source',
];
foreach ($expectedTexts as $expectedText) {
$session
->pageTextContains($expectedText);
}
}
// View MongoDB watchdog page-not-found report.
$this
->drupalGet(self::PATH_NOT_FOUND);
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
if ($statusCode == Response::HTTP_OK) {
// MongoDB watchdog page-not-found report was displayed.
$session
->pageTextContains("Top 'page not found' errors in MongoDB");
}
// View MongoDB watchdog access-denied report.
$this
->drupalGet(static::PATH_DENIED);
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
if ($statusCode == Response::HTTP_OK) {
// MongoDB watchdog access-denied report was displayed.
$session
->pageTextContains("Top 'access denied' errors in MongoDB");
}
// Create an event to ensure an event page exists, using the standard PSR-3
// service instead of the Drupal logger channel to ensure getting this
// logger with its specific features.
$expectedMessage = $this
->randomString(32);
/** @var \Drupal\mongodb_watchdog\Logger $logger */
$logger = $this->container
->get(Logger::SERVICE_LOGGER);
$logger
->info($expectedMessage, [
'with' => 'context',
]);
$selector = [
'message' => $expectedMessage,
];
$event = $logger
->templateCollection()
->findOne($selector, MongoDb::ID_PROJECTION);
$eventId = $event['_id'];
// View MongoDB Watchdog event page.
$this
->drupalGet(static::PATH_EVENT_BASE . $eventId);
$session = $this
->assertSession();
$session
->statusCodeEquals($statusCode);
// MongoDB watchdog event page was displayed.
if ($statusCode == Response::HTTP_OK) {
$expectedTexts = [
'Event template',
'ID',
'Changed',
'Count',
'Type',
'Message',
'Severity',
$eventId,
'Event occurrences',
$expectedMessage,
];
foreach ($expectedTexts as $expectedText) {
$session
->pageTextContains($expectedText);
}
}
}