77use Cake \Cache \Cache ;
88use Cake \I18n \I18n ;
99use Cake \TestSuite \TestCase ;
10+ use Laminas \Diactoros \UploadedFile ;
1011
1112/**
1213 * Tests for Validator.
@@ -80,6 +81,15 @@ public function setUp(): void
8081 'value_0 ' => 'Message from validation_non_default ' ,
8182 'value_1 ' => '' ,
8283 ],
84+ [
85+ 'domain ' => 'validation ' ,
86+ 'locale ' => I18n::getLocale (),
87+ 'context ' => '' ,
88+ 'singular ' => 'mimeType ' ,
89+ 'plural ' => '' ,
90+ 'value_0 ' => 'Valid mime types: {0} ' ,
91+ 'value_1 ' => '' ,
92+ ],
8393 ];
8494 foreach ($ messages as $ row ) {
8595 $ I18nMessages ->save ($ I18nMessages ->newEntity ($ row ));
@@ -89,7 +99,8 @@ public function setUp(): void
8999
90100 $ this ->validator
91101 ->add ('email ' , 'email ' , ['rule ' => 'email ' ])
92- ->add ('field ' , 'comparison ' , ['rule ' => ['comparison ' , '< ' , 50 ]]);
102+ ->add ('field ' , 'comparison ' , ['rule ' => ['comparison ' , '< ' , 50 ]])
103+ ->add ('file ' , 'mimeType ' , ['rule ' => ['mimeType ' , ['image/jpeg, image/png ' ]]]);
93104 }
94105
95106 /**
@@ -99,14 +110,18 @@ public function setUp(): void
99110 */
100111 public function testErrors ()
101112 {
113+ $ file = new UploadedFile (__FILE__ , 1 , UPLOAD_ERR_OK , 'foo.txt ' , 'text/plain ' );
114+
102115 $ errors = $ this ->validator ->validate ([
103116 'email ' => 'foo ' ,
104117 'field ' => '100 ' ,
118+ 'file ' => $ file ,
105119 ]);
106120
107121 $ expected = [
108122 'email ' => ['email ' => 'Enter a valid email ' ],
109123 'field ' => ['comparison ' => 'This value must be less than 50 ' ],
124+ 'file ' => ['mimeType ' => 'Valid mime types: image/jpeg, image/png ' ],
110125 ];
111126 $ this ->assertEquals ($ expected , $ errors );
112127 }
0 commit comments