function HtaccessTest::assertFileAccess

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/System/HtaccessTest.php \Drupal\Tests\system\Functional\System\HtaccessTest::assertFileAccess()
  2. 8.9.x 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 modules/system/system.test
Iterates over protected files and calls assertNoFileAccess().

File

modules/system/system.test, line 3372

Class

HtaccessTest
Tests .htaccess is working correctly.

Code

protected function assertFileAccess($path, $response_code) {
    $this->assertTrue(file_exists(drupal_realpath($path)), format_string('@filename exists.', array(
        '@filename' => $path,
    )));
    $this->drupalGet(file_create_url($path), array(
        'external' => TRUE,
    ));
    $this->assertResponse($response_code, "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.