function FileCopyTest::testNonWritableDestination

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

Tests that non-writable destination throw an exception.

@covers ::transform

File

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

Class

FileCopyTest
Tests the file_copy process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testNonWritableDestination() {
    $source = $this->createUri('file.txt', NULL, 'temporary');
    // Create the parent location.
    $this->createDirectory('public://dir');
    // Copy the file under public://dir/subdir1/.
    $this->doTransform($source, 'public://dir/subdir1/file.txt');
    // Check that 'subdir1' was created and the file was successfully migrated.
    $this->assertFileExists('public://dir/subdir1/file.txt');
    // Remove all permissions from public://dir to trigger a failure when
    // trying to create a subdirectory 'subdir2' inside public://dir.
    $this->fileSystem
        ->chmod('public://dir', 0);
    // Check that the proper exception is raised.
    $this->expectException(MigrateException::class);
    $this->expectExceptionMessage("Could not create or write to directory 'public://dir/subdir2'");
    $this->doTransform($source, 'public://dir/subdir2/file.txt');
}

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