You are here

public function FileBlobTest::testFileCreation in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php \Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process\FileBlobTest::testFileCreation()

Tests file creation.

@covers ::transform

File

tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php, line 203

Class

FileBlobTest
Tests the file_blob plugin.

Namespace

Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process

Code

public function testFileCreation() {

  /** @var \Drupal\migrate\MigrateExecutableInterface $executable */
  $executable = $this
    ->prophesize(MigrateExecutableInterface::class)
    ->reveal();
  $row = new Row([], []);
  $value = [
    'public://cat.jpeg',
    base64_decode($this->blob, TRUE),
  ];

  /** @var \Drupal\migrate_plus\Plugin\migrate\process\FileBlob $file_blob */
  $file_blob = $this->pluginManager
    ->createInstance('file_blob');
  $file = $file_blob
    ->transform($value, $executable, $row, 'destination_property');
  $this
    ->assertEquals('public://cat.jpeg', $file);
  $this
    ->assertEquals($this->sha1sum, sha1_file($file));

  // TODO: remove after 8.6 is no longer supported in
  // https://www.drupal.org/project/migrate_plus/issues/3035587
  if (version_compare(\Drupal::VERSION, '8.7', '>=')) {
    $configuration = [
      'reuse' => FileSystemInterface::EXISTS_ERROR,
    ];
  }
  else {
    $configuration = [
      'reuse' => FILE_EXISTS_ERROR,
    ];
  }

  /** @var \Drupal\migrate_plus\Plugin\migrate\process\FileBlob $file_blob */
  $file_blob = $this->pluginManager
    ->createInstance('file_blob', $configuration);

  /** @var \Drupal\migrate\MigrateExecutableInterface $executable */
  $file = $file_blob
    ->transform($value, $executable, $row, 'destination_property');
  $this
    ->assertEquals('public://cat.jpeg', $file);
  $this
    ->assertEquals($this->sha1sum, sha1_file($file));
}