class FileUploadSanitizeNameEventTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/File/FileUploadSanitizeNameEventTest.php \Drupal\Tests\Core\File\FileUploadSanitizeNameEventTest
- 10 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 \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\File\FileUploadSanitizeNameEventTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of FileUploadSanitizeNameEventTest
File
-
core/
tests/ Drupal/ Tests/ Core/ File/ FileUploadSanitizeNameEventTest.php, line 18
Namespace
Drupal\Tests\Core\FileView source
class FileUploadSanitizeNameEventTest extends UnitTestCase {
/**
* @covers ::setFilename
* @covers ::getFilename
*/
public function testSetFilename() : void {
$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() : void {
$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() : void {
$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() : void {
$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) : void {
$event = new FileUploadSanitizeNameEvent($filename, '');
$this->assertSame($filename, $event->getFilename());
}
/**
* Provides data for testEventFilenameFunctions().
*
* @return array
* Arrays with original file name.
*/
public static 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() : void {
$this->expectException(\RuntimeException::class);
$event = new FileUploadSanitizeNameEvent('test.txt', '');
$event->stopPropagation();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
FileUploadSanitizeNameEventTest::provideFilenames | public static | function | Provides data for testEventFilenameFunctions(). | |
FileUploadSanitizeNameEventTest::testAllowedExtensions | public | function | @covers ::getAllowedExtensions | |
FileUploadSanitizeNameEventTest::testConstructorException | public | function | @covers ::__construct @covers ::setFilename |
|
FileUploadSanitizeNameEventTest::testEventFilenameFunctions | public | function | Test event construction. | |
FileUploadSanitizeNameEventTest::testSetFilename | public | function | @covers ::setFilename @covers ::getFilename |
|
FileUploadSanitizeNameEventTest::testSetFilenameException | public | function | @covers ::setFilename | |
FileUploadSanitizeNameEventTest::testStopPropagation | public | function | @covers ::stopPropagation | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.