You are here

function MonitoringUITest::testSensorOverviewPage in Monitoring 7

Sensor over page tests coverage.

File

test/tests/monitoring.ui.test, line 100
Contains \MonitoringUITest.

Class

MonitoringUITest
Tests for the Monitoring UI.

Code

function testSensorOverviewPage() {
  $account = $this
    ->drupalCreateUser(array(
    'monitoring reports',
  ));
  $this
    ->drupalLogin($account);

  // Run the test_sensor and update the timestamp in the cache to make the
  // result the oldest.
  $this
    ->runSensor('test_sensor');
  $cid = 'monitoring_sensor_result:test_sensor';
  $cache = cache_get($cid);
  $cache->data['timestamp'] = $cache->data['timestamp'] - 1000;
  cache_set($cid, $cache->data, 'cache', REQUEST_TIME + 3600);
  $this
    ->drupalGet('admin/reports/monitoring');

  // Test if the Test sensor is listed as the oldest cached. We do not test
  // for the cached time as such test contains a risk of random fail.
  $this
    ->assertRaw(format_string('Sensor %sensor (%category) cached before', array(
    '%sensor' => 'Test sensor',
    '%category' => 'Test',
  )));

  // Test the overview table.
  $tbody = $this
    ->xpath('//table[@id="monitoring-sensors-overview"]/tbody');
  $rows = $tbody[0];
  $i = 0;
  foreach (monitoring_sensor_info_by_categories() as $category => $category_sensor_info) {
    $tr = $rows->tr[$i];
    $this
      ->assertEqual($category, $tr->td->h3);
    foreach ($category_sensor_info as $sensor_info) {
      $i++;
      $tr = $rows->tr[$i];
      $this
        ->assertEqual($tr->td[0]->span, $sensor_info
        ->getLabel());
    }
    $i++;
  }
}