public function FacetsTest::testBasicFunctionality in Select 2 8
Tests basic select2 functionality.
@dataProvider providerTestBasicFunctionality
File
- modules/
select2_facets/ tests/ src/ FunctionalJavascript/ FacetsTest.php, line 62
Class
- FacetsTest
- Tests the select2 element.
Namespace
Drupal\Tests\select2_facets\FunctionalJavascriptCode
public function testBasicFunctionality($config, $expected_settings) {
$facet = Facet::load('referenced');
$facet
->setWidget('select2', $config);
$facet
->save();
$this
->drupalGet('/test-entity-view');
$settings = $this
->getSession()
->getPage()
->findField('Referenced[]')
->getAttribute('data-select2-config');
foreach ($expected_settings as $key => $value) {
if ($key == 'ajax') {
$this
->assertArrayHasKey($key, Json::decode($settings));
}
else {
$this
->assertSame(Json::decode($settings)[$key], $value);
}
}
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->click('.form-item-referenced .select2-selection.select2-selection--multiple');
$page
->find('css', '.select2-search__field')
->setValue('Reference');
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', '//li[@class="select2-results__option" and text()="Reference 2"]'));
$page
->find('xpath', '//li[@class="select2-results__option" and text()="Reference 2"]')
->click();
$assert_session
->addressEquals('test-entity-view?f%5B0%5D=referenced%3A2');
$this
->click('.form-item-referenced .select2-selection.select2-selection--multiple');
$page
->find('css', '.select2-search__field')
->setValue('Reference');
$this
->assertNotEmpty($assert_session
->waitForElement('xpath', '//li[@class="select2-results__option" and text()="Reference 1"]'));
$page
->find('xpath', '//li[@class="select2-results__option" and text()="Reference 1"]')
->click();
$assert_session
->addressEquals('test-entity-view?f%5B0%5D=referenced%3A2&f%5B1%5D=referenced%3A1');
}