You are here

public function FilePathTest::testFilePath in Drupal 9

Executes all steps of migrations upgrade.

@dataProvider providerTestFilePath

Parameters

string $file_private_path: The source database file_private_path value.

string $file_public_path: The source database file_public_path value.

string $file_temporary_path: The source database file_temporary_path value.

string $private: The path to the source private files.

string $public: The path to the source public files.

string $temporary: The path to the source temporary files.

File

core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php, line 94

Class

FilePathTest
Tests the Drupal 7 public and private file migrations.

Namespace

Drupal\Tests\migrate_drupal_ui\Functional\d7

Code

public function testFilePath(string $file_private_path, string $file_public_path, string $file_temporary_path, string $private, string $public, string $temporary) {
  $this->sourceFileScheme['private'] = $file_private_path;
  $this->sourceFileScheme['public'] = $file_public_path;
  $this->sourceFileScheme['temporary'] = $file_temporary_path;
  $this->localDirectory['private'] = $private;
  $this->localDirectory['public'] = $public;
  $this->localDirectory['temporary'] = $temporary;

  // Create the source files.
  $this
    ->makeFiles();

  // Set the source db variables.
  $this->sourceDatabase
    ->update('variable')
    ->fields([
    'value' => serialize($file_private_path),
  ])
    ->condition('name', 'file_private_path')
    ->execute();
  $this->sourceDatabase
    ->update('variable')
    ->fields([
    'value' => serialize($file_public_path),
  ])
    ->condition('name', 'file_public_path')
    ->execute();
  $this->sourceDatabase
    ->update('variable')
    ->fields([
    'value' => serialize($file_temporary_path),
  ])
    ->condition('name', 'file_temporary_path')
    ->execute();
  $connection_options = $this->sourceDatabase
    ->getConnectionOptions();
  $driver = $connection_options['driver'];

  // Use the driver connection form to get the correct options out of the
  // database settings. This supports all of the databases we test against.
  $drivers = drupal_get_database_types();
  $form = $drivers[$driver]
    ->getFormOptions($connection_options);
  $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']);
  $edit = [
    $driver => $connection_options,
    'version' => '7',
  ];
  if (count($drivers) !== 1) {
    $edit['driver'] = $driver;
  }

  // Set the public and private base paths for the Credential Form.
  $edit['source_private_file_path'] = $this->fs
    ->realpath($this
    ->getSourcePath('private'));
  $edit['source_base_path'] = $this->fs
    ->realpath($this
    ->getSourcePath('public'));
  $edits = $this
    ->translatePostValues($edit);

  // Start the upgrade.
  $this
    ->drupalGet('/upgrade');
  $this
    ->submitForm([], 'Continue');
  $this
    ->submitForm($edits, 'Review upgrade');

  // The migrations are now in store - remove all but the file migrations.
  $store = \Drupal::service('tempstore.private')
    ->get('migrate_drupal_ui');
  $migration_array = array_intersect_key($store
    ->get('migrations'), array_flip([
    'd7_file',
    'd7_file_private',
  ]));
  $store
    ->set('migrations', $migration_array);

  // Perform the migrations.
  $this
    ->submitForm([], 'Perform upgrade');
  $this
    ->resetAll();
  $this
    ->assertFileMigrations();
}