protected function IntegrationTest::changeIndexDatasource in Search API 8
Changes the index's datasources and checks if it reacts correctly.
The expected behavior is that, when an index's datasources are changed, the tracker should remove all items from the datasources it no longer needs to handle and add the new ones.
2 calls to IntegrationTest::changeIndexDatasource()
- 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 1382
Class
- IntegrationTest
- Tests the overall functionality of the Search API framework and admin UI.
Namespace
Drupal\Tests\search_api\FunctionalCode
protected function changeIndexDatasource() {
$index = $this
->getIndex(TRUE);
$index
->reindex();
$user_count = \Drupal::entityQuery('user')
->accessCheck(FALSE)
->count()
->execute();
$node_count = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->count()
->execute();
// Enable indexing of users.
$settings_path = $this
->getIndexPath('edit');
$edit = [
'datasources[entity:user]' => TRUE,
'datasources[entity:node]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('Please configure the used datasources.');
$this
->submitForm([], 'Save');
$this
->checkForMetaRefresh();
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals($user_count + $node_count, $tracked_items, 'Correct number of items tracked after enabling the "User" datasource.');
// Disable indexing of users again.
$edit = [
'datasources[entity:user]' => FALSE,
'datasources[entity:node]' => TRUE,
];
$this
->drupalGet($settings_path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The index was successfully saved.');
$this
->executeTasks();
$tracked_items = $this
->countTrackedItems();
$this
->assertEquals($node_count, $tracked_items, 'Correct number of items tracked after disabling the "User" datasource.');
}