You are here

public function SmsFrameworkPhoneNumberVerifyForm::testVerifyForm in SMS Framework 2.1.x

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

Test phone number verification form.

File

tests/src/Functional/SmsFrameworkPhoneNumberVerifyForm.php, line 43

Class

SmsFrameworkPhoneNumberVerifyForm
Tests phone numbers verification code form.

Namespace

Drupal\Tests\sms\Functional

Code

public function testVerifyForm() {
  $account = $this
    ->drupalCreateUser([
    'sms verify phone number',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->createEntityWithPhoneNumber($this
    ->createPhoneNumberSettings('entity_test', 'entity_test'), [
    '+123123123',
  ]);
  $verification = $this
    ->getLastVerification();
  $code = $verification
    ->getCode();
  $this
    ->assertFalse($verification
    ->getStatus(), 'Phone number verification is not verified.');
  $this
    ->assertFalse(empty($code), 'Verification code is set.');

  // Invalid code.
  $edit['code'] = $this
    ->randomMachineName();
  $this
    ->drupalPostForm(Url::fromRoute('sms.phone.verify'), $edit, t('Verify code'));
  $this
    ->assertText(t('Invalid verification code.'));

  // Valid code.
  $edit['code'] = $code;
  $this
    ->drupalPostForm(Url::fromRoute('sms.phone.verify'), $edit, t('Verify code'));
  $this
    ->assertText(t('Phone number is now verified.'));

  // Reset verification code static cache.
  $this
    ->resetAll();
  $verification = $this
    ->getLastVerification();
  $this
    ->assertTrue($verification
    ->getStatus(), 'Phone number is verified.');
}