public function MonitoringServicesTest::testSensorConfig in Monitoring 8
Test sensor config API calls.
File
- tests/
src/ Functional/ MonitoringServicesTest.php, line 42
Class
- MonitoringServicesTest
- Tests for monitoring services.
Namespace
Drupal\Tests\monitoring\FunctionalCode
public function testSensorConfig() {
$this
->drupalLogin($this->servicesAccount);
$response_data = $this
->doJsonRequest('monitoring-sensor');
$this
->assertResponse(200);
foreach (monitoring_sensor_manager()
->getAllSensorConfig() as $sensor_name => $sensor_config) {
$this
->assertEqual($response_data[$sensor_name]['sensor'], $sensor_config
->id());
$this
->assertEqual($response_data[$sensor_name]['label'], $sensor_config
->getLabel());
$this
->assertEqual($response_data[$sensor_name]['category'], $sensor_config
->getCategory());
$this
->assertEqual($response_data[$sensor_name]['description'], $sensor_config
->getDescription());
$this
->assertEqual($response_data[$sensor_name]['numeric'], $sensor_config
->isNumeric());
$this
->assertEqual($response_data[$sensor_name]['value_label'], $sensor_config
->getValueLabel());
$this
->assertEqual($response_data[$sensor_name]['caching_time'], $sensor_config
->getCachingTime());
$this
->assertEqual($response_data[$sensor_name]['time_interval'], $sensor_config
->getTimeIntervalValue());
$this
->assertEqual($response_data[$sensor_name]['enabled'], $sensor_config
->isEnabled());
$this
->assertEqual($response_data[$sensor_name]['uri'], Url::fromRoute('rest.monitoring-sensor.GET', [
'id' => $sensor_name,
'_format' => 'json',
])
->setAbsolute()
->toString());
if ($sensor_config
->isDefiningThresholds()) {
$this
->assertEqual($response_data[$sensor_name]['thresholds'], $sensor_config
->getThresholds());
}
}
$sensor_name = 'sensor_that_does_not_exist';
$this
->doJsonRequest('monitoring-sensor/' . $sensor_name);
$this
->assertResponse(404);
$sensor_name = 'dblog_event_severity_error';
$response_data = $this
->doJsonRequest('monitoring-sensor/' . $sensor_name);
$this
->assertResponse(200);
$sensor_config = SensorConfig::load($sensor_name);
$this
->assertEqual($response_data['sensor'], $sensor_config
->id());
$this
->assertEqual($response_data['label'], $sensor_config
->getLabel());
$this
->assertEqual($response_data['category'], $sensor_config
->getCategory());
$this
->assertEqual($response_data['description'], $sensor_config
->getDescription());
$this
->assertEqual($response_data['numeric'], $sensor_config
->isNumeric());
$this
->assertEqual($response_data['value_label'], $sensor_config
->getValueLabel());
$this
->assertEqual($response_data['caching_time'], $sensor_config
->getCachingTime());
$this
->assertEqual($response_data['time_interval'], $sensor_config
->getTimeIntervalValue());
$this
->assertEqual($response_data['enabled'], $sensor_config
->isEnabled());
$this
->assertEqual($response_data['uri'], Url::fromRoute('rest.monitoring-sensor.GET', [
'id' => $sensor_name,
'_format' => 'json',
])
->setAbsolute()
->toString());
if ($sensor_config
->isDefiningThresholds()) {
$this
->assertEqual($response_data['thresholds'], $sensor_config
->getThresholds());
}
}