You are here

public function MigratePhoneNumberTestTrait::testPhoneSettingsMigration in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/Migrate/MigratePhoneNumberTestTrait.php \Drupal\Tests\sms\Kernel\Migrate\MigratePhoneNumberTestTrait::testPhoneSettingsMigration()
  2. 2.1.x tests/src/Kernel/Migrate/MigratePhoneNumberTestTrait.php \Drupal\Tests\sms\Kernel\Migrate\MigratePhoneNumberTestTrait::testPhoneSettingsMigration()

Tests migration of phone number settings based on legacy configuration.

File

tests/src/Kernel/Migrate/MigratePhoneNumberTestTrait.php, line 26

Class

MigratePhoneNumberTestTrait
This trait executes tests for D6 and D7 SMS Framework migrations.

Namespace

Drupal\Tests\sms\Kernel\Migrate

Code

public function testPhoneSettingsMigration() {
  $settings = PhoneNumberSettings::loadMultiple();
  $this
    ->assertEquals([], $settings);

  // Execute the phone number settings migration and confirm.
  $this
    ->executeMigration('phone_number_settings');

  // Confirm new phone number settings is created.
  $settings = PhoneNumberSettings::loadMultiple();
  $this
    ->assertEquals(1, count($settings));

  /** @var \Drupal\sms\Entity\PhoneNumberSettingsInterface $setting */
  $setting = reset($settings);
  $this
    ->assertEquals(PhoneNumberSettingsPlugin::DEFAULT_VERIFICATION_MESSAGE, $setting
    ->getVerificationMessage());
  $this
    ->assertEquals('phone_number', $setting
    ->getFieldName('phone_number'));
  $this
    ->assertEquals(TRUE, $setting
    ->getPurgeVerificationPhoneNumber());
  $this
    ->assertEquals('user', $setting
    ->getPhoneNumberBundle());
  $this
    ->assertEquals('user', $setting
    ->getPhoneNumberEntityTypeId());
  $this
    ->assertEquals(600, $setting
    ->getVerificationCodeLifetime());

  // Confirm that a new phone number field is created.
  $field_storage = FieldStorageConfig::load('user.phone_number');
  $this
    ->assertEquals('user.phone_number', $field_storage
    ->id());
  $this
    ->assertEquals('phone_number', $field_storage
    ->getName());
  $this
    ->assertEquals('user', $field_storage
    ->getTargetEntityTypeId());
  $this
    ->assertEquals('telephone', $field_storage
    ->getType());
  $field_config = FieldConfig::load('user.user.phone_number');
  $this
    ->assertEquals('user', $field_config
    ->getTargetEntityTypeId());
  $this
    ->assertEquals('user', $field_config
    ->getTargetBundle());
}