Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for Migrate CCK Field Plugin Manager testing.
|
||||
*/
|
||||
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
|
||||
function migrate_cckfield_plugin_manager_test_migrate_field_info_alter(array &$definitions) {
|
||||
if (isset($definitions['filefield'])) {
|
||||
$definitions['filefield']['class'] = D6FileField::class;
|
||||
}
|
||||
}
|
|
@ -11,7 +11,9 @@ use Drupal\migrate\Plugin\MigrationInterface;
|
|||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* }
|
||||
* },
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar"
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends CckFieldPluginBase {
|
||||
|
@ -19,11 +21,10 @@ class D6FileField extends CckFieldPluginBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$migration->setProcessOfProperty($field_name, [
|
||||
'class' => static::class,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,16 +7,13 @@ use Drupal\migrate\Plugin\MigrationInterface;
|
|||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "d6_no_core_version_specified"
|
||||
* id = "d6_no_core_version_specified",
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar",
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for Migrate Field Plugin Manager testing.
|
||||
*/
|
||||
|
||||
use Drupal\migrate_field_plugin_manager_test\Plugin\migrate\cckfield\d6\FileField;
|
||||
|
||||
function migrate_field_plugin_manager_test_migrate_field_info_alter(array &$definitions) {
|
||||
if (isset($definitions['filefield'])) {
|
||||
$definitions['filefield']['class'] = FileField::class;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_field_plugin_manager_test\Plugin\migrate\cckfield\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateCckField(
|
||||
* id = "filefield",
|
||||
* core = {6}
|
||||
* )
|
||||
*/
|
||||
class FileField extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$migration->mergeProcessOfProperty($field_name, [
|
||||
'class' => __CLASS__,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\migrate_field_plugin_manager_test\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
|
@ -11,21 +10,9 @@ use Drupal\migrate\Plugin\MigrationInterface;
|
|||
* core = {6},
|
||||
* type_map = {
|
||||
* "file" = "file"
|
||||
* }
|
||||
* },
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar"
|
||||
* )
|
||||
*/
|
||||
class D6FileField extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
||||
class D6FileField extends FieldPluginBase {}
|
||||
|
|
|
@ -3,25 +3,12 @@
|
|||
namespace Drupal\migrate_field_plugin_manager_test\Plugin\migrate\field;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "d6_no_core_version_specified"
|
||||
* id = "d6_no_core_version_specified",
|
||||
* source_module = "foo",
|
||||
* destination_module = "bar",
|
||||
* )
|
||||
*/
|
||||
class D6NoCoreVersionSpecified extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {}
|
||||
|
||||
}
|
||||
class D6NoCoreVersionSpecified extends FieldPluginBase {}
|
||||
|
|
|
@ -2,28 +2,31 @@
|
|||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\migrate_field_plugin_manager_test\Plugin\migrate\cckfield\d6\FileField;
|
||||
use Drupal\migrate_cckfield_plugin_manager_test\Plugin\migrate\cckfield\D6FileField;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class CckFieldBackwardsCompatibilityTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['file', 'migrate_field_plugin_manager_test'];
|
||||
public static $modules = ['file', 'migrate_cckfield_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Ensures that the cckfield backwards compatibility layer is invoked.
|
||||
*
|
||||
* @expectedDeprecation MigrateCckFieldInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.
|
||||
*/
|
||||
public function testBackwardsCompatibility() {
|
||||
$migration = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->getDefinition('d6_node:story');
|
||||
|
||||
$this->assertSame(FileField::class, $migration['process']['field_test_filefield']['class']);
|
||||
$this->assertSame(D6FileField::class, $migration['process']['field_test_filefield']['class']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Test that no dummy migrate_map tables are created.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class IdMapTableNoDummyTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
|
||||
*/
|
||||
protected $pluginManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->pluginManager = $this->container->get('plugin.manager.migration');
|
||||
$this->pluginManager->createInstance('d6_user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that dummy map tables do not exist.
|
||||
*/
|
||||
public function testNoDummyTables() {
|
||||
$database = \Drupal::database();
|
||||
$tables = $database->schema()->findTables('%migrate_map%');
|
||||
$dummy_tables = preg_grep("/.*migrate_map_([0-9a-fA-F]){13}/", $tables);
|
||||
$this->assertCount(0, $dummy_tables);
|
||||
}
|
||||
|
||||
}
|
|
@ -22,28 +22,20 @@ class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
|||
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])));
|
||||
$this->assertSame('d6_file', $plugin_manager->getPluginIdFromFieldType('file', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
// PluginNotFoundException and we'll never reach fail().
|
||||
$plugin_manager->getPluginIdFromFieldType('filefield', ['core' => 7]);
|
||||
$plugin_manager->getPluginIdFromFieldType('d6_file', ['core' => 7]);
|
||||
$this->fail('Expected Drupal\Component\Plugin\Exception\PluginNotFoundException.');
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_file' 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]));
|
||||
$this->assertSame('d6_no_core_version_specified', $plugin_manager->getPluginIdFromFieldType('d6_no_core_version_specified', ['core' => 6]));
|
||||
|
||||
try {
|
||||
// If this test passes, getPluginIdFromFieldType will raise a
|
||||
|
@ -52,7 +44,7 @@ class MigrateCckFieldPluginManagerTest extends MigrateDrupalTestBase {
|
|||
$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.");
|
||||
$this->assertSame($e->getMessage(), "Plugin ID 'd6_no_core_version_specified' was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'text', 'migrate_field_plugin_manager_test'];
|
||||
public static $modules = ['system', 'user', 'field', 'migrate_drupal', 'options', 'file', 'image', 'text', 'link', 'migrate_field_plugin_manager_test'];
|
||||
|
||||
/**
|
||||
* Tests that the correct MigrateField plugins are used.
|
||||
|
@ -32,7 +32,13 @@ class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
|
|||
$this->assertIdentical($e->getMessage(), "Plugin ID 'filefield' was not found.");
|
||||
}
|
||||
|
||||
$this->assertIdentical('link', $plugin_manager->getPluginIdFromFieldType('link', ['core' => 6]));
|
||||
$this->assertIdentical('link_field', $plugin_manager->getPluginIdFromFieldType('link_field', ['core' => 7]));
|
||||
$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('d6_text', $plugin_manager->getPluginIdFromFieldType('text', ['core' => 6]));
|
||||
$this->assertIdentical('d7_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]));
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate;
|
||||
|
||||
use Drupal\ban\Plugin\migrate\destination\BlockedIP;
|
||||
use Drupal\color\Plugin\migrate\destination\Color;
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase;
|
||||
use Drupal\migrate\Plugin\migrate\destination\Config;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\path\Plugin\migrate\destination\UrlAlias;
|
||||
use Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers;
|
||||
use Drupal\statistics\Plugin\migrate\destination\NodeCounter;
|
||||
use Drupal\system\Plugin\migrate\destination\d7\ThemeSettings;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateMigrationsTrait;
|
||||
use Drupal\user\Plugin\migrate\destination\UserData;
|
||||
|
||||
/**
|
||||
* Tests that all migrations are tagged as either content or configuration.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class DestinationCategoryTest extends MigrateDrupalTestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateMigrationsTrait;
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManager
|
||||
*/
|
||||
protected $migrationManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
$this->migrationManager = \Drupal::service('plugin.manager.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all D6 migrations are tagged as either Configuration or Content.
|
||||
*/
|
||||
public function testD6Categories() {
|
||||
$migrations = $this->drupal6Migrations();
|
||||
$this->assertArrayHasKey('d6_node:page', $migrations);
|
||||
$this->assertCategories($migrations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that all D7 migrations are tagged as either Configuration or Content.
|
||||
*/
|
||||
public function testD7Categories() {
|
||||
$migrations = $this->drupal7Migrations();
|
||||
$this->assertArrayHasKey('d7_node:page', $migrations);
|
||||
$this->assertCategories($migrations);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all migrations are tagged as either Configuration or Content.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface[] $migrations
|
||||
* The migrations.
|
||||
*/
|
||||
protected function assertCategories($migrations) {
|
||||
foreach ($migrations as $id => $migration) {
|
||||
$object_classes = class_parents($migration->getDestinationPlugin());
|
||||
$object_classes[] = get_class($migration->getDestinationPlugin());
|
||||
|
||||
// Ensure that the destination plugin is an instance of at least one of
|
||||
// the expected classes.
|
||||
if (in_array('Configuration', $migration->getMigrationTags(), TRUE)) {
|
||||
$this->assertNotEmpty(array_intersect($object_classes, $this->getConfigurationClasses()), "The migration $id is tagged as Configuration.");
|
||||
}
|
||||
elseif (in_array('Content', $migration->getMigrationTags(), TRUE)) {
|
||||
$this->assertNotEmpty(array_intersect($object_classes, $this->getContentClasses()), "The migration $id is tagged as Content.");
|
||||
}
|
||||
else {
|
||||
$this->fail("The migration $id is not tagged as either 'Content' or 'Configuration'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration classes.
|
||||
*
|
||||
* Configuration migrations should have a destination plugin that is an
|
||||
* instance of one of the following classes.
|
||||
*
|
||||
* @return array
|
||||
* The configuration class names.
|
||||
*/
|
||||
protected function getConfigurationClasses() {
|
||||
return [
|
||||
Color::class,
|
||||
Config::class,
|
||||
EntityConfigBase::class,
|
||||
ThemeSettings::class,
|
||||
ComponentEntityDisplayBase::class,
|
||||
ShortcutSetUsers::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content classes.
|
||||
*
|
||||
* Content migrations should have a destination plugin that is an instance
|
||||
* of one of the following classes.
|
||||
*
|
||||
* @return array
|
||||
* The content class names.
|
||||
*/
|
||||
protected function getContentClasses() {
|
||||
return [
|
||||
EntityContentBase::class,
|
||||
UrlAlias::class,
|
||||
BlockedIP::class,
|
||||
NodeCounter::class,
|
||||
UserData::class,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,443 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\media\Entity\Media;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests the entity content source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class ContentEntityTest extends KernelTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
use MediaTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'user',
|
||||
'migrate',
|
||||
'migrate_drupal',
|
||||
'system',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'field',
|
||||
'file',
|
||||
'image',
|
||||
'media',
|
||||
'media_test_source',
|
||||
'text',
|
||||
'filter',
|
||||
'language',
|
||||
'content_translation',
|
||||
];
|
||||
|
||||
/**
|
||||
* The bundle used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle = 'article';
|
||||
|
||||
/**
|
||||
* The name of the field used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName = 'field_entity_reference';
|
||||
|
||||
/**
|
||||
* The vocabulary ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $vocabulary = 'fruit';
|
||||
|
||||
/**
|
||||
* The test user.
|
||||
*
|
||||
* @var \Drupal\user\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* The migration plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
|
||||
*/
|
||||
protected $migrationPluginManager;
|
||||
|
||||
/**
|
||||
* The source plugin manager.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrateSourcePluginManager
|
||||
*/
|
||||
protected $sourcePluginManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installEntitySchema('media');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('user');
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('user', 'users_data');
|
||||
$this->installSchema('file', 'file_usage');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installConfig($this->modules);
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
// Create article content type.
|
||||
$node_type = NodeType::create(['type' => $this->bundle, 'name' => 'Article']);
|
||||
$node_type->save();
|
||||
|
||||
// Create a vocabulary.
|
||||
$vocabulary = Vocabulary::create([
|
||||
'name' => $this->vocabulary,
|
||||
'description' => $this->vocabulary,
|
||||
'vid' => $this->vocabulary,
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
]);
|
||||
$vocabulary->save();
|
||||
|
||||
// Create a term reference field on node.
|
||||
$this->createEntityReferenceField(
|
||||
'node',
|
||||
$this->bundle,
|
||||
$this->fieldName,
|
||||
'Term reference',
|
||||
'taxonomy_term',
|
||||
'default',
|
||||
['target_bundles' => [$this->vocabulary]],
|
||||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
|
||||
);
|
||||
// Create a term reference field on user.
|
||||
$this->createEntityReferenceField(
|
||||
'user',
|
||||
'user',
|
||||
$this->fieldName,
|
||||
'Term reference',
|
||||
'taxonomy_term',
|
||||
'default',
|
||||
['target_bundles' => [$this->vocabulary]],
|
||||
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
|
||||
);
|
||||
|
||||
// Create some data.
|
||||
$this->user = User::create([
|
||||
'name' => 'user123',
|
||||
'uid' => 1,
|
||||
'mail' => 'example@example.com',
|
||||
]);
|
||||
$this->user->save();
|
||||
|
||||
$term = Term::create([
|
||||
'vid' => $this->vocabulary,
|
||||
'name' => 'Apples',
|
||||
'uid' => $this->user->id(),
|
||||
]);
|
||||
$term->save();
|
||||
$this->user->set($this->fieldName, $term->id());
|
||||
$this->user->save();
|
||||
$node = Node::create([
|
||||
'type' => $this->bundle,
|
||||
'title' => 'Apples',
|
||||
$this->fieldName => $term->id(),
|
||||
'uid' => $this->user->id(),
|
||||
]);
|
||||
$node->save();
|
||||
$node->addTranslation('fr', [
|
||||
'title' => 'Pommes',
|
||||
$this->fieldName => $term->id(),
|
||||
])->save();
|
||||
|
||||
$this->sourcePluginManager = $this->container->get('plugin.manager.migrate.source');
|
||||
$this->migrationPluginManager = $this->container->get('plugin.manager.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for missing entity_type.
|
||||
*/
|
||||
public function testConstructorEntityTypeMissing() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [];
|
||||
$plugin_definition = [
|
||||
'entity_type' => '',
|
||||
];
|
||||
$this->setExpectedException(InvalidPluginDefinitionException::class, 'Missing required "entity_type" definition.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for non content entity.
|
||||
*/
|
||||
public function testConstructorNonContentEntity() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'node_type',
|
||||
];
|
||||
$this->setExpectedException(InvalidPluginDefinitionException::class, 'The entity type (node_type) is not supported. The "content_entity" source plugin only supports content entities.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:node_type', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for not bundleable entity.
|
||||
*/
|
||||
public function testConstructorNotBundable() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [
|
||||
'bundle' => 'foo',
|
||||
];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'user',
|
||||
];
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'A bundle was provided but the entity type (user) is not bundleable');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:user', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for invalid entity bundle.
|
||||
*/
|
||||
public function testConstructorInvalidBundle() {
|
||||
$migration = $this->prophesize(MigrationInterface::class)->reveal();
|
||||
$configuration = [
|
||||
'bundle' => 'foo',
|
||||
];
|
||||
$plugin_definition = [
|
||||
'entity_type' => 'node',
|
||||
];
|
||||
$this->setExpectedException(\InvalidArgumentException::class, 'The provided bundle (foo) is not valid for the (node) entity type.');
|
||||
ContentEntity::create($this->container, $configuration, 'content_entity:node', $plugin_definition, $migration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests user source plugin.
|
||||
*/
|
||||
public function testUserSource() {
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:user'));
|
||||
$user_source = $this->sourcePluginManager->createInstance('content_entity:user', $configuration, $migration);
|
||||
$this->assertSame('users', $user_source->__toString());
|
||||
$this->assertEquals(1, $user_source->count());
|
||||
$ids = $user_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('uid', $ids);
|
||||
$fields = $user_source->fields();
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$this->assertArrayHasKey('pass', $fields);
|
||||
$this->assertArrayHasKey('mail', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('roles', $fields);
|
||||
$user_source->rewind();
|
||||
$values = $user_source->current()->getSource();
|
||||
$this->assertEquals('example@example.com', $values['mail'][0]['value']);
|
||||
$this->assertEquals('user123', $values['name'][0]['value']);
|
||||
$this->assertEquals(1, $values['uid']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests file source plugin.
|
||||
*/
|
||||
public function testFileSource() {
|
||||
$file = File::create([
|
||||
'filename' => 'foo.txt',
|
||||
'uid' => $this->user->id(),
|
||||
'uri' => 'public://foo.txt',
|
||||
]);
|
||||
$file->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:file'));
|
||||
$file_source = $this->sourcePluginManager->createInstance('content_entity:file', $configuration, $migration);
|
||||
$this->assertSame('files', $file_source->__toString());
|
||||
$this->assertEquals(1, $file_source->count());
|
||||
$ids = $file_source->getIds();
|
||||
$this->assertArrayHasKey('fid', $ids);
|
||||
$fields = $file_source->fields();
|
||||
$this->assertArrayHasKey('fid', $fields);
|
||||
$this->assertArrayHasKey('filemime', $fields);
|
||||
$this->assertArrayHasKey('filename', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('uri', $fields);
|
||||
$file_source->rewind();
|
||||
$values = $file_source->current()->getSource();
|
||||
$this->assertEquals('text/plain', $values['filemime'][0]['value']);
|
||||
$this->assertEquals('public://foo.txt', $values['uri'][0]['value']);
|
||||
$this->assertEquals('foo.txt', $values['filename'][0]['value']);
|
||||
$this->assertEquals(1, $values['fid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests node source plugin.
|
||||
*/
|
||||
public function testNodeSource() {
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:node'));
|
||||
$node_source = $this->sourcePluginManager->createInstance('content_entity:node', ['bundle' => $this->bundle], $migration);
|
||||
$this->assertSame('content items', $node_source->__toString());
|
||||
$ids = $node_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('nid', $ids);
|
||||
$fields = $node_source->fields();
|
||||
$this->assertArrayHasKey('nid', $fields);
|
||||
$this->assertArrayHasKey('vid', $fields);
|
||||
$this->assertArrayHasKey('title', $fields);
|
||||
$this->assertArrayHasKey('uid', $fields);
|
||||
$this->assertArrayHasKey('sticky', $fields);
|
||||
$node_source->rewind();
|
||||
$values = $node_source->current()->getSource();
|
||||
$this->assertEquals($this->bundle, $values['type'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['nid']);
|
||||
$this->assertEquals('en', $values['langcode']);
|
||||
$this->assertEquals(1, $values['status'][0]['value']);
|
||||
$this->assertEquals('Apples', $values['title'][0]['value']);
|
||||
$this->assertEquals(1, $values['default_langcode'][0]['value']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
$node_source->next();
|
||||
$values = $node_source->current()->getSource();
|
||||
$this->assertEquals($this->bundle, $values['type'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['nid']);
|
||||
$this->assertEquals('fr', $values['langcode']);
|
||||
$this->assertEquals(1, $values['status'][0]['value']);
|
||||
$this->assertEquals('Pommes', $values['title'][0]['value']);
|
||||
$this->assertEquals(0, $values['default_langcode'][0]['value']);
|
||||
$this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests media source plugin.
|
||||
*/
|
||||
public function testMediaSource() {
|
||||
$values = [
|
||||
'id' => 'image',
|
||||
'label' => 'Image',
|
||||
'source' => 'test',
|
||||
'new_revision' => FALSE,
|
||||
];
|
||||
$media_type = $this->createMediaType('test', $values);
|
||||
$media = Media::create([
|
||||
'name' => 'Foo media',
|
||||
'uid' => $this->user->id(),
|
||||
'bundle' => $media_type->id(),
|
||||
]);
|
||||
$media->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
'bundle' => 'image',
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:media'));
|
||||
$media_source = $this->sourcePluginManager->createInstance('content_entity:media', $configuration, $migration);
|
||||
$this->assertSame('media items', $media_source->__toString());
|
||||
$this->assertEquals(1, $media_source->count());
|
||||
$ids = $media_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('mid', $ids);
|
||||
$fields = $media_source->fields();
|
||||
$this->assertArrayHasKey('bundle', $fields);
|
||||
$this->assertArrayHasKey('mid', $fields);
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$this->assertArrayHasKey('status', $fields);
|
||||
$media_source->rewind();
|
||||
$values = $media_source->current()->getSource();
|
||||
$this->assertEquals(1, $values['mid']);
|
||||
$this->assertEquals('Foo media', $values['name'][0]['value']);
|
||||
$this->assertEquals('Foo media', $values['thumbnail'][0]['title']);
|
||||
$this->assertEquals(1, $values['uid'][0]['target_id']);
|
||||
$this->assertEquals('image', $values['bundle'][0]['target_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests term source plugin.
|
||||
*/
|
||||
public function testTermSource() {
|
||||
$term2 = Term::create([
|
||||
'vid' => $this->vocabulary,
|
||||
'name' => 'Granny Smith',
|
||||
'uid' => $this->user->id(),
|
||||
'parent' => 1,
|
||||
]);
|
||||
$term2->save();
|
||||
|
||||
$configuration = [
|
||||
'include_translations' => FALSE,
|
||||
'bundle' => $this->vocabulary,
|
||||
];
|
||||
$migration = $this->migrationPluginManager->createStubMigration($this->migrationDefinition('content_entity:taxonomy_term'));
|
||||
$term_source = $this->sourcePluginManager->createInstance('content_entity:taxonomy_term', $configuration, $migration);
|
||||
$this->assertSame('taxonomy terms', $term_source->__toString());
|
||||
$this->assertEquals(2, $term_source->count());
|
||||
$ids = $term_source->getIds();
|
||||
$this->assertArrayHasKey('langcode', $ids);
|
||||
$this->assertArrayHasKey('tid', $ids);
|
||||
$fields = $term_source->fields();
|
||||
$this->assertArrayHasKey('vid', $fields);
|
||||
$this->assertArrayHasKey('tid', $fields);
|
||||
$this->assertArrayHasKey('name', $fields);
|
||||
$term_source->rewind();
|
||||
$values = $term_source->current()->getSource();
|
||||
$this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
|
||||
$this->assertEquals(1, $values['tid']);
|
||||
// @TODO: Add test coverage for parent in
|
||||
// https://www.drupal.org/project/drupal/issues/2940198
|
||||
$this->assertEquals('Apples', $values['name'][0]['value']);
|
||||
$term_source->next();
|
||||
$values = $term_source->current()->getSource();
|
||||
$this->assertEquals($this->vocabulary, $values['vid'][0]['target_id']);
|
||||
$this->assertEquals(2, $values['tid']);
|
||||
// @TODO: Add test coverage for parent in
|
||||
// https://www.drupal.org/project/drupal/issues/2940198
|
||||
$this->assertEquals('Granny Smith', $values['name'][0]['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a migration definition.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin id.
|
||||
*
|
||||
* @return array
|
||||
* The definition.
|
||||
*/
|
||||
protected function migrationDefinition($plugin_id) {
|
||||
return [
|
||||
'source' => [
|
||||
'plugin' => $plugin_id,
|
||||
],
|
||||
'process' => [],
|
||||
'destination' => [
|
||||
'plugin' => 'null',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
|||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d6\i18nVariable
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class i18nVariableTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @covers \Drupal\migrate_drupal\Plugin\migrate\source\d7\VariableTranslation
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class VariableTranslationTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['variable_store'] = [
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'fr',
|
||||
'name' => 'site_slogan',
|
||||
'value' => 'fr - site slogan',
|
||||
'serialized' => '0',
|
||||
],
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'fr',
|
||||
'name' => 'user_mail_status_blocked_subject',
|
||||
'value' => 'fr - BEGONE!',
|
||||
'serialized' => '0',
|
||||
],
|
||||
[
|
||||
'realm' => 'language',
|
||||
'realm_key' => 'is',
|
||||
'name' => 'site_slogan',
|
||||
'value' => 's:16:"is - site slogan";',
|
||||
'serialized' => '1',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
'language' => 'fr',
|
||||
'site_slogan' => 'fr - site slogan',
|
||||
'user_mail_status_blocked_subject' => 'fr - BEGONE!',
|
||||
],
|
||||
[
|
||||
'language' => 'is',
|
||||
'site_slogan' => 'is - site slogan',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected count.
|
||||
$tests[0]['expected_count'] = NULL;
|
||||
|
||||
// The migration configuration.
|
||||
$tests[0]['configuration']['variables'] = [
|
||||
'site_slogan',
|
||||
'user_mail_status_blocked_subject',
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -72,7 +72,7 @@ class ConfigTest extends MigrateSqlSourceTestBase {
|
|||
],
|
||||
'collections' => [
|
||||
'language.af',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
// Test with name and no collection in configuration.
|
||||
|
|
|
@ -114,8 +114,8 @@ class EntityContentBaseTest extends MigrateDrupal6TestBase {
|
|||
$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;
|
||||
$argument = Argument::that(function ($msg) {
|
||||
return strpos((string) $msg, htmlentities('The "no_language_entity_test" entity type does not support translations.')) !== FALSE;
|
||||
});
|
||||
$message->display($argument, Argument::any())
|
||||
->shouldBeCalled();
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeTestBase;
|
||||
|
||||
/**
|
||||
* Tests follow-up migrations.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class FollowUpMigrationsTest extends MigrateNodeTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// A requirement for d6_node_translation.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_language_content_settings',
|
||||
'd6_node',
|
||||
'd6_node_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test entity reference translations.
|
||||
*/
|
||||
public function testEntityReferenceTranslations() {
|
||||
// Test the entity reference field before the follow-up migrations.
|
||||
$node = Node::load(10);
|
||||
$this->assertSame('13', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('13', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('20', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('20', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(12)->getTranslation('en');
|
||||
$this->assertSame('10', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('11', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('11', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
// Run the follow-up migrations.
|
||||
$migration_plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
$migration_plugin_manager->clearCachedDefinitions();
|
||||
$follow_up_migrations = $migration_plugin_manager->createInstances('d6_entity_reference_translation');
|
||||
$this->executeMigrations(array_keys($follow_up_migrations));
|
||||
|
||||
// Test the entity reference field after the follow-up migrations.
|
||||
$node = Node::load(10);
|
||||
$this->assertSame('12', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('12', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('12', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('12', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(12)->getTranslation('en');
|
||||
$this->assertSame('10', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('fr');
|
||||
$this->assertSame('10', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('10', $translation->get('field_reference_2')->target_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d6;
|
||||
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Audit\AuditResult;
|
||||
use Drupal\migrate\Audit\IdAuditor;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
|
||||
|
||||
/**
|
||||
* Tests the migration auditor for ID conflicts.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDrupal6AuditIdsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateTestContentEntitiesTrait;
|
||||
use ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
|
||||
// Install required entity schemas.
|
||||
$this->installEntitySchemas();
|
||||
|
||||
// Install required schemas.
|
||||
$this->installSchema('book', ['book']);
|
||||
$this->installSchema('dblog', ['watchdog']);
|
||||
$this->installSchema('forum', ['forum_index']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('search', ['search_dataset']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('tracker', ['tracker_node', 'tracker_user']);
|
||||
|
||||
// Enable content moderation for nodes of type page.
|
||||
$this->installEntitySchema('content_moderation_state');
|
||||
$this->installConfig('content_moderation');
|
||||
NodeType::create(['type' => 'page'])->save();
|
||||
$workflow = $this->createEditorialWorkflow();
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
|
||||
$workflow->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multiple migrations to the same destination with no ID conflicts.
|
||||
*/
|
||||
public function testMultipleMigrationWithoutIdConflicts() {
|
||||
// Create a node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d6_node:page migration mapping table to simulate a
|
||||
// previously migrated node.
|
||||
$id_map = $this->getMigration('d6_node:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d6_node migrations for the page & article node type.
|
||||
// There should be no conflicts since the highest destination ID should be
|
||||
// equal to the highest migrated ID, as found in the aggregated mapping
|
||||
// tables of the two node migrations.
|
||||
$migrations = [
|
||||
$this->getMigration('d6_node:page'),
|
||||
$this->getMigration('d6_node:article'),
|
||||
];
|
||||
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with no ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithNoIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 6');
|
||||
|
||||
// Audit all Drupal 6 migrations that support it. There should be no
|
||||
// conflicts since no content has been created.
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithIdConflicts() {
|
||||
// Get all Drupal 6 migrations.
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 6');
|
||||
|
||||
// Create content.
|
||||
$this->createContent();
|
||||
|
||||
// Audit the IDs of all migrations. There should be conflicts since content
|
||||
// has been created.
|
||||
$conflicts = array_map(
|
||||
function (AuditResult $result) {
|
||||
return $result->passed() ? NULL : $result->getMigration()->getBaseId();
|
||||
},
|
||||
(new IdAuditor())->auditMultiple($migrations)
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'd6_aggregator_feed',
|
||||
'd6_aggregator_item',
|
||||
'd6_comment',
|
||||
'd6_custom_block',
|
||||
'd6_file',
|
||||
'd6_menu_links',
|
||||
'd6_node',
|
||||
'd6_node_revision',
|
||||
'd6_taxonomy_term',
|
||||
'd6_term_node_revision',
|
||||
'd6_user',
|
||||
'node_translation_menu_links',
|
||||
];
|
||||
$this->assertEmpty(array_diff(array_filter($conflicts), $expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests draft revisions ID conflicts.
|
||||
*/
|
||||
public function testDraftRevisionIdConflicts() {
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Create a draft revision.
|
||||
$node->moderation_state->value = 'draft';
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d6_node_revision:page migration mapping table to
|
||||
// simulate a previously migrated node revision.
|
||||
$id_map = $this->getMigration('d6_node_revision:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d6_node_revision migration. There should be
|
||||
// conflicts since a draft revision has been created.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d6_node_revision:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID conflicts for inaccessible nodes.
|
||||
*/
|
||||
public function testNodeGrantsIdConflicts() {
|
||||
// Enable the node_test module to restrict access to page nodes.
|
||||
$this->enableModules(['node_test']);
|
||||
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Audit the IDs of the d6_node migration. There should be conflicts
|
||||
// even though the new node is not accessible.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d6_node:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
|
||||
|
||||
/**
|
||||
* Tests follow-up migrations.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use FileMigrationSetupTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'comment',
|
||||
'datetime',
|
||||
'file',
|
||||
'image',
|
||||
'language',
|
||||
'link',
|
||||
'menu_ui',
|
||||
// A requirement for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fileMigrationSetup();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node_type',
|
||||
'd7_language_content_settings',
|
||||
'd7_comment_type',
|
||||
'd7_taxonomy_vocabulary',
|
||||
'd7_field',
|
||||
'd7_field_instance',
|
||||
'd7_node',
|
||||
'd7_node_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFileMigrationInfo() {
|
||||
return [
|
||||
'path' => 'public://sites/default/files/cube.jpeg',
|
||||
'size' => '3620',
|
||||
'base_path' => 'public://',
|
||||
'plugin_id' => 'd7_file',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test entity reference translations.
|
||||
*/
|
||||
public function testEntityReferenceTranslations() {
|
||||
// Test the entity reference field before the follow-up migrations.
|
||||
$node = Node::load(2);
|
||||
$this->assertSame('5', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('5', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('is');
|
||||
$this->assertSame('4', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(4);
|
||||
$this->assertSame('3', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('3', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('en');
|
||||
$this->assertSame('2', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
// Run the follow-up migrations.
|
||||
$migration_plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
$migration_plugin_manager->clearCachedDefinitions();
|
||||
$follow_up_migrations = $migration_plugin_manager->createInstances('d7_entity_reference_translation');
|
||||
$this->executeMigrations(array_keys($follow_up_migrations));
|
||||
|
||||
// Test the entity reference field after the follow-up migrations.
|
||||
$node = Node::load(2);
|
||||
$this->assertSame('4', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('is');
|
||||
$this->assertSame('4', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
|
||||
|
||||
$node = Node::load(4);
|
||||
$this->assertSame('2', $node->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $node->get('field_reference_2')->target_id);
|
||||
$translation = $node->getTranslation('en');
|
||||
$this->assertSame('2', $translation->get('field_reference')->target_id);
|
||||
$this->assertSame('2', $translation->get('field_reference_2')->target_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\d7;
|
||||
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Audit\AuditResult;
|
||||
use Drupal\migrate\Audit\IdAuditor;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait;
|
||||
|
||||
/**
|
||||
* Tests the migration auditor for ID conflicts.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
*/
|
||||
class MigrateDrupal7AuditIdsTest extends MigrateDrupal7TestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use CreateTestContentEntitiesTrait;
|
||||
use ContentModerationTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
// Enable all modules.
|
||||
self::$modules = array_keys($this->coreModuleListDataProvider());
|
||||
parent::setUp();
|
||||
|
||||
// Install required entity schemas.
|
||||
$this->installEntitySchemas();
|
||||
|
||||
// Install required schemas.
|
||||
$this->installSchema('book', ['book']);
|
||||
$this->installSchema('dblog', ['watchdog']);
|
||||
$this->installSchema('forum', ['forum_index']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('search', ['search_dataset']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('tracker', ['tracker_node', 'tracker_user']);
|
||||
|
||||
// Enable content moderation for nodes of type page.
|
||||
$this->installEntitySchema('content_moderation_state');
|
||||
$this->installConfig('content_moderation');
|
||||
NodeType::create(['type' => 'page'])->save();
|
||||
$workflow = $this->createEditorialWorkflow();
|
||||
$workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
|
||||
$workflow->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multiple migrations to the same destination with no ID conflicts.
|
||||
*/
|
||||
public function testMultipleMigrationWithoutIdConflicts() {
|
||||
// Create a node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d7_node:page migration mapping table to simulate a
|
||||
// previously migrated node.
|
||||
$id_map = $this->getMigration('d7_node:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d7_node migrations for the page & article node type.
|
||||
// There should be no conflicts since the highest destination ID should be
|
||||
// equal to the highest migrated ID, as found in the aggregated mapping
|
||||
// tables of the two node migrations.
|
||||
$migrations = [
|
||||
$this->getMigration('d7_node:page'),
|
||||
$this->getMigration('d7_node:article'),
|
||||
];
|
||||
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with no ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithNoIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 7');
|
||||
|
||||
// Audit the IDs of all Drupal 7 migrations. There should be no conflicts
|
||||
// since no content has been created.
|
||||
$results = (new IdAuditor())->auditMultiple($migrations);
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
foreach ($results as $result) {
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertTrue($result->passed());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all migrations with ID conflicts.
|
||||
*/
|
||||
public function testAllMigrationsWithIdConflicts() {
|
||||
$migrations = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createInstancesByTag('Drupal 7');
|
||||
|
||||
// Create content.
|
||||
$this->createContent();
|
||||
|
||||
// Audit the IDs of all Drupal 7 migrations. There should be conflicts since
|
||||
// content has been created.
|
||||
$conflicts = array_map(
|
||||
function (AuditResult $result) {
|
||||
return $result->passed() ? NULL : $result->getMigration()->getBaseId();
|
||||
},
|
||||
(new IdAuditor())->auditMultiple($migrations)
|
||||
);
|
||||
|
||||
$expected = [
|
||||
'd7_aggregator_feed',
|
||||
'd7_aggregator_item',
|
||||
'd7_comment',
|
||||
'd7_custom_block',
|
||||
'd7_file',
|
||||
'd7_file_private',
|
||||
'd7_menu_links',
|
||||
'd7_node',
|
||||
'd7_node_revision',
|
||||
'd7_taxonomy_term',
|
||||
'd7_user',
|
||||
'node_translation_menu_links',
|
||||
];
|
||||
$this->assertEmpty(array_diff(array_filter($conflicts), $expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests draft revisions ID conflicts.
|
||||
*/
|
||||
public function testDraftRevisionIdConflicts() {
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Create a draft revision.
|
||||
$node->moderation_state->value = 'draft';
|
||||
$node->setNewRevision(TRUE);
|
||||
$node->save();
|
||||
|
||||
// Insert data in the d7_node_revision:page migration mapping table to
|
||||
// simulate a previously migrated node revision.
|
||||
$id_map = $this->getMigration('d7_node_revision:page')->getIdMap();
|
||||
$table_name = $id_map->mapTableName();
|
||||
$id_map->getDatabase()->insert($table_name)
|
||||
->fields([
|
||||
'source_ids_hash' => 1,
|
||||
'sourceid1' => 1,
|
||||
'destid1' => 1,
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Audit the IDs of the d7_node_revision migration. There should be
|
||||
// conflicts since a draft revision has been created.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d7_node_revision:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ID conflicts for inaccessible nodes.
|
||||
*/
|
||||
public function testNodeGrantsIdConflicts() {
|
||||
// Enable the node_test module to restrict access to page nodes.
|
||||
$this->enableModules(['node_test']);
|
||||
|
||||
// Create a published node of type page.
|
||||
$node = Node::create(['type' => 'page', 'title' => 'foo']);
|
||||
$node->moderation_state->value = 'published';
|
||||
$node->save();
|
||||
|
||||
// Audit the IDs of the d7_node migration. There should be conflicts
|
||||
// even though the new node is not accessible.
|
||||
/** @var \Drupal\migrate\Audit\AuditResult $result */
|
||||
$result = (new IdAuditor())->audit($this->getMigration('d7_node:page'));
|
||||
$this->assertInstanceOf(AuditResult::class, $result);
|
||||
$this->assertFalse($result->passed());
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\migrate_drupal\Kernel\dependencies;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
|
@ -67,7 +67,7 @@ class MigrateDependenciesTest extends MigrateDrupal6TestBase {
|
|||
$executable = new MigrateExecutable($migration, $this);
|
||||
$this->startCollectingMessages();
|
||||
$executable->import();
|
||||
$this->assertEqual($this->migrateMessages['error'], [SafeMarkup::format('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', ['@id' => $migration->id()])]);
|
||||
$this->assertEqual($this->migrateMessages['error'], [new FormattableMarkup('Migration @id did not meet the requirements. Missing migrations d6_aggregator_feed. requirements: d6_aggregator_feed.', ['@id' => $migration->id()])]);
|
||||
$this->collectMessages = FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Traits;
|
||||
|
||||
trait CreateMigrationsTrait {
|
||||
|
||||
/**
|
||||
* Create instances of all Drupal 6 migrations.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations
|
||||
*/
|
||||
public function drupal6Migrations() {
|
||||
$dirs = \Drupal::service('module_handler')->getModuleDirectories();
|
||||
$migrate_drupal_directory = $dirs['migrate_drupal'];
|
||||
$this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal6.php");
|
||||
return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 6');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instances of all Drupal 7 migrations.
|
||||
*
|
||||
* @return \Drupal\migrate\Plugin\MigrationInterface[]
|
||||
* The migrations
|
||||
*/
|
||||
public function drupal7Migrations() {
|
||||
$dirs = \Drupal::service('module_handler')->getModuleDirectories();
|
||||
$migrate_drupal_directory = $dirs['migrate_drupal'];
|
||||
$this->loadFixture("$migrate_drupal_directory/tests/fixtures/drupal7.php");
|
||||
return \Drupal::service('plugin.manager.migration')->createInstancesByTag('Drupal 7');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,210 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Traits;
|
||||
|
||||
/**
|
||||
* Provides helper methods for creating test content.
|
||||
*/
|
||||
trait CreateTestContentEntitiesTrait {
|
||||
|
||||
/**
|
||||
* Gets required modules.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getRequiredModules() {
|
||||
return [
|
||||
'aggregator',
|
||||
'block_content',
|
||||
'comment',
|
||||
'field',
|
||||
'file',
|
||||
'link',
|
||||
'menu_link_content',
|
||||
'migrate_drupal',
|
||||
'node',
|
||||
'options',
|
||||
'system',
|
||||
'taxonomy',
|
||||
'text',
|
||||
'user',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Install required entity schemas.
|
||||
*/
|
||||
protected function installEntitySchemas() {
|
||||
$this->installEntitySchema('aggregator_feed');
|
||||
$this->installEntitySchema('aggregator_item');
|
||||
$this->installEntitySchema('block_content');
|
||||
$this->installEntitySchema('comment');
|
||||
$this->installEntitySchema('file');
|
||||
$this->installEntitySchema('menu_link_content');
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installEntitySchema('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create several pieces of generic content.
|
||||
*/
|
||||
protected function createContent() {
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
// Create an aggregator feed.
|
||||
if ($entity_type_manager->hasDefinition('aggregator_feed')) {
|
||||
$feed = $entity_type_manager->getStorage('aggregator_feed')->create([
|
||||
'title' => 'feed',
|
||||
'url' => 'http://www.example.com',
|
||||
]);
|
||||
$feed->save();
|
||||
|
||||
// Create an aggregator feed item.
|
||||
$item = $entity_type_manager->getStorage('aggregator_item')->create([
|
||||
'title' => 'feed item',
|
||||
'fid' => $feed->id(),
|
||||
'link' => 'http://www.example.com',
|
||||
]);
|
||||
$item->save();
|
||||
}
|
||||
|
||||
// Create a block content.
|
||||
if ($entity_type_manager->hasDefinition('block_content')) {
|
||||
$block = $entity_type_manager->getStorage('block_content')->create([
|
||||
'info' => 'block',
|
||||
'type' => 'block',
|
||||
]);
|
||||
$block->save();
|
||||
}
|
||||
|
||||
// Create a node.
|
||||
if ($entity_type_manager->hasDefinition('node')) {
|
||||
$node = $entity_type_manager->getStorage('node')->create([
|
||||
'type' => 'page',
|
||||
'title' => 'page',
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Create a comment.
|
||||
if ($entity_type_manager->hasDefinition('comment')) {
|
||||
$comment = $entity_type_manager->getStorage('comment')->create([
|
||||
'comment_type' => 'comment',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'entity_id' => $node->id(),
|
||||
]);
|
||||
$comment->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a file.
|
||||
if ($entity_type_manager->hasDefinition('file')) {
|
||||
$file = $entity_type_manager->getStorage('file')->create([
|
||||
'uri' => 'public://example.txt',
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
|
||||
// Create a menu link.
|
||||
if ($entity_type_manager->hasDefinition('menu_link_content')) {
|
||||
$menu_link = $entity_type_manager->getStorage('menu_link_content')->create([
|
||||
'title' => 'menu link',
|
||||
'link' => ['uri' => 'http://www.example.com'],
|
||||
'menu_name' => 'tools',
|
||||
]);
|
||||
$menu_link->save();
|
||||
}
|
||||
|
||||
// Create a taxonomy term.
|
||||
if ($entity_type_manager->hasDefinition('taxonomy_term')) {
|
||||
$term = $entity_type_manager->getStorage('taxonomy_term')->create([
|
||||
'name' => 'term',
|
||||
'vid' => 'term',
|
||||
]);
|
||||
$term->save();
|
||||
}
|
||||
|
||||
// Create a user.
|
||||
if ($entity_type_manager->hasDefinition('user')) {
|
||||
$user = $entity_type_manager->getStorage('user')->create([
|
||||
'name' => 'user',
|
||||
'mail' => 'user@example.com',
|
||||
]);
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create several pieces of generic content.
|
||||
*/
|
||||
protected function createContentPostUpgrade() {
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
|
||||
// Create a block content.
|
||||
if ($entity_type_manager->hasDefinition('block_content')) {
|
||||
$block = $entity_type_manager->getStorage('block_content')->create([
|
||||
'info' => 'Post upgrade block',
|
||||
'type' => 'block',
|
||||
]);
|
||||
$block->save();
|
||||
}
|
||||
|
||||
// Create a node.
|
||||
if ($entity_type_manager->hasDefinition('node')) {
|
||||
$node = $entity_type_manager->getStorage('node')->create([
|
||||
'type' => 'page',
|
||||
'title' => 'Post upgrade page',
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Create a comment.
|
||||
if ($entity_type_manager->hasDefinition('comment')) {
|
||||
$comment = $entity_type_manager->getStorage('comment')->create([
|
||||
'comment_type' => 'comment',
|
||||
'field_name' => 'comment',
|
||||
'entity_type' => 'node',
|
||||
'entity_id' => $node->id(),
|
||||
]);
|
||||
$comment->save();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a file.
|
||||
if ($entity_type_manager->hasDefinition('file')) {
|
||||
$file = $entity_type_manager->getStorage('file')->create([
|
||||
'uri' => 'public://post_upgrade_example.txt',
|
||||
]);
|
||||
$file->save();
|
||||
}
|
||||
|
||||
// Create a menu link.
|
||||
if ($entity_type_manager->hasDefinition('menu_link_content')) {
|
||||
$menu_link = $entity_type_manager->getStorage('menu_link_content')->create([
|
||||
'title' => 'post upgrade menu link',
|
||||
'link' => ['uri' => 'http://www.drupal.org'],
|
||||
'menu_name' => 'tools',
|
||||
]);
|
||||
$menu_link->save();
|
||||
}
|
||||
|
||||
// Create a taxonomy term.
|
||||
if ($entity_type_manager->hasDefinition('taxonomy_term')) {
|
||||
$term = $entity_type_manager->getStorage('taxonomy_term')->create([
|
||||
'name' => 'post upgrade term',
|
||||
'vid' => 'term',
|
||||
]);
|
||||
$term->save();
|
||||
}
|
||||
|
||||
// Create a user.
|
||||
if ($entity_type_manager->hasDefinition('user')) {
|
||||
$user = $entity_type_manager->getStorage('user')->create([
|
||||
'name' => 'universe',
|
||||
'mail' => 'universe@example.com',
|
||||
]);
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -43,7 +43,7 @@ class DrupalSqlBaseTest extends MigrateTestCase {
|
|||
*/
|
||||
public function testSourceProviderNotActive() {
|
||||
$plugin_definition['requirements_met'] = TRUE;
|
||||
$plugin_definition['source_provider'] = 'module1';
|
||||
$plugin_definition['source_module'] = 'module1';
|
||||
/** @var \Drupal\Core\State\StateInterface $state */
|
||||
$state = $this->getMock('Drupal\Core\State\StateInterface');
|
||||
/** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
|
||||
|
@ -57,7 +57,7 @@ class DrupalSqlBaseTest extends MigrateTestCase {
|
|||
}
|
||||
catch (RequirementsException $e) {
|
||||
// Ensure requirements are set on the exception.
|
||||
$this->assertEquals(['source_provider' => 'module1'], $e->getRequirements());
|
||||
$this->assertEquals(['source_module' => 'module1'], $e->getRequirements());
|
||||
// Re-throw so PHPUnit can assert the exception.
|
||||
throw $e;
|
||||
}
|
||||
|
|
|
@ -150,10 +150,10 @@ class TestDrupal6SqlBase extends DrupalSqlBase {
|
|||
'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.'),
|
||||
'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."),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate_drupal\Unit\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class VariableTranslationTest 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\VariableTranslation';
|
||||
|
||||
/**
|
||||
* Define bare minimum migration configuration.
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
'highWaterProperty' => ['field' => 'test'],
|
||||
'source' => [
|
||||
'plugin' => 'variable_translation',
|
||||
'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' => [
|
||||
['name' => 'site_slogan', 'language' => 'fr', 'value' => 's:19:"Migrate est génial";'],
|
||||
['name' => 'site_name', 'language' => 'fr', 'value' => 's:11:"nom de site";'],
|
||||
['name' => 'site_slogan', 'language' => 'mi', 'value' => 's:19:"Ko whakamataku heke";'],
|
||||
['name' => 'site_name', 'language' => 'mi', 'value' => 's:9:"ingoa_pae";'],
|
||||
],
|
||||
];
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
|||
* Tests the variable source plugin.
|
||||
*
|
||||
* @group migrate_drupal
|
||||
* @group legacy
|
||||
*/
|
||||
class i18nVariableTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
|
@ -43,7 +44,7 @@ class i18nVariableTest extends MigrateSqlSourceTestCase {
|
|||
'language' => 'mi',
|
||||
'site_slogan' => 'Ko whakamataku heke',
|
||||
'site_name' => 'ingoa_pae',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue