99use Cake \Core \Configure ;
1010use Cake \I18n \I18n ;
1111use Cake \TestSuite \TestCase ;
12+ use Laminas \Diactoros \UploadedFile ;
1213
1314/**
1415 * Tests for Validator.
@@ -83,6 +84,15 @@ public function setUp(): void
8384 'value_0 ' => 'Message from validation_non_default ' ,
8485 'value_1 ' => '' ,
8586 ],
87+ [
88+ 'domain ' => 'validation ' ,
89+ 'locale ' => I18n::getLocale (),
90+ 'context ' => '' ,
91+ 'singular ' => 'mimeType ' ,
92+ 'plural ' => '' ,
93+ 'value_0 ' => 'Valid mime types: {0} ' ,
94+ 'value_1 ' => '' ,
95+ ],
8696 ];
8797 foreach ($ messages as $ row ) {
8898 $ I18nMessages ->save ($ I18nMessages ->newEntity ($ row ));
@@ -92,7 +102,8 @@ public function setUp(): void
92102
93103 $ this ->validator
94104 ->add ('email ' , 'email ' , ['rule ' => 'email ' ])
95- ->add ('field ' , 'comparison ' , ['rule ' => ['comparison ' , '< ' , 50 ]]);
105+ ->add ('field ' , 'comparison ' , ['rule ' => ['comparison ' , '< ' , 50 ]])
106+ ->add ('file ' , 'mimeType ' , ['rule ' => ['mimeType ' , ['image/jpeg, image/png ' ]]]);
96107 }
97108
98109 /**
@@ -102,14 +113,18 @@ public function setUp(): void
102113 */
103114 public function testErrors ()
104115 {
116+ $ file = new UploadedFile (__FILE__ , 1 , UPLOAD_ERR_OK , 'foo.txt ' , 'text/plain ' );
117+
105118 $ errors = $ this ->validator ->validate ([
106119 'email ' => 'foo ' ,
107120 'field ' => '100 ' ,
121+ 'file ' => $ file ,
108122 ]);
109123
110124 $ expected = [
111125 'email ' => ['email ' => 'Enter a valid email ' ],
112126 'field ' => ['comparison ' => 'This value must be less than 50 ' ],
127+ 'file ' => ['mimeType ' => 'Valid mime types: image/jpeg, image/png ' ],
113128 ];
114129 $ this ->assertEquals ($ expected , $ errors );
115130 }
0 commit comments