function HtaccessTest::testFileAccess

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

Iterates over protected files and calls assertNoFileAccess().

File

core/modules/system/tests/src/Functional/System/HtaccessTest.php, line 108

Class

HtaccessTest
Tests .htaccess is working correctly.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testFileAccess() : void {
    foreach ($this->getProtectedFiles() as $file => $response_code) {
        $this->assertFileAccess($file, $response_code);
    }
    // Test that adding "/1" to a .php URL does not make it accessible.
    $this->drupalGet('core/lib/Drupal.php/1');
    $this->assertSession()
        ->statusCodeEquals(403);
    // Test that it is possible to have path aliases containing .php.
    $type = $this->drupalCreateContentType();
    // Create a node aliased to test.php.
    $node = $this->drupalCreateNode([
        'title' => 'This is a node',
        'type' => $type->id(),
        'path' => '/test.php',
    ]);
    $node->save();
    $this->drupalGet('test.php');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains('This is a node');
    // Update node's alias to test.php/test.
    $node->path = '/test.php/test';
    $node->save();
    $this->drupalGet('test.php/test');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains('This is a node');
}

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