public function SolrFieldNamesTest::testSolrFieldNames in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 tests/src/Kernel/SolrFieldNamesTest.php \Drupal\Tests\search_api_solr\Kernel\SolrFieldNamesTest::testSolrFieldNames()
- 8 tests/src/Kernel/SolrFieldNamesTest.php \Drupal\Tests\search_api_solr\Kernel\SolrFieldNamesTest::testSolrFieldNames()
- 4.x tests/src/Kernel/SolrFieldNamesTest.php \Drupal\Tests\search_api_solr\Kernel\SolrFieldNamesTest::testSolrFieldNames()
@covers ::getSolrFieldNames
File
- tests/
src/ Kernel/ SolrFieldNamesTest.php, line 39
Class
- SolrFieldNamesTest
- Tests index and search capabilities using the Solr search backend.
Namespace
Drupal\Tests\search_api_solr\KernelCode
public function testSolrFieldNames() {
// Multi-value link field.
$field = FieldStorageConfig::create([
'field_name' => 'field_links',
'entity_type' => 'user',
'type' => 'link',
'cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED,
]);
$field
->save();
FieldConfig::create([
'field_storage' => $field,
'bundle' => 'user',
])
->save();
// Single-value text field.
$field = FieldStorageConfig::create([
'field_name' => 'field_bio',
'entity_type' => 'user',
'type' => 'string_long',
'cardinality' => 1,
]);
$field
->save();
FieldConfig::create([
'field_storage' => $field,
'bundle' => 'user',
])
->save();
$index = Index::create([
'id' => 'index',
'datasource_settings' => [
'entity:node' => [
'plugin_id' => 'entity:node',
'settings' => [],
],
],
'field_settings' => [
'title' => [
'label' => 'Link title',
'type' => 'string',
'datasource_id' => 'entity:node',
'property_path' => 'uid:entity:field_links:title',
],
'bio' => [
'label' => 'Bio field',
'type' => 'string',
'datasource_id' => 'entity:node',
'property_path' => 'uid:entity:field_bio:value',
],
],
]);
$backend = SearchApiSolrBackend::create($this->container, [], 'test', []);
$fields = $backend
->getSolrFieldNames($index);
$this
->assertSame($fields['title'], 'sm_title');
$this
->assertSame($fields['bio'], 'ss_bio');
$fields = $index
->getFields();
$cardinality = $this
->invokeMethod($backend, 'getPropertyPathCardinality', [
$fields['title']
->getPropertyPath(),
$fields['title']
->getDatasource()
->getPropertyDefinitions(),
]);
$this
->assertEqual(FieldStorageConfigInterface::CARDINALITY_UNLIMITED, $cardinality);
$cardinality = $this
->invokeMethod($backend, 'getPropertyPathCardinality', [
$fields['bio']
->getPropertyPath(),
$fields['bio']
->getDatasource()
->getPropertyDefinitions(),
]);
$this
->assertEqual(1, $cardinality);
}