You are here

public function FileCopyTest::testSuccessfulCopies in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulCopies()

Tests successful imports/copies.

File

core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php, line 47

Class

FileCopyTest
Tests the file_copy process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testSuccessfulCopies() {
  $file = $this
    ->createUri(NULL, NULL, 'temporary');
  $file_absolute = $this->fileSystem
    ->realpath($file);
  $data_sets = [
    // Test a local to local copy.
    [
      $this->root . '/core/tests/fixtures/files/image-test.jpg',
      'public://file1.jpg',
    ],
    // Test a temporary file using an absolute path.
    [
      $file_absolute,
      'temporary://test.jpg',
    ],
    // Test a temporary file using a relative path.
    [
      $file_absolute,
      'temporary://core/tests/fixtures/files/test.jpg',
    ],
  ];
  foreach ($data_sets as $data) {
    list($source_path, $destination_path) = $data;
    $actual_destination = $this
      ->doTransform($source_path, $destination_path);
    $this
      ->assertFileExists($destination_path);

    // Make sure we didn't accidentally do a move.
    $this
      ->assertFileExists($source_path);
    $this
      ->assertSame($actual_destination, $destination_path, 'The import returned the copied filename.');
  }
}