You are here

protected function MigrateUploadTest::setUp in Zircon Profile 8

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

Performs setup tasks before each individual test method is run.

Overrides MigrateDrupal6TestBase::setUp

File

core/modules/file/src/Tests/Migrate/d6/MigrateUploadTest.php, line 25
Contains \Drupal\file\Tests\Migrate\d6\MigrateUploadTest.

Class

MigrateUploadTest
Migrate association data between nodes and files.

Namespace

Drupal\file\Tests\Migrate\d6

Code

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

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

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

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