You are here

public function FileBlobTest::testFileCreation in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8.4 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() : void {

  /** @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));
  $configuration = [
    'reuse' => FileSystemInterface::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));
}