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/73' into develop
Browse files Browse the repository at this point in the history
Forward port #73
  • Loading branch information
weierophinney committed Apr 7, 2016
2 parents 239b1d0 + 8b6c26d commit 6c8cff0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#67](https://github.com/zendframework/zend-inputfilter/pull/67) fixes
- [#67](https://github.com/zendframework/zend-inputfilter/pull/67) and
[#73](https://github.com/zendframework/zend-inputfilter/pull/73) fix
localization of the `NotEmpty` validation error message (created for any
required input for which a value was not provided).

Expand Down
11 changes: 10 additions & 1 deletion src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ protected function injectNotEmptyValidator()
*/
protected function prepareRequiredValidationFailureMessage()
{
$notEmpty = $this->getValidatorChain()->plugin(NotEmpty::class);
$chain = $this->getValidatorChain();
$notEmpty = $chain->plugin(NotEmpty::class);

foreach ($chain->getValidators() as $validator) {
if ($validator['instance'] instanceof NotEmpty) {
$notEmpty = $validator['instance'];
break;
}
}

$templates = $notEmpty->getOption('messageTemplates');
$message = $templates[NotEmpty::IS_EMPTY];
$translator = $notEmpty->getTranslator();
Expand Down
33 changes: 33 additions & 0 deletions test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,39 @@ public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidat
$this->assertRequiredValidationErrorMessage($input);
}

/**
* @group 28
* @group 69
*/
public function testRequiredWithoutFallbackAndValueNotSetProvidesAttachedNotEmptyValidatorIsEmptyErrorMessage()
{
$input = new Input();
$input->setRequired(true);

$customMessage = [
NotEmptyValidator::IS_EMPTY => "Custom message",
];

$notEmpty = $this->getMockBuilder(NotEmptyValidator::class)
->setMethods(['getOption'])
->getMock();

$notEmpty->expects($this->once())
->method('getOption')
->with('messageTemplates')
->willReturn($customMessage);

$input->getValidatorChain()
->attach($notEmpty);

$this->assertFalse(
$input->isValid(),
'isValid() should always return false when no fallback value is present, '
. 'the input is required, and no data is set.'
);
$this->assertEquals($customMessage, $input->getMessages());
}

/**
* @group 28
* @group 60
Expand Down

0 comments on commit 6c8cff0

Please sign in to comment.