Commit 00d4deb8 authored by webchick's avatar webchick

Issue #2568203 by phenaproxima, mikeryan: Remove migrate-db.sh in favor of core tools

parent 7940793a
......@@ -20,14 +20,6 @@
*/
abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageInterface {
/**
* The file path(s) to the dumped database(s) to load into the child site.
*
* @var array
*/
public $databaseDumpFiles = array();
/**
* TRUE to collect messages instead of displaying them.
*
......@@ -52,6 +44,13 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
*/
protected $migration;
/**
* The source database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $sourceDatabase;
public static $modules = array('migrate');
/**
......@@ -60,6 +59,7 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
protected function setUp() {
parent::setUp();
$this->createMigrationConnection();
$this->sourceDatabase = Database::getConnection('default', 'migrate');
}
/**
......@@ -119,28 +119,6 @@ private function cleanupMigrateConnection() {
}
}
/**
* Load Drupal 6 database dumps to be used.
*
* @param array $files
* An array of files.
* @param string $method
* The name of the method in the dump class to use. Defaults to 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) {
if (substr($file, -3) == '.gz') {
$file = "compress.zlib://$file";
require $file;
}
preg_match('/^namespace (.*);$/m', file_get_contents($file), $matches);
$class = $matches[1] . '\\' . basename($file, '.php');
(new $class(Database::getConnection('default', 'migrate')))->$method();
}
}
/**
* Prepare any dependent migrations.
*
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase.
*/
namespace Drupal\migrate_drupal\Tests\Dump;
use Drupal\Core\Database\Connection;
/**
* Base class for the dump classes.
*/
class DrupalDumpBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* An array of tables that have already been created.
*
* @var array
*/
protected $migrateTables;
/**
* Sample database schema and values.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* Create a new table from a Drupal table definition if it doesn't exist.
*
* @param string $name
* The name of the table to create.
* @param array $table
* A Schema API table definition array.
*/
protected function createTable($name, array $table) {
// This must be on the database connection to be shared among classes.
if (empty($this->database->migrateTables[$name])) {
$this->database->migrateTables[$name] = TRUE;
$this->database->schema()->createTable($name, $table);
}
}
}
......@@ -7,6 +7,7 @@
namespace Drupal\migrate_drupal\Tests;
use Drupal\Core\Database\Database;
use Drupal\migrate\Tests\MigrateTestBase;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
......@@ -27,21 +28,26 @@ abstract class MigrateDrupalTestBase extends MigrateTestBase {
*/
protected function setUp() {
parent::setUp();
$tables = file_scan_directory($this->getDumpDirectory(), '/.php$/', array('recurse' => FALSE));
$this->loadDumps(array_keys($tables));
$this->installEntitySchema('user');
$this->installConfig(['migrate_drupal', 'system']);
}
/**
* Returns the path to the dump directory.
* Loads a database fixture into the source database connection.
*
* @return string
* A string that represents the dump directory path.
* @param string $path
* Path to the dump file.
*/
protected function getDumpDirectory() {
return __DIR__ . '/Table';
protected function loadFixture($path) {
$default_db = Database::getConnection()->getKey();
Database::setActiveConnection($this->sourceDatabase->getKey());
if (substr($path, -3) == '.gz') {
$path = 'compress.zlib://' . $path;
}
require $path;
Database::setActiveConnection($default_db);
}
/**
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\MigrateTableDumpTest.
*/
namespace Drupal\migrate_drupal\Tests;
use Drupal\simpletest\KernelTestBase;
/**
* Validates the table dumps.
*
* @group migrate_drupal
*/
class MigrateTableDumpTest extends KernelTestBase {
protected function verifyDumpFiles($directory) {
$tables = file_scan_directory($directory, '/.php$/');
foreach ($tables as $table) {
$contents = rtrim(file_get_contents($table->uri));
$this->assertIdentical(substr($contents, -32), md5(substr($contents, 0, -33)), $table->uri);
}
}
public function testMigrateDrupal6TableDumps() {
$this->verifyDumpFiles(__DIR__ . '/Table/d6');
}
public function testMigrateDrupal7TableDumps() {
$this->verifyDumpFiles(__DIR__ . '/Table/d7');
}
}
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Table\d6\Access.
*
* THIS IS A GENERATED FILE. DO NOT EDIT.
*
* @see core/scripts/migrate-db.sh
* @see https://www.drupal.org/sandbox/benjy/2405029
*/
namespace Drupal\migrate_drupal\Tests\Table\d6;
use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase;
/**
* Generated file to represent the access table.
*/
class Access extends DrupalDumpBase {
public function load() {
$this->createTable("access", array(
'primary key' => array(
'aid',
),
'fields' => array(
'aid' => array(
'type' => 'serial',
'not null' => TRUE,
'length' => '11',
),
'mask' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),
),
'mysql_character_set' => 'utf8',
));
$this->database->insert("access")->fields(array(
'aid',
'mask',
'type',
'status',
))
->execute();
}
}
#131cb9eb08548867ec92c3373ac67a42
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Table\d6\Actions.
*
* THIS IS A GENERATED FILE. DO NOT EDIT.
*
* @see core/scripts/migrate-db.sh
* @see https://www.drupal.org/sandbox/benjy/2405029
*/
namespace Drupal\migrate_drupal\Tests\Table\d6;
use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase;
/**
* Generated file to represent the actions table.
*/
class Actions extends DrupalDumpBase {
public function load() {
$this->createTable("actions", array(
'primary key' => array(
'aid',
),
'fields' => array(
'aid' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '0',
),
'type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '32',
'default' => '',
),
'callback' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'parameters' => array(
'type' => 'text',
'not null' => TRUE,
'length' => 100,
),
'description' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '0',
),
),
'mysql_character_set' => 'utf8',
));
$this->database->insert("actions")->fields(array(
'aid',
'type',
'callback',
'parameters',
'description',
))
->values(array(
'aid' => 'comment_publish_action',
'type' => 'comment',
'callback' => 'comment_publish_action',
'parameters' => '',
'description' => 'Publish comment',
))->values(array(
'aid' => 'comment_unpublish_action',
'type' => 'comment',
'callback' => 'comment_unpublish_action',
'parameters' => '',
'description' => 'Unpublish comment',
))->values(array(
'aid' => 'node_make_sticky_action',
'type' => 'node',
'callback' => 'node_make_sticky_action',
'parameters' => '',
'description' => 'Make post sticky',
))->values(array(
'aid' => 'node_make_unsticky_action',
'type' => 'node',
'callback' => 'node_make_unsticky_action',
'parameters' => '',
'description' => 'Make post unsticky',
))->values(array(
'aid' => 'node_promote_action',
'type' => 'node',
'callback' => 'node_promote_action',
'parameters' => '',
'description' => 'Promote post to front page',
))->values(array(
'aid' => 'node_publish_action',
'type' => 'node',
'callback' => 'node_publish_action',
'parameters' => '',
'description' => 'Publish post',
))->values(array(
'aid' => 'node_save_action',
'type' => 'node',
'callback' => 'node_save_action',
'parameters' => '',
'description' => 'Save post',
))->values(array(
'aid' => 'node_unpromote_action',
'type' => 'node',
'callback' => 'node_unpromote_action',
'parameters' => '',
'description' => 'Remove post from front page',
))->values(array(
'aid' => 'node_unpublish_action',
'type' => 'node',
'callback' => 'node_unpublish_action',
'parameters' => '',
'description' => 'Unpublish post',
))->values(array(
'aid' => 'user_block_ip_action',
'type' => 'user',
'callback' => 'user_block_ip_action',
'parameters' => '',
'description' => 'Ban IP address of current user',
))->values(array(
'aid' => 'user_block_user_action',
'type' => 'user',
'callback' => 'user_block_user_action',
'parameters' => '',
'description' => 'Block current user',
))->execute();
}
}
#31f375c70c6a362432e25e1256101076
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Table\d6\ActionsAid.
*
* THIS IS A GENERATED FILE. DO NOT EDIT.
*
* @see core/scripts/migrate-db.sh
* @see https://www.drupal.org/sandbox/benjy/2405029
*/
namespace Drupal\migrate_drupal\Tests\Table\d6;
use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase;
/**
* Generated file to represent the actions_aid table.
*/
class ActionsAid extends DrupalDumpBase {
public function load() {
$this->createTable("actions_aid", array(
'primary key' => array(
'aid',
),
'fields' => array(
'aid' => array(
'type' => 'serial',
'not null' => TRUE,
'length' => '10',
'unsigned' => TRUE,
),
),
'mysql_character_set' => 'utf8',
));
$this->database->insert("actions_aid")->fields(array(
'aid',
))
->execute();
}
}
#a58e383f81c657ac36eabc980e148fbd
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Table\d6\AggregatorCategory.
*
* THIS IS A GENERATED FILE. DO NOT EDIT.
*
* @see core/scripts/migrate-db.sh
* @see https://www.drupal.org/sandbox/benjy/2405029
*/
namespace Drupal\migrate_drupal\Tests\Table\d6;
use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase;
/**
* Generated file to represent the aggregator_category table.
*/
class AggregatorCategory extends DrupalDumpBase {
public function load() {
$this->createTable("aggregator_category", array(
'primary key' => array(
'cid',
),
'fields' => array(
'cid' => array(
'type' => 'serial',
'not null' => TRUE,
'length' => '11',
),
'title' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'description' => array(
'type' => 'text',
'not null' => TRUE,
'length' => 100,
),
'block' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),
),
'mysql_character_set' => 'utf8',
));
$this->database->insert("aggregator_category")->fields(array(
'cid',
'title',
'description',
'block',
))
->execute();
}
}
#836a3ecaf192c09b996431f0c4b71fe6
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\Table\d6\AggregatorFeed.
*
* THIS IS A GENERATED FILE. DO NOT EDIT.
*
* @see core/scripts/migrate-db.sh
* @see https://www.drupal.org/sandbox/benjy/2405029
*/
namespace Drupal\migrate_drupal\Tests\Table\d6;
use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase;
/**
* Generated file to represent the aggregator_feed table.
*/
class AggregatorFeed extends DrupalDumpBase {
public function load() {
$this->createTable("aggregator_feed", array(
'primary key' => array(
'fid',
),
'fields' => array(
'fid' => array(
'type' => 'serial',
'not null' => TRUE,
'length' => '11',
),
'title' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'url' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'refresh' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),
'checked' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),
'link' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'description' => array(
'type' => 'text',
'not null' => TRUE,
'length' => 100,
),
'image' => array(
'type' => 'text',
'not null' => TRUE,
'length' => 100,
),
'etag' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
),
'modified' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),
'block' => array(
'type' => 'int',
'not null' => TRUE,
'length' => '11',
'default' => '0',
),