WebformElementValidateMultipleTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementValidateMultipleTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementValidateMultipleTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_validate_multiple',
];
public function testValidateMultiple() {
$this
->drupalGet('/webform/test_element_validate_multiple');
$this
->assertFieldByName('webform_element_multiple_textfield_three[items][0][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three[items][1][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three[items][2][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three[items][3][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three_table_add');
$edit = [
'webform_element_multiple_textfield_three[add][more_items]' => 2,
];
$this
->drupalPostForm(NULL, $edit, 'webform_element_multiple_textfield_three_table_add');
$this
->assertFieldByName('webform_element_multiple_textfield_three[items][0][_item_]');
$this
->assertFieldByName('webform_element_multiple_textfield_three[items][1][_item_]');
$this
->assertFieldByName('webform_element_multiple_textfield_three[items][2][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three[items][3][_item_]');
$this
->assertNoFieldByName('webform_element_multiple_textfield_three_table_add');
$edit = [
'webform_element_multiple_checkboxes_two[one]' => 'one',
'webform_element_multiple_checkboxes_two[two]' => 'two',
'webform_element_multiple_checkboxes_two[three]' => 'three',
'webform_element_multiple_select_two[]' => [
'one',
'two',
'three',
],
];
$this
->drupalPostForm('/webform/test_element_validate_multiple', $edit, 'Submit');
$this
->assertRaw('Please check only two options.');
$this
->assertRaw('<em class="placeholder">webform_element_multiple_select_two</em>: this element cannot hold more than 2 values.');
}
}