Commit 91ab3cc3 authored by alexpott's avatar alexpott

Issue #2514168 by phenaproxima, mikeryan, benjy: Streamline migrate_drupal integration tests

parent 8cb41027
......@@ -8,7 +8,9 @@
namespace Drupal\migrate\Tests;
use Drupal\Core\Database\Database;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessageInterface;
use Drupal\migrate\Row;
use Drupal\simpletest\KernelTestBase;
......@@ -73,21 +75,6 @@ protected function tearDown() {
parent::tearDown();
}
/**
* Prepare the migration.
*
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration object.
* @param array $files
* An array of files.
*/
protected function prepare(MigrationInterface $migration, array $files = array()) {
$this->loadDumps($files);
if ($this instanceof MigrateDumpAlterInterface) {
static::migrateDumpAlter($this);
}
}
/**
* Load Drupal 6 database dumps to be used.
*
......@@ -96,7 +83,7 @@ protected function prepare(MigrationInterface $migration, array $files = array()
* @param string $method
* The name of the method in the dump class to use. Defaults to load.
*/
protected function loadDumps($files, $method = 'load') {
protected function loadDumps(array $files, $method = 'load') {
// Load the database from the portable PHP dump.
// The files may be gzipped.
foreach ($files as $file) {
......@@ -137,6 +124,22 @@ protected function prepareMigrations(array $id_mappings) {
}
}
/**
* Executes a single migration.
*
* @param string|\Drupal\migrate\Entity\MigrationInterface $migration
* The migration to execute, or its ID.
*/
protected function executeMigration($migration) {
if (is_string($migration)) {
$migration = Migration::load($migration);
}
if ($this instanceof MigrateDumpAlterInterface) {
static::migrateDumpAlter($this);
}
(new MigrateExecutable($migration, $this))->import();
}
/**
* {@inheritdoc}
*/
......
......@@ -28,7 +28,7 @@ abstract class MigrateDrupalTestBase extends MigrateTestBase {
*/
protected function setUp() {
parent::setUp();
$this->loadDumps([$this->getDumpDirectory() . '/System.php']);
$this->loadDumps(['System.php']);
$this->installEntitySchema('user');
$this->installConfig(['migrate_drupal', 'system']);
......@@ -44,6 +44,14 @@ protected function getDumpDirectory() {
return __DIR__ . '/Table';
}
/**
* {@inheritdoc}
*/
protected function loadDumps(array $files, $method = 'load') {
$files = array_map(function($file) { return $this->getDumpDirectory() . '/' . $file; }, $files);
parent::loadDumps($files, $method);
}
/**
* Turn all the migration templates for the specified drupal version into
* real migration entities so we can test them.
......
......@@ -8,8 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to action.settings.yml.
......@@ -32,13 +30,8 @@ class MigrateActionConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_action_settings');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_action_settings');
}
/**
......
......@@ -8,8 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to aggregator.settings.yml.
......@@ -32,13 +30,8 @@ class MigrateAggregatorConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_aggregator_settings');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_aggregator_settings');
}
/**
......
......@@ -8,8 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\aggregator\Entity\Feed;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to aggregator_feed entities.
......@@ -26,14 +24,8 @@ class MigrateAggregatorFeedTest extends MigrateDrupal6TestBase {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$migration = entity_load('migration', 'd6_aggregator_feed');
$dumps = array(
$this->getDumpDirectory() . '/AggregatorFeed.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['AggregatorFeed.php']);
$this->executeMigration('d6_aggregator_feed');
}
/**
......
......@@ -8,9 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\aggregator\Entity\Item;
use Drupal\Core\Language\LanguageInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade aggregator items.
......@@ -47,14 +44,8 @@ protected function setUp() {
));
$entity->enforceIsNew();
$entity->save();
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_aggregator_item');
$dumps = array(
$this->getDumpDirectory() . '/AggregatorItem.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['AggregatorItem.php']);
$this->executeMigration('d6_aggregator_item');
}
/**
......
......@@ -7,12 +7,7 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Language\Language;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade custom blocks.
......@@ -31,26 +26,16 @@ protected function setUp() {
$this->installConfig(array('block_content'));
$this->installEntitySchema('block_content');
$migration = entity_load('migration', 'd6_block_content_type');
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$migration = entity_load('migration', 'd6_block_content_body_field');
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->executeMigration('d6_block_content_type');
$this->executeMigration('d6_block_content_body_field');
$this->prepareMigrations(array(
'd6_filter_format' => array(
array(array(2), array('full_html'))
)
));
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_custom_block');
$dumps = array(
$this->getDumpDirectory() . '/Boxes.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Boxes.php']);
$this->executeMigration('d6_custom_block');
}
/**
......
......@@ -7,8 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\block\Entity\Block;
/**
......@@ -72,16 +70,8 @@ protected function setUp() {
// Install one of D8's test themes.
\Drupal::service('theme_handler')->install(array('test_theme'));
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_block');
$dumps = array(
$this->getDumpDirectory() . '/Blocks.php',
$this->getDumpDirectory() . '/BlocksRoles.php',
$this->getDumpDirectory() . '/AggregatorFeed.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Blocks.php', 'BlocksRoles.php', 'AggregatorFeed.php']);
$this->executeMigration('d6_block');
}
/**
......
......@@ -8,9 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to book.settings.yml.
......@@ -33,14 +30,8 @@ class MigrateBookConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_book_settings');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_book_settings');
}
/**
......
......@@ -7,8 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\node\Entity\Node;
/**
......@@ -44,15 +42,8 @@ protected function setUp() {
}
$this->prepareMigrations($id_mappings);
// Load database dumps to provide source data.
$dumps = array(
$this->getDumpDirectory() . '/Book.php',
$this->getDumpDirectory() . '/MenuLinks.php',
);
$this->loadDumps($dumps);
// Migrate books..
$migration = entity_load('migration', 'd6_book');
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Book.php', 'MenuLinks.php']);
$this->executeMigration('d6_book');
}
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Database\Database;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Entity\Node;
......
......@@ -7,11 +7,7 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Language\LanguageInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade comments.
......@@ -60,21 +56,16 @@ protected function setUp() {
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_comment');
$dumps = array(
$this->getDumpDirectory() . '/Node.php',
$this->getDumpDirectory() . '/NodeRevisions.php',
$this->getDumpDirectory() . '/ContentTypeStory.php',
$this->getDumpDirectory() . '/ContentTypeTestPlanet.php',
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
$this->getDumpDirectory() . '/Comments.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps([
'Node.php',
'NodeRevisions.php',
'ContentTypeStory.php',
'ContentTypeTestPlanet.php',
'Variable.php',
'NodeType.php',
'Comments.php',
]);
$this->executeMigration('d6_comment');
}
/**
......
......@@ -8,8 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\comment\Entity\CommentType;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment type.
......@@ -30,16 +28,8 @@ protected function setUp() {
$this->installEntitySchema('comment');
$this->installConfig(['node', 'comment']);
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_comment_type');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_type');
}
/**
......
......@@ -7,9 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Base class for Drupal 6 comment variables to Drupal 8 entity display tests.
*/
......@@ -30,13 +27,6 @@ abstract class MigrateCommentVariableDisplayBase extends MigrateDrupal6TestBase
*/
static $modules = array('comment', 'node');
/**
* The database dumps used.
*
* @var array
*/
protected $dumps;
/**
* The node types being tested.
*
......@@ -66,21 +56,14 @@ protected function setUp() {
'required' => 1,
))->save();
}
$this->dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
);
$id_mappings = array(
'd6_comment_field_instance' => array(
array(array('page'), array('node', 'comment', 'page')),
),
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', static::MIGRATION);
$this->prepare($migration, $this->dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration(static::MIGRATION);
}
......
......@@ -7,9 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment subject variable to core.entity_form_display.comment.*.default.yml
*
......@@ -43,15 +40,8 @@ protected function setUp() {
),
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_comment_entity_form_display_subject');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_entity_form_display_subject');
}
/**
......
......@@ -8,8 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment variables to field.storage.node.comment.yml.
......@@ -42,15 +40,8 @@ protected function setUp() {
),
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_comment_field');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_field');
}
/**
......
......@@ -7,9 +7,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade comment variables to field.instance.node.*.comment.yml.
*
......@@ -50,15 +47,8 @@ protected function setUp() {
'type' => 'comment',
'translatable' => '0',
))->save();
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_comment_field_instance');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/NodeType.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->loadDumps(['Variable.php', 'NodeType.php']);
$this->executeMigration('d6_comment_field_instance');
}
/**
......
......@@ -8,9 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\contact\Entity\ContactForm;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate contact categories to contact.form.*.yml.
......@@ -31,13 +28,8 @@ class MigrateContactCategoryTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_contact_category');
$dumps = array(
$this->getDumpDirectory() . '/Contact.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
$this->loadDumps(['Contact.php']);
$this->executeMigration('d6_contact_category');
}
/**
......
......@@ -8,9 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to contact.settings.yml.
......@@ -41,14 +38,8 @@ protected function setUp() {
),
);
$this->prepareMigrations($id_mappings);
$migration = entity_load('migration', 'd6_contact_settings');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
$this->getDumpDirectory() . '/Contact.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
$this->loadDumps(['Variable.php', 'Contact.php']);
$this->executeMigration('d6_contact_settings');
}
/**
......
......@@ -7,10 +7,7 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
use Drupal\Core\Database\Database;
/**
......@@ -25,14 +22,8 @@ class MigrateDateFormatTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_date_formats');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_date_formats');
}
/**
......
......@@ -8,9 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to dblog.settings.yml.
......@@ -33,13 +30,8 @@ class MigrateDblogConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$migration = entity_load('migration', 'd6_dblog_settings');
$dumps = array(
$this->getDumpDirectory() . '/Variable.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_dblog_settings');
}
/**
......
......@@ -206,49 +206,46 @@ protected function setUp() {
* {@inheritdoc}
*/
protected function getDumps() {
$tests_path = $this->getDumpDirectory();
$dumps = array(
$tests_path . '/AggregatorFeed.php',
$tests_path . '/AggregatorItem.php',
$tests_path . '/Blocks.php',
$tests_path . '/BlocksRoles.php',
$tests_path . '/Book.php',
$tests_path . '/Boxes.php',
$tests_path . '/Comments.php',
$tests_path . '/Contact.php',
$tests_path . '/ContentFieldMultivalue.php',
$tests_path . '/ContentFieldTest.php',
$tests_path . '/ContentFieldTestTwo.php',
$tests_path . '/ContentNodeField.php',
$tests_path . '/ContentNodeFieldInstance.php',
$tests_path . '/ContentTypeStory.php',
$tests_path . '/ContentTypeTestPlanet.php',
$tests_path . '/EventTimezones.php',
$tests_path . '/Files.php',
$tests_path . '/FilterFormats.php',
$tests_path . '/Filters.php',
$tests_path . '/MenuCustom.php',
$tests_path . '/MenuLinks.php',
$tests_path . '/Node.php',
$tests_path . '/NodeRevisions.php',
$tests_path . '/NodeType.php',
$tests_path . '/Permission.php',