You are here

function ValidatorTest::testFileValidateExtensions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/ValidatorTest.php \Drupal\file\Tests\ValidatorTest::testFileValidateExtensions()

Test the file_validate_extensions() function.

File

core/modules/file/src/Tests/ValidatorTest.php, line 46
Contains \Drupal\file\Tests\ValidatorTest.

Class

ValidatorTest
Tests the functions used to validate uploaded files.

Namespace

Drupal\file\Tests

Code

function testFileValidateExtensions() {
  $file = entity_create('file', array(
    'filename' => 'asdf.txt',
  ));
  $errors = file_validate_extensions($file, 'asdf txt pork');
  $this
    ->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File');
  $file
    ->setFilename('asdf.txt');
  $errors = file_validate_extensions($file, 'exe png');
  $this
    ->assertEqual(count($errors), 1, 'Invalid extension blocked.', 'File');
}