protected function SearchApiSolrTest::checkDatasourceAdditionAndDeletion in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 tests/src/Kernel/SearchApiSolrTest.php \Drupal\Tests\search_api_solr\Kernel\SearchApiSolrTest::checkDatasourceAdditionAndDeletion()
Tests addition and deletion of a data source.
1 call to SearchApiSolrTest::checkDatasourceAdditionAndDeletion()
- SearchApiSolrTest::checkBackendSpecificFeatures in tests/
src/ Kernel/ SearchApiSolrTest.php - Checks backend specific features.
File
- tests/
src/ Kernel/ SearchApiSolrTest.php, line 880
Class
- SearchApiSolrTest
- Tests index and search capabilities using the Solr search backend.
Namespace
Drupal\Tests\search_api_solr\KernelCode
protected function checkDatasourceAdditionAndDeletion() {
$this
->indexItems($this->indexId);
$results = $this
->buildSearch()
->execute();
$this
->assertEquals(5, $results
->getResultCount(), 'Number of indexed entities is correct.');
try {
$results = $this
->buildSearch()
->addCondition('uid', 0, '>')
->execute();
$this
->fail('Field uid must not yet exists in this index.');
} catch (\Exception $e) {
$this
->assertEquals('Filter term on unknown or unindexed field uid.', $e
->getMessage());
}
$index = $this
->getIndex();
$index
->set('datasource_settings', $index
->get('datasource_settings') + [
'entity:user' => [],
]);
$info = [
'label' => 'uid',
'type' => 'integer',
'datasource_id' => 'entity:user',
'property_path' => 'uid',
];
$index
->addField($this->fieldsHelper
->createField($index, 'uid', $info));
$index
->save();
User::create([
'uid' => 1,
'name' => 'root',
'langcode' => 'en',
])
->save();
$this
->indexItems($this->indexId);
$results = $this
->buildSearch()
->execute();
$this
->assertEquals(6, $results
->getResultCount(), 'Number of indexed entities in multi datasource index is correct.');
$results = $this
->buildSearch()
->addCondition('uid', 0, '>')
->execute();
$this
->assertEquals(1, $results
->getResultCount(), 'Search for users returned correct number of results.');
$index = $this
->getIndex();
$index
->removeDatasource('entity:user')
->save();
$this
->ensureCommit($index);
$results = $this
->buildSearch()
->execute();
$this
->assertEquals(5, $results
->getResultCount(), 'Number of indexed entities is correct.');
try {
$results = $this
->buildSearch()
->addCondition('uid', 0, '>')
->execute();
$this
->fail('Field uid must not yet exists in this index.');
} catch (\Exception $e) {
$this
->assertEquals('Filter term on unknown or unindexed field uid.', $e
->getMessage());
}
}