function MigrateUpgradeTestBase::assertUpgrade

Same name in other branches
  1. 9 core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase::assertUpgrade()
  2. 10 core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php \Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase::assertUpgrade()

Asserts the upgrade completed successfully.

Parameters

array $entity_counts: An array of entity count, where the key is the entity type and the value is the number of the entities that should exist post migration.

Throws

\Behat\Mink\Exception\ExpectationException

5 calls to MigrateUpgradeTestBase::assertUpgrade()
MigrateUpgradeExecuteTestBase::doUpgradeAndIncremental in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php
Executes an upgrade and then an incremental upgrade.
Upgrade6Test::testUpgrade in core/modules/forum/tests/src/Functional/migrate_drupal/d6/Upgrade6Test.php
Executes all steps of migrations upgrade.
Upgrade7Test::testUpgrade in core/modules/forum/tests/src/Functional/migrate_drupal/d7/Upgrade7Test.php
Executes all steps of migrations upgrade.
UpgradeTest::testUpgrade in core/modules/statistics/tests/src/Functional/migrate_drupal/d6/UpgradeTest.php
Executes all steps of migrations upgrade.
UpgradeTest::testUpgrade in core/modules/statistics/tests/src/Functional/migrate_drupal/d7/UpgradeTest.php
Executes all steps of migrations upgrade.

File

core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php, line 240

Class

MigrateUpgradeTestBase
Provides a base class for testing migration upgrades in the UI.

Namespace

Drupal\Tests\migrate_drupal_ui\Functional

Code

protected function assertUpgrade(array $entity_counts) {
    $session = $this->assertSession();
    $session->pageTextContains(t('Congratulations, you upgraded Drupal!'));
    // Assert the count of entities after the upgrade. First, reset all the
    // statics after migration to ensure entities are loadable.
    $this->resetAll();
    // Check that the expected number of entities is the same as the actual
    // number of entities.
    $entity_definitions = array_keys(\Drupal::entityTypeManager()->getDefinitions());
    ksort($entity_counts);
    $expected_count_keys = array_keys($entity_counts);
    sort($entity_definitions);
    $this->assertSame($expected_count_keys, $entity_definitions);
    // Assert the correct number of entities exists.
    $actual_entity_counts = [];
    foreach ($entity_definitions as $entity_type) {
        $actual_entity_counts[$entity_type] = (int) \Drupal::entityQuery($entity_type)->accessCheck(FALSE)
            ->count()
            ->execute();
    }
    $this->assertSame($entity_counts, $actual_entity_counts);
    $plugin_manager = \Drupal::service('plugin.manager.migration');
    $version = $this->getLegacyDrupalVersion($this->sourceDatabase);
    
    /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
    $all_migrations = $plugin_manager->createInstancesByTag('Drupal ' . $version);
    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.
            $this->assertNotSame(MigrateIdMapInterface::STATUS_FAILED, $row['source_row_status'], $message);
            $this->assertNotSame(MigrateIdMapInterface::STATUS_NEEDS_UPDATE, $row['source_row_status'], $message);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.