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

Commit

Permalink
Merge branch 'hotfix/185' into develop
Browse files Browse the repository at this point in the history
Forward port #185
  • Loading branch information
michalbundyra committed Aug 28, 2019
2 parents 35e1fea + 2ce5f2a commit 26a84ae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#185](https://github.com/zendframework/zend-inputfilter/pull/185) fixes
validation response on invalid file upload request.

- [#181](https://github.com/zendframework/zend-inputfilter/pull/181) fixes
missing abstract service factory registration in `Module` as per the
[latest documentation](https://docs.zendframework.com/zend-inputfilter/specs/#setup).
Expand Down
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 26a84ae

Please sign in to comment.