public function WebformElementValidatePatternTest::testPattern in Webform 6.x
Same name and namespace in other branches
- 8.5 tests/src/Functional/Element/WebformElementValidatePatternTest.php \Drupal\Tests\webform\Functional\Element\WebformElementValidatePatternTest::testPattern()
Tests pattern validation.
File
- tests/
src/ Functional/ Element/ WebformElementValidatePatternTest.php, line 22
Class
- WebformElementValidatePatternTest
- Tests for webform pattern validation.
Namespace
Drupal\Tests\webform\Functional\ElementCode
public function testPattern() {
// Check rendering.
$this
->drupalGet('/webform/test_element_validate_pattern');
$this
->assertRaw('<input pattern="Hello" data-drupal-selector="edit-pattern" aria-describedby="edit-pattern--description" type="text" id="edit-pattern" name="pattern" value="" size="60" maxlength="255" class="form-text" />');
$this
->assertRaw('<input pattern="Hello" data-webform-pattern-error="You did not enter 'Hello'" data-drupal-selector="edit-pattern-error" aria-describedby="edit-pattern-error--description" type="text" id="edit-pattern-error" name="pattern_error" value="" size="60" maxlength="255" class="form-text" />');
$this
->assertRaw('<input pattern="Hello" data-webform-pattern-error="You did not enter Hello" data-drupal-selector="edit-pattern-error-html" aria-describedby="edit-pattern-error-html--description" type="text" id="edit-pattern-error-html" name="pattern_error_html" value="" size="60" maxlength="255" class="form-text" />');
$this
->assertRaw('<input pattern="\\u2E8F" data-drupal-selector="edit-pattern-unicode" aria-describedby="edit-pattern-unicode--description" type="text" id="edit-pattern-unicode" name="pattern_unicode" value="" size="60" maxlength="255" class="form-text" />');
// Check validation.
$edit = [
'pattern' => 'GoodBye',
'pattern_error' => 'GoodBye',
'pattern_error_html' => 'GoodBye',
'pattern_unicode' => 'Unicode',
];
$this
->drupalPostForm('/webform/test_element_validate_pattern', $edit, 'Submit');
$this
->assertRaw('<li><em class="placeholder">pattern</em> field is not in the right format.</li>');
$this
->assertRaw('<li>You did not enter 'Hello'</li>');
$this
->assertRaw('<li>You did not enter <strong>Hello</strong></li>');
$this
->assertRaw('<li><em class="placeholder">pattern_unicode</em> field is not in the right format.</li>');
// Check validation.
$edit = [
'pattern' => 'Hello',
'pattern_error' => 'Hello',
'pattern_error_html' => 'Hello',
'pattern_unicode' => '⺏',
];
$this
->drupalPostForm('/webform/test_element_validate_pattern', $edit, 'Submit');
$this
->assertNoRaw('<li><em class="placeholder">pattern</em> field is not in the right format.</li>');
$this
->assertNoRaw('<li>You did not enter 'Hello'</li>');
$this
->assertNoRaw('<li>You did not enter <strong>Hello</strong></li>');
$this
->assertNoRaw('<li><em class="placeholder">pattern_unicode</em> field is not in the right format.</li>');
}