3 namespace Drupal\Tests\file\Kernel;
7 * Tests the file_validate() function.
11 class ValidateTest extends FileManagedUnitTestBase {
13 * Test that the validators passed into are checked.
15 public function testCallerValidation() {
16 $file = $this->createFile();
19 $this->assertEqual(file_validate($file, []), [], 'Validating an empty array works successfully.');
20 $this->assertFileHooksCalled(['validate']);
22 // Use the file_test.module's test validator to ensure that passing tests
25 file_test_set_return('validate', []);
26 $passing = ['file_test_validator' => [[]]];
27 $this->assertEqual(file_validate($file, $passing), [], 'Validating passes.');
28 $this->assertFileHooksCalled(['validate']);
30 // Now test for failures in validators passed in and by hook_validate.
32 file_test_set_return('validate', ['Epic fail']);
33 $failing = ['file_test_validator' => [['Failed', 'Badly']]];
34 $this->assertEqual(file_validate($file, $failing), ['Failed', 'Badly', 'Epic fail'], 'Validating returns errors.');
35 $this->assertFileHooksCalled(['validate']);