WebformElementOptionsTest.php in Webform 6.x
File
tests/src/Functional/Element/WebformElementOptionsTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementOptionsTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_options',
];
public function testElementOptions() {
$this
->drupalGet('/webform/test_element_options');
$this
->assertRaw('<input class="js-webform-options-sync form-text" data-drupal-selector="edit-webform-options-maxlength-options-items-0-value" type="text" id="edit-webform-options-maxlength-options-items-0-value" name="webform_options_maxlength[options][items][0][value]" value="one" size="60" maxlength="20" placeholder="Enter value…" />');
$this
->assertRaw('<input data-drupal-selector="edit-webform-options-maxlength-options-items-0-text" type="text" id="edit-webform-options-maxlength-options-items-0-text" name="webform_options_maxlength[options][items][0][text]" value="One" size="60" maxlength="20" placeholder="Enter text…" class="form-text" />');
$this
->drupalPostForm('/webform/test_element_options', [], 'Submit');
$this
->assertRaw("webform_options: { }\nwebform_options_default_value:\n one: One\n two: Two\n three: Three\nwebform_options_maxlength:\n one: One\n two: Two\n three: Three\nwebform_options_optgroup:\n 'Group One':\n one: One\n 'Group Two':\n two: Two\n 'Group Three':\n three: Three\nwebform_element_options_entity: yes_no\nwebform_element_options_custom:\n one: One\n two: Two\n three: Three");
$this
->drupalPostForm('/webform/test_element_options', [
'webform_element_options_custom[options]' => 'yes_no',
], 'Submit');
$this
->assertRaw("webform_element_options_custom: yes_no");
$edit = [
'webform_options[options][items][0][value]' => 'test',
'webform_options[options][items][1][value]' => 'test',
];
$this
->drupalPostForm('/webform/test_element_options', $edit, 'Submit');
$this
->assertRaw('The <em class="placeholder">Option value</em> \'test\' is already in use. It must be unique.');
}
}