Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #185 from ruzann/master
Browse files Browse the repository at this point in the history
Fixed "Empty validation message for file input when sent array for file input #184"
  • Loading branch information
michalbundyra committed Aug 28, 2019
2 parents e4101c9 + 2b4b984 commit 7335a4a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/FileInput/HttpServerFileInputDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public function isValid($context = null)
'type' => '',
'error' => UPLOAD_ERR_NO_FILE,
];
} elseif (! isset($rawValue['tmp_name']) && ! isset($rawValue[0]['tmp_name'])) {
// This can happen when sent not file and just array
$rawValue = [
'tmp_name' => '',
'name' => '',
'size' => 0,
'type' => '',
'error' => UPLOAD_ERR_NO_FILE,
];
}

if (is_array($rawValue) && isset($rawValue['tmp_name'])) {
Expand Down
17 changes: 17 additions & 0 deletions test/FileInput/HttpServerFileInputDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ public function testValidationsRunWithoutFileArrayDueToAjaxPost()
$this->assertFalse($this->input->isValid());
}

public function testValidationsRunWithoutFileArrayIsSend()
{
$this->input->setAutoPrependUploadValidator(true);
$this->assertTrue($this->input->getAutoPrependUploadValidator());
$this->assertTrue($this->input->isRequired());
$this->input->setValue([]);
$expectedNormalizedValue = [
'tmp_name' => '',
'name' => '',
'size' => 0,
'type' => '',
'error' => UPLOAD_ERR_NO_FILE,
];
$this->input->setValidatorChain($this->createValidatorChainMock([[$expectedNormalizedValue, null, false]]));
$this->assertFalse($this->input->isValid());
}

public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null)
{
$this->markTestSkipped('Test is not enabled in FileInputTest');
Expand Down

0 comments on commit 7335a4a

Please sign in to comment.