You are here

public function FileCopyTest::testSuccessfulMoves in Drupal 10

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

Tests successful moves.

File

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

Class

FileCopyTest
Tests the file_copy process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testSuccessfulMoves() {
  $file_1 = $this
    ->createUri(NULL, NULL, 'temporary');
  $file_1_absolute = $this->fileSystem
    ->realpath($file_1);
  $file_2 = $this
    ->createUri(NULL, NULL, 'temporary');
  $file_2_absolute = $this->fileSystem
    ->realpath($file_2);
  $local_file = $this
    ->createUri(NULL, NULL, 'public');
  $data_sets = [
    // Test a local to local copy.
    [
      $local_file,
      'public://file1.jpg',
    ],
    // Test a temporary file using an absolute path.
    [
      $file_1_absolute,
      'temporary://test.jpg',
    ],
    // Test a temporary file using a relative path.
    [
      $file_2_absolute,
      'temporary://core/tests/fixtures/files/test.jpg',
    ],
  ];
  foreach ($data_sets as $data) {
    [
      $source_path,
      $destination_path,
    ] = $data;
    $actual_destination = $this
      ->doTransform($source_path, $destination_path, [
      'move' => TRUE,
    ]);
    $this
      ->assertFileExists($destination_path);
    $this
      ->assertFileDoesNotExist($source_path);
    $this
      ->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
  }
}