WebformElementSelectTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementSelectTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementSelectTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_select',
];
public function testSelectElement() {
$this
->drupalGet('/webform/test_element_select');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-optional" id="edit-select-empty-option-optional" name="select_empty_option_optional" class="form-select"><option value="" selected="selected">- None -</option>');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-optional-default-value" id="edit-select-empty-option-optional-default-value" name="select_empty_option_optional_default_value" class="form-select"><option value="">- None -</option>');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-required" id="edit-select-empty-option-required" name="select_empty_option_required" class="form-select required" required="required" aria-required="true"><option value="" selected="selected">- Select -</option>');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('element.default_empty_option', FALSE)
->save();
$this
->drupalGet('/webform/test_element_select');
$this
->assertNoRaw('<select data-drupal-selector="edit-select-empty-option-optional" id="edit-select-empty-option-optional" name="select_empty_option_optional" class="form-select"><option value="" selected="selected">- None -</option>');
$this
->assertNoRaw('<select data-drupal-selector="edit-select-empty-option-optional-default-value" id="edit-select-empty-option-optional-default-value" name="select_empty_option_optional_default_value" class="form-select"><option value="">- None -</option>');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-required" id="edit-select-empty-option-required" name="select_empty_option_required" class="form-select required" required="required" aria-required="true"><option value="" selected="selected">- Select -</option>');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('element.default_empty_option', TRUE)
->set('element.default_empty_option_required', '{required}')
->set('element.default_empty_option_optional', '{optional}')
->save();
$this
->drupalGet('/webform/test_element_select');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-optional" id="edit-select-empty-option-optional" name="select_empty_option_optional" class="form-select"><option value="" selected="selected">{optional}</option>');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-optional-default-value" id="edit-select-empty-option-optional-default-value" name="select_empty_option_optional_default_value" class="form-select"><option value="">{optional}</option>');
$this
->assertRaw('<select data-drupal-selector="edit-select-empty-option-required" id="edit-select-empty-option-required" name="select_empty_option_required" class="form-select required" required="required" aria-required="true"><option value="" selected="selected">{required}</option>');
}
}