FileMigrationTestTrait.php

Same filename and directory in other branches
  1. 9 core/modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php
  2. 8.9.x core/modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php
  3. 10 core/modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php

Namespace

Drupal\Tests\file\Kernel\Migrate\d6

File

core/modules/file/tests/src/Kernel/Migrate/d6/FileMigrationTestTrait.php

View source
<?php

declare (strict_types=1);
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/tests/fixtures';
            $source['constants']['source_base_path'] = $this->root . '/';
            $migration->set('source', $source);
        }
    }

}

Traits

Title Deprecated Summary
FileMigrationTestTrait Helper for setting up a file migration test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.