public function ViewsTest::testFormAltering in Search API Autocomplete 8
Tests that Views forms are altered correctly.
@dataProvider formAlteringDataProvider
See also
search_api_autocomplete_form_views_exposed_form_alter()
File
- tests/
src/ Kernel/ ViewsTest.php, line 168
Class
- ViewsTest
- Tests Views integration of the Autocomplete module.
Namespace
Drupal\Tests\search_api_autocomplete\KernelCode
public function testFormAltering($display_id, $expect_altered) {
$this
->installConfig('search_api_autocomplete_test');
Search::create([
'id' => 'search_api_autocomplete_test_view',
'label' => 'Search API Autocomplete Test view',
'index_id' => 'autocomplete_search_index',
'suggester_settings' => [
'live_results' => [],
],
'search_settings' => [
'views:search_api_autocomplete_test_view' => [
'displays' => [
'default' => TRUE,
'selected' => [
'page_2',
],
],
],
],
])
->save();
$view = View::load('search_api_autocomplete_test_view');
/** @var \Drupal\views\ViewExecutable $executable */
$executable = $view
->getExecutable();
$this
->assertTrue($executable
->setDisplay($display_id));
$executable
->initHandlers();
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
$exposed_form = $executable->display_handler
->getPlugin('exposed_form');
$form = $exposed_form
->renderExposedForm();
$keys_element = $form['keys'] ?? $form['keys_wrapper']['keys'];
if ($expect_altered) {
$this
->assertEquals('search_api_autocomplete', $keys_element['#type']);
}
else {
$this
->assertEquals('textfield', $keys_element['#type']);
}
}