You are here

public function MigratePhoneNumberTestTrait::testRollBack 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::testRollBack()
  2. 2.1.x tests/src/Kernel/Migrate/MigratePhoneNumberTestTrait.php \Drupal\Tests\sms\Kernel\Migrate\MigratePhoneNumberTestTrait::testRollBack()

Tests that conditions are reverted after rollback.

File

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

Class

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

Namespace

Drupal\Tests\sms\Kernel\Migrate

Code

public function testRollBack() {
  $this
    ->loadFixture($this
    ->smsUserFixtureFilePath());
  $this
    ->installEntitySchema('sms');
  $this
    ->installEntitySchema('sms_phone_number_verification');

  // Create an entity form display.
  EntityFormDisplay::create([
    'targetEntityType' => 'user',
    'bundle' => 'user',
    'mode' => 'default',
  ])
    ->setStatus(TRUE)
    ->save();
  $this
    ->executeMigrations($this
    ->getMigrationsToTest());
  $this
    ->assertVerifiedPhoneNumber(User::load(40), '1234567890');

  // Test that the default entity form display has the field added.
  $entity_form_display = EntityFormDisplay::load('user.user.default');
  $this
    ->assertNotNull($entity_form_display
    ->getComponent('phone_number'));

  // Rollback migration and check that verifications, phone number settings
  // and phone number fields are removed.
  $this
    ->rollBackMigrations($this
    ->getMigrationsToRollBack());

  // Assert no phone number verifications, phone number settings or phone
  // number fields exist.
  $this
    ->assertEquals([], PhoneNumberVerification::loadMultiple());
  $this
    ->assertEquals([], PhoneNumberSettings::loadMultiple());
  $this
    ->assertNull(FieldConfig::loadByName('user', 'user', 'phone_number'));
  $this
    ->assertNull(FieldStorageConfig::loadByName('user', 'phone_number'));

  // Test that the display field is removed.
  $entity_form_display = EntityFormDisplay::load('user.user.default');
  $this
    ->assertNull($entity_form_display
    ->getComponent('phone_number'));
}