// Created private files without usage are by default not accessible
// for a user different from the owner, but createFile always uses uid 1
// as the owner of the files. Therefore make it permanent to allow access
// if a module allows it.
$file->setPermanent(); $file->save();
// Test that the file transferred correctly.
$this->assertSame($contents, $this->getSession()->getPage()->getContent(), 'Contents of the file are correct.');
// 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(['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->assertEquals(['Failed', 'Badly', 'Epic fail'], file_validate($file, $failing), 'Validating returns errors.'); $this->assertFileHooksCalled(['validate']); }