You are here

protected function IntegrationTest::disableEnableIndex in Search API 8

Disables and enables an index and checks if it reacts correctly.

The expected behavior is that, when an index is disabled, all its items are removed from both the tracker and the server.

When it is enabled again, the items are re-added to the tracker.

2 calls to IntegrationTest::disableEnableIndex()
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 1345

Class

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

Namespace

Drupal\Tests\search_api\Functional

Code

protected function disableEnableIndex() {

  // Disable the index and check that no items are tracked.
  $settings_path = $this
    ->getIndexPath('edit');
  $edit = [
    'status' => FALSE,
  ];
  $this
    ->drupalGet($settings_path);
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');
  $tracked_items = $this
    ->countTrackedItems();
  $this
    ->assertEquals(0, $tracked_items, 'No items are tracked after disabling the index.');
  $tracked_items = \Drupal::database()
    ->select('search_api_item', 'i')
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEquals(0, $tracked_items, 'No items left in tracking table.');

  // @todo Also try to verify whether the items got deleted from the server.
  // Re-enable the index and check that the items are tracked again.
  $edit = [
    'status' => TRUE,
  ];
  $this
    ->drupalGet($settings_path);
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');
  $tracked_items = $this
    ->countTrackedItems();
  $this
    ->assertEquals(2, $tracked_items, 'After enabling the index, 2 items are tracked.');
}