WebformElementValidateMinlengthTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementValidateMinlengthTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
class WebformElementValidateMinlengthTest extends WebformElementBrowserTestBase {
protected static $testWebforms = [
'test_element_validate_minlength',
];
public function testValidateMinlength() {
$webform = Webform::load('test_element_validate_minlength');
$this
->drupalGet('/webform/test_element_validate_minlength');
$this
->assertCssSelect('#edit-minlength-textfield[minlength="5"]');
$this
->assertCssSelect('#edit-minlength-textfield-required[minlength="5"]');
$this
->postSubmission($webform, [
'minlength_textfield' => 'X',
]);
$this
->assertRaw('<em class="placeholder">minlength_textfield</em> cannot be less than <em class="placeholder">5</em> characters but is currently <em class="placeholder">1</em> characters long.');
$this
->postSubmission($webform, [
'minlength_textfield' => '',
]);
$this
->assertNoRaw('<em class="placeholder">minlength_textfield</em> cannot be less than <em class="placeholder">5</em> characters but is currently <em class="placeholder">0</em> characters long.');
$this
->postSubmission($webform, [
'minlength_textfield_required' => '',
]);
$this
->assertNoRaw('<em class="placeholder">minlength_textfield_required</em> cannot be less than <em class="placeholder">5</em> characters but is currently <em class="placeholder">0</em> characters long.');
$this
->assertRaw('minlength_textfield_required field is required.');
}
}