public function Select2BoxesTests::testListWidget in Select2 Boxes 8
Test widget for a list type of fields.
File
- tests/
src/ FunctionalJavascript/ Select2BoxesTests.php, line 161
Class
- Select2BoxesTests
- Class for testing Select2Boxes.
Namespace
Drupal\Tests\select2boxes\FunctionalJavascriptCode
public function testListWidget() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
// Go the the "Manage Form Display" form.
$this
->drupalGet('admin/structure/types/manage/select2boxes_test_content_type/form-display');
// Set list widget for the Test list field.
$assert_session
->elementExists('xpath', '//select[@name="fields[field_test_list][type]"]')
->setValue(static::$pluginIds[0]);
$assert_session
->assertWaitOnAjaxRequest();
$page
->pressButton('Save');
// Check if the submission has been successful.
$this
->assertSession()
->pageTextContains('Your settings have been saved.');
// Now let's check the node creation page.
$this
->drupalGet('node/add/select2boxes_test_content_type');
// Check that the select element exists.
$select = $assert_session
->selectExists('edit-field-test-list');
// Check if all required html attributes are exist
// for the list field.
$assert_session
->elementAttributeExists('css', '#edit-field-test-list', 'data-jquery-once-autocomplete');
$assert_session
->elementAttributeExists('css', '#edit-field-test-list', 'data-select2-autocomplete-list-widget');
$this
->assertTrue($select
->hasClass('select2-widget'));
}