17
17
use Zend \InputFilter \Input ;
18
18
use Zend \InputFilter \InputInterface ;
19
19
use Zend \Validator ;
20
- use Zend \Validator \NotEmpty ;
21
20
use Zend \Validator \ValidatorChain ;
22
21
23
22
/**
@@ -35,21 +34,6 @@ public function setUp()
35
34
$ this ->input = new Input ('foo ' );
36
35
}
37
36
38
- public function assertRequiredValidationErrorMessage ($ input , $ message = '' )
39
- {
40
- $ message = $ message ?: 'Expected failure message for required input ' ;
41
- $ message .= '; ' ;
42
-
43
- $ messages = $ input ->getMessages ();
44
- $ this ->assertInternalType ('array ' , $ messages , $ message . ' non-array messages array ' );
45
-
46
- $ notEmpty = new NotEmpty ();
47
- $ messageTemplates = $ notEmpty ->getOption ('messageTemplates ' );
48
- $ this ->assertSame ([
49
- NotEmpty::IS_EMPTY => $ messageTemplates [NotEmpty::IS_EMPTY ],
50
- ], $ messages , $ message . ' missing NotEmpty::IS_EMPTY key and/or contains additional messages ' );
51
- }
52
-
53
37
public function testConstructorRequiresAName ()
54
38
{
55
39
$ this ->assertEquals ('foo ' , $ this ->input ->getName ());
@@ -184,59 +168,28 @@ public function testRequiredWithoutFallbackAndValueNotSetThenFail()
184
168
$ input = $ this ->input ;
185
169
$ input ->setRequired (true );
186
170
187
- $ this ->assertFalse (
188
- $ input ->isValid (),
189
- 'isValid() should be return always false when no fallback value, is required, and not data is set. '
190
- );
191
- $ this ->assertRequiredValidationErrorMessage ($ input );
192
- }
193
-
194
- public function testRequiredWithoutFallbackAndValueNotSetThenFailReturnsCustomErrorMessageWhenSet ()
195
- {
196
- $ input = $ this ->input ;
197
- $ input ->setRequired (true );
198
- $ input ->setErrorMessage ('FAILED TO VALIDATE ' );
171
+ $ expectedMessages = [
172
+ 'inputRequired ' => 'Value is required ' ,
173
+ ];
199
174
200
175
$ this ->assertFalse (
201
176
$ input ->isValid (),
202
177
'isValid() should be return always false when no fallback value, is required, and not data is set. '
203
178
);
204
- $ this ->assertSame ([ ' FAILED TO VALIDATE ' ] , $ input ->getMessages ());
179
+ $ this ->assertEquals ( $ expectedMessages , $ input ->getMessages (), ' getMessages() value not match ' );
205
180
}
206
181
207
- /**
208
- * @group 28
209
- * @group 60
210
- */
211
- public function testRequiredWithoutFallbackAndValueNotSetProvidesNotEmptyValidatorIsEmptyErrorMessage ()
212
- {
213
- $ input = $ this ->input ;
214
- $ input ->setRequired (true );
215
-
216
- $ this ->assertFalse (
217
- $ input ->isValid (),
218
- 'isValid() should always return false when no fallback value is present, '
219
- . 'the input is required, and no data is set. '
220
- );
221
- $ this ->assertRequiredValidationErrorMessage ($ input );
222
- }
223
-
224
- /**
225
- * @group 28
226
- * @group 60
227
- */
228
- public function testRequiredWithoutFallbackAndValueNotSetProvidesCustomErrorMessageWhenSet ()
182
+ public function testRequiredWithoutFallbackAndValueNotSetThenFailWithCustomErrorMessage ()
229
183
{
230
184
$ input = $ this ->input ;
231
185
$ input ->setRequired (true );
232
- $ input ->setErrorMessage ('FAILED TO VALIDATE ' );
186
+ $ input ->setErrorMessage ('fooErrorMessage ' );
233
187
234
188
$ this ->assertFalse (
235
189
$ input ->isValid (),
236
- 'isValid() should always return false when no fallback value is present, '
237
- . 'the input is required, and no data is set. '
190
+ 'isValid() should be return always false when no fallback value, is required, and not data is set. '
238
191
);
239
- $ this ->assertSame (['FAILED TO VALIDATE ' ], $ input ->getMessages ());
192
+ $ this ->assertEquals (['fooErrorMessage ' ], $ input ->getMessages (), ' getMessages() value not match ' );
240
193
}
241
194
242
195
public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid ()
0 commit comments