protected function IntegrationTest::checkCustomAutocompleteScript in Search API Autocomplete 8
Tests whether using a custom autocomplete script is properly supported.
See also
\Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\suggester\CustomScript
1 call to IntegrationTest::checkCustomAutocompleteScript()
- IntegrationTest::testModule in tests/
src/ FunctionalJavascript/ IntegrationTest.php - Tests the complete functionality of the module via the UI.
File
- tests/
src/ FunctionalJavascript/ IntegrationTest.php, line 352
Class
- IntegrationTest
- Tests the functionality of the whole module from a user's perspective.
Namespace
Drupal\Tests\search_api_autocomplete\FunctionalJavascriptCode
protected function checkCustomAutocompleteScript() {
$assert_session = $this
->assertSession();
\Drupal::configFactory()
->getEditable('search_api_autocomplete.settings')
->set('enable_custom_scripts', TRUE)
->save();
$this
->drupalGet($this
->getAdminPath('edit'));
// This gets the request path to the "tests" directory.
$path = str_replace(DRUPAL_ROOT, '', dirname(dirname(__DIR__)));
$path .= '/search_api_autocomplete_test/core/custom_autocomplete_script.php';
$this
->click('input[name="suggesters[enabled][custom_script]"]');
$page = $this
->getSession()
->getPage();
$page
->find('css', 'details[data-drupal-selector="edit-suggesters-settings-custom-script"] > summary')
->click();
$edit = [
'suggesters[enabled][custom_script]' => TRUE,
'suggesters[settings][custom_script][path]' => $path,
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('search-api-autocomplete-test');
$assert_session
->elementAttributeContains('css', 'input[data-drupal-selector="edit-keys"]', 'data-search-api-autocomplete-search', $this->searchId);
$elements = $this
->getAutocompleteSuggestions();
$this
->assertCount(4, $elements);
$suggestions = [];
foreach ($elements as $element) {
$suggestions[] = $element
->getText();
}
sort($suggestions);
$expected = [
'display: page',
'filter: keys',
'q: Tést',
"search_api_autocomplete_search: {$this->searchId}",
];
$this
->assertEquals($expected, $suggestions, 'Unexpected suggestions returned by custom script.');
$this
->drupalGet($this
->getAdminPath('edit'));
$page = $this
->getSession()
->getPage();
$page
->find('css', 'details[data-drupal-selector="edit-suggesters-settings-custom-script"] > summary')
->click();
$edit = [
'suggesters[settings][custom_script][path]' => '',
'suggesters[enabled][custom_script]' => FALSE,
];
$this
->submitForm($edit, 'Save');
}