You are here

function MonitoringSearchAPITest::testSensors in Monitoring 7

Tests individual sensors.

File

test/tests/monitoring.search_api.test, line 31
Contains \MonitoringSearchAPITest.

Class

MonitoringSearchAPITest
Tests for search API sensor.

Code

function testSensors() {

  // Create content first to avoid a Division by zero error.
  // @todo: This should be fixed in Search API in theme_search_api_index().
  $this
    ->drupalCreateContentType(array(
    'type' => 'article',
    'name' => 'article',
  ));
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // Configure Search API.
  monitoring_setup_search_api();

  // Reset sensor info so that sensor for newly created search api index
  // gets picked up.
  $this->sensorManager
    ->resetCache();

  // Load indexes.
  $indexes = search_api_index_load_multiple(FALSE);

  // Two new articles, none indexed
  $result = $this
    ->runSensor('search_api_monitoring_test_index');
  $this
    ->assertEqual($result
    ->getValue(), 2);

  // Index existing content.
  search_api_index_items($indexes['monitoring_test_index']);

  // Create additional content.
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
  ));

  // New articles are not yet indexed
  $result = $this
    ->runSensor('search_api_monitoring_test_index');
  $this
    ->assertEqual($result
    ->getValue(), 3);

  // Index remaining articles.
  search_api_index_items($indexes['monitoring_test_index']);

  // Everything should be indexed.
  $result = $this
    ->runSensor('search_api_monitoring_test_index');
  $this
    ->assertEqual($result
    ->getValue(), 0);
}