public function Select2WidgetTest::testLimitedCount in Select 2 8
Test multiple field selection with 2 items.
File
- tests/
src/ FunctionalJavascript/ FieldWidget/ Select2WidgetTest.php, line 142
Class
- Select2WidgetTest
- Tests select2 simple widget.
Namespace
Drupal\Tests\select2\FunctionalJavascript\FieldWidgetCode
public function testLimitedCount() {
$this
->createField('select2', 'node', 'test', 'list_string', [
'allowed_values' => [
'foo' => 'Foo',
'bar' => 'Bar',
'gaga' => 'Gaga',
],
'cardinality' => 2,
], [], 'select2', []);
$page = $this
->getSession()
->getPage();
$this
->drupalGet('/node/add/test');
$page
->fillField('title[0][value]', 'Test node');
$this
->selectOption('edit-select2', [
'foo',
'gaga',
]);
$page
->pressButton('Save');
$node = $this
->getNodeByTitle('Test node');
$this
->assertSame([
[
'value' => 'foo',
],
[
'value' => 'gaga',
],
], $node->select2
->getValue());
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->scrollElementInView('.form-item-select2 .select2-selection.select2-selection--multiple');
$this
->click('.form-item-select2 .select2-selection.select2-selection--multiple');
$this
->assertSession()
->elementTextContains('css', '.select2-dropdown .select2-results', 'You can only select 2 items');
}