You are here

public function HtaccessTest::testFileAccess in Drupal 9

Same name and namespace in other branches
  1. 8 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 104

Class

HtaccessTest
Tests .htaccess is working correctly.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testFileAccess() {
  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');
}