View source
<?php
namespace Drupal\Tests\media_migration\Kernel\Migrate;
use Drupal\Core\Site\Settings;
use Drupal\media_migration\MediaMigration;
use Drupal\Tests\media_migration\Traits\MediaMigrationTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
abstract class MediaMigrationTestBase extends MigrateDrupalTestBase {
use MediaMigrationTestTrait;
protected $profile = 'standard';
protected function loadFixture($path) {
if (!empty($path)) {
parent::loadFixture($path);
}
}
public function setUp() {
parent::setUp();
$this
->loadFixture($this
->getFixtureFilePath());
$module_handler = \Drupal::moduleHandler();
$this
->installEntitySchema('file');
$this
->installSchema('file', 'file_usage');
if ($module_handler
->moduleExists('node')) {
$this
->installEntitySchema('node');
$this
->installSchema('node', 'node_access');
}
if ($module_handler
->moduleExists('embed')) {
$this
->installEntitySchema('embed_button');
}
if ($module_handler
->moduleExists('media')) {
$this
->installEntitySchema('media');
}
if ($module_handler
->moduleExists('comment')) {
$this
->installEntitySchema('comment');
$this
->installSchema('comment', 'comment_entity_statistics');
}
$this
->installSchema('media_migration', MediaMigration::MEDIA_UUID_PROPHECY_TABLE);
}
protected function setEmbedTokenDestinationFilterPlugin($new_filter_plugin_id) {
$current_filter_plugin_id = MediaMigration::getEmbedTokenDestinationFilterPlugin();
if ($new_filter_plugin_id !== $current_filter_plugin_id) {
$this
->setSetting(MediaMigration::MEDIA_TOKEN_DESTINATION_FILTER_SETTINGS, $new_filter_plugin_id);
}
}
protected function setEmbedMediaReferenceMethod($new_reference_method) {
$current_method = Settings::get(MediaMigration::MEDIA_REFERENCE_METHOD_SETTINGS);
if ($current_method !== $new_reference_method) {
$this
->setSetting(MediaMigration::MEDIA_REFERENCE_METHOD_SETTINGS, $new_reference_method);
}
}
protected function setClassicNodeMigration(bool $classic_node_migration) {
$current_method = Settings::get('migrate_node_migrate_type_classic', FALSE);
if ($current_method !== $classic_node_migration) {
$this
->setSetting('migrate_node_migrate_type_classic', $classic_node_migration);
}
}
protected function executeMediaMigrations(bool $classic_node_migration = FALSE) {
$fs_fixture_path = implode(DIRECTORY_SEPARATOR, [
DRUPAL_ROOT,
drupal_get_path('module', 'media_migration'),
'tests',
'fixtures',
]);
$file_migration = $this
->getMigration('d7_file');
$source = $file_migration
->getSourceConfiguration();
$source['constants']['source_base_path'] = $fs_fixture_path;
$file_migration
->set('source', $source);
$this
->executeMigration($file_migration);
$this
->executeMediaConfigurationMigrations();
$this
->executeMigrations([
'd7_view_modes',
'd7_field',
'd7_comment_type',
'd7_node_type',
'd7_field_instance',
'd7_field_formatter_settings',
'd7_field_instance_widget_settings',
'd7_embed_button_media',
'd7_filter_format',
'd7_user_role',
'd7_user',
'd7_file_entity',
$classic_node_migration ? 'd7_node' : 'd7_node_complete',
]);
}
protected function executeMediaConfigurationMigrations() {
$this
->executeMigrations([
'd7_media_view_modes',
'd7_file_entity_type',
'd7_file_entity_source_field',
'd7_file_entity_source_field_config',
'd7_file_entity_formatter',
'd7_file_entity_widget',
]);
}
}