You are here

public function HtaccessTest::testFileAccess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/HtaccessTest.php \Drupal\system\Tests\System\HtaccessTest::testFileAccess()

Iterates over protected files and calls assertNoFileAccess().

File

core/modules/system/src/Tests/System/HtaccessTest.php, line 95
Contains \Drupal\system\Tests\System\HtaccessTest.

Class

HtaccessTest
Tests .htaccess is working correctly.

Namespace

Drupal\system\Tests\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
    ->assertResponse(403, "Access to core/lib/Drupal.php/1 is denied.");

  // Test that it is possible to have path aliases containing .php.
  $type = $this
    ->drupalCreateContentType();

  // Create an 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
    ->assertResponse(200);
  $this
    ->assertText('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
    ->assertResponse(200);
  $this
    ->assertText('This is a node');
}