@@ -124,36 +124,89 @@ public function testRulePresent()
124
124
$ this ->assertTrue ($ v2 ->passes ());
125
125
}
126
126
127
- public function testValidationMessages ()
127
+ public function testSetCustomMessagesInValidator ()
128
128
{
129
- $ validation = $ this ->validator ->make ([
130
- 'email ' => '' ,
131
- 'number ' => 5
129
+ $ this ->validator ->setMessages ([
130
+ 'required ' => 'foo ' ,
131
+ 'email ' => 'bar '
132
+ ]);
133
+
134
+ $ this ->validator ->setMessage ('numeric ' , 'baz ' );
135
+
136
+ $ validation = $ this ->validator ->validate ([
137
+ 'foo ' => null ,
138
+ 'email ' => 'invalid email ' ,
139
+ 'something ' => 'not numeric '
132
140
], [
133
- 'email ' => 'required|email ' ,
134
- 'number ' => 'min:6|max:4|between:1,4 '
141
+ 'foo ' => 'required ' ,
142
+ 'email ' => 'email ' ,
143
+ 'something ' => 'numeric '
144
+ ]);
145
+
146
+ $ errors = $ validation ->errors ();
147
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
148
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
149
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
150
+ }
151
+
152
+ public function testSetCustomMessagesInValidation ()
153
+ {
154
+ $ validation = $ this ->validator ->make ([
155
+ 'foo ' => null ,
156
+ 'email ' => 'invalid email ' ,
157
+ 'something ' => 'not numeric '
135
158
], [
136
- 'email.required ' => 'Kolom email tidak boleh kosong ' ,
137
- 'required ' => ':attribute harus diisi ' ,
138
- 'number.max ' => 'number > :max ' ,
139
- 'number.min ' => 'number < :min ' ,
140
- 'number.between ' => ':min - :max '
159
+ 'foo ' => 'required ' ,
160
+ 'email ' => 'email ' ,
161
+ 'something ' => 'numeric '
141
162
]);
142
163
143
- $ validation ->setAlias ('email ' , 'e-mail ' );
164
+ $ validation ->setMessages ([
165
+ 'required ' => 'foo ' ,
166
+ 'email ' => 'bar '
167
+ ]);
168
+
169
+ $ validation ->setMessage ('numeric ' , 'baz ' );
170
+
144
171
$ validation ->validate ();
145
172
146
173
$ errors = $ validation ->errors ();
174
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'foo ' );
175
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'bar ' );
176
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'baz ' );
177
+ }
147
178
148
- $ first_error = $ errors ->first ('email ' );
149
- $ error_required = $ errors ->get ('email ' , 'required ' );
150
-
151
- $ this ->assertEquals ($ first_error , 'Kolom email tidak boleh kosong ' );
152
- $ this ->assertEquals ($ error_required , 'Kolom email tidak boleh kosong ' );
179
+ public function testSetAttributeAliases ()
180
+ {
181
+ $ validation = $ this ->validator ->make ([
182
+ 'foo ' => null ,
183
+ 'email ' => 'invalid email ' ,
184
+ 'something ' => 'not numeric '
185
+ ], [
186
+ 'foo ' => 'required ' ,
187
+ 'email ' => 'email ' ,
188
+ 'something ' => 'numeric '
189
+ ]);
190
+
191
+ $ validation ->setMessages ([
192
+ 'required ' => ':attribute foo ' ,
193
+ 'email ' => ':attribute bar ' ,
194
+ 'numeric ' => ':attribute baz '
195
+ ]);
196
+
197
+ $ validation ->setAliases ([
198
+ 'foo ' => 'Foo ' ,
199
+ 'email ' => 'Bar ' ,
200
+ ]);
201
+
202
+ $ validation ->setAlias ('something ' , 'Baz ' );
153
203
154
- $ this ->assertEquals ($ errors ->get ('number ' , 'max ' ), 'number > 4 ' );
155
- $ this ->assertEquals ($ errors ->get ('number ' , 'min ' ), 'number < 6 ' );
156
- $ this ->assertEquals ($ errors ->get ('number ' , 'between ' ), '1 - 4 ' );
204
+ $ validation ->validate ();
205
+
206
+ $ errors = $ validation ->errors ();
207
+ $ this ->assertEquals ($ errors ->get ('foo ' , 'required ' ), 'Foo foo ' );
208
+ $ this ->assertEquals ($ errors ->get ('email ' , 'email ' ), 'Bar bar ' );
209
+ $ this ->assertEquals ($ errors ->get ('something ' , 'numeric ' ), 'Baz baz ' );
157
210
}
158
211
159
212
/**
0 commit comments