You are here

public function WebformElementTelephoneTest::testTelephone in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/Element/WebformElementTelephoneTest.php \Drupal\Tests\webform\Functional\Element\WebformElementTelephoneTest::testTelephone()

Test telephone element.

File

tests/src/Functional/Element/WebformElementTelephoneTest.php, line 40

Class

WebformElementTelephoneTest
Tests for telephone element.

Namespace

Drupal\Tests\webform\Functional\Element

Code

public function testTelephone() {
  $this
    ->drupalGet('/webform/test_element_telephone');

  // Check basic tel.
  $this
    ->assertRaw('<input data-drupal-selector="edit-tel-default" type="tel" id="edit-tel-default" name="tel_default" value="" size="30" maxlength="128" class="form-tel" />');

  // Check international tel.
  $this
    ->assertRaw('<input class="js-webform-telephone-international webform-webform-telephone-international form-tel" data-drupal-selector="edit-tel-international" type="tel" id="edit-tel-international" name="tel_international" value="" size="30" maxlength="128" />');

  // Check international telephone valddation.
  $this
    ->assertRaw('<input data-drupal-selector="edit-tel-validation-e164" type="tel" id="edit-tel-validation-e164" name="tel_validation_e164" value="" size="30" maxlength="128" class="form-tel" />');

  // Check USE telephone validation.
  $this
    ->assertRaw('<input data-drupal-selector="edit-tel-validation-national" aria-describedby="edit-tel-validation-national--description" type="tel" id="edit-tel-validation-national" name="tel_validation_national" value="" size="30" maxlength="128" class="form-tel" />');

  // Check telephone validation missing plus sign.
  $edit = [
    'tel_validation_e164' => '12024561111',
    'tel_validation_national' => '12024561111',
  ];
  $this
    ->drupalPostForm('/webform/test_element_telephone', $edit, 'Submit');
  $this
    ->assertRaw('The phone number <em class="placeholder">12024561111</em> is not valid.');

  // Check telephone validation with plus sign.
  $edit = [
    'tel_validation_e164' => '+12024561111',
    'tel_validation_national' => '+12024561111',
  ];
  $this
    ->drupalPostForm('/webform/test_element_telephone', $edit, 'Submit');
  $this
    ->assertNoRaw('The phone number <em class="placeholder">12024561111</em> is not valid.');

  // Check telephone validation with non US number.
  $edit = [
    'tel_validation_national' => '+74956970349',
  ];
  $this
    ->drupalPostForm('/webform/test_element_telephone', $edit, 'Submit');
  $this
    ->assertRaw('The phone number <em class="placeholder">+74956970349</em> is not valid.');
}