You are here

public function DownloadTest::testWriteProtectedDestination in Drupal 10

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

Tests that an exception is thrown if the destination URI is not writable.

File

core/modules/migrate/tests/src/Kernel/process/DownloadTest.php, line 62

Class

DownloadTest
Tests the download process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testWriteProtectedDestination() {

  // Create a pre-existing file at the destination.
  $destination_uri = $this
    ->createUri('not-writable.txt');

  // Make the destination non-writable.
  $this->container
    ->get('file_system')
    ->chmod($destination_uri, 0444);

  // Pass or fail, we'll need to make the file writable again so the test
  // can clean up after itself.
  $fix_permissions = function () use ($destination_uri) {
    $this->container
      ->get('file_system')
      ->chmod($destination_uri, 0755);
  };
  try {
    $this
      ->doTransform($destination_uri);
    $fix_permissions();
    $this
      ->fail('MigrateException was not thrown for non-writable destination URI.');
  } catch (MigrateException $e) {
    $this
      ->assertTrue(TRUE, 'MigrateException was thrown for non-writable destination URI.');
    $fix_permissions();
  }
}