You are here

public function MigrateFileTest::testFiles in Zircon Profile 8

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

Tests the Drupal 6 files to Drupal 8 migration.

File

core/modules/file/src/Tests/Migrate/d6/MigrateFileTest.php, line 80
Contains \Drupal\file\Tests\Migrate\d6\MigrateFileTest.

Class

MigrateFileTest
file migration.

Namespace

Drupal\file\Tests\Migrate\d6

Code

public function testFiles() {
  $this
    ->assertEntity(1, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1');
  $this
    ->assertEntity(2, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1');
  $this
    ->assertEntity(3, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1');
  $this
    ->assertEntity(5, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1');

  // Test that we can re-import and also test with file_directory_path set.
  \Drupal::database()
    ->truncate(Migration::load('d6_file')
    ->getIdMap()
    ->mapTableName())
    ->execute();

  // Update the file_directory_path.
  Database::getConnection('default', 'migrate')
    ->update('variable')
    ->fields(array(
    'value' => serialize('files/test'),
  ))
    ->condition('name', 'file_directory_path')
    ->execute();
  Database::getConnection('default', 'migrate')
    ->update('variable')
    ->fields(array(
    'value' => serialize($this
      ->getTempFilesDirectory()),
  ))
    ->condition('name', 'file_directory_temp')
    ->execute();
  $migration = \Drupal::entityManager()
    ->getStorage('migration')
    ->loadUnchanged('d6_file');
  $this
    ->executeMigration($migration);
  $file = File::load(2);
  $this
    ->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file
    ->getFileUri());

  // Ensure that a temporary file has been migrated.
  $file = File::load(6);
  $this
    ->assertIdentical('temporary://' . static::getUniqueFilename(), $file
    ->getFileUri());

  // File 7, created in static::migrateDumpAlter(), shares a path with
  // file 5, which means it should be skipped entirely.
  $this
    ->assertNull(File::load(7));
}