class FileUploadSanitizeNameEventTest in Drupal 10
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/File/FileUploadSanitizeNameEventTest.php \Drupal\Tests\Core\File\FileUploadSanitizeNameEventTest
FileUploadSanitizeNameEvent tests.
@group file @coversDefaultClass \Drupal\Core\File\Event\FileUploadSanitizeNameEvent
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\File\FileUploadSanitizeNameEventTest
Expanded class hierarchy of FileUploadSanitizeNameEventTest
File
- core/
tests/ Drupal/ Tests/ Core/ File/ FileUploadSanitizeNameEventTest.php, line 16
Namespace
Drupal\Tests\Core\FileView source
class FileUploadSanitizeNameEventTest extends UnitTestCase {
/**
* @covers ::setFilename
* @covers ::getFilename
*/
public function testSetFilename() {
$event = new FileUploadSanitizeNameEvent('foo.txt', '');
$this
->assertSame('foo.txt', $event
->getFilename());
$event
->setFilename('foo.html');
$this
->assertSame('foo.html', $event
->getFilename());
}
/**
* @covers ::setFilename
*/
public function testSetFilenameException() {
$event = new FileUploadSanitizeNameEvent('foo.txt', '');
$this
->assertSame('foo.txt', $event
->getFilename());
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('$filename must be a filename with no path information, "bar/foo.html" provided');
$event
->setFilename('bar/foo.html');
}
/**
* @covers ::__construct
* @covers ::setFilename
*/
public function testConstructorException() {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('$filename must be a filename with no path information, "bar/foo.txt" provided');
new FileUploadSanitizeNameEvent('bar/foo.txt', '');
}
/**
* @covers ::getAllowedExtensions
*/
public function testAllowedExtensions() {
$event = new FileUploadSanitizeNameEvent('foo.txt', '');
$this
->assertSame([], $event
->getAllowedExtensions());
$event = new FileUploadSanitizeNameEvent('foo.txt', 'gif png');
$this
->assertSame([
'gif',
'png',
], $event
->getAllowedExtensions());
}
/**
* Test event construction.
*
* @dataProvider provideFilenames
* @covers ::__construct
* @covers ::getFilename
*
* @param string $filename
* The filename to test
*/
public function testEventFilenameFunctions(string $filename) {
$event = new FileUploadSanitizeNameEvent($filename, '');
$this
->assertSame($filename, $event
->getFilename());
}
/**
* Provides data for testEventFilenameFunctions().
*
* @return array
* Arrays with original file name.
*/
public function provideFilenames() {
return [
'ASCII filename with extension' => [
'example.txt',
],
'ASCII filename with complex extension' => [
'example.html.twig',
],
'ASCII filename with lots of dots' => [
'dotty.....txt',
],
'Unicode filename with extension' => [
'Ä Ö Ü Å Ø äöüåøhello.txt',
],
'Unicode filename without extension' => [
'Ä Ö Ü Å Ø äöüåøhello',
],
];
}
/**
* @covers ::stopPropagation
*/
public function testStopPropagation() {
$this
->expectException(\RuntimeException::class);
$event = new FileUploadSanitizeNameEvent('test.txt', '');
$event
->stopPropagation();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileUploadSanitizeNameEventTest:: |
public | function | Provides data for testEventFilenameFunctions(). | |
FileUploadSanitizeNameEventTest:: |
public | function | @covers ::getAllowedExtensions | |
FileUploadSanitizeNameEventTest:: |
public | function | @covers ::__construct @covers ::setFilename | |
FileUploadSanitizeNameEventTest:: |
public | function | Test event construction. | |
FileUploadSanitizeNameEventTest:: |
public | function | @covers ::setFilename @covers ::getFilename | |
FileUploadSanitizeNameEventTest:: |
public | function | @covers ::setFilename | |
FileUploadSanitizeNameEventTest:: |
public | function | @covers ::stopPropagation | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 206 | |
UnitTestCase:: |
public static | function |