function ImageStyleDownloadAccessControlTest::testNonPublicSchemeInvokesFileDownloadHook
Same name and namespace in other branches
- 11.x core/modules/image/tests/src/Functional/ImageStyleDownloadAccessControlTest.php \Drupal\Tests\image\Functional\ImageStyleDownloadAccessControlTest::testNonPublicSchemeInvokesFileDownloadHook()
Tests that hook_file_download runs for non-public scheme derivatives.
File
-
core/
modules/ image/ tests/ src/ Functional/ ImageStyleDownloadAccessControlTest.php, line 118
Class
- ImageStyleDownloadAccessControlTest
- Tests access control for downloading image styles.
Namespace
Drupal\Tests\image\FunctionalCode
public function testNonPublicSchemeInvokesFileDownloadHook() : void {
$this->fileSystem
->copy(\Drupal::root() . '/core/tests/fixtures/files/image-1.png', 'image-test-dummy://image.png');
$token = $this->style
->getPathToken('image-test-dummy://image.png');
$url = Url::fromRoute('image_module_test.image_style_protected', [
'image_style' => $this->style
->id(),
'scheme' => 'image-test-dummy',
], [
'query' => [
'file' => 'image.png',
ImageStyleInterface::TOKEN => $token,
],
'absolute' => TRUE,
])
->toString();
// The hook denies by default, so the derivative must not be served.
$this->drupalGet($url);
$this->assertSession()
->statusCodeEquals(403);
// Set the state variable so that file download hook in image_module_test
// allows the access of the file.
\Drupal::state()->set('image_module_test.allow_image_test_dummy', TRUE);
$this->drupalGet($url);
$this->assertSession()
->statusCodeEquals(200);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.