You are here

protected function IntegrationTest::checkIndexing in Search API 8

Tests whether indexing via the UI works correctly.

2 calls to IntegrationTest::checkIndexing()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Search API's admin UI.
IntegrationTest::testIntegerIndex in tests/src/Functional/IntegrationTest.php
Tests what happens when an index has an integer as id/label.

File

tests/src/Functional/IntegrationTest.php, line 1466

Class

IntegrationTest
Tests the overall functionality of the Search API framework and admin UI.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function checkIndexing() {
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);
  $this
    ->drupalCreateNode([
    'type' => 'article',
  ]);

  // Skip indexing for one node.
  $key = 'search_api_test.backend.indexItems.skip';
  \Drupal::state()
    ->set($key, [
    'entity:node/' . $node
      ->id() . ':' . $node
      ->language()
      ->getId(),
  ]);

  // Ensure all items need to be indexed.
  $this
    ->getIndex()
    ->reindex();
  $this
    ->drupalGet($this
    ->getIndexPath());
  $this
    ->submitForm([], 'Index now');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->checkForMetaRefresh();
  $count = \Drupal::entityQuery('node')
    ->accessCheck(FALSE)
    ->count()
    ->execute() - 1;
  $this
    ->assertSession()
    ->pageTextContains("Successfully indexed {$count} items.");
  $this
    ->assertSession()
    ->pageTextContains('1 item could not be indexed.');
  $this
    ->assertSession()
    ->pageTextNotContains("Couldn't index items.");
  $this
    ->assertSession()
    ->pageTextNotContains('An error occurred');
  $this
    ->drupalGet($this
    ->getIndexPath());
  $this
    ->submitForm([], 'Index now');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains("Couldn't index items.");
  $this
    ->assertSession()
    ->pageTextNotContains('An error occurred');
  \Drupal::state()
    ->set($key, []);
  $this
    ->setError('backend', 'indexItems');
  $this
    ->drupalGet($this
    ->getIndexPath());
  $this
    ->submitForm([], 'Index now');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains("Couldn't index items.");
  $this
    ->assertSession()
    ->pageTextNotContains('An error occurred');
  $this
    ->setError('backend', 'indexItems', FALSE);
  $this
    ->drupalGet($this
    ->getIndexPath());
  $this
    ->submitForm([], 'Index now');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains("Successfully indexed 1 item.");
  $this
    ->assertSession()
    ->pageTextNotContains('could not be indexed.');
  $this
    ->assertSession()
    ->pageTextNotContains("Couldn't index items.");
  $this
    ->assertSession()
    ->pageTextNotContains('An error occurred');
}