public function ValidatorTest::testFileValidateNameLength in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/Kernel/ValidatorTest.php \Drupal\Tests\file\Kernel\ValidatorTest::testFileValidateNameLength()
This will ensure the filename length is valid.
File
- core/
modules/ file/ tests/ src/ Kernel/ ValidatorTest.php, line 121
Class
- ValidatorTest
- Tests the functions used to validate uploaded files.
Namespace
Drupal\Tests\file\KernelCode
public function testFileValidateNameLength() {
// Create a new file entity.
$file = File::create();
// Add a filename with an allowed length and test it.
$file
->setFilename(str_repeat('x', 240));
$this
->assertEqual(strlen($file
->getFilename()), 240);
$errors = file_validate_name_length($file);
$this
->assertCount(0, $errors, 'No errors reported for 240 length filename.');
// Add a filename with a length too long and test it.
$file
->setFilename(str_repeat('x', 241));
$errors = file_validate_name_length($file);
$this
->assertCount(1, $errors, 'An error reported for 241 length filename.');
// Add a filename with an empty string and test it.
$file
->setFilename('');
$errors = file_validate_name_length($file);
$this
->assertCount(1, $errors, 'An error reported for 0 length filename.');
}