diff --git a/composer.json b/composer.json index 32083eac..d5638d7f 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ ], "autoload": { "psr-4": { - "Zend\\InputFilter": "src/" + "Zend\\InputFilter\\": "src/" } }, "require": { diff --git a/src/Input.php b/src/Input.php index 85312c6c..9985b795 100644 --- a/src/Input.php +++ b/src/Input.php @@ -241,7 +241,7 @@ public function merge(InputInterface $input) $this->setErrorMessage($input->getErrorMessage()); $this->setName($input->getName()); $this->setRequired($input->isRequired()); - $this->setValue($input->getValue()); + $this->setValue($input->getRawValue()); $filterChain = $input->getFilterChain(); $this->getFilterChain()->merge($filterChain); diff --git a/test/InputTest.php b/test/InputTest.php index 980ad330..68416b4b 100644 --- a/test/InputTest.php +++ b/test/InputTest.php @@ -215,4 +215,29 @@ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists() $this->assertEquals(1, count($validators)); $this->assertEquals($notEmptyMock, $validators[0]['instance']); } + + public function testMerge() + { + $input = new Input('foo'); + $input->setValue(' 123 '); + $filter = new Filter\StringTrim(); + $input->getFilterChain()->attach($filter); + $validator = new Validator\Digits(); + $input->getValidatorChain()->addValidator($validator); + + $input2 = new Input('bar'); + $input2->merge($input); + $validatorChain = $input->getValidatorChain(); + $filterChain = $input->getFilterChain(); + + $this->assertEquals(' 123 ', $input2->getRawValue()); + $this->assertEquals(1, $validatorChain->count()); + $this->assertEquals(1, $filterChain->count()); + + $validators = $validatorChain->getValidators(); + $this->assertInstanceOf('Zend\Validator\Digits', $validators[0]['instance']); + + $filters = $filterChain->getFilters()->toArray(); + $this->assertInstanceOf('Zend\Filter\StringTrim', $filters[0]); + } }