View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
class WebformElementInputMaskTest extends WebformElementBrowserTestBase {
public static $modules = [
'webform_test_element_input_masks',
];
protected static $testWebforms = [
'test_element_input_mask',
];
public function testInputMask() {
$webform = Webform::load('test_element_input_mask');
$this
->postSubmission($webform);
$this
->assertRaw("currency: '\$ 1.00'\ncurrency_negative: '-\$ 1.00'\ncurrency_positive_negative: '\$ 1.00'\ndatetime: ''\ndecimal: ''\nemail: ''\nip: ''\nlicense_plate: ''\nmac: ''\npercentage: ''\nphone: ''\nssn: ''\nvin: ''\nzip: ''\nuppercase: ''\nlowercase: ''\ncustom: ''\nmodule: ''");
$edit = [
'email' => 'example@example.com',
'datetime' => '2007-06-09\'T\'17:46:21',
'decimal' => '9.9',
'ip' => '255.255.255.255',
'currency' => '$ 9.99',
'currency_negative' => '-$ 9.99',
'currency_positive_negative' => '-$ 9.99',
'percentage' => '99 %',
'phone' => '(999) 999-9999',
'license_plate' => '9-AAA-999',
'mac' => '99-99-99-99-99-99',
'ssn' => '999-99-9999',
'vin' => 'JA3AY11A82U020534',
'zip' => '99999-9999',
'uppercase' => 'UPPERCASE',
'lowercase' => 'lowercase',
'module' => '999',
];
$this
->postSubmission($webform, $edit);
$this
->assertRaw("currency: '\$ 9.99'\ncurrency_negative: '-\$ 9.99'\ncurrency_positive_negative: '-\$ 9.99'\ndatetime: '2007-06-09''T''17:46:21'\ndecimal: '9.9'\nemail: example@example.com\nip: 255.255.255.255\nlicense_plate: 9-AAA-999\nmac: 99-99-99-99-99-99\npercentage: '99 %'\nphone: '(999) 999-9999'\nssn: 999-99-9999\nvin: JA3AY11A82U020534\nzip: 99999-9999\nuppercase: UPPERCASE\nlowercase: lowercase\ncustom: ''\nmodule: '999'");
$edit = [
'currency' => '$ 9.9_',
'currency_negative' => '-$ 9.9_',
'currency_positive_negative' => '-$ 9.9_',
'decimal' => '9._',
'ip' => '255.255.255.__',
'mac' => '99-99-99-99-99-_)',
'percentage' => '_ %',
'phone' => '(999) 999-999_',
'ssn' => '999-99-999_',
'zip' => '99999-999_',
'module' => '99_',
];
$this
->postSubmission($webform, $edit);
foreach ($edit as $name => $value) {
$this
->assertRaw('<em class="placeholder">' . $name . '</em> field is not in the right format.');
}
$this
->postSubmission($webform, [
'currency' => '$ 0.00',
]);
$this
->assertRaw('currency field is required.');
}
}