|
11 | 11 |
|
12 | 12 | use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
13 | 13 | use PHPUnit_Framework_TestCase as TestCase;
|
| 14 | +use ReflectionProperty; |
14 | 15 | use stdClass;
|
15 | 16 | use Zend\Filter;
|
16 | 17 | use Zend\Filter\FilterChain;
|
17 | 18 | use Zend\InputFilter\Input;
|
18 | 19 | use Zend\InputFilter\InputInterface;
|
19 | 20 | use Zend\Validator;
|
| 21 | +use Zend\Validator\NotEmpty; |
20 | 22 | use Zend\Validator\ValidatorChain;
|
21 | 23 |
|
22 | 24 | /**
|
@@ -175,17 +177,33 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail()
|
175 | 177 | $this->assertEquals(['Value is required'], $input->getMessages(), 'getMessages() value not match');
|
176 | 178 | }
|
177 | 179 |
|
178 |
| - public function testRequiredWithoutFallbackAndValueNotSetThenFailWithCustomErrorMessage() |
| 180 | + /** |
| 181 | + * @group 28 |
| 182 | + * @group 60 |
| 183 | + */ |
| 184 | + public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage() |
179 | 185 | {
|
180 | 186 | $input = $this->input;
|
181 | 187 | $input->setRequired(true);
|
182 |
| - $input->setErrorMessage('fooErrorMessage'); |
183 | 188 |
|
184 | 189 | $this->assertFalse(
|
185 | 190 | $input->isValid(),
|
186 |
| - 'isValid() should be return always false when no fallback value, is required, and not data is set.' |
| 191 | + 'isValid() should always return false when no fallback value is present, ' |
| 192 | + . 'the input is required, and no data is set.' |
| 193 | + ); |
| 194 | + $messages = $input->getMessages(); |
| 195 | + $this->assertInternalType('array', $messages); |
| 196 | + $this->assertArrayHasKey(NotEmpty::IS_EMPTY, $messages); |
| 197 | + |
| 198 | + $notEmpty = new NotEmpty(); |
| 199 | + $r = new ReflectionProperty($notEmpty, 'messageTemplates'); |
| 200 | + $r->setAccessible(true); |
| 201 | + $messageTemplates = $r->getValue($notEmpty); |
| 202 | + $this->assertEquals( |
| 203 | + $messageTemplates[NotEmpty::IS_EMPTY], |
| 204 | + $messages[NotEmpty::IS_EMPTY], |
| 205 | + 'getMessages() values do not match' |
187 | 206 | );
|
188 |
| - $this->assertEquals(['fooErrorMessage'], $input->getMessages(), 'getMessages() value not match'); |
189 | 207 | }
|
190 | 208 |
|
191 | 209 | public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid()
|
|
0 commit comments