public function MultiselectElementJavascriptTest::testSelection in Multiselect 8
Same name and namespace in other branches
- 2.x tests/src/FunctionalJavascript/MultiselectElementJavascriptTest.php \Drupal\Tests\multiselect\FunctionalJavascript\MultiselectElementJavascriptTest::testSelection()
Tests selection and deselection of multiselect element.
File
- tests/
src/ FunctionalJavascript/ MultiselectElementJavascriptTest.php, line 34
Class
- MultiselectElementJavascriptTest
- Tests the multiselect element using JavaScript.
Namespace
Drupal\Tests\multiselect\FunctionalJavascriptCode
public function testSelection() {
$this
->drupalGet('/multiselect_test/page');
$wrapper_selector = '.js-form-item-no-default';
$available_selector = "{$wrapper_selector} #edit-no-default-available";
$available_options = [
'apple' => 'Apple',
'banana' => 'Banana',
'cherry' => 'Cherry',
];
$this
->assertOptions($available_selector, $available_options);
$selected_selector = "{$wrapper_selector} #edit-no-default";
$selected_options = [];
$this
->assertOptions($selected_selector, $selected_options);
$driver = $this
->getSession()
->getDriver();
$driver
->selectOption($this
->cssSelectToXpath($available_selector), 'apple');
$driver
->click($this
->cssSelectToXpath("{$wrapper_selector} .multiselect-add"));
unset($available_options['apple']);
$selected_options['apple'] = 'Apple';
$this
->assertOptions($available_selector, $available_options);
$this
->assertOptions($selected_selector, $selected_options);
$driver
->selectOption($this
->cssSelectToXpath($available_selector), 'cherry');
$driver
->click($this
->cssSelectToXpath("{$wrapper_selector} .multiselect-add"));
unset($available_options['cherry']);
$selected_options['cherry'] = 'Cherry';
$this
->assertOptions($available_selector, $available_options);
$this
->assertOptions($selected_selector, $selected_options);
$driver
->selectOption($this
->cssSelectToXpath($selected_selector), 'apple');
$driver
->click($this
->cssSelectToXpath("{$wrapper_selector} .multiselect-remove"));
$available_options['apple'] = 'Apple';
unset($selected_options['apple']);
$this
->assertOptions($available_selector, $available_options);
$this
->assertOptions($selected_selector, $selected_options);
$driver
->selectOption($this
->cssSelectToXpath($selected_selector), 'cherry');
$driver
->click($this
->cssSelectToXpath("{$wrapper_selector} .multiselect-remove"));
$available_options['cherry'] = 'Cherry';
unset($selected_options['cherry']);
$this
->assertOptions($available_selector, $available_options);
$this
->assertOptions($selected_selector, $selected_options);
}