public function SearchApiBackendUnitTest::testIndexField in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
- 8 tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
- 4.x tests/src/Unit/SearchApiBackendUnitTest.php \Drupal\Tests\search_api_solr\Unit\SearchApiBackendUnitTest::testIndexField()
@covers ::addIndexField
@dataProvider addIndexFieldDataProvider
Parameters
mixed $input: Field value.
string $type: Field type.
mixed $expected: Expected result.
File
- tests/
src/ Unit/ SearchApiBackendUnitTest.php, line 48
Class
- SearchApiBackendUnitTest
- Tests functionality of the backend.
Namespace
Drupal\Tests\search_api_solr\UnitCode
public function testIndexField($input, $type, $expected) {
$field = 'testField';
$document = $this
->prophesize(Document::class);
if (NULL !== $expected) {
if (is_array($expected)) {
$document
->addField($field, $expected[0], $expected[1])
->shouldBeCalled();
}
else {
$document
->addField($field, $expected)
->shouldBeCalled();
}
}
else {
$document
->addField($field, $expected)
->shouldNotBeCalled();
}
$args = [
$document
->reveal(),
$field,
[
$input,
],
$type,
];
// Get dummies for most constructor args of SearchApiSolrBackend.
$module_handler = $this
->prophesize(ModuleHandlerInterface::class)
->reveal();
$config = $this
->prophesize(Config::class)
->reveal();
$language_manager = $this
->prophesize(LanguageManagerInterface::class)
->reveal();
$solr_connector_plugin_manager = $this
->prophesize(SolrConnectorPluginManager::class)
->reveal();
$fields_helper = $this
->prophesize(FieldsHelperInterface::class)
->reveal();
$data_type_helper = $this
->prophesize(DataTypeHelperInterface::class)
->reveal();
// This helper is actually used.
$query_helper = new Helper();
$backend = new SearchApiSolrBackend([], NULL, [], $module_handler, $config, $language_manager, $solr_connector_plugin_manager, $fields_helper, $data_type_helper, $query_helper);
// addIndexField() should convert the $input according to $type and call
// Document::addField() with the correctly converted $input.
$this
->invokeMethod($backend, 'addIndexField', $args, []);
}