@@ -174,91 +174,6 @@ public function testRulePresent()
174
174
$ this ->assertTrue ($ v2 ->passes ());
175
175
}
176
176
177
- public function testSetCustomMessagesInValidator ()
178
- {
179
- $ this ->validator ->setMessages ([
180
- 'required ' => 'foo ' ,
181
- 'email ' => 'bar '
182
- ]);
183
-
184
- $ this ->validator ->setMessage ('numeric ' , 'baz ' );
185
-
186
- $ validation = $ this ->validator ->validate ([
187
- 'foo ' => null ,
188
- 'email ' => 'invalid email ' ,
189
- 'something ' => 'not numeric '
190
- ], [
191
- 'foo ' => 'required ' ,
192
- 'email ' => 'email ' ,
193
- 'something ' => 'numeric '
194
- ]);
195
-
196
- $ errors = $ validation ->errors ();
197
- $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
198
- $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
199
- $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
200
- }
201
-
202
- public function testSetCustomMessagesInValidation ()
203
- {
204
- $ validation = $ this ->validator ->make ([
205
- 'foo ' => null ,
206
- 'email ' => 'invalid email ' ,
207
- 'something ' => 'not numeric '
208
- ], [
209
- 'foo ' => 'required ' ,
210
- 'email ' => 'email ' ,
211
- 'something ' => 'numeric '
212
- ]);
213
-
214
- $ validation ->setMessages ([
215
- 'required ' => 'foo ' ,
216
- 'email ' => 'bar '
217
- ]);
218
-
219
- $ validation ->setMessage ('numeric ' , 'baz ' );
220
-
221
- $ validation ->validate ();
222
-
223
- $ errors = $ validation ->errors ();
224
- $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
225
- $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
226
- $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
227
- }
228
-
229
- public function testSetAttributeAliases ()
230
- {
231
- $ validation = $ this ->validator ->make ([
232
- 'foo ' => null ,
233
- 'email ' => 'invalid email ' ,
234
- 'something ' => 'not numeric '
235
- ], [
236
- 'foo ' => 'required ' ,
237
- 'email ' => 'email ' ,
238
- 'something ' => 'numeric '
239
- ]);
240
-
241
- $ validation ->setMessages ([
242
- 'required ' => ':attribute foo ' ,
243
- 'email ' => ':attribute bar ' ,
244
- 'numeric ' => ':attribute baz '
245
- ]);
246
-
247
- $ validation ->setAliases ([
248
- 'foo ' => 'Foo ' ,
249
- 'email ' => 'Bar ' ,
250
- ]);
251
-
252
- $ validation ->setAlias ('something ' , 'Baz ' );
253
-
254
- $ validation ->validate ();
255
-
256
- $ errors = $ validation ->errors ();
257
- $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'Foo foo ' );
258
- $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'Bar bar ' );
259
- $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'Baz baz ' );
260
- }
261
-
262
177
/**
263
178
* @expectedException \Rakit\Validation\RuleNotFoundException
264
179
*/
@@ -526,4 +441,111 @@ public function testArrayValidation()
526
441
$ this ->assertNotNull ($ errors ->get ('cart_items.3.qty ' , 'numeric ' ));
527
442
$ this ->assertNotNull ($ errors ->get ('cart_items.4.id_product ' , 'numeric ' ));
528
443
}
444
+
445
+ public function testSetCustomMessagesInValidator ()
446
+ {
447
+ $ this ->validator ->setMessages ([
448
+ 'required ' => 'foo ' ,
449
+ 'email ' => 'bar ' ,
450
+ 'comments.*.text ' => 'baz '
451
+ ]);
452
+
453
+ $ this ->validator ->setMessage ('numeric ' , 'baz ' );
454
+
455
+ $ validation = $ this ->validator ->validate ([
456
+ 'foo ' => null ,
457
+ 'email ' => 'invalid email ' ,
458
+ 'something ' => 'not numeric ' ,
459
+ 'comments ' => [
460
+ ['id ' => 4 , 'text ' => '' ],
461
+ ['id ' => 5 , 'text ' => 'foo ' ],
462
+ ]
463
+ ], [
464
+ 'foo ' => 'required ' ,
465
+ 'email ' => 'email ' ,
466
+ 'something ' => 'numeric ' ,
467
+ 'comments.*.text ' => 'required '
468
+ ]);
469
+
470
+ $ errors = $ validation ->errors ();
471
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
472
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
473
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
474
+ $ this ->assertEquals ($ errors ->get ('comments.0.text ' , 'required ' ), 'baz ' );
475
+ }
476
+
477
+ public function testSetCustomMessagesInValidation ()
478
+ {
479
+ $ validation = $ this ->validator ->make ([
480
+ 'foo ' => null ,
481
+ 'email ' => 'invalid email ' ,
482
+ 'something ' => 'not numeric ' ,
483
+ 'comments ' => [
484
+ ['id ' => 4 , 'text ' => '' ],
485
+ ['id ' => 5 , 'text ' => 'foo ' ],
486
+ ]
487
+ ], [
488
+ 'foo ' => 'required ' ,
489
+ 'email ' => 'email ' ,
490
+ 'something ' => 'numeric ' ,
491
+ 'comments.*.text ' => 'required '
492
+ ]);
493
+
494
+ $ validation ->setMessages ([
495
+ 'required ' => 'foo ' ,
496
+ 'email ' => 'bar ' ,
497
+ 'comments.*.text ' => 'baz '
498
+ ]);
499
+
500
+ $ validation ->setMessage ('numeric ' , 'baz ' );
501
+
502
+ $ validation ->validate ();
503
+
504
+ $ errors = $ validation ->errors ();
505
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
506
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
507
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
508
+ $ this ->assertEquals ($ errors ->get ('comments.0.text ' , 'required ' ), 'baz ' );
509
+ }
510
+
511
+ public function testSetAttributeAliases ()
512
+ {
513
+ $ validation = $ this ->validator ->make ([
514
+ 'foo ' => null ,
515
+ 'email ' => 'invalid email ' ,
516
+ 'something ' => 'not numeric ' ,
517
+ 'comments ' => [
518
+ ['id ' => 4 , 'text ' => '' ],
519
+ ['id ' => 5 , 'text ' => 'foo ' ],
520
+ ]
521
+ ], [
522
+ 'foo ' => 'required ' ,
523
+ 'email ' => 'email ' ,
524
+ 'something ' => 'numeric ' ,
525
+ 'comments.*.text ' => 'required '
526
+ ]);
527
+
528
+ $ validation ->setMessages ([
529
+ 'required ' => ':attribute foo ' ,
530
+ 'email ' => ':attribute bar ' ,
531
+ 'numeric ' => ':attribute baz ' ,
532
+ 'comments.*.text ' => ':attribute qux '
533
+ ]);
534
+
535
+ $ validation ->setAliases ([
536
+ 'foo ' => 'Foo ' ,
537
+ 'email ' => 'Bar '
538
+ ]);
539
+
540
+ $ validation ->setAlias ('something ' , 'Baz ' );
541
+ $ validation ->setAlias ('comments.*.text ' , 'Qux ' );
542
+
543
+ $ validation ->validate ();
544
+
545
+ $ errors = $ validation ->errors ();
546
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'Foo foo ' );
547
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'Bar bar ' );
548
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'Baz baz ' );
549
+ $ this ->assertEquals ($ errors ->get ('comments.0.text ' , 'required ' ), 'Qux qux ' );
550
+ }
529
551
}
0 commit comments