Commit 8b3a7003 authored by catch's avatar catch

Issue #2683579 by alexpott, benjy: Improve migrate UI tests

parent e8ae6689
......@@ -8,12 +8,15 @@
namespace Drupal\migrate_drupal_ui\Tests;
use Drupal\Core\Database\Database;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate_drupal\MigrationCreationTrait;
use Drupal\simpletest\WebTestBase;
/**
* Provides a base class for testing migration upgrades in the UI.
*/
abstract class MigrateUpgradeTestBase extends WebTestBase {
use MigrationCreationTrait;
/**
* Use the Standard profile to test help implementations of many core modules.
......@@ -32,7 +35,7 @@ abstract class MigrateUpgradeTestBase extends WebTestBase {
*
* @var array
*/
public static $modules = ['migrate_drupal_ui'];
public static $modules = ['migrate_drupal_ui', 'telephone'];
/**
* {@inheritdoc}
......@@ -150,6 +153,32 @@ protected function testMigrateUpgrade() {
$expected_count = isset($expected_counts[$entity_type]) ? $expected_counts[$entity_type] : 0;
$this->assertEqual($expected_count, $real_count, "Found $real_count $entity_type entities, expected $expected_count.");
}
$version_tag = 'Drupal ' . $this->getLegacyDrupalVersion($this->sourceDatabase);
$plugin_manager = \Drupal::service('plugin.manager.migration');
/** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */
$all_migrations = $plugin_manager->createInstancesByTag($version_tag);
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 = "Successful 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 {
$this->pass($message);
}
}
}
}
/**
......
......@@ -30,7 +30,7 @@ protected function setUp() {
* {@inheritdoc}
*/
protected function getSourceBasePath() {
return './';
return __DIR__ . '/files';
}
/**
......@@ -45,9 +45,9 @@ protected function getEntityCounts() {
'comment_type' => 2,
'contact_form' => 5,
'editor' => 2,
'field_config' => 61,
'field_storage_config' => 42,
'file' => 6,
'field_config' => 62,
'field_storage_config' => 43,
'file' => 7,
'filter_format' => 8,
'image_style' => 5,
'migration' => 105,
......
<h1>SimpleTest HTML</h1>
\ No newline at end of file
......@@ -45,9 +45,9 @@ protected function getEntityCounts() {
'comment_type' => 7,
'contact_form' => 3,
'editor' => 2,
'field_config' => 40,
'field_storage_config' => 30,
'file' => 0,
'field_config' => 41,
'field_storage_config' => 31,
'file' => 1,
'filter_format' => 7,
'image_style' => 6,
'migration' => 59,
......
********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment