You are here

public function MonitoringUITest::testAggregateSensorTimeIntervalConfig in Monitoring 8

Tests the entity aggregator sensors.

Tests the entity aggregator with time interval settings and verbosity.

File

tests/src/Functional/MonitoringUITest.php, line 91

Class

MonitoringUITest
Tests for the Monitoring UI.

Namespace

Drupal\Tests\monitoring\Functional

Code

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

  // Create some nodes.
  $node1 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
  ));
  $node2 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
  ));

  // Visit the overview and make sure the sensor is displayed.
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('2 druplicons in 1 day');

  // Visit the sensor edit form.
  $this
    ->drupalGet('admin/config/system/monitoring/sensors/entity_aggregate_test');

  // Test for the default value.
  $this
    ->assertFieldByName('settings[aggregation][time_interval_field]', 'created');
  $this
    ->assertFieldByName('settings[aggregation][time_interval_value]', 86400);

  // Visit the sensor detail page with verbose output.
  $this
    ->drupalGet('admin/reports/monitoring/sensors/entity_aggregate_test');

  // Check that there is no Save button on the detail page.
  $this
    ->assertNoLink('Save');
  $this
    ->drupalPostForm(NULL, array(), 'Run now');

  // The node labels should appear in verbose output.
  $this
    ->assertText('label');
  $this
    ->assertLink($node1
    ->getTitle());
  $this
    ->assertLink($node2
    ->getTitle());

  // Check the sensor overview to verify that the sensor result is
  // calculated and the sensor message is displayed.
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('2 druplicons in 1 day');

  // Update the time interval and set value to no restriction.
  $this
    ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
    'settings[aggregation][time_interval_value]' => 0,
  ), t('Save'));

  // Visit the overview and make sure that no time interval is displayed.
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('2 druplicons');
  $this
    ->assertNoText('2 druplicons in');

  // Update the time interval and empty interval field.
  $this
    ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
    'settings[aggregation][time_interval_field]' => '',
    'settings[aggregation][time_interval_value]' => 86400,
  ), t('Save'));

  // Visit the overview and make sure that no time interval is displayed
  // which also make sures no change in time interval applies.
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('2 druplicons');
  $this
    ->assertNoText('2 druplicons in');

  // Update the time interval field with an invalid value.
  $this
    ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
    'settings[aggregation][time_interval_field]' => 'invalid-field',
  ), t('Save'));

  // Assert the error message.
  $this
    ->assertText('The specified time interval field invalid-field does not exist or is not type timestamp.');
}