You are here

protected function HtaccessTest::assertFileAccess 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::assertFileAccess()
  2. 10 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::assertFileAccess()

Asserts that a file exists and requesting it returns a specific response.

Parameters

string $path: Path to file. Without leading slash.

int $response_code: The expected response code. For example: 200, 403 or 404.

1 call to HtaccessTest::assertFileAccess()
HtaccessTest::testFileAccess in core/modules/system/tests/src/Functional/System/HtaccessTest.php
Iterates over protected files and calls assertNoFileAccess().

File

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

Class

HtaccessTest
Tests .htaccess is working correctly.

Namespace

Drupal\Tests\system\Functional\System

Code

protected function assertFileAccess($path, $response_code) {
  $this
    ->assertFileExists(\Drupal::root() . '/' . $path);
  $this
    ->drupalGet($path);
  $this
    ->assertEquals($response_code, $this
    ->getSession()
    ->getStatusCode(), "Response code to {$path} should be {$response_code}");
}