class FileUploadSanitizeNameEventTest
Same name and namespace in other branches
- 11.x 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
- 9 core/tests/Drupal/Tests/Core/File/FileUploadSanitizeNameEventTest.php \Drupal\Tests\Core\File\FileUploadSanitizeNameEventTest
FileUploadSanitizeNameEvent tests.
Attributes
#[CoversClass(FileUploadSanitizeNameEvent::class)]
#[Group('file')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- 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 17
Namespace
Drupal\Tests\Core\FileView source
class FileUploadSanitizeNameEventTest extends UnitTestCase {
/**
* Tests set filename.
*
* @legacy-covers ::setFilename
* @legacy-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());
}
/**
* Tests set filename exception.
*/
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');
}
/**
* Tests constructor exception.
*
* @legacy-covers ::__construct
* @legacy-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', '');
}
/**
* Tests allowed extensions.
*
* @legacy-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.
*
* @param string $filename
* The filename to test.
*
* @legacy-covers ::__construct
* @legacy-covers ::getFilename
*/
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() : array {
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',
],
];
}
/**
* Tests stop propagation.
*/
public function testStopPropagation() : void {
$this->expectException(\RuntimeException::class);
$event = new FileUploadSanitizeNameEvent('test.txt', '');
$event->stopPropagation();
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | ||
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | |||
| FileUploadSanitizeNameEventTest::provideFilenames | public static | function | Provides data for testEventFilenameFunctions(). | ||
| FileUploadSanitizeNameEventTest::testAllowedExtensions | public | function | Tests allowed extensions. | ||
| FileUploadSanitizeNameEventTest::testConstructorException | public | function | Tests constructor exception. | ||
| FileUploadSanitizeNameEventTest::testEventFilenameFunctions | public | function | Test event construction. | ||
| FileUploadSanitizeNameEventTest::testSetFilename | public | function | Tests set filename. | ||
| FileUploadSanitizeNameEventTest::testSetFilenameException | public | function | Tests set filename exception. | ||
| FileUploadSanitizeNameEventTest::testStopPropagation | public | function | Tests stop propagation. | ||
| 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::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::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | ||
| UnitTestCase::setUp | protected | function | 366 | ||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.