You are here

protected function MigrateUploadTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php \Drupal\Tests\file\Kernel\Migrate\d6\MigrateUploadTest::setUp()

Overrides MigrateDrupal6TestBase::setUp

File

core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php, line 28

Class

MigrateUploadTest
Migrate association data between nodes and files.

Namespace

Drupal\Tests\file\Kernel\Migrate\d6

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('file');
  $this
    ->installEntitySchema('node');
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $id_mappings = [
    'd6_file' => [],
  ];

  // Create new file entities.
  for ($i = 1; $i <= 3; $i++) {
    $file = File::create([
      'fid' => $i,
      'uid' => 1,
      'filename' => 'druplicon.txt',
      'uri' => "public://druplicon-{$i}.txt",
      'filemime' => 'text/plain',
      'created' => 1,
      'changed' => 1,
    ]);
    $file
      ->setPermanent();
    $file
      ->enforceIsNew();
    file_put_contents($file
      ->getFileUri(), 'hello world');

    // Save it, inserting a new record.
    $file
      ->save();
    $id_mappings['d6_file'][] = [
      [
        $i,
      ],
      [
        $i,
      ],
    ];
  }
  $this
    ->prepareMigrations($id_mappings);
  $this
    ->migrateContent([
    'translations',
  ]);

  // Since we are only testing a subset of the file migration, do not check
  // that the full file migration has been run.
  $migration = $this
    ->getMigration('d6_upload');
  $migration
    ->set('requirements', []);
  $this
    ->executeMigration($migration);
}