public function ValidateTest::testCallerValidation in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/Kernel/ValidateTest.php \Drupal\Tests\file\Kernel\ValidateTest::testCallerValidation()
Test that the validators passed into are checked.
File
- core/
modules/ file/ tests/ src/ Kernel/ ValidateTest.php, line 15
Class
- ValidateTest
- Tests the file_validate() function.
Namespace
Drupal\Tests\file\KernelCode
public function testCallerValidation() {
$file = $this
->createFile();
// Empty validators.
$this
->assertEqual(file_validate($file, []), [], 'Validating an empty array works successfully.');
$this
->assertFileHooksCalled([
'validate',
]);
// Use the file_test.module's test validator to ensure that passing tests
// return correctly.
file_test_reset();
file_test_set_return('validate', []);
$passing = [
'file_test_validator' => [
[],
],
];
$this
->assertEqual(file_validate($file, $passing), [], 'Validating passes.');
$this
->assertFileHooksCalled([
'validate',
]);
// Now test for failures in validators passed in and by hook_validate.
file_test_reset();
file_test_set_return('validate', [
'Epic fail',
]);
$failing = [
'file_test_validator' => [
[
'Failed',
'Badly',
],
],
];
$this
->assertEqual(file_validate($file, $failing), [
'Failed',
'Badly',
'Epic fail',
], 'Validating returns errors.');
$this
->assertFileHooksCalled([
'validate',
]);
}