public function FileValidateTest::testInsecureExtensions in Drupal 7
Tests hard-coded security check in file_validate().
File
- modules/
simpletest/ tests/ file.test, line 2361 - This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.
Class
- FileValidateTest
- Tests the file_validate() function..
Code
public function testInsecureExtensions() {
$file = $this
->createFile('test.php', 'Invalid PHP');
// Test that file_validate() will check for insecure extensions by default.
$errors = file_validate($file, array());
$this
->assertEqual('For security reasons, your upload has been rejected.', $errors[0]);
$this
->assertFileHooksCalled(array(
'validate',
));
file_test_reset();
// Test that the 'allow_insecure_uploads' is respected.
variable_set('allow_insecure_uploads', 1);
$errors = file_validate($file, array());
$this
->assertEqual(array(), $errors);
$this
->assertFileHooksCalled(array(
'validate',
));
}