You are here

public function FileCopyTest::testNonWritableDestination 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::testNonWritableDestination()
  2. 9 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');
}