function UploadedFileValidatorTest::testValidateFail

Same name in other branches
  1. 10 core/modules/file/tests/src/Kernel/Validation/UploadedFileValidatorTest.php \Drupal\Tests\file\Kernel\Validation\UploadedFileValidatorTest::testValidateFail()

@covers ::validate @dataProvider validateProvider

File

core/modules/file/tests/src/Kernel/Validation/UploadedFileValidatorTest.php, line 86

Class

UploadedFileValidatorTest
Tests the uploaded file validator.

Namespace

Drupal\Tests\file\Kernel\Validation

Code

public function testValidateFail(int $errorCode, string $message) : void {
    $uploadedFile = new UploadedFile(path: $this->path, originalName: $this->filename, error: $errorCode, test: TRUE);
    $violations = $this->validator
        ->validate($uploadedFile, [
        'maxSize' => $this->maxSize,
    ]);
    $this->assertCount(1, $violations);
    $violation = $violations->get(0);
    $this->assertInstanceOf(TranslatableMarkup::class, $violation->getMessage());
    $this->assertEquals(sprintf($message, $this->filename), $violation->getMessage());
    $this->assertEquals($errorCode, $violation->getCode());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.