You are here

protected function MigrateFileTest::setUp in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php \Drupal\file\Tests\Migrate\d6\MigrateFileTest::setUp()
  2. 8 core/modules/file/src/Tests/Migrate/d7/MigrateFileTest.php \Drupal\file\Tests\Migrate\d7\MigrateFileTest::setUp()
Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/Migrate/d7/MigrateFileTest.php \Drupal\file\Tests\Migrate\d7\MigrateFileTest::setUp()

Performs setup tasks before each individual test method is run.

Overrides MigrateDrupal7TestBase::setUp

File

core/modules/file/src/Tests/Migrate/d7/MigrateFileTest.php, line 26
Contains \Drupal\file\Tests\Migrate\d7\MigrateFileTest.

Class

MigrateFileTest
Migrates all files in the file_managed table.

Namespace

Drupal\file\Tests\Migrate\d7

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installEntitySchema('file');
  $fs = \Drupal::service('file_system');

  // The public file directory active during the test will serve as the
  // root of the fictional Drupal 7 site we're migrating.
  $fs
    ->mkdir('public://sites/default/files', NULL, TRUE);
  file_put_contents('public://sites/default/files/cube.jpeg', str_repeat('*', 3620));

  /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
  $migration = entity_load('migration', 'd7_file');

  // Set the destination plugin's source_base_path configuration value, which
  // would normally be set by the user running the migration.
  $migration
    ->set('destination', [
    'plugin' => 'entity:file',
    // Note that source_base_path must include a trailing slash because it's
    // prepended directly to the value of the source path property.
    'source_base_path' => $fs
      ->realpath($this->publicFilesDirectory) . '/',
    // This is set in the migration's YAML file, but we need to repeat it
    // here because all the destination configuration must be set at once.
    'source_path_property' => 'filepath',
  ]);
  $this
    ->executeMigration($migration);
}