function HtaccessTest::getProtectedFiles

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::getProtectedFiles()
  2. 8.9.x core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::getProtectedFiles()
  3. 10 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::getProtectedFiles()
  4. 11.x core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::getProtectedFiles()

Get an array of file paths for access testing.

1 call to HtaccessTest::getProtectedFiles()
HtaccessTest::testFileAccess in modules/system/system.test
Iterates over protected files and calls assertNoFileAccess().

File

modules/system/system.test, line 3300

Class

HtaccessTest
Tests .htaccess is working correctly.

Code

protected function getProtectedFiles() {
    drupal_mkdir($path = 'public://' . $this->randomName());
    // Tests the FilesMatch directive which denies access to certain file
    // extensions.
    $file_exts_to_deny = array(
        'engine',
        'inc',
        'info',
        'install',
        'make',
        'module',
        'module~',
        'module.bak',
        'module.orig',
        'module.save',
        'module.swo',
        'module.swp',
        'php~',
        'php.bak',
        'php.orig',
        'php.save',
        'php.swo',
        'php.swp',
        'profile',
        'po',
        'sh',
        'sql',
        'test',
        'theme',
        'tpl.php',
        'xtmpl',
    );
    foreach ($file_exts_to_deny as $file_ext) {
        $file_paths["{$path}/access_test.{$file_ext}"] = 403;
    }
    // Test extensions that should be permitted.
    $file_exts_to_allow = array(
        'php-info.txt',
    );
    foreach ($file_exts_to_allow as $file_ext) {
        $file_paths["{$path}/access_test.{$file_ext}"] = 200;
    }
    // Ensure web server configuration files cannot be accessed.
    $file_paths["{$path}/.htaccess"] = 403;
    $file_paths["{$path}/web.config"] = 403;
    return $file_paths;
}

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