function MigrateUploadTest::setUp

Same name in other branches
  1. 8.9.x core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php \Drupal\Tests\file\Kernel\Migrate\d6\MigrateUploadTest::setUp()
  2. 10 core/modules/file/tests/src/Kernel/Migrate/d6/MigrateUploadTest.php \Drupal\Tests\file\Kernel\Migrate\d6\MigrateUploadTest::setUp()
  3. 11.x 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);
}

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