public function SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidget in SMS Framework 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SmsFrameworkPhoneNumberWidgetTest.php \Drupal\Tests\sms\Functional\SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidget()
 - 2.1.x tests/src/Functional/SmsFrameworkPhoneNumberWidgetTest.php \Drupal\Tests\sms\Functional\SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidget()
 
Test telephone widget using entity form.
File
- tests/
src/ Functional/ SmsFrameworkPhoneNumberWidgetTest.php, line 39  
Class
- SmsFrameworkPhoneNumberWidgetTest
 - Tests phone numbers.
 
Namespace
Drupal\Tests\sms\FunctionalCode
public function testPhoneNumberWidget() {
  $phone_number_settings = $this
    ->createPhoneNumberSettings('entity_test', 'entity_test');
  $field_phone_number = $phone_number_settings
    ->getFieldName('phone_number');
  $form_field_phone_number = $field_phone_number . '[0][value]';
  $test_entity = $this
    ->createEntityWithPhoneNumber($phone_number_settings);
  // No verification code created.
  $this
    ->drupalGet($test_entity
    ->toUrl('edit-form'));
  $t_args = [
    '@url' => Url::fromRoute('sms.phone.verify')
      ->toString(),
    '@time' => '1 hour',
  ];
  $this
    ->assertRaw(t('Enter a phone number. A verification code will be sent as an SMS message, you must enter the code into the <a href="@url">verification form</a> within @time.', $t_args));
  // Create verification code, wait for confirmation.
  $edit = [
    $form_field_phone_number => '+123123123',
  ];
  $this
    ->drupalPostForm($test_entity
    ->toUrl('edit-form'), $edit, t('Save'));
  $this
    ->assertRaw(t('A verification code has been sent to this phone number. Go to the <a href="@url">verification form</a> and enter the code. The code will expire if it is not verified in', $t_args));
  $input = $this
    ->xpath('//input[@name="' . $form_field_phone_number . '" and @disabled="disabled"]');
  $this
    ->assertTrue(count($input) === 1, 'The phone number text field is disabled.');
  // Verify the code.
  $phone_verification = $this
    ->getLastVerification();
  $phone_verification
    ->setStatus(TRUE)
    ->save();
  // Check phone number is verified.
  $this
    ->drupalGet($test_entity
    ->toUrl('edit-form'));
  $this
    ->assertRaw(t('This phone number is verified. <strong>Warning:</strong> Modifying this phone number will remove verification.'));
  $input = $this
    ->xpath('//input[@name="' . $form_field_phone_number . '" and @disabled="disabled"]');
  $this
    ->assertTrue(count($input) === 0, 'The phone number text field is enabled.');
}