You are here

protected function IntegrationTest::setReadOnly in Search API 8

Sets an index to "read only" and checks if it reacts correctly.

The expected behavior is that, when an index is set to "read only", it keeps tracking but won't index any items.

2 calls to IntegrationTest::setReadOnly()
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 1283

Class

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

Namespace

Drupal\Tests\search_api\Functional

Code

protected function setReadOnly() {
  $index = $this
    ->getIndex(TRUE);
  $index
    ->reindex();
  $index_path = $this
    ->getIndexPath();
  $settings_path = $index_path . '/edit';

  // Re-enable tracking of all bundles. After this there should be two
  // unindexed items tracked by the index.
  $edit = [
    'status' => TRUE,
    'read_only' => TRUE,
    'datasource_configs[entity:node][bundles][default]' => 0,
    'datasource_configs[entity:node][bundles][selected][article]' => TRUE,
    'datasource_configs[entity:node][bundles][selected][page]' => TRUE,
  ];
  $this
    ->drupalGet($settings_path);
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');
  $index = $this
    ->getIndex(TRUE);
  $remaining_before = $this
    ->countRemainingItems();
  $this
    ->drupalGet($index_path);
  $this
    ->assertSession()
    ->pageTextNotContains('Index now');

  // Also try indexing via the API to make sure it is really not possible.
  $indexed = $this
    ->indexItems();
  $this
    ->assertEquals(0, $indexed, 'No items were indexed after setting the index to "read only".');
  $remaining_after = $this
    ->countRemainingItems();
  $this
    ->assertEquals($remaining_before, $remaining_after, 'No items were indexed after setting the index to "read only".');

  // Disable "read only" and verify indexing now works again.
  $edit = [
    'read_only' => FALSE,
    'datasource_configs[entity:node][bundles][default]' => 1,
    'datasource_configs[entity:node][bundles][selected][article]' => FALSE,
    'datasource_configs[entity:node][bundles][selected][page]' => FALSE,
  ];
  $this
    ->drupalGet($settings_path);
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');
  $this
    ->drupalGet($index_path);
  $this
    ->submitForm([], 'Index now');
  $this
    ->checkForMetaRefresh();
  $remaining_after = $index
    ->getTrackerInstance()
    ->getRemainingItemsCount();
  $this
    ->assertEquals(0, $remaining_after, 'Items were indexed after removing the "read only" flag.');
}