function DummyStreamWrapperFileTest::testFileUpload
Same name and namespace in other branches
- main core/modules/file/tests/src/Functional/DummyStreamWrapperFileTest.php \Drupal\Tests\file\Functional\DummyStreamWrapperFileTest::testFileUpload()
Tests that overridden cache control works.
Attributes
#[DataProvider('streamWrapperProvider')]
File
-
core/
modules/ file/ tests/ src/ Functional/ DummyStreamWrapperFileTest.php, line 69
Class
- DummyStreamWrapperFileTest
- Tests the file uploading functions.
Namespace
Drupal\Tests\file\FunctionalCode
public function testFileUpload(string $streamWrapper, string $cacheControlHeader, string $fileUrlBasePath) : void {
// Set the stream wrapper value, so we can validate and set the
// Cache-Control header accordingly for testing.
\Drupal::keyValue('file_test')->set('file_test_active_stream_wrapper', $streamWrapper);
$file = \Drupal::service('file.repository')->writeData($this->randomMachineName(), \sprintf('%s://example.txt', $streamWrapper));
$entity = EntityTest::create();
$entity->file_test->target_id = $file->id();
$entity->file_test->display = 1;
$entity->name->value = $this->randomMachineName();
$entity->save();
self::assertStringContainsString($fileUrlBasePath, \Drupal::service('file_url_generator')->generateString($file->getFileUri()));
$this->drupalGet(\Drupal::service('file_url_generator')->generateAbsoluteString($file->getFileUri()));
$this->assertSession()
->responseHeaderContains('Cache-Control', $cacheControlHeader);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.