function DownloadTest::testWriteProtectedDestination

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/process/DownloadTest.php \Drupal\Tests\migrate\Kernel\process\DownloadTest::testWriteProtectedDestination()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/process/DownloadTest.php \Drupal\Tests\migrate\Kernel\process\DownloadTest::testWriteProtectedDestination()
  3. 11.x 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 64

Class

DownloadTest
Tests the download process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

public function testWriteProtectedDestination() : void {
  // 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();
  }
}

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