You are here

protected function IntegrationTest::editIndex in Search API 8

Tests editing a search index via the UI.

1 call to IntegrationTest::editIndex()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Search API's admin UI.

File

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

Class

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

Namespace

Drupal\Tests\search_api\Functional

Code

protected function editIndex() {
  $tracked_items = $this
    ->countTrackedItems();
  $edit_path = 'admin/config/search/search-api/index/' . $this->indexId . '/edit';
  $this
    ->drupalGet($edit_path);

  // Check if it's possible to change the machine name.
  $elements = $this
    ->xpath('//form[@id="search-api-index-edit-form"]/div[contains(@class, "form-item-id")]/input[@disabled]');
  $this
    ->assertEquals(1, count($elements), 'Machine name cannot be changed.');

  // Test the AJAX functionality for configuring the tracker.
  $edit = [
    'tracker' => 'search_api_test',
  ];
  $this
    ->submitForm($edit, 'tracker_configure');
  $edit['tracker_config[foo]'] = 'foobar';
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');

  // Verify that everything was changed correctly.
  $index = $this
    ->getIndex(TRUE);
  $tracker = $index
    ->getTrackerInstance();
  $this
    ->assertInstanceOf(TestTracker::class, $tracker, get_class($tracker));
  $this
    ->assertInstanceOf(TestTracker::class, $tracker, 'Tracker was successfully switched.');
  $configuration = [
    'foo' => 'foobar',
    'dependencies' => [],
  ];
  $this
    ->assertEquals($configuration, $tracker
    ->getConfiguration(), 'Tracker config was successfully saved.');
  $this
    ->assertEquals($tracked_items, $this
    ->countTrackedItems(), 'Items are still correctly tracked.');

  // Revert back to the default tracker for the rest of the test.
  $this
    ->drupalGet($edit_path);
  $edit = [
    'tracker' => 'default',
  ];
  $this
    ->submitForm($edit, 'tracker_configure');
  $edit['tracker_config[indexing_order]'] = 'fifo';
  $this
    ->submitForm($edit, 'Save');
  $this
    ->checkForMetaRefresh();
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('The index was successfully saved.');
  $index = $this
    ->getIndex(TRUE);
  $tracker = $index
    ->getTrackerInstance();
  $this
    ->assertInstanceOf(Basic::class, $tracker, 'Tracker was successfully switched.');
}