file_validate_name_length example

/** * This will ensure the filename length is valid. */
  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->assertEquals(240, strlen($file->getFilename()));
    $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.');
  }
Home | Imprint | This part of the site doesn't use cookies.