1 dblog.test | protected DBLogTestCase::testFilter() |
Tests the database log filter functionality at admin/reports/dblog.
File
- core/
modules/ dblog/ tests/ dblog.test, line 496 - Tests for dblog.module.
Class
- DBLogTestCase
- Tests logging messages to the database.
Code
protected function testFilter() {
$this->backdropLogin($this->big_user);
// Clear the log to ensure that only generated entries will be found.
db_delete('watchdog')->execute();
// Generate 9 random watchdog entries.
$type_names = array();
$types = array();
for ($i = 0; $i < 3; $i++) {
$type_names[] = $type_name = $this->randomName();
$severity = WATCHDOG_EMERGENCY;
for ($j = 0; $j < 3; $j++) {
$types[] = $type = array(
'count' => $j + 1,
'type' => $type_name,
'severity' => $severity++,
);
$this->generateLogEntries($type['count'], $type['type'], $type['severity']);
}
}
// View the database log page.
$this->backdropGet('admin/reports/dblog');
// Confirm that all the entries are displayed.
$count = $this->getTypeCount($types);
foreach ($types as $key => $type) {
$this->assertEqual($count[$key], $type['count'], 'Count matched');
}
// Filter by each type and confirm that entries with various severities are
// displayed.
foreach ($type_names as $type_name) {
$edit = array(
'type[]' => array($type_name),
);
$this->backdropPost(NULL, $edit, t('Filter'));
// Count the number of entries of this type.
$type_count = 0;
foreach ($types as $type) {
if ($type['type'] == $type_name) {
$type_count += $type['count'];
}
}
$count = $this->getTypeCount($types);
$this->assertEqual(array_sum($count), $type_count, 'Count matched');
}
// Set the filter to match each of the two filter-type attributes and
// confirm the correct number of entries are displayed.
foreach ($types as $key => $type) {
$edit = array(
'type[]' => array($type['type']),
'severity[]' => array($type['severity']),
);
$this->backdropPost(NULL, $edit, t('Filter'));
$count = $this->getTypeCount($types);
$this->assertEqual(array_sum($count), $type['count'], 'Count matched');
}
// Clear all logs and make sure the confirmation message is found.
$this->backdropPost('admin/reports/dblog', array(), t('Clear log messages'));
$this->assertText(t('Database log cleared.'), 'Confirmation message found');
}