function FileValidatorTest::testValidate
Same name in other branches
- 10 core/modules/file/tests/src/Kernel/Validation/FileValidatorTest.php \Drupal\Tests\file\Kernel\Validation\FileValidatorTest::testValidate()
Tests the validator.
File
-
core/
modules/ file/ tests/ src/ Kernel/ Validation/ FileValidatorTest.php, line 28
Class
- FileValidatorTest
- Tests the file validator.
Namespace
Drupal\Tests\file\Kernel\ValidationCode
public function testValidate() : void {
// Use plugin IDs to test they work.
// Each Constraint has its own tests under
// core/modules/file/tests/src/Kernel/Plugin/Validation/Constraint.
$validators = [
'FileNameLength' => [],
];
file_test_reset();
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(0, $violations);
$this->assertCount(1, file_test_get_calls('validate'));
file_test_reset();
$this->file
->set('filename', '');
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(1, $violations);
$this->assertEquals($violations[0]->getMessage(), $violations[0]->getMessage(), 'Message names are equal');
$this->assertCount(1, file_test_get_calls('validate'));
file_test_reset();
$this->file
->set('filename', $this->randomMachineName(241));
$violations = $this->validator
->validate($this->file, $validators);
$this->assertCount(1, $violations);
$this->assertEquals("The file's name exceeds the 240 characters limit. Rename the file and try again.", $violations[0]->getMessage());
$this->assertCount(1, file_test_get_calls('validate'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.