You are here

public function SmsFrameworkPhoneNumberTest::testPhoneNumberVerificationCreated in SMS Framework 2.x

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

Test verification code creation on entity postsave.

See also

_sms_entity_postsave()

File

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

Class

SmsFrameworkPhoneNumberTest
General phone number verification tests.

Namespace

Drupal\Tests\sms\Functional

Code

public function testPhoneNumberVerificationCreated() {
  $phone_number_settings = $this
    ->createPhoneNumberSettings('entity_test', 'entity_test');
  $phone_numbers = [
    '+123123123',
    '+456456456',
    '+789789789',
  ];
  for ($quantity = 1; $quantity < 3; $quantity++) {
    $test_entity = $this
      ->createEntityWithPhoneNumber($phone_number_settings, array_slice($phone_numbers, 0, $quantity));
    $this
      ->assertEqual($quantity, $this
      ->countVerificationCodes($test_entity), 'There is ' . $quantity . ' verification code.');

    // Ensure post-save did not create verification codes if one already
    // exists.
    $test_entity
      ->save();
    $this
      ->assertEqual($quantity, $this
      ->countVerificationCodes($test_entity), 'Additional verification codes were not created.');
  }
}