WebformElementValidatePatternTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementValidatePatternTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
class WebformElementValidatePatternTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_validate_pattern',
];
public function testPattern() {
$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" />');
$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>');
$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>');
}
}