You are here

public function DrushWithMigrateUpgradeFromMediaTest::testMigrationWithDrush in Media Migration 8

Tests migrations with Migrate Upgrade, Drush and Migrate Tools.

File

tests/src/Functional/DrushWithMigrateUpgradeFromMediaTest.php, line 29

Class

DrushWithMigrateUpgradeFromMediaTest
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_entity_audio_public',
    'upgrade_d7_file_entity_document_public',
    'upgrade_d7_file_entity_formatter_audio',
    'upgrade_d7_file_entity_formatter_document',
    'upgrade_d7_file_entity_formatter_image',
    'upgrade_d7_file_entity_formatter_remote_video',
    'upgrade_d7_file_entity_formatter_video',
    'upgrade_d7_file_entity_image_public',
    'upgrade_d7_file_entity_source_field_audio',
    'upgrade_d7_file_entity_source_field_config_audio',
    'upgrade_d7_file_entity_source_field_config_document',
    'upgrade_d7_file_entity_source_field_config_image',
    'upgrade_d7_file_entity_source_field_config_remote_video',
    'upgrade_d7_file_entity_source_field_config_video',
    'upgrade_d7_file_entity_source_field_document',
    'upgrade_d7_file_entity_source_field_image',
    'upgrade_d7_file_entity_source_field_remote_video',
    'upgrade_d7_file_entity_source_field_video',
    'upgrade_d7_file_entity_type_audio',
    'upgrade_d7_file_entity_type_document',
    'upgrade_d7_file_entity_type_image',
    'upgrade_d7_file_entity_type_remote_video',
    'upgrade_d7_file_entity_type_video',
    'upgrade_d7_file_entity_video_public',
    'upgrade_d7_file_entity_video_vimeo',
    'upgrade_d7_file_entity_video_youtube',
    'upgrade_d7_file_entity_widget_audio',
    'upgrade_d7_file_entity_widget_document',
    'upgrade_d7_file_entity_widget_image',
    'upgrade_d7_file_entity_widget_remote_video',
    'upgrade_d7_file_entity_widget_video',
    'upgrade_d7_media_view_modes',
  ], array_keys($media_migrations));
  $this
    ->assertAudioMediaMigrations($media_migrations);
  $this
    ->assertDocumentMediaMigrations($media_migrations);
  $this
    ->assertImageMediaMigrations($media_migrations);
  $this
    ->assertRemoteVideoMediaMigrations($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');

  // 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 "content" 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
    ->assertMedia1FieldValues();
  $this
    ->assertMedia2FieldValues();
  $this
    ->assertMedia3FieldValues();
  $this
    ->assertMedia4FieldValues();
  $this
    ->assertMedia5FieldValues();
  $this
    ->assertMedia6FieldValues();
  $this
    ->assertMedia7FieldValues();
  $this
    ->assertMedia8FieldValues();
  $this
    ->assertMedia9FieldValues();
  $this
    ->assertMedia10FieldValues();
  $this
    ->assertMedia11FieldValues();
  $this
    ->assertMedia12FieldValues();
}