You are here

public function MigrateUpgradeCommerce1Test::testMigrateUpgrade in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/tests/src/Functional/commerce1/MigrateUpgradeCommerce1Test.php \Drupal\Tests\commerce_migrate_commerce\Functional\commerce1\MigrateUpgradeCommerce1Test::testMigrateUpgrade()
  2. 3.0.x modules/commerce/tests/src/Functional/commerce1/MigrateUpgradeCommerce1Test.php \Drupal\Tests\commerce_migrate_commerce\Functional\commerce1\MigrateUpgradeCommerce1Test::testMigrateUpgrade()

Executes all steps of migrations upgrade.

File

modules/commerce/tests/src/Functional/commerce1/MigrateUpgradeCommerce1Test.php, line 94

Class

MigrateUpgradeCommerce1Test
Tests Commerce 1 upgrade using the migrate UI.

Namespace

Drupal\Tests\commerce_migrate_commerce\Functional\commerce1

Code

public function testMigrateUpgrade() {
  $this
    ->drupalGet('/upgrade');
  $session = $this
    ->assertSession();
  $session
    ->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal {$this->destinationSiteVersion}.");
  $this
    ->submitForm([], 'Continue');
  $session
    ->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.');

  // Get valid credentials.
  $edits = $this
    ->translatePostValues($this
    ->getCredentials());
  $this
    ->submitForm($edits, 'Review upgrade');
  $session
    ->statusCodeEquals(200);
  $this
    ->submitForm([], 'Perform upgrade');
  $this
    ->assertUpgrade($this
    ->getEntityCounts());
  $plugin_manager = \Drupal::service('plugin.manager.migration');

  /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
  $all_migrations = $plugin_manager
    ->createInstancesByTag('Drupal 7');
  foreach ($all_migrations as $migration) {
    $id_map = $migration
      ->getIdMap();
    foreach ($id_map as $source_id => $map) {

      // Convert $source_id into a keyless array so that
      // \Drupal\migrate\Plugin\migrate\id_map\Sql::getSourceHash() works as
      // expected.
      $source_id_values = array_values(unserialize($source_id));
      $row = $id_map
        ->getRowBySource($source_id_values);
      $destination = serialize($id_map
        ->currentDestination());
      $message = "Migration of {$source_id} to {$destination} as part of the {$migration->id()} migration. The source row status is " . $row['source_row_status'];

      // A completed migration should have maps with
      // MigrateIdMapInterface::STATUS_IGNORED or
      // MigrateIdMapInterface::STATUS_IMPORTED.
      if ($row['source_row_status'] == MigrateIdMapInterface::STATUS_FAILED || $row['source_row_status'] == MigrateIdMapInterface::STATUS_NEEDS_UPDATE) {
        $this
          ->fail($message);
      }
      else {
        self::assertNotEmpty($message);
      }
    }
  }
}