function SecurityFileUploadEventSubscriberTest::testSanitizeNameNoMunge
Same name in other branches
- 10 core/modules/system/tests/src/Unit/Event/SecurityFileUploadEventSubscriberTest.php \Drupal\Tests\system\Unit\Event\SecurityFileUploadEventSubscriberTest::testSanitizeNameNoMunge()
- 11.x core/modules/system/tests/src/Unit/Event/SecurityFileUploadEventSubscriberTest.php \Drupal\Tests\system\Unit\Event\SecurityFileUploadEventSubscriberTest::testSanitizeNameNoMunge()
Tests file name sanitization without file munging.
@dataProvider provideFilenamesNoMunge
@covers ::sanitizeName
Parameters
string $filename: The original filename.
string $allowed_extensions: The allowed extensions.
File
-
core/
modules/ system/ tests/ src/ Unit/ Event/ SecurityFileUploadEventSubscriberTest.php, line 107
Class
- SecurityFileUploadEventSubscriberTest
- SecurityFileUploadEventSubscriber tests.
Namespace
Drupal\Tests\system\Unit\EventCode
public function testSanitizeNameNoMunge(string $filename, string $allowed_extensions) {
$config_factory = $this->getConfigFactoryStub([
'system.file' => [
'allow_insecure_uploads' => FALSE,
],
]);
$subscriber = new SecurityFileUploadEventSubscriber($config_factory);
$event = new FileUploadSanitizeNameEvent($filename, $allowed_extensions);
$subscriber->sanitizeName($event);
// Check the results of the configured sanitization.
$this->assertSame($filename, $event->getFilename());
$this->assertSame(FALSE, $event->isSecurityRename());
$config_factory = $this->getConfigFactoryStub([
'system.file' => [
'allow_insecure_uploads' => TRUE,
],
]);
$event = new FileUploadSanitizeNameEvent($filename, $allowed_extensions);
$subscriber = new SecurityFileUploadEventSubscriber($config_factory);
$subscriber->sanitizeName($event);
// Check the results of the configured sanitization.
$this->assertSame($filename, $event->getFilename());
$this->assertSame(FALSE, $event->isSecurityRename());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.