function MonitoringCoreTest::testSensorDisappearedSensors in Monitoring 7
Tests for SensorDisappearedSensors.
We provide a separate test method for the SensorDisappearedSensors as we need to enable and disable additional modules.
File
- test/
tests/ monitoring.core.test, line 359 - Contains \MonitoringCoreTest.
Class
- MonitoringCoreTest
- Tests for cron sensor.
Code
function testSensorDisappearedSensors() {
// Enable the comment module.
module_enable(array(
'comment',
));
// Run the disappeared sensor - it should not report any problems.
$result = $this
->runSensor('monitoring_disappeared_sensors');
$this
->assertTrue($result
->isOk());
$log = $this
->loadWatchdog();
$this
->assertEqual(count($log), 1, 'There should be one log entry: all sensors enabled by default added.');
$sensor_info = monitoring_sensor_manager()
->getSensorInfo();
$this
->assertEqual(format_string($log[0]->message, unserialize($log[0]->variables)), format_string('@count new sensor/s added: @names', array(
'@count' => count($sensor_info),
'@names' => implode(', ', array_keys($sensor_info)),
)));
// Disable the comment module so that the comment_new sensor goes away.
module_disable(array(
'comment',
));
// The comment_new sensor has gone away and therefore we should have the
// critical status.
$result = $this
->runSensor('monitoring_disappeared_sensors');
$this
->assertTrue($result
->isCritical());
$this
->assertEqual($result
->getMessage(), 'Missing sensor comment_new');
// There should be no new logs.
$this
->assertEqual(count($this
->loadWatchdog()), 1);
// Enable the comment module to test the correct procedure of removing
// sensors.
module_enable(array(
'comment',
));
// Now we should be back to normal.
$result = $this
->runSensor('monitoring_disappeared_sensors');
$this
->assertTrue($result
->isOk());
$this
->assertEqual(count($this
->loadWatchdog()), 1);
// Do the correct procedure to remove a sensor - first disable the sensor
// and then disable the comment module.
$this->sensorManager
->disableSensor('comment_new');
module_disable(array(
'comment',
));
// The sensor should not report any problem this time.
$result = $this
->runSensor('monitoring_disappeared_sensors');
$this
->assertTrue($result
->isOk());
$log = $this
->loadWatchdog();
$this
->assertEqual(count($log), 2, 'Removal of comment_new sensor should be logged.');
$this
->assertEqual(format_string($log[1]->message, unserialize($log[1]->variables)), format_string('@count new sensor/s removed: @names', array(
'@count' => 1,
'@names' => 'comment_new',
)));
// === Test the UI === //
$account = $this
->drupalCreateUser(array(
'administer monitoring',
));
$this
->drupalLogin($account);
// Enable comment module and the comment_new sensor.
module_enable(array(
'comment',
));
$this->sensorManager
->enableSensor('comment_new');
// We should have the message that no sensors are missing.
$this
->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
$this
->assertNoText(t('This action will clear the missing sensors and the critical sensor status will go away.'));
// Disable sensor and the comment module. This is the correct procedure and
// therefore there should be no missing sensors.
$this->sensorManager
->disableSensor('comment_new');
$this
->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
$this
->assertNoText(t('This action will clear the missing sensors and the critical sensor status will go away.'));
// Enable comment module and the comment_new sensor.
module_enable(array(
'comment',
));
$this->sensorManager
->enableSensor('comment_new');
// Now disable the comment module to have the comment_new sensor disappear.
module_disable(array(
'comment',
));
// Run the monitoring_disappeared_sensors sensor to get the status message that should
// be found in the settings form.
$this
->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
$this
->assertText('Missing sensor comment_new');
// Now reset the sensor list - we should get the "no missing sensors"
// message.
$this
->drupalPost(NULL, array(), t('Clear missing sensors'));
$this
->assertText(t('All missing sensors have been cleared.'));
$this
->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
$this
->assertNoText('Missing sensor comment_new');
}