You are here

function SearchByPageNodesReindexTest::testReindexingAutomatic in Search by Page 8

Tests that cycling through content reindexing happens correctly.

File

tests/src/Functional/search_by_page.test, line 564
Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com

Class

SearchByPageNodesReindexTest
Tests when nodes are reindexed.

Namespace

Drupal\Tests\search_by_page\Functional

Code

function testReindexingAutomatic() {
  $this
    ->drupalLogin($this->superuser);
  $search_path = $this->envinfo1['page_path'];

  // Set to reindex automatically on normal cycle.
  $this
    ->drupalPostForm('admin/config/search/search_by_page/edit/' . $this->envid1, array(
    'search_by_page_nodes_min_time' => 1,
    'search_by_page_nodes_max_time' => 0,
  ), 'Save configuration');
  drupal_flush_all_caches();
  variable_initialize();

  // Set search so it only indexes 1 node per cron run.
  \Drupal::state()
    ->set('search_by_page_cron_limit', 1);

  // Figure out the current index times of the nodes.
  $orig = $this
    ->getIndexTimes();

  // In a loop: run cron, and verify each time that the oldest item
  // (or one of them, if there was a tie) was reindexed.
  for ($i = 0; $i < 10; $i++) {

    // Run cron - should reindex just one node.
    $this
      ->doCronrun();
    $this
      ->drupalLogin($this->superuser);

    // Figure out the current index times of the nodes.
    $new = $this
      ->getIndexTimes();

    // Verify that only one was indexed, and it was the oldest one.
    $this
      ->verifyIndexCycling($orig, $new);
    $orig = $new;
  }
}