Commit ae6c7444 authored by catch's avatar catch

Issue #2578263 by Jo Fitzgerald, quietone, svendecabooter, yogeshmpawar,...

Issue #2578263 by Jo Fitzgerald, quietone, svendecabooter, yogeshmpawar, phenaproxima, imalabya, heddn, alexpott, xjm: Add helper functions to MigrateDrupal7TestBase
parent 8da1546f
......@@ -19,7 +19,6 @@ class MigrateBookTest extends MigrateDrupal7TestBase {
'book',
'menu_ui',
'node',
'taxonomy',
'text',
];
......@@ -28,15 +27,11 @@ class MigrateBookTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(['node']);
$this->installSchema('book', ['book']);
$this->installSchema('node', ['node_access']);
$this->migrateUsers(FALSE);
$this->migrateContentTypes();
$this->executeMigrations([
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_node',
'd7_book',
]);
......
......@@ -23,10 +23,9 @@ class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment', 'node']);
$this->migrateContentTypes();
$this->migrateCommentTypes();
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_comment_entity_display',
......
......@@ -23,11 +23,8 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigrations([
'd7_comment_type',
'd7_comment_entity_form_display_subject',
]);
$this->migrateCommentTypes();
$this->executeMigration('d7_comment_entity_form_display_subject');
}
/**
......
......@@ -23,10 +23,9 @@ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment', 'node']);
$this->migrateContentTypes();
$this->migrateCommentTypes();
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_comment_entity_form_display',
......
......@@ -23,10 +23,9 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment', 'node']);
$this->migrateContentTypes();
$this->migrateCommentTypes();
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
]);
......
......@@ -23,11 +23,8 @@ class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigrations([
'd7_comment_type',
'd7_comment_field',
]);
$this->migrateCommentTypes();
$this->executeMigration('d7_comment_field');
}
/**
......
......@@ -39,23 +39,16 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(['comment', 'node']);
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('node', ['node_access']);
$this->migrateContent();
$this->executeMigrations([
'language',
'd7_node_type',
'd7_language_content_settings',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_node',
'd7_node_translation',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_comment_entity_display',
......
......@@ -23,8 +23,7 @@ class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['comment']);
$this->executeMigration('d7_comment_type');
$this->migrateCommentTypes();
}
/**
......
......@@ -2,13 +2,9 @@
namespace Drupal\Tests\field\Kernel\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests migration of D7 field formatter settings.
......@@ -20,9 +16,9 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'datetime',
'file',
'image',
'link',
'menu_ui',
'node',
'taxonomy',
'telephone',
......@@ -34,121 +30,8 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
CommentType::create([
'id' => 'comment_node_page',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_article',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_blog',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_book',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_forum',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_test_content_type',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'page',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'article',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'blog',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'book',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'forum',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'test_content_type',
'label' => $this->randomMachineName(),
])->save();
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
// Give one unfortunate field instance invalid display settings to ensure
// that the migration provides an empty array as a default (thus avoiding
// an "unsupported operand types" fatal).
Database::getConnection('default', 'migrate')
->update('field_config_instance')
->fields([
'data' => serialize([
'label' => 'Body',
'widget' =>
[
'type' => 'text_textarea_with_summary',
'settings' =>
[
'rows' => 20,
'summary_rows' => 5,
],
'weight' => -4,
'module' => 'text',
],
'settings' =>
[
'display_summary' => TRUE,
'text_processing' => 1,
'user_register_form' => FALSE,
],
'display' =>
[
'default' =>
[
'label' => 'hidden',
'type' => 'text_default',
'settings' => [],
'module' => 'text',
'weight' => 0,
],
'teaser' =>
[
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
// settings is always expected to be an array. Making it NULL
// causes a fatal.
'settings' => NULL,
'module' => 'text',
'weight' => 0,
],
],
'required' => FALSE,
'description' => '',
]),
])
->condition('entity_type', 'node')
->condition('bundle', 'article')
->condition('field_name', 'body')
->execute();
$this->migrateFields();
$this->executeMigrations([
'd7_field',
'd7_field_instance',
'd7_view_modes',
'd7_field_formatter_settings',
]);
......
......@@ -4,8 +4,6 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Tests\migrate\Kernel\NodeCommentCombinationTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
......@@ -15,19 +13,16 @@
*/
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
use NodeCommentCombinationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'comment',
'datetime',
'file',
'image',
'link',
'menu_ui',
'node',
'system',
'taxonomy',
'telephone',
'text',
......@@ -38,15 +33,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->createNodeCommentCombination('page');
$this->createNodeCommentCombination('article');
$this->createNodeCommentCombination('blog');
$this->createNodeCommentCombination('book');
$this->createNodeCommentCombination('forum', 'comment_forum');
$this->createNodeCommentCombination('test_content_type');
Vocabulary::create(['vid' => 'test_vocabulary'])->save();
$this->executeMigrations(['d7_field', 'd7_field_instance']);
$this->migrateFields();
}
/**
......
......@@ -21,15 +21,13 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'datetime',
'field',
'file',
'image',
'link',
'menu_ui',
'node',
'taxonomy',
'telephone',
'text',
'menu_ui',
];
/**
......@@ -37,20 +35,8 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->executeMigrations([
'd7_node_type',
'd7_comment_type',
'd7_taxonomy_vocabulary',
'd7_field',
'd7_field_instance',
'd7_field_instance_widget_settings',
]);
$this->migrateFields();
$this->executeMigration('d7_field_instance_widget_settings');
}
/**
......
......@@ -24,9 +24,8 @@ class MigrateLanguageContentSettingsTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigrations(['d7_node_type', 'd7_language_content_settings']);
$this->migrateContentTypes();
$this->executeMigration('d7_language_content_settings');
}
/**
......
......@@ -36,14 +36,13 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('menu_link_content');
$this->installEntitySchema('node');
$this->installSchema('node', ['node_access']);
$this->installConfig(static::$modules);
$this->migrateUsers(FALSE);
$this->migrateContentTypes();
$this->executeMigrations([
'language',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_language_content_settings',
'd7_node',
'd7_node_translation',
......
......@@ -2,6 +2,12 @@
namespace Drupal\Tests\migrate\Kernel;
/**
* @deprecated in Drupal 8.7.x, will be removed before Drupal 9.0.0. Use
* \Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase::migrateFields()
* instead.
*/
use Drupal\comment\Entity\CommentType;
use Drupal\node\Entity\NodeType;
......@@ -20,6 +26,8 @@
* comment_node_{type}.
*/
protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
@trigger_error('NodeCommentCombinationTrait::createNodeCommentCombination() is deprecated in Drupal 8.7.x, will be removed before Drupal 9.0.0. Use \Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase::migrateFields() instead.', E_USER_DEPRECATED);
if (!$comment_type) {
$comment_type = "comment_node_$node_type";
}
......
......@@ -21,7 +21,6 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
'content_translation',
'comment',
'datetime',
'file',
'image',
'language',
'link',
......@@ -42,22 +41,15 @@ protected function setUp() {
$this->fileMigrationSetup();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->installSchema('node', ['node_access']);
$this->migrateUsers();
$this->migrateFields();
$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',
]);
......
......@@ -24,4 +24,85 @@ protected function getFixtureFilePath() {
return __DIR__ . '/../../../fixtures/drupal7.php';
}
/**
* Executes all field migrations.
*/
protected function migrateFields() {
$this->executeMigration('d7_field');
$this->migrateContentTypes();
$this->migrateCommentTypes();
$this->executeMigrations(['d7_taxonomy_vocabulary', 'd7_field_instance']);
}
/**
* Executes all user migrations.
*
* @param bool $include_pictures
* (optional) If TRUE, migrates user pictures. Defaults to TRUE.
*/
protected function migrateUsers($include_pictures = TRUE) {
$migrations = ['d7_user_role', 'd7_user'];
if ($include_pictures) {
// Prepare to migrate user pictures as well.
$this->installEntitySchema('file');
$migrations = array_merge([
'user_picture_field',
'user_picture_field_instance',
], $migrations);
}
$this->executeMigrations($migrations);
}
/**
* Migrates node types.
*/
protected function migrateContentTypes() {
$this->installConfig(['node']);
$this->installEntitySchema('node');
$this->executeMigration('d7_node_type');
}
/**
* Migrates comment types.
*/
protected function migrateCommentTypes() {
$this->installConfig(['comment']);
$this->executeMigration('d7_comment_type');
}
/**
* Executes all content migrations.
*
* @param bool $include_revisions
* (optional) If TRUE, migrates node revisions. Defaults to FALSE.
*/
protected function migrateContent($include_revisions = FALSE) {
$this->migrateContentTypes();
$this->migrateCommentTypes();
$this->migrateUsers(FALSE);
// Uses executeMigrations() rather than executeMigration() because the
// former includes all of the migration derivatives, e.g.
// d7_node:article.
$this->executeMigrations(['d7_node']);
if ($include_revisions) {
$this->executeMigrations(['d7_node_revision']);
}
}
/**
* Executes all taxonomy term migrations.
*/
protected function migrateTaxonomyTerms() {
$this->installEntitySchema('taxonomy_term');
$this->migrateFields();
// Uses executeMigrations() rather than executeMigration() because the
// former includes all of the migration derivatives, e.g.
// d7_taxonomy_term:tags.
$this->executeMigrations(['d7_taxonomy_term']);
}
}
......@@ -24,9 +24,6 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
'content_translation',
'comment',
'datetime',
'file',
'filter',
'forum',
'image',
'language',
'link',
......@@ -47,27 +44,18 @@ protected function setUp() {
$this->fileMigrationSetup();
$this->installEntitySchema('node');
$this->installEntitySchema('comment');
$this->installEntitySchema('taxonomy_term');
$this->installConfig(static::$modules);
$this->installSchema('comment', ['comment_entity_statistics']);
$this->installSchema('forum', ['forum', 'forum_index']);
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['sequences']);
$this->migrateUsers();
$this->migrateFields();
$this->executeMigrations([
'language',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_language_content_settings',
'd7_comment_type',
'd7_comment_field',
'd7_comment_field_instance',
'd7_taxonomy_vocabulary',
'd7_field',
'd7_field_instance',
'd7_node',
'd7_node_translation',
'd7_entity_translation_settings',
......
......@@ -19,9 +19,8 @@ class MigrateNodeTitleLabelTest extends MigrateDrupal7TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->installEntitySchema('node');
$this->executeMigrations(['d7_node_type', 'd7_node_title_label']);
$this->migrateContentTypes();
$this->executeMigration('d7_node_title_label');
}
/**
......
......@@ -20,15 +20,14 @@ class MigrateNodeTypeTest extends MigrateDrupal7TestBase {
*
* @var array
*/
public static $modules = ['node', 'text', 'filter', 'menu_ui'];
public static $modules = ['node', 'text', 'menu_ui'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
$this->executeMigration('d7_node_type');
$this->migrateContentTypes();
}
/**
......
......@@ -32,18 +32,15 @@ class NodeTranslationRedirectTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig('node');
$this->installSchema('node', ['node_access']);
$this->installSchema('system', ['key_value']);
$this->migrateUsers(FALSE);
$this->migrateContentTypes();
$this->executeMigrations([
'language',
'd7_language_types',
'd7_language_negotiation_settings',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_node',
'd7_node_translation',
]);
......
......@@ -31,15 +31,12 @@ class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig('node');
$this->installSchema('node', ['node_access']);
$this->migrateUsers(FALSE);
$this->migrateContentTypes();
$this->executeMigrations([
'language',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_node',
'd7_node_translation',
'd7_url_alias',
......
......@@ -33,8 +33,7 @@ protected function setUp() {
$this->installEntitySchema('menu_link_content');
$this->installSchema('shortcut', ['shortcut_set_users']);
\Drupal::service('router.builder')->rebuild();
$this->executeMigration('d7_user_role');
$this->executeMigration('d7_user');
$this->migrateUsers(FALSE);
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('d7_menu');
$this->executeMigration('d7_menu_links');
......
......@@ -31,16 +31,13 @@ class MigrateNodeCounterTest extends MigrateDrupal7TestBase {
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installConfig('node');
$this->installSchema('node', ['node_access']);
$this->installSchema('statistics', ['node_counter']);
$this->migrateUsers(FALSE);
$this->migrateContentTypes();
$this->executeMigrations([
'language',
'd7_user_role',
'd7_user',
'd7_node_type',
'd7_language_content_settings',
'd7_node',
'd7_node_translation',
......
......@@ -2,9 +2,6 @@
namespace Drupal\Tests\taxonomy\Kernel\Migrate\d7;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;