@@ -552,4 +552,54 @@ public function testValidateCollection()
552
552
$ this ->assertContains ('The input appears to be a local network name but local network names are not allowed ' , $ messages [1 ]['email ' ]);
553
553
// @codingStandardsIgnoreEnd
554
554
}
555
+
556
+ public function testValidateCollectionWithCustomErrorMessage ()
557
+ {
558
+ $ inputFilter = new InputFilter ();
559
+ $ inputFilter ->add ([
560
+ 'name ' => 'email ' ,
561
+ 'required ' => true ,
562
+ 'validators ' => [
563
+ ['name ' => EmailAddress::class],
564
+ ['name ' => NotEmpty::class],
565
+ ],
566
+ 'error_message ' => 'CUSTOM ERROR MESSAGE ' ,
567
+ ]);
568
+ $ inputFilter ->add ([
569
+ 'name ' => 'name ' ,
570
+ 'required ' => true ,
571
+ 'validators ' => [
572
+ ['name ' => NotEmpty::class],
573
+ ],
574
+ ]);
575
+
576
+ $ collectionInputFilter = $ this ->inputFilter ;
577
+ $ collectionInputFilter ->setInputFilter ($ inputFilter );
578
+
579
+ $ collectionInputFilter ->setData ([
580
+ [
581
+ 'name ' => 'Tom ' ,
582
+ ],
583
+ [
584
+ 'email ' => 'tom@tom ' ,
585
+ 'name ' => 'Tom ' ,
586
+ ],
587
+ ]);
588
+
589
+ $ isValid = $ collectionInputFilter ->isValid ();
590
+ $ messages = $ collectionInputFilter ->getMessages ();
591
+
592
+
593
+ $ this ->assertFalse ($ isValid );
594
+ $ this ->assertCount (2 , $ messages );
595
+
596
+ $ this ->assertArrayHasKey ('email ' , $ messages [0 ]);
597
+ $ this ->assertCount (1 , $ messages [0 ]['email ' ]);
598
+ $ this ->assertContains ('CUSTOM ERROR MESSAGE ' , $ messages [0 ]['email ' ]);
599
+ $ this ->assertNotContains ('Value is required and can \'t be empty ' , $ messages [0 ]['email ' ]);
600
+
601
+ $ this ->assertArrayHasKey ('email ' , $ messages [1 ]);
602
+ $ this ->assertCount (1 , $ messages [1 ]['email ' ]);
603
+ $ this ->assertContains ('CUSTOM ERROR MESSAGE ' , $ messages [1 ]['email ' ]);
604
+ }
555
605
}
0 commit comments