View source
<?php
namespace Drupal\search_autocomplete\Tests\Entity;
use Drupal\simpletest\WebTestBase;
class UnicityConfigTest extends WebTestBase {
public static $modules = [
'node',
'search_autocomplete',
];
public $adminUser;
public static function getInfo() {
return [
'name' => 'Test Autocompletion Configuration test.',
'description' => 'Test unicity autocompletion configurations scenario.',
'group' => 'Search Autocomplete',
];
}
public function testUniqueId() {
$this
->drupalGet('admin/config/search/search_autocomplete/add');
$config_name = "testing";
$config = [
'label' => 'test-label',
'selector' => 'input#edit',
];
$this
->drupalPostForm(NULL, [
'label' => $config['label'],
'id' => $config_name,
'selector' => $config['selector'],
], 'Create Autocompletion Configuration');
$this
->drupalGet('admin/config/search/search_autocomplete/add');
$config_name = "testing";
$config = [
'label' => 'test-another',
'selector' => 'another',
];
$this
->drupalPostForm(NULL, [
'label' => $config['label'],
'id' => $config_name,
'selector' => $config['selector'],
], 'Create Autocompletion Configuration');
$this
->assertRaw(t('The machine-readable name is already in use. It must be unique.'));
}
public function testUniqueSelector() {
$this
->drupalGet('admin/config/search/search_autocomplete/add');
$config_name = "test1";
$config = [
'label' => 'test1',
'selector' => 'input#edit',
];
$this
->drupalPostForm(NULL, [
'label' => $config['label'],
'id' => $config_name,
'selector' => $config['selector'],
], 'Create Autocompletion Configuration');
$this
->drupalGet('admin/config/search/search_autocomplete/add');
$config_name = "test2";
$config = [
'label' => 'test2',
'selector' => 'input#edit',
];
$this
->drupalPostForm(NULL, [
'label' => $config['label'],
'id' => $config_name,
'selector' => $config['selector'],
], 'Create Autocompletion Configuration');
$this
->assertRaw('The selector ID must be unique.');
}
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer search autocomplete',
]);
$this
->drupalLogin($this->adminUser);
}
}