function FileCopyTest::testSuccessfulMoves

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulMoves()
  2. 10 core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulMoves()
  3. 11.x core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php \Drupal\Tests\migrate\Kernel\process\FileCopyTest::testSuccessfulMoves()

Test 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) {
        list($source_path, $destination_path) = $data;
        $actual_destination = $this->doTransform($source_path, $destination_path, [
            'move' => TRUE,
        ]);
        $this->assertFileExists($destination_path);
        $this->assertFileNotExists($source_path);
        $this->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.