You are here

public function SmsFrameworkPhoneNumberTest::testPhoneNumberVerificationMessage in SMS Framework 8

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

Ensure phone number verification SMS sent.

See also

_sms_entity_postsave()

File

tests/src/Functional/SmsFrameworkPhoneNumberTest.php, line 55

Class

SmsFrameworkPhoneNumberTest
General phone number verification tests.

Namespace

Drupal\Tests\sms\Functional

Code

public function testPhoneNumberVerificationMessage() {
  $test_gateway = $this
    ->createMemoryGateway([
    'skip_queue' => TRUE,
  ]);
  $this
    ->setFallbackGateway($test_gateway);
  $phone_numbers = [
    '+123123123',
  ];
  $phone_number_settings = $this
    ->createPhoneNumberSettings('entity_test', 'entity_test');
  $this
    ->createEntityWithPhoneNumber($phone_number_settings, $phone_numbers);
  $sms_message = $this
    ->getLastTestMessage($test_gateway);
  $this
    ->assertTrue($sms_message instanceof SmsMessageInterface, 'SMS verification message sent.');
  $this
    ->assertEqual($sms_message
    ->getRecipients(), $phone_numbers, 'Sent to correct phone number.');
  $phone_verification = $this
    ->getLastVerification();
  $data['sms_verification_code'] = $phone_verification
    ->getCode();
  $message = \Drupal::token()
    ->replace($phone_number_settings
    ->getVerificationMessage(), $data);
  $this
    ->assertEqual($sms_message
    ->getMessage(), $message, 'Sent correct message.');
}