public function Select2EntityReferenceWidgetTest::testAutocompleteDragnDrop in Select 2 8
Tests the autocomplete drag n drop.
File
- tests/
src/ FunctionalJavascript/ FieldWidget/ Select2EntityReferenceWidgetTest.php, line 440
Class
- Select2EntityReferenceWidgetTest
- Tests select2 entity reference widget.
Namespace
Drupal\Tests\select2\FunctionalJavascript\FieldWidgetCode
public function testAutocompleteDragnDrop() {
$this
->markTestSkipped('Testing drag and drop is currently not possible due to a bug in chromedriver. See https://www.drupal.org/node/3084730.');
$this
->createField('select2', 'node', 'test', 'entity_reference', [
'target_type' => 'entity_test_mulrevpub',
'cardinality' => -1,
], [
'handler' => 'default:entity_test_mulrevpub',
'handler_settings' => [
'auto_create' => FALSE,
],
], 'select2_entity_reference', [
'autocomplete' => TRUE,
'match_operator' => 'CONTAINS',
]);
EntityTestMulRevPub::create([
'name' => 'foo',
])
->save();
EntityTestMulRevPub::create([
'name' => 'bar',
])
->save();
EntityTestMulRevPub::create([
'name' => 'gaga',
])
->save();
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('/node/add/test');
$page
->fillField('title[0][value]', 'Test node');
$this
->click('.form-item-select2 .select2-selection.select2-selection--multiple');
$page
->find('css', '.select2-search__field')
->setValue('fo');
$assert_session
->waitForElement('xpath', '//li[contains(@class, "select2-results__option") and text()="foo"]');
$page
->find('xpath', '//li[contains(@class, "select2-results__option") and text()="foo"]')
->click();
$this
->click('.form-item-select2 .select2-selection.select2-selection--multiple');
$page
->find('css', '.select2-search__field')
->setValue('ba');
$assert_session
->waitForElement('xpath', '//li[contains(@class, "select2-results__option") and text()="bar"]');
$page
->find('xpath', '//li[contains(@class, "select2-results__option") and text()="bar"]')
->click();
$this
->click('.form-item-select2 .select2-selection.select2-selection--multiple');
$page
->find('css', '.select2-search__field')
->setValue('ga');
$assert_session
->waitForElement('xpath', '//li[contains(@class, "select2-results__option") and text()="gaga"]');
$page
->find('xpath', '//li[contains(@class, "select2-results__option") and text()="gaga"]')
->click();
$this
->dragDropElement($page
->find('xpath', '//li[contains(@class, "select2-selection__choice") and text()="gaga"]'), -100, 0);
$this
->dragDropElement($page
->find('xpath', '//li[contains(@class, "select2-selection__choice") and text()="foo"]'), 50, 0);
$page
->pressButton('Save');
$node = $this
->getNodeByTitle('Test node', TRUE);
$this
->assertEquals([
[
'target_id' => 3,
],
[
'target_id' => 2,
],
[
'target_id' => 1,
],
], $node->select2
->getValue());
}