You are here

public function SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidgetWithExpiredVerificationCode in SMS Framework 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/SmsFrameworkPhoneNumberWidgetTest.php \Drupal\Tests\sms\Functional\SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidgetWithExpiredVerificationCode()
  2. 2.1.x tests/src/Functional/SmsFrameworkPhoneNumberWidgetTest.php \Drupal\Tests\sms\Functional\SmsFrameworkPhoneNumberWidgetTest::testPhoneNumberWidgetWithExpiredVerificationCode()

Test behavior of widget when verification code expires.

File

tests/src/Functional/SmsFrameworkPhoneNumberWidgetTest.php, line 84

Class

SmsFrameworkPhoneNumberWidgetTest
Tests phone numbers.

Namespace

Drupal\Tests\sms\Functional

Code

public function testPhoneNumberWidgetWithExpiredVerificationCode() {
  $phone_number_settings = $this
    ->createPhoneNumberSettings('entity_test', 'entity_test');
  $test_entity = $this
    ->createEntityWithPhoneNumber($phone_number_settings, [
    '+123123123',
  ]);

  // Force verification code to expire.
  $phone_verification = $this
    ->getLastVerification();
  $phone_verification
    ->set('created', time() - ($phone_number_settings
    ->getVerificationCodeLifetime() + 1))
    ->save();
  $this
    ->drupalGet($test_entity
    ->toUrl('edit-form'));
  $this
    ->assertRaw(t('Verification code expired. Try again later.'));
  $this
    ->cronRun();
  $this
    ->drupalGet($test_entity
    ->toUrl('edit-form'));
  $t_args = [
    '@url' => Url::fromRoute('sms.phone.verify')
      ->toString(),
    '@time' => '1 hour',
  ];

  // Ensure phone number was purged.
  $field_phone_number = $phone_number_settings
    ->getFieldName('phone_number');
  $this
    ->assertFieldByName($field_phone_number . '[0][value]', '');
  $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));
}