Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / file / tests / src / Kernel / ValidateTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Kernel;
4
5 /**
6  * Tests the file_validate() function.
7  *
8  * @group file
9  */
10 class ValidateTest extends FileManagedUnitTestBase {
11
12   /**
13    * Test that the validators passed into are checked.
14    */
15   public function testCallerValidation() {
16     $file = $this->createFile();
17
18     // Empty validators.
19     $this->assertEqual(file_validate($file, []), [], 'Validating an empty array works successfully.');
20     $this->assertFileHooksCalled(['validate']);
21
22     // Use the file_test.module's test validator to ensure that passing tests
23     // return correctly.
24     file_test_reset();
25     file_test_set_return('validate', []);
26     $passing = ['file_test_validator' => [[]]];
27     $this->assertEqual(file_validate($file, $passing), [], 'Validating passes.');
28     $this->assertFileHooksCalled(['validate']);
29
30     // Now test for failures in validators passed in and by hook_validate.
31     file_test_reset();
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']);
36   }
37
38 }