You are here

protected function SmsFrameworkBrowserTestBase::createPhoneNumberSettings in SMS Framework 8

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

Utility to create phone number settings.

Creates new field storage and field configs.

Return value

\Drupal\sms\Entity\PhoneNumberSettingsInterface A phone number settings entity.

15 calls to SmsFrameworkBrowserTestBase::createPhoneNumberSettings()
SmsFrameworkPhoneNumberAdminTest::testPhoneNumberList in tests/src/Functional/SmsFrameworkPhoneNumberAdminTest.php
Tests phone number list.
SmsFrameworkPhoneNumberTest::testPhoneNumberVerificationCreated in tests/src/Functional/SmsFrameworkPhoneNumberTest.php
Test verification code creation on entity postsave.
SmsFrameworkPhoneNumberTest::testPhoneNumberVerificationDeleted in tests/src/Functional/SmsFrameworkPhoneNumberTest.php
Ensure phone number verification are deleted.
SmsFrameworkPhoneNumberTest::testPhoneNumberVerificationMessage in tests/src/Functional/SmsFrameworkPhoneNumberTest.php
Ensure phone number verification SMS sent.
SmsFrameworkPhoneNumberVerifyForm::testVerifyForm in tests/src/Functional/SmsFrameworkPhoneNumberVerifyForm.php
Test phone number verification form.

... See full list

File

tests/src/Functional/SmsFrameworkBrowserTestBase.php, line 59

Class

SmsFrameworkBrowserTestBase
Base test class for functional browser tests.

Namespace

Drupal\Tests\sms\Functional

Code

protected function createPhoneNumberSettings($entity_type_id, $bundle) {
  $entity_type_manager = \Drupal::entityTypeManager();

  /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
  $field_storage = $entity_type_manager
    ->getStorage('field_storage_config')
    ->create([
    'entity_type' => $entity_type_id,
    'field_name' => Unicode::strtolower($this
      ->randomMachineName()),
    'type' => 'telephone',
  ]);
  $field_storage
    ->setCardinality(1)
    ->save();
  $entity_type_manager
    ->getStorage('field_config')
    ->create([
    'entity_type' => $entity_type_id,
    'bundle' => $bundle,
    'field_name' => $field_storage
      ->getName(),
  ])
    ->save();

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */
  $entity_form_display = EntityFormDisplay::load($entity_type_id . '.' . $bundle . '.default');
  if (!$entity_form_display) {
    $entity_form_display = EntityFormDisplay::create([
      'targetEntityType' => $entity_type_id,
      'bundle' => $bundle,
      'mode' => 'default',
      'status' => TRUE,
    ]);
  }
  $entity_form_display
    ->save();
  $entity_form_display
    ->setComponent($field_storage
    ->getName(), [
    'type' => 'sms_telephone',
  ])
    ->save();

  /** @var \Drupal\sms\Entity\PhoneNumberSettingsInterface $phone_number_settings */
  $phone_number_settings = $entity_type_manager
    ->getStorage('phone_number_settings')
    ->create();
  $phone_number_settings
    ->setFieldName('phone_number', $field_storage
    ->getName())
    ->setPhoneNumberEntityTypeId($entity_type_id)
    ->setPhoneNumberBundle($bundle)
    ->setVerificationCodeLifetime(3601)
    ->setVerificationMessage('Verification code is [sms:verification-code]')
    ->setPurgeVerificationPhoneNumber(TRUE)
    ->save();
  return $phone_number_settings;
}