Skip to content
Snippets Groups Projects
Commit 49b4f933 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2264717 by penyaskito: Convert MigrateDrupal6Test into a reusable...

Issue #2264717 by penyaskito: Convert MigrateDrupal6Test into a reusable abstract class which can be reused for D7 and other migrations .
parent c040367f
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\MigrateFullDrupalTestBase.
*/
namespace Drupal\migrate_drupal\Tests;
use Drupal\migrate\MigrateExecutable;
use Drupal\simpletest\TestBase;
/**
* Test helper for running a complete Drupal migration.
*/
abstract class MigrateFullDrupalTestBase extends MigrateDrupalTestBase {
/**
* Get the dump classes required for this migration test.
*
* @return array
* The list of files containing dumps.
*/
protected abstract function getDumps();
/**
* Get the test classes that needs to be run for this test.
*
* @return array
* The list of test fully-classified class names.
*/
protected abstract function getTestClassesList();
/**
* {@inheritdoc}
*/
public function tearDown() {
// Move the results of every class under ours. This is solely for
// reporting, the filename will guide developers.
self::getDatabaseConnection()
->update('simpletest')
->fields(array('test_class' => get_class($this)))
->condition('test_id', $this->testId)
->execute();
parent::tearDown();
}
/**
* Test the complete Drupal migration.
*/
public function testDrupal() {
$dumps = $this->getDumps();
$this->loadDumps($dumps);
$classes = $this->getTestClassesList();
// Run every migration in the order specified by the storage controller.
foreach (entity_load_multiple('migration', static::$migrations) as $migration) {
(new MigrateExecutable($migration, $this))->import();
}
foreach ($classes as $class) {
$test_object = new $class($this->testId);
$test_object->databasePrefix = $this->databasePrefix;
$test_object->container = $this->container;
// run() does a lot of setup and tear down work which we don't need:
// it would setup a new database connection and wouldn't find the
// Drupal dump. Also by skipping the setUp() methods there are no id
// mappings or entities prepared. The tests run against solely migrated
// data.
foreach (get_class_methods($test_object) as $method) {
if (strtolower(substr($method, 0, 4)) == 'test') {
// Insert a fail record. This will be deleted on completion to ensure
// that testing completed.
$method_info = new \ReflectionMethod($class, $method);
$caller = array(
'file' => $method_info->getFileName(),
'line' => $method_info->getStartLine(),
'function' => $class . '->' . $method . '()',
);
$completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller);
// Run the test method.
try {
$test_object->$method();
}
catch (\Exception $e) {
$this->exceptionHandler($e);
}
// Remove the completion check record.
TestBase::deleteAssert($completion_check_id);
}
}
// Add the pass/fail/exception/debug results.
foreach ($this->results as $key => &$value) {
$value += $test_object->results[$key];
}
}
}
}
......@@ -7,14 +7,12 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
use Drupal\simpletest\TestBase;
use Drupal\migrate_drupal\Tests\MigrateFullDrupalTestBase;
/**
* Test the complete Drupal 6 migration.
*/
class MigrateDrupal6Test extends MigrateDrupalTestBase {
class MigrateDrupal6Test extends MigrateFullDrupalTestBase {
/**
* Modules to enable.
......@@ -50,98 +48,11 @@ class MigrateDrupal6Test extends MigrateDrupalTestBase {
);
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Migrate Drupal 6',
'description' => 'Test every Drupal 6 migration',
'group' => 'Migrate Drupal',
);
}
/**
* {@inheritdoc}
*/
public function tearDown() {
// Move the results of every class under ours. This is solely for
// reporting, the filename will guide developers.
self::getDatabaseConnection()
->update('simpletest')
->fields(array('test_class' => get_class($this)))
->condition('test_id', $this->testId)
->execute();
parent::tearDown();
}
/**
* Test the complete Drupal 6 migration.
* Migrations to run in the test.
*
* @var array
*/
public function testDrupal6() {
$tests_path = $this->getDumpDirectory();
$dumps = array(
$tests_path . '/Drupal6ActionSettings.php',
$tests_path . '/Drupal6AggregatorFeed.php',
$tests_path . '/Drupal6AggregatorItem.php',
$tests_path . '/Drupal6AggregatorSettings.php',
$tests_path . '/Drupal6Block.php',
$tests_path . '/Drupal6BookSettings.php',
$tests_path . '/Drupal6Box.php',
$tests_path . '/Drupal6Comment.php',
$tests_path . '/Drupal6CommentVariable.php',
$tests_path . '/Drupal6ContactCategory.php',
$tests_path . '/Drupal6ContactSettings.php',
$tests_path . '/Drupal6DateFormat.php',
$tests_path . '/Drupal6DblogSettings.php',
$tests_path . '/Drupal6FieldInstance.php',
$tests_path . '/Drupal6FieldSettings.php',
$tests_path . '/Drupal6File.php',
$tests_path . '/Drupal6FileSettings.php',
$tests_path . '/Drupal6FilterFormat.php',
$tests_path . '/Drupal6ForumSettings.php',
$tests_path . '/Drupal6LocaleSettings.php',
$tests_path . '/Drupal6Menu.php',
$tests_path . '/Drupal6MenuSettings.php',
$tests_path . '/Drupal6NodeBodyInstance.php',
$tests_path . '/Drupal6Node.php',
$tests_path . '/Drupal6NodeRevision.php',
$tests_path . '/Drupal6NodeSettings.php',
$tests_path . '/Drupal6NodeType.php',
$tests_path . '/Drupal6SearchPage.php',
$tests_path . '/Drupal6SearchSettings.php',
$tests_path . '/Drupal6SimpletestSettings.php',
$tests_path . '/Drupal6StatisticsSettings.php',
$tests_path . '/Drupal6SyslogSettings.php',
$tests_path . '/Drupal6SystemCron.php',
// This dump contains the file directory path to the simpletest directory
// where the files are.
$tests_path . '/Drupal6SystemFile.php',
$tests_path . '/Drupal6SystemFilter.php',
$tests_path . '/Drupal6SystemImageGd.php',
$tests_path . '/Drupal6SystemImage.php',
$tests_path . '/Drupal6SystemMaintenance.php',
$tests_path . '/Drupal6SystemPerformance.php',
$tests_path . '/Drupal6SystemRss.php',
$tests_path . '/Drupal6SystemSite.php',
$tests_path . '/Drupal6SystemTheme.php',
$tests_path . '/Drupal6TaxonomySettings.php',
$tests_path . '/Drupal6TaxonomyTerm.php',
$tests_path . '/Drupal6TaxonomyVocabulary.php',
$tests_path . '/Drupal6TermNode.php',
$tests_path . '/Drupal6TextSettings.php',
$tests_path . '/Drupal6UpdateSettings.php',
$tests_path . '/Drupal6UploadInstance.php',
$tests_path . '/Drupal6Upload.php',
$tests_path . '/Drupal6UrlAlias.php',
$tests_path . '/Drupal6UserMail.php',
$tests_path . '/Drupal6User.php',
$tests_path . '/Drupal6UserProfileFields.php',
$tests_path . '/Drupal6UserRole.php',
$tests_path . '/Drupal6VocabularyField.php',
);
$this->loadDumps($dumps);
$migrations = array(
static $migrations = array(
'd6_action_settings',
'd6_aggregator_settings',
'd6_aggregator_feed',
......@@ -223,6 +134,91 @@ public function testDrupal6() {
'd6_vocabulary_field_instance',
'd6_vocabulary_field',
);
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Migrate Drupal 6',
'description' => 'Test every Drupal 6 migration',
'group' => 'Migrate Drupal',
);
}
/**
* {@inheritdoc}
*/
protected function getDumps() {
$tests_path = $this->getDumpDirectory();
$dumps = array(
$tests_path . '/Drupal6ActionSettings.php',
$tests_path . '/Drupal6AggregatorFeed.php',
$tests_path . '/Drupal6AggregatorItem.php',
$tests_path . '/Drupal6AggregatorSettings.php',
$tests_path . '/Drupal6Block.php',
$tests_path . '/Drupal6BookSettings.php',
$tests_path . '/Drupal6Box.php',
$tests_path . '/Drupal6Comment.php',
$tests_path . '/Drupal6CommentVariable.php',
$tests_path . '/Drupal6ContactCategory.php',
$tests_path . '/Drupal6ContactSettings.php',
$tests_path . '/Drupal6DateFormat.php',
$tests_path . '/Drupal6DblogSettings.php',
$tests_path . '/Drupal6FieldInstance.php',
$tests_path . '/Drupal6FieldSettings.php',
$tests_path . '/Drupal6File.php',
$tests_path . '/Drupal6FileSettings.php',
$tests_path . '/Drupal6FilterFormat.php',
$tests_path . '/Drupal6ForumSettings.php',
$tests_path . '/Drupal6LocaleSettings.php',
$tests_path . '/Drupal6Menu.php',
$tests_path . '/Drupal6MenuSettings.php',
$tests_path . '/Drupal6NodeBodyInstance.php',
$tests_path . '/Drupal6Node.php',
$tests_path . '/Drupal6NodeRevision.php',
$tests_path . '/Drupal6NodeSettings.php',
$tests_path . '/Drupal6NodeType.php',
$tests_path . '/Drupal6SearchPage.php',
$tests_path . '/Drupal6SearchSettings.php',
$tests_path . '/Drupal6SimpletestSettings.php',
$tests_path . '/Drupal6StatisticsSettings.php',
$tests_path . '/Drupal6SyslogSettings.php',
$tests_path . '/Drupal6SystemCron.php',
// This dump contains the file directory path to the simpletest directory
// where the files are.
$tests_path . '/Drupal6SystemFile.php',
$tests_path . '/Drupal6SystemFilter.php',
$tests_path . '/Drupal6SystemImageGd.php',
$tests_path . '/Drupal6SystemImage.php',
$tests_path . '/Drupal6SystemMaintenance.php',
$tests_path . '/Drupal6SystemPerformance.php',
$tests_path . '/Drupal6SystemRss.php',
$tests_path . '/Drupal6SystemSite.php',
$tests_path . '/Drupal6SystemTheme.php',
$tests_path . '/Drupal6TaxonomySettings.php',
$tests_path . '/Drupal6TaxonomyTerm.php',
$tests_path . '/Drupal6TaxonomyVocabulary.php',
$tests_path . '/Drupal6TermNode.php',
$tests_path . '/Drupal6TextSettings.php',
$tests_path . '/Drupal6UpdateSettings.php',
$tests_path . '/Drupal6UploadInstance.php',
$tests_path . '/Drupal6Upload.php',
$tests_path . '/Drupal6UrlAlias.php',
$tests_path . '/Drupal6UserMail.php',
$tests_path . '/Drupal6User.php',
$tests_path . '/Drupal6UserProfileFields.php',
$tests_path . '/Drupal6UserRole.php',
$tests_path . '/Drupal6VocabularyField.php',
);
return $dumps;
}
/**
* {@inheritdoc}
*/
protected function getTestClassesList() {
$classes = array(
__NAMESPACE__ . '\MigrateActionConfigsTest',
__NAMESPACE__ . '\MigrateAggregatorConfigsTest',
......@@ -305,46 +301,8 @@ public function testDrupal6() {
__NAMESPACE__ . '\MigrateVocabularyFieldInstanceTest',
__NAMESPACE__ . '\MigrateVocabularyFieldTest',
);
// Run every migration in the order specified by the storage controller.
foreach (entity_load_multiple('migration', $migrations) as $migration) {
(new MigrateExecutable($migration, $this))->import();
}
foreach ($classes as $class) {
$test_object = new $class($this->testId);
$test_object->databasePrefix = $this->databasePrefix;
$test_object->container = $this->container;
// run() does a lot of setup and tear down work which we don't need:
// it would setup a new database connection and wouldn't find the
// Drupal 6 dump. Also by skipping the setUp() methods there are no id
// mappings or entities prepared. The tests run against solely migrated
// data.
foreach (get_class_methods($test_object) as $method) {
if (strtolower(substr($method, 0, 4)) == 'test') {
// Insert a fail record. This will be deleted on completion to ensure
// that testing completed.
$method_info = new \ReflectionMethod($class, $method);
$caller = array(
'file' => $method_info->getFileName(),
'line' => $method_info->getStartLine(),
'function' => $class . '->' . $method . '()',
);
$completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller);
// Run the test method.
try {
$test_object->$method();
}
catch (\Exception $e) {
$this->exceptionHandler($e);
}
// Remove the completion check record.
TestBase::deleteAssert($completion_check_id);
}
}
// Add the pass/fail/exception/debug results.
foreach ($this->results as $key => &$value) {
$value += $test_object->results[$key];
}
}
return $classes;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment