You are here

public function DrushWithMigrateUpgradeFromFileTest::testMigrationWithDrush in Media Migration 8

Tests migrations with Migrate Upgrade, Drush and Migrate Tools.

File

tests/src/Functional/DrushWithMigrateUpgradeFromFileTest.php, line 36

Class

DrushWithMigrateUpgradeFromFileTest
Tests Migrate Upgrade compatibility and verifies usage steps of README.

Namespace

Drupal\Tests\media_migration\Functional

Code

public function testMigrationWithDrush() {

  // Execute the migrate upgrade drush command from the README.
  // @code
  // drush migrate:upgrade\
  //   --configure-only\
  //   --legacy-db-key=[db-key-of-source-site]\
  //   --legacy-root=[path-to-source-site]
  // @endcode
  $this
    ->drush('migrate:upgrade', [
    '--configure-only',
  ], [
    'legacy-db-key' => $this->sourceDatabase
      ->getKey(),
    'legacy-root' => drupal_get_path('module', 'media_migration') . '/tests/fixtures',
  ]);
  $migrations = $this->container
    ->get('entity_type.manager')
    ->getStorage('migration')
    ->loadMultiple();

  // "D7_field" migration should depend on file entity type image because the
  // "image" media type has an additional number field.
  $this
    ->assertD7FieldMigration($migrations['upgrade_d7_field']);

  // Check the IDs of migrations belonging to media migration.
  $media_migrations = array_filter($migrations, function (MigrationEntityInterface $migration_config) {
    $entity_array = $migration_config
      ->toArray();
    return in_array(MediaMigration::MIGRATION_TAG_MAIN, $entity_array['migration_tags']);
  });
  $this
    ->assertSame([
    'upgrade_d7_file_plain_application_public',
    'upgrade_d7_file_plain_audio_public',
    'upgrade_d7_file_plain_formatter_audio',
    'upgrade_d7_file_plain_formatter_document',
    'upgrade_d7_file_plain_formatter_image',
    'upgrade_d7_file_plain_formatter_video',
    'upgrade_d7_file_plain_image_public',
    'upgrade_d7_file_plain_source_field_audio',
    'upgrade_d7_file_plain_source_field_config_audio',
    'upgrade_d7_file_plain_source_field_config_document',
    'upgrade_d7_file_plain_source_field_config_image',
    'upgrade_d7_file_plain_source_field_config_video',
    'upgrade_d7_file_plain_source_field_document',
    'upgrade_d7_file_plain_source_field_image',
    'upgrade_d7_file_plain_source_field_video',
    'upgrade_d7_file_plain_text_public',
    'upgrade_d7_file_plain_type_audio',
    'upgrade_d7_file_plain_type_document',
    'upgrade_d7_file_plain_type_image',
    'upgrade_d7_file_plain_type_video',
    'upgrade_d7_file_plain_video_public',
    'upgrade_d7_file_plain_widget_audio',
    'upgrade_d7_file_plain_widget_document',
    'upgrade_d7_file_plain_widget_image',
    'upgrade_d7_file_plain_widget_video',
  ], array_keys($media_migrations));
  $this
    ->assertAudioMediaMigrations($media_migrations);
  $this
    ->assertDocumentMediaMigrations($media_migrations);
  $this
    ->assertImageMediaMigrations($media_migrations);
  $this
    ->assertVideoMediaMigrations($media_migrations);

  // Set the migration database connection.
  // @code
  // drush php:eval \
  //   "\Drupal::state()->set('source_db', [
  //      'key' => [db-key-of-source-site],
  //      'target' => 'default',
  //    ]);"
  // @endcode
  // @code
  // drush php:eval \
  //   "\Drupal::state()->set('migrate.fallback_state_key', 'source_db');"
  // @endcode
  $this
    ->drush('php:eval', [
    "\\Drupal::state()->set('source_db', ['key' => {$this->sourceDatabase->getKey()}, 'target' => 'default']);",
  ]);
  $this
    ->drush('php:eval', [
    "\\Drupal::state()->set('migrate.fallback_state_key', 'source_db');",
  ]);
  $this
    ->assertArticleBodyFieldMigrationProcesses('upgrade_d7_node_complete_article', [
    [
      'plugin' => 'get',
      'source' => 'body',
    ],
    [
      'plugin' => 'media_wysiwyg_filter',
    ],
    [
      'plugin' => 'ckeditor_link_file_to_linkit',
    ],
  ]);

  // Execute the migrate import "config" drush command from the README.
  // @code
  // drush migrate:import\
  //   --execute-dependencies\
  //   --group=migrate_drupal_7\
  //   --tag=Configuration
  // @endcode
  $this
    ->drush('migrate:import', [
    '--execute-dependencies',
  ], [
    'group' => 'migrate_drupal_7',
    'tag' => 'Configuration',
  ]);

  // Execute the migrate import "config" drush command from the README.
  // @code
  // drush migrate:import\
  //   --execute-dependencies\
  //   --group=migrate_drupal_7\
  //   --tag=Content
  // @endcode
  $this
    ->drush('migrate:import', [
    '--execute-dependencies',
  ], [
    'group' => 'migrate_drupal_7',
    'tag' => 'Content',
  ]);
  $this
    ->resetAll();
  $this
    ->assertNonMediaToMedia1FieldValues();
  $this
    ->assertNonMediaToMedia2FieldValues();
  $this
    ->assertNonMediaToMedia3FieldValues();
  $this
    ->assertNonMediaToMedia6FieldValues();
  $this
    ->assertNonMediaToMedia7FieldValues();
  $this
    ->assertNonMediaToMedia8FieldValues();
  $this
    ->assertNonMediaToMedia9FieldValues();
  $this
    ->assertNonMediaToMedia10FieldValues();
  $this
    ->assertNonMediaToMedia11FieldValues();
  $this
    ->assertNonMediaToMedia12FieldValues();
}