function FileTransferTest::testJail

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php \Drupal\Tests\system\Functional\FileTransfer\FileTransferTest::testJail()
  2. 8.9.x core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php \Drupal\Tests\system\Functional\FileTransfer\FileTransferTest::testJail()
  3. 11.x core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php \Drupal\Tests\system\Functional\FileTransfer\FileTransferTest::testJail()

File

core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php, line 79

Class

FileTransferTest
Tests recursive file copy operations with the file transfer jail.

Namespace

Drupal\Tests\system\Functional\FileTransfer

Code

public function testJail() : void {
    $source = $this->_buildFakeModule();
    // This convoluted piece of code is here because our testing framework does
    // not support expecting exceptions.
    $got_it = FALSE;
    try {
        $this->testConnection
            ->copyDirectory($source, sys_get_temp_dir());
    } catch (FileTransferException $e) {
        $got_it = TRUE;
    }
    $this->assertTrue($got_it, 'Was not able to copy a directory outside of the jailed area.');
    $got_it = TRUE;
    try {
        $this->testConnection
            ->copyDirectory($source, $this->root . '/' . PublicStream::basePath());
    } catch (FileTransferException $e) {
        $got_it = FALSE;
    }
    $this->assertTrue($got_it, 'Was able to copy a directory inside of the jailed area');
}

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