function LegacyValidateTest::testCallerValidation
Same name in other branches
- 11.x core/modules/file/tests/src/Kernel/LegacyValidateTest.php \Drupal\Tests\file\Kernel\LegacyValidateTest::testCallerValidation()
Tests that the validators passed into are checked.
File
-
core/
modules/ file/ tests/ src/ Kernel/ LegacyValidateTest.php, line 18
Class
- LegacyValidateTest
- Tests the file_validate() function.
Namespace
Drupal\Tests\file\KernelCode
public function testCallerValidation() : void {
$file = $this->createFile();
// Empty validators.
$this->expectDeprecation('file_validate() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'file.validator\' service instead. See https://www.drupal.org/node/3363700');
$this->assertEquals([], file_validate($file, []), 'Validating an empty array works successfully.');
$this->assertFileHooksCalled([]);
// 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->assertEquals([], file_validate($file, $passing), 'Validating passes.');
$this->assertFileHooksCalled([]);
// Now test for failures in validators passed in and by hook_validate.
file_test_reset();
$failing = [
'file_test_validator' => [
[
'Failed',
'Badly',
],
],
];
$this->assertEquals([
'Failed',
'Badly',
], file_validate($file, $failing), 'Validating returns errors.');
$this->assertFileHooksCalled([]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.