You are here

FileMigrationTestTrait.php in Drupal 8

File

core/modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php
View source
<?php

namespace Drupal\Tests\file\Kernel\Migrate\d6;

use Drupal\migrate\Plugin\MigrationInterface;

/**
 * Helper for setting up a file migration test.
 */
trait FileMigrationTestTrait {

  /**
   * Setup and execute d6_file migration.
   */
  protected function setUpMigratedFiles() {
    $this
      ->installEntitySchema('file');
    $this
      ->installConfig([
      'file',
    ]);
    $this
      ->executeMigration('d6_file');
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareMigration(MigrationInterface $migration) {

    // File migrations need a source_base_path.
    // @see MigrateUpgradeRunBatch::run
    $destination = $migration
      ->getDestinationConfiguration();
    if ($destination['plugin'] === 'entity:file') {

      // Make sure we have a single trailing slash.
      $source = $migration
        ->getSourceConfiguration();
      $source['site_path'] = 'core/modules/simpletest';
      $source['constants']['source_base_path'] = $this->root . '/';
      $migration
        ->set('source', $source);
    }
  }

}

Traits

Namesort descending Description
FileMigrationTestTrait Helper for setting up a file migration test.