3 namespace Drupal\Tests\file\Kernel\Migrate\d7;
5 use Drupal\Core\StreamWrapper\PublicStream;
6 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
9 * A trait to setup the file migration.
11 trait FileMigrationSetupTrait {
14 * Prepare the file migration for running.
16 protected function fileMigrationSetup() {
17 $this->installSchema('file', ['file_usage']);
18 $this->installEntitySchema('file');
19 $this->container->get('stream_wrapper_manager')->registerWrapper('public', PublicStream::class, StreamWrapperInterface::NORMAL);
21 $fs = \Drupal::service('file_system');
22 // The public file directory active during the test will serve as the
23 // root of the fictional Drupal 7 site we're migrating.
24 $fs->mkdir('public://sites/default/files', NULL, TRUE);
25 file_put_contents('public://sites/default/files/cube.jpeg', str_repeat('*', 3620));
27 /** @var \Drupal\migrate\Plugin\Migration $migration */
28 $migration = $this->getMigration('d7_file');
29 // Set the source plugin's source_base_path configuration value, which
30 // would normally be set by the user running the migration.
31 $source = $migration->getSourceConfiguration();
32 $source['constants']['source_base_path'] = $fs->realpath('public://');
33 $migration->set('source', $source);
34 $this->executeMigration($migration);