You are here

protected function OverviewPageTest::assertEntityStatusChange in Search API 8

Asserts enable/disable operations for a search server or index.

Parameters

\Drupal\search_api\ServerInterface|\Drupal\search_api\IndexInterface $entity: A search server or index.

1 call to OverviewPageTest::assertEntityStatusChange()
OverviewPageTest::checkServerAndIndexStatusChanges in tests/src/Functional/OverviewPageTest.php
Tests enable/disable operations for servers and indexes through the UI.

File

tests/src/Functional/OverviewPageTest.php, line 179

Class

OverviewPageTest
Tests the Search API overview page.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function assertEntityStatusChange($entity) {
  $this
    ->drupalGet($this->overviewPageUrl);
  $row_class = Html::cleanCssIdentifier($entity
    ->getEntityTypeId() . '-' . $entity
    ->id());
  $rows = $this
    ->xpath('//tr[contains(@class,"' . $row_class . '") and contains(@class, "search-api-list-enabled")]');
  $this
    ->assertNotEmpty($rows, 'The newly created entity is enabled by default.');

  // The first "Disable" link on the page belongs to our server, the second
  // one to our index.
  $this
    ->clickLink('Disable', $entity instanceof ServerInterface ? 0 : 1);

  // Submit the confirmation form and test that the entity has been disabled.
  $this
    ->submitForm([], 'Disable');
  $rows = $this
    ->xpath('//tr[contains(@class,"' . $row_class . '") and contains(@class, "search-api-list-disabled")]');
  $this
    ->assertNotEmpty($rows, 'The entity has been disabled.');

  // Now enable the entity and verify that the operation succeeded.
  $this
    ->clickLink('Enable');
  $this
    ->drupalGet($this->overviewPageUrl);
  $rows = $this
    ->xpath('//tr[contains(@class,"' . $row_class . '") and contains(@class, "search-api-list-enabled")]');
  $this
    ->assertNotEmpty($rows, 'The entity has benn enabled.');
}