function HtaccessTest::assertFileAccess

Same name in other branches
  1. 7.x modules/system/system.test \HtaccessTest::assertFileAccess()
  2. 9 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::assertFileAccess()
  3. 10 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::assertFileAccess()
  4. 11.x 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}");
}

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