View source
<?php
namespace Drupal\search_autocomplete\Tests\Entity;
use Drupal\Tests\BrowserTestBase;
class NoSelectorConfigTest extends BrowserTestBase {
public static $modules = [
'node',
'search_autocomplete',
];
public $adminUser;
public static function getInfo() {
return [
'name' => 'Test Autocompletion Configuration test.',
'description' => 'Test special autocompletion configurations scenario.',
'group' => 'Search Autocomplete',
];
}
public function testAdditionFromUrl() {
$options = [
'query' => [
'label' => 'test label',
'selector' => 'input#edit',
],
];
$this
->drupalGet('admin/config/search/search_autocomplete/add', $options);
$config_name = "testing_from_url";
$config = [
'label' => 'test label',
'selector' => 'input#edit',
'minChar' => 3,
'maxSuggestions' => 10,
'autoSubmit' => TRUE,
'autoRedirect' => TRUE,
'noResultLabel' => 'No results found for [search-phrase]. Click to perform full search.',
'noResultValue' => '[search-phrase]',
'noResultLink' => '',
'moreResultsLabel' => 'View all results for [search-phrase].',
'moreResultsValue' => '[search-phrase]',
'moreResultsLink' => '',
'source' => 'autocompletion_callbacks_nodes::nodes_autocompletion_callback',
'theme' => 'basic-blue.css',
];
$this
->assertFieldByName('label', $config['label']);
$this
->assertFieldByName('selector', $config['selector']);
$this
->drupalPostForm(NULL, [
'label' => $config['label'],
'id' => $config_name,
'selector' => $config['selector'],
], 'Create Autocompletion Configuration');
$this
->assertUrl('/admin/config/search/search_autocomplete/manage/' . $config_name);
$this
->assertFieldByName('label', $config['label']);
$this
->assertFieldByName('selector', $config['selector']);
$this
->assertFieldByName('minChar', $config['minChar']);
$this
->assertFieldByName('maxSuggestions', $config['maxSuggestions']);
$this
->assertFieldByName('autoSubmit', $config['autoSubmit']);
$this
->assertFieldByName('autoRedirect', $config['autoRedirect']);
$this
->assertFieldByName('noResultLabel', $config['noResultLabel']);
$this
->assertFieldByName('noResultValue', $config['noResultValue']);
$this
->assertFieldByName('noResultLink', $config['noResultLink']);
$this
->assertFieldByName('moreResultsLabel', $config['moreResultsLabel']);
$this
->assertFieldByName('moreResultsValue', $config['moreResultsValue']);
$this
->assertFieldByName('moreResultsLink', $config['moreResultsLink']);
$this
->assertFieldByName('source', $config['source']);
$this
->assertOptionSelected('edit-theme', $config['theme']);
}
protected function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer search autocomplete',
]);
$this
->drupalLogin($this->adminUser);
}
}