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

Fixed "Empty validation message for file input when sent array for file input #184" #185

Merged
merged 8 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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