You are here

protected function IntegrationTest::editServer in Search API 8

Tests whether editing a server works correctly.

1 call to IntegrationTest::editServer()
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 406

Class

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

Namespace

Drupal\Tests\search_api\Functional

Code

protected function editServer() {
  $path = 'admin/config/search/search-api/server/' . $this->serverId . '/edit';
  $this
    ->drupalGet($path);

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

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $this->indexStorage
    ->load($this->indexId);
  $remaining = $index
    ->getTrackerInstance()
    ->getRemainingItemsCount();
  $this
    ->assertEquals(0, $remaining, 'Index was not scheduled for re-indexing when saving its server.');
  $this
    ->setReturnValue('backend', 'postUpdate', TRUE);
  $this
    ->drupalGet($path);
  $this
    ->submitForm($edit, 'Save');
  $tracked_items = $this
    ->countTrackedItems();
  $remaining = $index
    ->getTrackerInstance()
    ->getRemainingItemsCount();
  $this
    ->assertEquals($tracked_items, $remaining, 'Backend could trigger re-indexing upon save.');
  $this
    ->assertEquals($tracked_items_before, $tracked_items, 'Items are still tracked after re-indexing was triggered.');
}