function FileValidateTest::testInsecureExtensions

Tests hard-coded security check in file_validate().

File

modules/simpletest/tests/file.test, line 2415

Class

FileValidateTest
Tests the <a href="/api/drupal/includes%21file.inc/function/file_validate/7.x" title="Checks that a file meets the criteria specified by the validators." class="local">file_validate</a>() 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',
    ));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.