Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
web/core/modules/migrate_drupal/tests
fixtures
modules
migrate_cckfield_plugin_manager_test
migrate_cckfield_plugin_manager_test.info.yml
src/Plugin/migrate/cckfield
migrate_overwrite_test
src
Kernel
MigrateCckFieldPluginManagerTest.phpMigrateDrupalTestBase.php
Plugin/migrate/source/d8
d6
d7
dependencies
Unit/source
46345
web/core/modules/migrate_drupal/tests/fixtures/drupal6.php
vendored
Normal file
46345
web/core/modules/migrate_drupal/tests/fixtures/drupal6.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
44437
web/core/modules/migrate_drupal/tests/fixtures/drupal7.php
vendored
Normal file
44437
web/core/modules/migrate_drupal/tests/fixtures/drupal7.php
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate cck field plugin manager test'
|
||||
type: module
|
||||
description: 'Example module demonstrating the cck field plugin manager in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_file",
|
||||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_no_core_version_specified"
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate property overwrite test'
|
||||
type: module
|
||||
description: 'Example module demonstrating property overwrite support in the Migrate API.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,31 @@
|
|||
id: users
|
||||
label: User migration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: d6_user
|
||||
process:
|
||||
# If the entity's ID is migrated, the Migrate API will try to update
|
||||
# an existing entity with that ID. If no entity with that ID already
|
||||
# exists, it will be created.
|
||||
uid: uid
|
||||
name: name
|
||||
mail: mail
|
||||
password: password
|
||||
'signature/value':
|
||||
plugin: default_value
|
||||
default_value: 'The answer is 42.'
|
||||
destination:
|
||||
plugin: entity:user
|
||||
# If the destination is going to update an existing user, you can optionally
|
||||
# specify the properties that should be overwritten. For example, if the
|
||||
# migration tries to import user 31 and user 31 already exists in the
|
||||
# destination database, only the 'name' and 'mail' properties of the user
|
||||
# will be overwritten. If user 31 doesn't exist, it will be created and
|
||||
# the overwrite_properties list will be ignored.
|
||||
overwrite_properties:
|
||||
- name
|
||||
- mail
|
||||
# It's possible to overwrite nested properties too.
|
||||
- 'signature/value'
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
|
||||
/**
|
||||
* Tests the cck field plugin manager.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_cckfield_plugin_manager_test');
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateCckField plugins are used.
|
||||
*/
|
||||
public function testPluginSelection() {
|
||||
$plugin_manager = \Drupal::service('plugin.manager.migrate.cckfield');
|
||||
|
||||
$plugin_id = $plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 6]);
|
||||
$this->assertIdentical('Drupal\\file\\Plugin\\migrate\\cckfield\\d6\\FileField', get_class($plugin_manager->createInstance($plugin_id, ['core' => 6])));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
|
||||
}
|
||||
|
||||
$this->assertIdentical('image', $plugin_manager->getPluginIdFromFieldType('image', ['core' => 7]));
|
||||
$this->assertIdentical('file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 7]));
|
||||
$this->assertIdentical('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
|
||||
|
||||
$this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
|
||||
$this->assertIdentical('text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 7]));
|
||||
|
||||
// Test fallback when no core version is specified.
|
||||
$this->assertIdentical('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupalTestBase extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('system', 'user', 'field', 'migrate_drupal', 'options', 'file');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installConfig(['migrate_drupal', 'system']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a database fixture into the source database connection.
|
||||
*
|
||||
* @param string $path
|
||||
* Path to the dump file.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the config source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d8\Config
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class ConfigTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$data = [];
|
||||
|
||||
// The source database tables.
|
||||
$data[0]['source_data'] = [
|
||||
'config' => [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:14:"af - Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => '',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:9:"Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => 'language.de',
|
||||
'name' => 'user.settings',
|
||||
'data' => 'a:1:{s:9:"anonymous";s:14:"de - Anonymous";}',
|
||||
],
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => 'b:0;',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$data[0]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'user.settings',
|
||||
'data' => [
|
||||
'anonymous' => 'af - Anonymous',
|
||||
],
|
||||
],
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => FALSE,
|
||||
],
|
||||
];
|
||||
$data[0]['expected_count'] = NULL;
|
||||
$data[0]['configuration'] = [
|
||||
'names' => [
|
||||
'user.settings',
|
||||
'bar',
|
||||
],
|
||||
'collections' => [
|
||||
'language.af',
|
||||
]
|
||||
];
|
||||
|
||||
// Test with name and no collection in configuration.
|
||||
$data[1]['source_data'] = $data[0]['source_data'];
|
||||
$data[1]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.af',
|
||||
'name' => 'bar',
|
||||
'data' => FALSE,
|
||||
],
|
||||
];
|
||||
$data[1]['expected_count'] = NULL;
|
||||
$data[1]['configuration'] = [
|
||||
'names' => [
|
||||
'bar',
|
||||
],
|
||||
];
|
||||
|
||||
// Test with collection and no name in configuration.
|
||||
$data[2]['source_data'] = $data[0]['source_data'];
|
||||
$data[2]['expected_results'] = [
|
||||
[
|
||||
'collection' => 'language.de',
|
||||
'name' => 'user.settings',
|
||||
'data' => [
|
||||
'anonymous' => 'de - Anonymous',
|
||||
],
|
||||
],
|
||||
];
|
||||
$data[2]['expected_count'] = NULL;
|
||||
$data[2]['configuration'] = [
|
||||
'collections' => [
|
||||
'language.de',
|
||||
],
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessageInterface;
|
||||
use Drupal\user\Entity\User;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class EntityContentBaseTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_overwrite_test'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a field on the user entity so that we can test nested property
|
||||
// overwrites.
|
||||
// @see static::testOverwriteSelectedNestedProperty()
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'signature',
|
||||
'entity_type' => 'user',
|
||||
'type' => 'text_long',
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => 'signature',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
])->save();
|
||||
|
||||
User::create([
|
||||
'uid' => 2,
|
||||
'name' => 'Ford Prefect',
|
||||
'mail' => 'ford.prefect@localhost',
|
||||
'signature' => array(
|
||||
array(
|
||||
'value' => 'Bring a towel.',
|
||||
'format' => 'filtered_html',
|
||||
),
|
||||
),
|
||||
'init' => 'proto@zo.an',
|
||||
])->save();
|
||||
|
||||
$this->executeMigrations(['d6_filter_format', 'd6_user_role']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests overwriting all mapped properties in the destination entity (default
|
||||
* behavior).
|
||||
*/
|
||||
public function testOverwriteAllMappedProperties() {
|
||||
$this->executeMigration('d6_user');
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = User::load(2);
|
||||
$this->assertIdentical('john.doe', $account->label());
|
||||
$this->assertIdentical('john.doe@example.com', $account->getEmail());
|
||||
$this->assertIdentical('doe@example.com', $account->getInitialEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests overwriting selected properties in the destination entity, specified
|
||||
* in the destination configuration.
|
||||
*/
|
||||
public function testOverwriteProperties() {
|
||||
// Execute the migration in migrate_overwrite_test, which documents how
|
||||
// property overwrites work.
|
||||
$this->executeMigration('users');
|
||||
|
||||
/** @var \Drupal\user\UserInterface $account */
|
||||
$account = User::load(2);
|
||||
$this->assertIdentical('john.doe', $account->label());
|
||||
$this->assertIdentical('john.doe@example.com', $account->getEmail());
|
||||
$this->assertIdentical('The answer is 42.', $account->signature->value);
|
||||
// This value is not overwritten because it's not listed in
|
||||
// overwrite_properties.
|
||||
$this->assertIdentical('proto@zo.an', $account->getInitialEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that translation destination fails for untranslatable entities.
|
||||
*/
|
||||
public function testUntranslatable() {
|
||||
$this->enableModules(['language_test']);
|
||||
$this->installEntitySchema('no_language_entity_test');
|
||||
|
||||
/** @var MigrationInterface $migration */
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration([
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'ids' => ['id' => ['type' => 'integer']],
|
||||
'data_rows' => [['id' => 1]],
|
||||
],
|
||||
'process' => [
|
||||
'id' => 'id',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:no_language_entity_test',
|
||||
'translations' => TRUE,
|
||||
],
|
||||
]);
|
||||
|
||||
$message = $this->prophesize(MigrateMessageInterface::class);
|
||||
// Match the expected message. Can't use default argument types, because
|
||||
// we need to convert to string from TranslatableMarkup.
|
||||
$argument = Argument::that(function($msg) {
|
||||
return strpos((string) $msg, "This entity type does not support translation") !== FALSE;
|
||||
});
|
||||
$message->display($argument, Argument::any())
|
||||
->shouldBeCalled();
|
||||
|
||||
$executable = new MigrateExecutable($migration, $message->reveal());
|
||||
$executable->import();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal 6 migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupal6TestBase extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'datetime',
|
||||
'filter',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'options',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal6.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all user migrations.
|
||||
*
|
||||
* @param bool $include_pictures
|
||||
* If TRUE, migrates user pictures.
|
||||
*/
|
||||
protected function migrateUsers($include_pictures = TRUE) {
|
||||
$this->executeMigrations(['d6_filter_format', 'd6_user_role']);
|
||||
|
||||
if ($include_pictures) {
|
||||
$this->installEntitySchema('file');
|
||||
$this->executeMigrations([
|
||||
'd6_file',
|
||||
'd6_user_picture_file',
|
||||
'user_picture_field',
|
||||
'user_picture_field_instance',
|
||||
'user_picture_entity_display',
|
||||
'user_picture_entity_form_display',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->executeMigration('d6_user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates node types.
|
||||
*/
|
||||
protected function migrateContentTypes() {
|
||||
$this->installConfig(['node']);
|
||||
$this->executeMigration('d6_node_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all field migrations.
|
||||
*/
|
||||
protected function migrateFields() {
|
||||
$this->migrateContentTypes();
|
||||
$this->executeMigrations([
|
||||
'd6_field',
|
||||
'd6_field_instance',
|
||||
'd6_field_instance_widget_settings',
|
||||
'd6_view_modes',
|
||||
'd6_field_formatter_settings',
|
||||
'd6_upload_field',
|
||||
'd6_upload_field_instance',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all content migrations.
|
||||
*
|
||||
* @param array $include
|
||||
* Extra things to include as part of the migrations. Values may be
|
||||
* 'revisions' or 'translations'.
|
||||
*/
|
||||
protected function migrateContent($include = []) {
|
||||
if (in_array('translations', $include)) {
|
||||
$this->executeMigrations(['language']);
|
||||
}
|
||||
$this->migrateUsers(FALSE);
|
||||
$this->migrateFields();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->executeMigrations(['d6_node_settings', 'd6_node']);
|
||||
|
||||
if (in_array('translations', $include)) {
|
||||
$this->executeMigrations(['translations']);
|
||||
}
|
||||
if (in_array('revisions', $include)) {
|
||||
$this->executeMigrations(['d6_node_revision']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all taxonomy migrations.
|
||||
*/
|
||||
protected function migrateTaxonomy() {
|
||||
$this->migrateContentTypes();
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->executeMigrations([
|
||||
'd6_taxonomy_vocabulary',
|
||||
'd6_vocabulary_field',
|
||||
'd6_vocabulary_field_instance',
|
||||
'd6_vocabulary_entity_display',
|
||||
'd6_vocabulary_entity_form_display',
|
||||
'd6_taxonomy_term',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Base class for Drupal 7 migration tests.
|
||||
*/
|
||||
abstract class MigrateDrupal7TestBase extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadFixture($this->getFixtureFilePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fixture file.
|
||||
*/
|
||||
protected function getFixtureFilePath() {
|
||||
return __DIR__ . '/../../../fixtures/drupal7.php';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\dependencies;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Ensure the consistency among the dependencies for migrate.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDependenciesTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['aggregator', 'comment'];
|
||||
|
||||
/**
|
||||
* Tests that the order is correct when loading several migrations.
|
||||
*/
|
||||
public function testMigrateDependenciesOrder() {
|
||||
$migration_items = array('d6_comment', 'd6_filter_format', 'd6_node:page');
|
||||
$migrations = $this->container->get('plugin.manager.migration')->createInstances($migration_items);
|
||||
$expected_order = array('d6_filter_format', 'd6_node:page', 'd6_comment');
|
||||
$this->assertIdentical(array_keys($migrations), $expected_order);
|
||||
$expected_requirements = array(
|
||||
// d6_comment depends on d6_node:*, which the deriver expands into every
|
||||
// variant of d6_node.
|
||||
'd6_node:article',
|
||||
'd6_node:company',
|
||||
'd6_node:employee',
|
||||
'd6_node:event',
|
||||
'd6_node:page',
|
||||
'd6_node:sponsor',
|
||||
'd6_node:story',
|
||||
'd6_node:test_event',
|
||||
'd6_node:test_page',
|
||||
'd6_node:test_planet',
|
||||
'd6_node:test_story',
|
||||
'd6_node_type',
|
||||
'd6_node_settings',
|
||||
'd6_filter_format',
|
||||
'd6_user',
|
||||
'd6_comment_type',
|
||||
'd6_comment_entity_display',
|
||||
'd6_comment_entity_form_display',
|
||||
);
|
||||
// Migration dependencies for comment include dependencies for node
|
||||
// migration as well.
|
||||
$actual_requirements = $migrations['d6_comment']->get('requirements');
|
||||
$this->assertIdentical(count($actual_requirements), count($expected_requirements));
|
||||
foreach ($expected_requirements as $requirement) {
|
||||
$this->assertIdentical($actual_requirements[$requirement], $requirement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests dependencies on the migration of aggregator feeds & items.
|
||||
*/
|
||||
public function testAggregatorMigrateDependencies() {
|
||||
/** @var \Drupal\migrate\Plugin\Migration $migration */
|
||||
$migration = $this->getMigration('d6_aggregator_item');
|
||||
$executable = new MigrateExecutable($migration, $this);
|
||||
$this->startCollectingMessages();
|
||||
$executable->import();
|
||||
$this->assertEqual($this->migrateMessages['error'], array(SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', array('@id' => $migration->id()))));
|
||||
$this->collectMessages = FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class DrupalSqlBaseTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'DrupalSqlBase',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* Minimum database contents needed to test DrupalSqlBase.
|
||||
*/
|
||||
protected $databaseContents = array(
|
||||
'system' => array(
|
||||
array(
|
||||
'filename' => 'sites/all/modules/module1',
|
||||
'name' => 'module1',
|
||||
'type' => 'module',
|
||||
'status' => 0,
|
||||
'schema_version' => -1,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @covers ::checkRequirements
|
||||
*/
|
||||
public function testSourceProviderNotActive() {
|
||||
$plugin_definition['requirements_met'] = TRUE;
|
||||
$plugin_definition['source_provider'] = 'module1';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$plugin = new TestDrupalSqlBase([], 'placeholder_id', $plugin_definition, $this->getMigration(), $state, $entity_manager);
|
||||
$plugin->setDatabase($this->getDatabase($this->databaseContents));
|
||||
$system_data = $plugin->getSystemData();
|
||||
$this->setExpectedException(RequirementsException::class, 'The module module1 is not enabled in the source site.');
|
||||
try {
|
||||
$plugin->checkRequirements();
|
||||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Ensure requirements are set on the exception.
|
||||
$this->assertEquals(['source_provider' => 'module1'], $e->getRequirements());
|
||||
// Re-throw so PHPUnit can assert the exception.
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Extends the DrupalSqlBase abstract class.
|
||||
*/
|
||||
class TestDrupalSqlBase extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks DrupalSqlBase to set a new database connection for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $database
|
||||
* The new connection to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSourceSqlTestCase
|
||||
*/
|
||||
public function setDatabase(Connection $database) {
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
/**
|
||||
* Tests variable multirow source w/ high water handling.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableMultiRowSourceWithHighwaterTest extends VariableMultiRowTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->migrationConfiguration['highWaterProperty']['field'] = 'test';
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
/**
|
||||
* Tests D6 variable multirow source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableMultiRowTest extends VariableMultiRowTestBase {
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Base class for variable multirow source unit tests.
|
||||
*/
|
||||
abstract class VariableMultiRowTestBase extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow';
|
||||
|
||||
// The fake Migration configuration entity.
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_variable_multirow',
|
||||
'variables' => array(
|
||||
'foo',
|
||||
'bar',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array('name' => 'foo', 'value' => 1),
|
||||
array('name' => 'bar', 'value' => FALSE),
|
||||
);
|
||||
|
||||
protected $databaseContents = array(
|
||||
'variable' => array(
|
||||
array('name' => 'foo', 'value' => 'i:1;'),
|
||||
array('name' => 'bar', 'value' => 'b:0;'),
|
||||
),
|
||||
);
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\Variable';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => array('field' => 'test'),
|
||||
'source' => array(
|
||||
'plugin' => 'd6_variable',
|
||||
'variables' => array(
|
||||
'foo',
|
||||
'bar',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
'foo' => 1,
|
||||
'bar' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
protected $databaseContents = array(
|
||||
'variable' => array(
|
||||
array('name' => 'foo', 'value' => 'i:1;'),
|
||||
array('name' => 'bar', 'value' => 'b:0;'),
|
||||
),
|
||||
);
|
||||
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate_drupal\Unit\source\d6\Drupal6SqlBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
/**
|
||||
* Tests the D6 SQL base class.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class Drupal6SqlBaseTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'Drupal6SqlBase',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* Minimum database contents needed to test Drupal6SqlBase.
|
||||
*/
|
||||
protected $databaseContents = array(
|
||||
'system' => array(
|
||||
array(
|
||||
'filename' => 'sites/all/modules/module1',
|
||||
'name' => 'module1',
|
||||
'type' => 'module',
|
||||
'status' => 1,
|
||||
'schema_version' => -1,
|
||||
),
|
||||
array(
|
||||
'filename' => 'sites/all/modules/module2',
|
||||
'name' => 'module2',
|
||||
'type' => 'module',
|
||||
'status' => 0,
|
||||
'schema_version' => 7201,
|
||||
),
|
||||
array(
|
||||
'filename' => 'sites/all/modules/test2',
|
||||
'name' => 'test2',
|
||||
'type' => 'theme',
|
||||
'status' => 1,
|
||||
'schema_version' => -1,
|
||||
),
|
||||
),
|
||||
'variable' => array(
|
||||
array(
|
||||
'name' => 'my_variable',
|
||||
'value' => 'b:1;',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$plugin = 'placeholder_id';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->base = new TestDrupal6SqlBase($this->migrationConfiguration, $plugin, array(), $this->getMigration(), $state, $entity_manager);
|
||||
$this->base->setDatabase($this->getDatabase($this->databaseContents));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::getSystemData().
|
||||
*/
|
||||
public function testGetSystemData() {
|
||||
$system_data = $this->base->getSystemData();
|
||||
// Should be 1 theme and 2 modules.
|
||||
$this->assertEquals(1, count($system_data['theme']));
|
||||
$this->assertEquals(2, count($system_data['module']));
|
||||
|
||||
// Calling again should be identical.
|
||||
$this->assertSame($system_data, $this->base->getSystemData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::moduleExists().
|
||||
*/
|
||||
public function testDrupal6ModuleExists() {
|
||||
// This module should exist.
|
||||
$this->assertTrue($this->base->moduleExistsWrapper('module1'));
|
||||
|
||||
// These modules should not exist.
|
||||
$this->assertFalse($this->base->moduleExistsWrapper('module2'));
|
||||
$this->assertFalse($this->base->moduleExistsWrapper('module3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::getModuleSchemaVersion().
|
||||
*/
|
||||
public function testGetModuleSchemaVersion() {
|
||||
// Non-existent module.
|
||||
$this->assertFalse($this->base->getModuleSchemaVersionWrapper('module3'));
|
||||
|
||||
// Disabled module should still return schema version.
|
||||
$this->assertEquals(7201, $this->base->getModuleSchemaVersionWrapper('module2'));
|
||||
|
||||
// Enabled module.
|
||||
$this->assertEquals(-1, $this->base->getModuleSchemaVersionWrapper('module1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for Drupal6SqlBase::variableGet().
|
||||
*/
|
||||
public function testVariableGet() {
|
||||
// Test default value.
|
||||
$this->assertEquals('my_default', $this->base->variableGetWrapper('non_existent_variable', 'my_default'));
|
||||
|
||||
// Test non-default.
|
||||
$this->assertSame(TRUE, $this->base->variableGetWrapper('my_variable', FALSE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Extends the Drupal6SqlBase abstract class.
|
||||
*/
|
||||
class TestDrupal6SqlBase extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'filename' => t('The path of the primary file for this item.'),
|
||||
'name' => t('The name of the item; e.g. node.'),
|
||||
'type' => t('The type of the item, either module, theme, or theme_engine.'),
|
||||
'owner' => t("A theme's 'parent'. Can be either a theme or an engine."),
|
||||
'status' => t('Boolean indicating whether or not this item is enabled.'),
|
||||
'throttle' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'),
|
||||
'bootstrap' => t('Boolean indicating whether this module is loaded during Drupal\'s early bootstrapping phase (e.g. even before the page cache is consulted).'),
|
||||
'schema_version' => t('The module\'s database schema version number.'),
|
||||
'weight' => t('The order in which this module\'s hooks should be invoked.'),
|
||||
'info' => t('A serialized array containing information from the module\'s .info file.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->database
|
||||
->select('system', 's')
|
||||
->fields('s', array('filename', 'name', 'schema_version'));
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks Drupal6SqlBase to set a new database connection for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Connection $database
|
||||
* The new connection to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
|
||||
*/
|
||||
public function setDatabase(Connection $database) {
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaks Drupal6SqlBase to set a new module handler for tests.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The new module handler to use.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\MigrateSqlTestCase
|
||||
*/
|
||||
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method moduleExists().
|
||||
*/
|
||||
public function moduleExistsWrapper($module) {
|
||||
return parent::moduleExists($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method getModuleSchemaVersion().
|
||||
*/
|
||||
public function getModuleSchemaVersionWrapper($module) {
|
||||
return parent::getModuleSchemaVersion($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method to test protected method variableGet().
|
||||
*/
|
||||
public function variableGetWrapper($name, $default) {
|
||||
return parent::variableGet($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class i18nVariableTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable';
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => array('field' => 'test'),
|
||||
'source' => [
|
||||
'plugin' => 'i18n_variable',
|
||||
'variables' => [
|
||||
'site_slogan',
|
||||
'site_name',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected results from the source.
|
||||
*/
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'Migrate est génial',
|
||||
'site_name' => 'nom de site',
|
||||
],
|
||||
[
|
||||
'language' => 'mi',
|
||||
'site_slogan' => 'Ko whakamataku heke',
|
||||
'site_name' => 'ingoa_pae',
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Database contents for tests.
|
||||
*/
|
||||
protected $databaseContents = [
|
||||
'i18n_variable' => [
|
||||
array('name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'),
|
||||
array('name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'),
|
||||
array('name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'),
|
||||
array('name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'),
|
||||
],
|
||||
];
|
||||
|
||||
}
|
Reference in a new issue