class FileExtensionSecureConstraintValidatorTest
Same name and namespace in other branches
- 10 core/modules/file/tests/src/Kernel/Plugin/Validation/Constraint/FileExtensionSecureConstraintValidatorTest.php \Drupal\Tests\file\Kernel\Plugin\Validation\Constraint\FileExtensionSecureConstraintValidatorTest
Tests the FileExtensionSecureConstraintValidator.
@group file
@coversDefaultClass \Drupal\file\Plugin\Validation\Constraint\FileExtensionSecureConstraintValidator
Hierarchy
- class \Drupal\Tests\file\Kernel\Validation\FileValidatorTestBase
- class \Drupal\Tests\file\Kernel\Plugin\Validation\Constraint\FileExtensionSecureConstraintValidatorTest implements \Drupal\Tests\file\Kernel\Validation\FileValidatorTestBase
Expanded class hierarchy of FileExtensionSecureConstraintValidatorTest
File
-
core/
modules/ file/ tests/ src/ Kernel/ Plugin/ Validation/ Constraint/ FileExtensionSecureConstraintValidatorTest.php, line 15
Namespace
Drupal\Tests\file\Kernel\Plugin\Validation\ConstraintView source
class FileExtensionSecureConstraintValidatorTest extends FileValidatorTestBase {
/**
* @covers ::validate
*/
public function testValidate() : void {
// Test success with .txt extension.
$validators = [
'FileExtensionSecure' => [],
];
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(0, $violations);
// Test failure with .php extension.
$this->file
->setFilename('foo.php');
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(1, $violations);
$this->assertEquals('For security reasons, your upload has been rejected.', $violations->get(0)
->getMessage());
// Test success with .php extension and allow_insecure_uploads.
$this->config('system.file')
->set('allow_insecure_uploads', TRUE)
->save();
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(0, $violations);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. | |
ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. | |
FileExtensionSecureConstraintValidatorTest::testValidate | public | function | @covers ::validate[[api-linebreak]] | |
FileValidatorTestBase::$file | protected | property | The file. | |
FileValidatorTestBase::$modules | protected static | property | Modules to install. | 1 |
FileValidatorTestBase::$validator | protected | property | The file validator. | |
FileValidatorTestBase::setUp | protected | function | 2 | |
StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.