protected function OverviewPageTest::checkServerAndIndexStatusChanges in Search API 8
Tests enable/disable operations for servers and indexes through the UI.
1 call to OverviewPageTest::checkServerAndIndexStatusChanges()
- OverviewPageTest::testOverviewPage in tests/
src/ Functional/ OverviewPageTest.php - Tests various scenarios for the overview page.
File
- tests/
src/ Functional/ OverviewPageTest.php, line 118
Class
- OverviewPageTest
- Tests the Search API overview page.
Namespace
Drupal\Tests\search_api\FunctionalCode
protected function checkServerAndIndexStatusChanges() {
$server = $this
->getTestServer();
$this
->assertEntityStatusChange($server);
// Re-create the index for this test.
$this
->getTestIndex()
->delete();
$index = $this
->getTestIndex();
$this
->assertEntityStatusChange($index);
// Disable the server and test that both itself and the index have been
// disabled.
$server
->setStatus(FALSE)
->save();
$this
->drupalGet($this->overviewPageUrl);
$server_class = Html::cleanCssIdentifier($server
->getEntityTypeId() . '-' . $server
->id());
$index_class = Html::cleanCssIdentifier($index
->getEntityTypeId() . '-' . $index
->id());
$servers = $this
->xpath('//tr[contains(@class,"' . $server_class . '") and contains(@class, "search-api-list-disabled")]');
$this
->assertNotEmpty($servers, 'The server has been disabled.');
$indexes = $this
->xpath('//tr[contains(@class,"' . $index_class . '") and contains(@class, "search-api-list-disabled")]');
$this
->assertNotEmpty($indexes, 'The index has been disabled.');
// Test that an index can't be enabled if its server is disabled.
// @todo A non-working "Enable" link should not be displayed at all.
$this
->clickLink('Enable', 1);
$this
->drupalGet($this->overviewPageUrl);
$indexes = $this
->xpath('//tr[contains(@class,"' . $index_class . '") and contains(@class, "search-api-list-disabled")]');
$this
->assertNotEmpty($indexes, 'The index could not be enabled.');
// Enable the server and try again.
$server
->setStatus(TRUE)
->save();
$this
->drupalGet($this->overviewPageUrl);
// This time the server is enabled so the first 'enable' link belongs to the
// index.
$this
->clickLink('Enable');
$this
->drupalGet($this->overviewPageUrl);
$indexes = $this
->xpath('//tr[contains(@class,"' . $index_class . '") and contains(@class, "search-api-list-enabled")]');
$this
->assertNotEmpty($indexes, 'The index has been enabled.');
// Create a new index without a server assigned and test that it can't be
// enabled. The overview UI is not very consistent at the moment, so test
// using API functions for now.
$index2 = Index::create([
'id' => 'test_index_2',
'name' => 'WebTest index 2',
'datasource_settings' => [
'entity:node' => [],
],
]);
$index2
->save();
$this
->assertFalse($index2
->status(), 'The newly created index without a server is disabled by default.');
$index2
->setStatus(TRUE)
->save();
$this
->assertFalse($index2
->status(), 'The newly created index without a server cannot be enabled.');
}