| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* FormHelperTest file
|
|
|
4 |
*
|
|
|
5 |
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
|
|
6 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
7 |
*
|
|
|
8 |
* Licensed under The MIT License
|
|
|
9 |
* For full copyright and license information, please see the LICENSE.txt
|
|
|
10 |
* Redistributions of files must retain the above copyright notice
|
|
|
11 |
*
|
|
|
12 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
13 |
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
|
|
14 |
* @package Cake.Test.Case.View.Helper
|
|
|
15 |
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
App::uses('ClassRegistry', 'Utility');
|
|
|
20 |
App::uses('Controller', 'Controller');
|
|
|
21 |
App::uses('View', 'View');
|
|
|
22 |
App::uses('Model', 'Model');
|
|
|
23 |
App::uses('Security', 'Utility');
|
|
|
24 |
App::uses('CakeRequest', 'Network');
|
|
|
25 |
App::uses('HtmlHelper', 'View/Helper');
|
|
|
26 |
App::uses('FormHelper', 'View/Helper');
|
|
|
27 |
App::uses('Router', 'Routing');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* ContactTestController class
|
|
|
31 |
*
|
|
|
32 |
* @package Cake.Test.Case.View.Helper
|
|
|
33 |
*/
|
|
|
34 |
class ContactTestController extends Controller {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* uses property
|
|
|
38 |
*
|
|
|
39 |
* @var mixed null
|
|
|
40 |
*/
|
|
|
41 |
public $uses = null;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Contact class
|
|
|
46 |
*
|
|
|
47 |
* @package Cake.Test.Case.View.Helper
|
|
|
48 |
*/
|
|
|
49 |
class Contact extends CakeTestModel {
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* useTable property
|
|
|
53 |
*
|
|
|
54 |
* @var boolean
|
|
|
55 |
*/
|
|
|
56 |
public $useTable = false;
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Default schema
|
|
|
60 |
*
|
|
|
61 |
* @var array
|
|
|
62 |
*/
|
|
|
63 |
protected $_schema = array(
|
|
|
64 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
65 |
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
66 |
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
67 |
'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
68 |
'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
69 |
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
|
|
|
70 |
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
71 |
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
|
|
|
72 |
'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
|
|
|
73 |
);
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* validate property
|
|
|
77 |
*
|
|
|
78 |
* @var array
|
|
|
79 |
*/
|
|
|
80 |
public $validate = array(
|
|
|
81 |
'non_existing' => array(),
|
|
|
82 |
'idontexist' => array(),
|
|
|
83 |
'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false),
|
|
|
84 |
'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')),
|
|
|
85 |
'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
|
|
|
86 |
'imrequiredonboth' => array(
|
|
|
87 |
'required' => array('rule' => 'alphaNumeric'),
|
|
|
88 |
),
|
|
|
89 |
'string_required' => 'notEmpty',
|
|
|
90 |
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
|
|
|
91 |
'imrequiredtoo' => array('rule' => 'notEmpty'),
|
|
|
92 |
'required_one' => array('required' => array('rule' => array('notEmpty'))),
|
|
|
93 |
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
|
|
|
94 |
'imalsonotrequired' => array(
|
|
|
95 |
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
|
|
|
96 |
'between' => array('rule' => array('between', 5, 30)),
|
|
|
97 |
),
|
|
|
98 |
'imalsonotrequired2' => array(
|
|
|
99 |
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
|
|
|
100 |
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
|
|
|
101 |
),
|
|
|
102 |
'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true),
|
|
|
103 |
'iamrequiredalways' => array(
|
|
|
104 |
'email' => array('rule' => 'email'),
|
|
|
105 |
'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
|
|
|
106 |
'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
|
|
|
107 |
),
|
|
|
108 |
'boolean_field' => array('rule' => 'boolean')
|
|
|
109 |
);
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* schema method
|
|
|
113 |
*
|
|
|
114 |
* @return void
|
|
|
115 |
*/
|
|
|
116 |
public function setSchema($schema) {
|
|
|
117 |
$this->_schema = $schema;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* hasAndBelongsToMany property
|
|
|
122 |
*
|
|
|
123 |
* @var array
|
|
|
124 |
*/
|
|
|
125 |
public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact'));
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* hasAndBelongsToMany property
|
|
|
129 |
*
|
|
|
130 |
* @var array
|
|
|
131 |
*/
|
|
|
132 |
public $belongsTo = array('User' => array('className' => 'UserForm'));
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* ContactTagsContact class
|
|
|
137 |
*
|
|
|
138 |
* @package Cake.Test.Case.View.Helper
|
|
|
139 |
*/
|
|
|
140 |
class ContactTagsContact extends CakeTestModel {
|
|
|
141 |
|
|
|
142 |
/**
|
|
|
143 |
* useTable property
|
|
|
144 |
*
|
|
|
145 |
* @var boolean
|
|
|
146 |
*/
|
|
|
147 |
public $useTable = false;
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Default schema
|
|
|
151 |
*
|
|
|
152 |
* @var array
|
|
|
153 |
*/
|
|
|
154 |
protected $_schema = array(
|
|
|
155 |
'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
156 |
'contact_tag_id' => array(
|
|
|
157 |
'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
|
|
|
158 |
)
|
|
|
159 |
);
|
|
|
160 |
|
|
|
161 |
/**
|
|
|
162 |
* schema method
|
|
|
163 |
*
|
|
|
164 |
* @return void
|
|
|
165 |
*/
|
|
|
166 |
public function setSchema($schema) {
|
|
|
167 |
$this->_schema = $schema;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* ContactNonStandardPk class
|
|
|
174 |
*
|
|
|
175 |
* @package Cake.Test.Case.View.Helper
|
|
|
176 |
*/
|
|
|
177 |
class ContactNonStandardPk extends Contact {
|
|
|
178 |
|
|
|
179 |
/**
|
|
|
180 |
* primaryKey property
|
|
|
181 |
*
|
|
|
182 |
* @var string
|
|
|
183 |
*/
|
|
|
184 |
public $primaryKey = 'pk';
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
* schema method
|
|
|
188 |
*
|
|
|
189 |
* @return void
|
|
|
190 |
*/
|
|
|
191 |
public function schema($field = false) {
|
|
|
192 |
$this->_schema = parent::schema();
|
|
|
193 |
$this->_schema['pk'] = $this->_schema['id'];
|
|
|
194 |
unset($this->_schema['id']);
|
|
|
195 |
return $this->_schema;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* ContactTag class
|
|
|
202 |
*
|
|
|
203 |
* @package Cake.Test.Case.View.Helper
|
|
|
204 |
*/
|
|
|
205 |
class ContactTag extends Model {
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* useTable property
|
|
|
209 |
*
|
|
|
210 |
* @var boolean
|
|
|
211 |
*/
|
|
|
212 |
public $useTable = false;
|
|
|
213 |
|
|
|
214 |
/**
|
|
|
215 |
* schema definition
|
|
|
216 |
*
|
|
|
217 |
* @var array
|
|
|
218 |
*/
|
|
|
219 |
protected $_schema = array(
|
|
|
220 |
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
221 |
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
|
|
222 |
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
223 |
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
|
|
224 |
);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
/**
|
|
|
228 |
* UserForm class
|
|
|
229 |
*
|
|
|
230 |
* @package Cake.Test.Case.View.Helper
|
|
|
231 |
*/
|
|
|
232 |
class UserForm extends CakeTestModel {
|
|
|
233 |
|
|
|
234 |
/**
|
|
|
235 |
* useTable property
|
|
|
236 |
*
|
|
|
237 |
* @var boolean
|
|
|
238 |
*/
|
|
|
239 |
public $useTable = false;
|
|
|
240 |
|
|
|
241 |
/**
|
|
|
242 |
* hasMany property
|
|
|
243 |
*
|
|
|
244 |
* @var array
|
|
|
245 |
*/
|
|
|
246 |
public $hasMany = array(
|
|
|
247 |
'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
|
|
|
248 |
));
|
|
|
249 |
|
|
|
250 |
/**
|
|
|
251 |
* schema definition
|
|
|
252 |
*
|
|
|
253 |
* @var array
|
|
|
254 |
*/
|
|
|
255 |
protected $_schema = array(
|
|
|
256 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
257 |
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
|
|
|
258 |
'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
|
|
|
259 |
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
|
|
|
260 |
'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
|
|
|
261 |
'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
|
|
|
262 |
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
263 |
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
264 |
);
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
* OpenidUrl class
|
|
|
269 |
*
|
|
|
270 |
* @package Cake.Test.Case.View.Helper
|
|
|
271 |
*/
|
|
|
272 |
class OpenidUrl extends CakeTestModel {
|
|
|
273 |
|
|
|
274 |
/**
|
|
|
275 |
* useTable property
|
|
|
276 |
*
|
|
|
277 |
* @var boolean
|
|
|
278 |
*/
|
|
|
279 |
public $useTable = false;
|
|
|
280 |
|
|
|
281 |
/**
|
|
|
282 |
* belongsTo property
|
|
|
283 |
*
|
|
|
284 |
* @var array
|
|
|
285 |
*/
|
|
|
286 |
public $belongsTo = array('UserForm' => array(
|
|
|
287 |
'className' => 'UserForm', 'foreignKey' => 'user_form_id'
|
|
|
288 |
));
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
* validate property
|
|
|
292 |
*
|
|
|
293 |
* @var array
|
|
|
294 |
*/
|
|
|
295 |
public $validate = array('openid_not_registered' => array());
|
|
|
296 |
|
|
|
297 |
/**
|
|
|
298 |
* schema method
|
|
|
299 |
*
|
|
|
300 |
* @var array
|
|
|
301 |
*/
|
|
|
302 |
protected $_schema = array(
|
|
|
303 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
304 |
'user_form_id' => array(
|
|
|
305 |
'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
|
|
|
306 |
),
|
|
|
307 |
'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
308 |
);
|
|
|
309 |
|
|
|
310 |
/**
|
|
|
311 |
* beforeValidate method
|
|
|
312 |
*
|
|
|
313 |
* @return void
|
|
|
314 |
*/
|
|
|
315 |
public function beforeValidate($options = array()) {
|
|
|
316 |
$this->invalidate('openid_not_registered');
|
|
|
317 |
return true;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
/**
|
|
|
323 |
* ValidateUser class
|
|
|
324 |
*
|
|
|
325 |
* @package Cake.Test.Case.View.Helper
|
|
|
326 |
*/
|
|
|
327 |
class ValidateUser extends CakeTestModel {
|
|
|
328 |
|
|
|
329 |
/**
|
|
|
330 |
* useTable property
|
|
|
331 |
*
|
|
|
332 |
* @var boolean
|
|
|
333 |
*/
|
|
|
334 |
public $useTable = false;
|
|
|
335 |
|
|
|
336 |
/**
|
|
|
337 |
* hasOne property
|
|
|
338 |
*
|
|
|
339 |
* @var array
|
|
|
340 |
*/
|
|
|
341 |
public $hasOne = array('ValidateProfile' => array(
|
|
|
342 |
'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
|
|
|
343 |
));
|
|
|
344 |
|
|
|
345 |
/**
|
|
|
346 |
* schema method
|
|
|
347 |
*
|
|
|
348 |
* @var array
|
|
|
349 |
*/
|
|
|
350 |
protected $_schema = array(
|
|
|
351 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
352 |
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
353 |
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
354 |
'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
|
|
|
355 |
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
356 |
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
357 |
);
|
|
|
358 |
|
|
|
359 |
/**
|
|
|
360 |
* beforeValidate method
|
|
|
361 |
*
|
|
|
362 |
* @return void
|
|
|
363 |
*/
|
|
|
364 |
public function beforeValidate($options = array()) {
|
|
|
365 |
$this->invalidate('email');
|
|
|
366 |
return false;
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
/**
|
|
|
372 |
* ValidateProfile class
|
|
|
373 |
*
|
|
|
374 |
* @package Cake.Test.Case.View.Helper
|
|
|
375 |
*/
|
|
|
376 |
class ValidateProfile extends CakeTestModel {
|
|
|
377 |
|
|
|
378 |
/**
|
|
|
379 |
* useTable property
|
|
|
380 |
*
|
|
|
381 |
* @var boolean
|
|
|
382 |
*/
|
|
|
383 |
public $useTable = false;
|
|
|
384 |
|
|
|
385 |
/**
|
|
|
386 |
* schema property
|
|
|
387 |
*
|
|
|
388 |
* @var array
|
|
|
389 |
*/
|
|
|
390 |
protected $_schema = array(
|
|
|
391 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
392 |
'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
393 |
'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
394 |
'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
395 |
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
396 |
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
397 |
);
|
|
|
398 |
|
|
|
399 |
/**
|
|
|
400 |
* hasOne property
|
|
|
401 |
*
|
|
|
402 |
* @var array
|
|
|
403 |
*/
|
|
|
404 |
public $hasOne = array('ValidateItem' => array(
|
|
|
405 |
'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
|
|
|
406 |
));
|
|
|
407 |
|
|
|
408 |
/**
|
|
|
409 |
* belongsTo property
|
|
|
410 |
*
|
|
|
411 |
* @var array
|
|
|
412 |
*/
|
|
|
413 |
public $belongsTo = array('ValidateUser' => array(
|
|
|
414 |
'className' => 'ValidateUser', 'foreignKey' => 'user_id'
|
|
|
415 |
));
|
|
|
416 |
|
|
|
417 |
/**
|
|
|
418 |
* beforeValidate method
|
|
|
419 |
*
|
|
|
420 |
* @return void
|
|
|
421 |
*/
|
|
|
422 |
public function beforeValidate($options = array()) {
|
|
|
423 |
$this->invalidate('full_name');
|
|
|
424 |
$this->invalidate('city');
|
|
|
425 |
return false;
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
/**
|
|
|
431 |
* ValidateItem class
|
|
|
432 |
*
|
|
|
433 |
* @package Cake.Test.Case.View.Helper
|
|
|
434 |
*/
|
|
|
435 |
class ValidateItem extends CakeTestModel {
|
|
|
436 |
|
|
|
437 |
/**
|
|
|
438 |
* useTable property
|
|
|
439 |
*
|
|
|
440 |
* @var boolean
|
|
|
441 |
*/
|
|
|
442 |
public $useTable = false;
|
|
|
443 |
|
|
|
444 |
/**
|
|
|
445 |
* schema property
|
|
|
446 |
*
|
|
|
447 |
* @var array
|
|
|
448 |
*/
|
|
|
449 |
protected $_schema = array(
|
|
|
450 |
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
451 |
'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
452 |
'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
453 |
'description' => array(
|
|
|
454 |
'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
|
|
|
455 |
),
|
|
|
456 |
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
457 |
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
458 |
);
|
|
|
459 |
|
|
|
460 |
/**
|
|
|
461 |
* belongsTo property
|
|
|
462 |
*
|
|
|
463 |
* @var array
|
|
|
464 |
*/
|
|
|
465 |
public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
|
|
|
466 |
|
|
|
467 |
/**
|
|
|
468 |
* beforeValidate method
|
|
|
469 |
*
|
|
|
470 |
* @return void
|
|
|
471 |
*/
|
|
|
472 |
public function beforeValidate($options = array()) {
|
|
|
473 |
$this->invalidate('description');
|
|
|
474 |
return false;
|
|
|
475 |
}
|
|
|
476 |
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
/**
|
|
|
480 |
* TestMail class
|
|
|
481 |
*
|
|
|
482 |
* @package Cake.Test.Case.View.Helper
|
|
|
483 |
*/
|
|
|
484 |
class TestMail extends CakeTestModel {
|
|
|
485 |
|
|
|
486 |
/**
|
|
|
487 |
* useTable property
|
|
|
488 |
*
|
|
|
489 |
* @var boolean
|
|
|
490 |
*/
|
|
|
491 |
public $useTable = false;
|
|
|
492 |
|
|
|
493 |
}
|
|
|
494 |
|
|
|
495 |
/**
|
|
|
496 |
* FormHelperTest class
|
|
|
497 |
*
|
|
|
498 |
* @package Cake.Test.Case.View.Helper
|
|
|
499 |
* @property FormHelper $Form
|
|
|
500 |
*/
|
|
|
501 |
class FormHelperTest extends CakeTestCase {
|
|
|
502 |
|
|
|
503 |
/**
|
|
|
504 |
* Fixtures to be used
|
|
|
505 |
*
|
|
|
506 |
* @var array
|
|
|
507 |
*/
|
|
|
508 |
public $fixtures = array('core.post');
|
|
|
509 |
|
|
|
510 |
/**
|
|
|
511 |
* Do not load the fixtures by default
|
|
|
512 |
*
|
|
|
513 |
* @var boolean
|
|
|
514 |
*/
|
|
|
515 |
public $autoFixtures = false;
|
|
|
516 |
|
|
|
517 |
/**
|
|
|
518 |
* setUp method
|
|
|
519 |
*
|
|
|
520 |
* @return void
|
|
|
521 |
*/
|
|
|
522 |
public function setUp() {
|
|
|
523 |
parent::setUp();
|
|
|
524 |
|
|
|
525 |
Configure::write('Config.language', 'eng');
|
|
|
526 |
Configure::write('App.base', '');
|
|
|
527 |
Configure::delete('Asset');
|
|
|
528 |
$this->Controller = new ContactTestController();
|
|
|
529 |
$this->View = new View($this->Controller);
|
|
|
530 |
|
|
|
531 |
$this->Form = new FormHelper($this->View);
|
|
|
532 |
$this->Form->Html = new HtmlHelper($this->View);
|
|
|
533 |
$this->Form->request = new CakeRequest('contacts/add', false);
|
|
|
534 |
$this->Form->request->here = '/contacts/add';
|
|
|
535 |
$this->Form->request['action'] = 'add';
|
|
|
536 |
$this->Form->request->webroot = '';
|
|
|
537 |
$this->Form->request->base = '';
|
|
|
538 |
|
|
|
539 |
ClassRegistry::addObject('Contact', new Contact());
|
|
|
540 |
ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk());
|
|
|
541 |
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
|
|
|
542 |
ClassRegistry::addObject('User', new UserForm());
|
|
|
543 |
ClassRegistry::addObject('ValidateItem', new ValidateItem());
|
|
|
544 |
ClassRegistry::addObject('ValidateUser', new ValidateUser());
|
|
|
545 |
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
|
|
|
546 |
|
|
|
547 |
$this->oldSalt = Configure::read('Security.salt');
|
|
|
548 |
|
|
|
549 |
$this->dateRegex = array(
|
|
|
550 |
'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
551 |
'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
|
|
|
552 |
'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
553 |
'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
554 |
'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
|
|
|
555 |
'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
|
|
|
556 |
);
|
|
|
557 |
|
|
|
558 |
Configure::write('Security.salt', 'foo!');
|
|
|
559 |
}
|
|
|
560 |
|
|
|
561 |
/**
|
|
|
562 |
* tearDown method
|
|
|
563 |
*
|
|
|
564 |
* @return void
|
|
|
565 |
*/
|
|
|
566 |
public function tearDown() {
|
|
|
567 |
parent::tearDown();
|
|
|
568 |
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
|
|
|
569 |
Configure::write('Security.salt', $this->oldSalt);
|
|
|
570 |
}
|
|
|
571 |
|
|
|
572 |
/**
|
|
|
573 |
* testFormCreateWithSecurity method
|
|
|
574 |
*
|
|
|
575 |
* Test form->create() with security key.
|
|
|
576 |
*
|
|
|
577 |
* @return void
|
|
|
578 |
*/
|
|
|
579 |
public function testCreateWithSecurity() {
|
|
|
580 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
581 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
582 |
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
|
|
583 |
$expected = array(
|
|
|
584 |
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
|
|
|
585 |
'div' => array('style' => 'display:none;'),
|
|
|
586 |
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
|
|
587 |
array('input' => array(
|
|
|
588 |
'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id'
|
|
|
589 |
)),
|
|
|
590 |
'/div'
|
|
|
591 |
);
|
|
|
592 |
$this->assertTags($result, $expected);
|
|
|
593 |
|
|
|
594 |
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
|
|
|
595 |
$expected['form']['id'] = 'MyForm';
|
|
|
596 |
$this->assertTags($result, $expected);
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
/**
|
|
|
600 |
* testFormCreateGetNoSecurity method
|
|
|
601 |
*
|
|
|
602 |
* Test form->create() with no security key as its a get form
|
|
|
603 |
*
|
|
|
604 |
* @return void
|
|
|
605 |
*/
|
|
|
606 |
public function testCreateEndGetNoSecurity() {
|
|
|
607 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
608 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
609 |
$result = $this->Form->create('Contact', array('type' => 'get', 'url' => '/contacts/add'));
|
|
|
610 |
$this->assertNotContains('Token', $result);
|
|
|
611 |
|
|
|
612 |
$result = $this->Form->end('Save');
|
|
|
613 |
$this->assertNotContains('Token', $result);
|
|
|
614 |
}
|
|
|
615 |
|
|
|
616 |
/**
|
|
|
617 |
* test that create() clears the fields property so it starts fresh
|
|
|
618 |
*
|
|
|
619 |
* @return void
|
|
|
620 |
*/
|
|
|
621 |
public function testCreateClearingFields() {
|
|
|
622 |
$this->Form->fields = array('model_id');
|
|
|
623 |
$this->Form->create('Contact');
|
|
|
624 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
/**
|
|
|
628 |
* Tests form hash generation with model-less data
|
|
|
629 |
*
|
|
|
630 |
* @return void
|
|
|
631 |
*/
|
|
|
632 |
public function testValidateHashNoModel() {
|
|
|
633 |
$this->Form->request['_Token'] = array('key' => 'foo');
|
|
|
634 |
$result = $this->Form->secure(array('anything'));
|
|
|
635 |
$this->assertRegExp('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
/**
|
|
|
639 |
* Tests that models with identical field names get resolved properly
|
|
|
640 |
*
|
|
|
641 |
* @return void
|
|
|
642 |
*/
|
|
|
643 |
public function testDuplicateFieldNameResolution() {
|
|
|
644 |
$result = $this->Form->create('ValidateUser');
|
|
|
645 |
$this->assertEquals(array('ValidateUser'), $this->Form->entity());
|
|
|
646 |
|
|
|
647 |
$result = $this->Form->input('ValidateItem.name');
|
|
|
648 |
$this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
|
|
|
649 |
|
|
|
650 |
$result = $this->Form->input('ValidateUser.name');
|
|
|
651 |
$this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
|
|
|
652 |
$this->assertRegExp('/name="data\[ValidateUser\]\[name\]"/', $result);
|
|
|
653 |
$this->assertRegExp('/type="text"/', $result);
|
|
|
654 |
|
|
|
655 |
$result = $this->Form->input('ValidateItem.name');
|
|
|
656 |
$this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
|
|
|
657 |
$this->assertRegExp('/name="data\[ValidateItem\]\[name\]"/', $result);
|
|
|
658 |
$this->assertRegExp('/<textarea/', $result);
|
|
|
659 |
|
|
|
660 |
$result = $this->Form->input('name');
|
|
|
661 |
$this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
|
|
|
662 |
$this->assertRegExp('/name="data\[ValidateUser\]\[name\]"/', $result);
|
|
|
663 |
$this->assertRegExp('/type="text"/', $result);
|
|
|
664 |
}
|
|
|
665 |
|
|
|
666 |
/**
|
|
|
667 |
* Tests that hidden fields generated for checkboxes don't get locked
|
|
|
668 |
*
|
|
|
669 |
* @return void
|
|
|
670 |
*/
|
|
|
671 |
public function testNoCheckboxLocking() {
|
|
|
672 |
$this->Form->request['_Token'] = array('key' => 'foo');
|
|
|
673 |
$this->assertSame(array(), $this->Form->fields);
|
|
|
674 |
|
|
|
675 |
$this->Form->checkbox('check', array('value' => '1'));
|
|
|
676 |
$this->assertSame($this->Form->fields, array('check'));
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
/**
|
|
|
680 |
* testFormSecurityFields method
|
|
|
681 |
*
|
|
|
682 |
* Test generation of secure form hash generation.
|
|
|
683 |
*
|
|
|
684 |
* @return void
|
|
|
685 |
*/
|
|
|
686 |
public function testFormSecurityFields() {
|
|
|
687 |
$key = 'testKey';
|
|
|
688 |
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
|
|
|
689 |
|
|
|
690 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
691 |
$result = $this->Form->secure($fields);
|
|
|
692 |
|
|
|
693 |
$hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
|
|
|
694 |
$hash .= ':' . 'Model.valid';
|
|
|
695 |
$hash = urlencode($hash);
|
|
|
696 |
|
|
|
697 |
$expected = array(
|
|
|
698 |
'div' => array('style' => 'display:none;'),
|
|
|
699 |
array('input' => array(
|
|
|
700 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
701 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
702 |
)),
|
|
|
703 |
array('input' => array(
|
|
|
704 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
705 |
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
706 |
)),
|
|
|
707 |
'/div'
|
|
|
708 |
);
|
|
|
709 |
$this->assertTags($result, $expected);
|
|
|
710 |
|
|
|
711 |
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
|
|
|
712 |
$this->Form->Html->loadConfig('htmlhelper_tags', $path);
|
|
|
713 |
$result = $this->Form->secure($fields);
|
|
|
714 |
$expected = array(
|
|
|
715 |
'div' => array('class' => 'hidden'),
|
|
|
716 |
array('input' => array(
|
|
|
717 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
718 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
719 |
)),
|
|
|
720 |
array('input' => array(
|
|
|
721 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
722 |
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
723 |
)),
|
|
|
724 |
'/div'
|
|
|
725 |
);
|
|
|
726 |
$this->assertTags($result, $expected);
|
|
|
727 |
}
|
|
|
728 |
|
|
|
729 |
/**
|
|
|
730 |
* Tests correct generation of number fields for double and float fields
|
|
|
731 |
*
|
|
|
732 |
* @return void
|
|
|
733 |
*/
|
|
|
734 |
public function testTextFieldGenerationForFloats() {
|
|
|
735 |
$model = ClassRegistry::getObject('Contact');
|
|
|
736 |
$model->setSchema(array('foo' => array(
|
|
|
737 |
'type' => 'float',
|
|
|
738 |
'null' => false,
|
|
|
739 |
'default' => null,
|
|
|
740 |
'length' => 10
|
|
|
741 |
)));
|
|
|
742 |
|
|
|
743 |
$this->Form->create('Contact');
|
|
|
744 |
$result = $this->Form->input('foo');
|
|
|
745 |
$expected = array(
|
|
|
746 |
'div' => array('class' => 'input number'),
|
|
|
747 |
'label' => array('for' => 'ContactFoo'),
|
|
|
748 |
'Foo',
|
|
|
749 |
'/label',
|
|
|
750 |
array('input' => array(
|
|
|
751 |
'type' => 'number',
|
|
|
752 |
'name' => 'data[Contact][foo]',
|
|
|
753 |
'id' => 'ContactFoo',
|
|
|
754 |
'step' => 'any'
|
|
|
755 |
)),
|
|
|
756 |
'/div'
|
|
|
757 |
);
|
|
|
758 |
$this->assertTags($result, $expected);
|
|
|
759 |
|
|
|
760 |
$result = $this->Form->input('foo', array('step' => 0.5));
|
|
|
761 |
$expected = array(
|
|
|
762 |
'div' => array('class' => 'input number'),
|
|
|
763 |
'label' => array('for' => 'ContactFoo'),
|
|
|
764 |
'Foo',
|
|
|
765 |
'/label',
|
|
|
766 |
array('input' => array(
|
|
|
767 |
'type' => 'number',
|
|
|
768 |
'name' => 'data[Contact][foo]',
|
|
|
769 |
'id' => 'ContactFoo',
|
|
|
770 |
'step' => '0.5'
|
|
|
771 |
)),
|
|
|
772 |
'/div'
|
|
|
773 |
);
|
|
|
774 |
$this->assertTags($result, $expected);
|
|
|
775 |
}
|
|
|
776 |
|
|
|
777 |
/**
|
|
|
778 |
* Tests correct generation of number fields for integer fields
|
|
|
779 |
*
|
|
|
780 |
* @return void
|
|
|
781 |
*/
|
|
|
782 |
public function testTextFieldTypeNumberGenerationForIntegers() {
|
|
|
783 |
$model = ClassRegistry::getObject('Contact');
|
|
|
784 |
$model->setSchema(array('foo' => array(
|
|
|
785 |
'type' => 'integer',
|
|
|
786 |
'null' => false,
|
|
|
787 |
'default' => null,
|
|
|
788 |
'length' => null
|
|
|
789 |
)));
|
|
|
790 |
|
|
|
791 |
$this->Form->create('Contact');
|
|
|
792 |
$result = $this->Form->input('foo');
|
|
|
793 |
$expected = array(
|
|
|
794 |
'div' => array('class' => 'input number'),
|
|
|
795 |
'label' => array('for' => 'ContactFoo'),
|
|
|
796 |
'Foo',
|
|
|
797 |
'/label',
|
|
|
798 |
array('input' => array(
|
|
|
799 |
'type' => 'number', 'name' => 'data[Contact][foo]',
|
|
|
800 |
'id' => 'ContactFoo'
|
|
|
801 |
)),
|
|
|
802 |
'/div'
|
|
|
803 |
);
|
|
|
804 |
$this->assertTags($result, $expected);
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
/**
|
|
|
808 |
* testFormSecurityMultipleFields method
|
|
|
809 |
*
|
|
|
810 |
* Test secure() with multiple row form. Ensure hash is correct.
|
|
|
811 |
*
|
|
|
812 |
* @return void
|
|
|
813 |
*/
|
|
|
814 |
public function testFormSecurityMultipleFields() {
|
|
|
815 |
$key = 'testKey';
|
|
|
816 |
|
|
|
817 |
$fields = array(
|
|
|
818 |
'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
|
|
|
819 |
'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
|
|
|
820 |
'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
|
|
|
821 |
);
|
|
|
822 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
823 |
$result = $this->Form->secure($fields);
|
|
|
824 |
|
|
|
825 |
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
|
|
|
826 |
$hash .= '%7CModel.1.hidden%7CModel.1.valid';
|
|
|
827 |
|
|
|
828 |
$expected = array(
|
|
|
829 |
'div' => array('style' => 'display:none;'),
|
|
|
830 |
array('input' => array(
|
|
|
831 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
832 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
833 |
)),
|
|
|
834 |
array('input' => array(
|
|
|
835 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
836 |
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
837 |
)),
|
|
|
838 |
'/div'
|
|
|
839 |
);
|
|
|
840 |
$this->assertTags($result, $expected);
|
|
|
841 |
}
|
|
|
842 |
|
|
|
843 |
/**
|
|
|
844 |
* testFormSecurityMultipleSubmitButtons
|
|
|
845 |
*
|
|
|
846 |
* test form submit generation and ensure that _Token is only created on end()
|
|
|
847 |
*
|
|
|
848 |
* @return void
|
|
|
849 |
*/
|
|
|
850 |
public function testFormSecurityMultipleSubmitButtons() {
|
|
|
851 |
$key = 'testKey';
|
|
|
852 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
853 |
|
|
|
854 |
$this->Form->create('Addresses');
|
|
|
855 |
$this->Form->input('Address.title');
|
|
|
856 |
$this->Form->input('Address.first_name');
|
|
|
857 |
|
|
|
858 |
$result = $this->Form->submit('Save', array('name' => 'save'));
|
|
|
859 |
$expected = array(
|
|
|
860 |
'div' => array('class' => 'submit'),
|
|
|
861 |
'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
|
|
|
862 |
'/div',
|
|
|
863 |
);
|
|
|
864 |
$this->assertTags($result, $expected);
|
|
|
865 |
$result = $this->Form->submit('Cancel', array('name' => 'cancel'));
|
|
|
866 |
$expected = array(
|
|
|
867 |
'div' => array('class' => 'submit'),
|
|
|
868 |
'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
|
|
|
869 |
'/div',
|
|
|
870 |
);
|
|
|
871 |
$this->assertTags($result, $expected);
|
|
|
872 |
$result = $this->Form->end(null);
|
|
|
873 |
|
|
|
874 |
$expected = array(
|
|
|
875 |
'div' => array('style' => 'display:none;'),
|
|
|
876 |
array('input' => array(
|
|
|
877 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
878 |
'value' => 'preg:/.+/', 'id' => 'preg:/TokenFields\d+/'
|
|
|
879 |
)),
|
|
|
880 |
array('input' => array(
|
|
|
881 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
882 |
'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
883 |
)),
|
|
|
884 |
'/div'
|
|
|
885 |
);
|
|
|
886 |
$this->assertTags($result, $expected);
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
/**
|
|
|
890 |
* Test that buttons created with foo[bar] name attributes are unlocked correctly.
|
|
|
891 |
*
|
|
|
892 |
* @return void
|
|
|
893 |
*/
|
|
|
894 |
public function testSecurityButtonNestedNamed() {
|
|
|
895 |
$key = 'testKey';
|
|
|
896 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
897 |
|
|
|
898 |
$this->Form->create('Addresses');
|
|
|
899 |
$this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
|
|
|
900 |
$result = $this->Form->unlockField();
|
|
|
901 |
$this->assertEquals(array('Address.button'), $result);
|
|
|
902 |
}
|
|
|
903 |
|
|
|
904 |
/**
|
|
|
905 |
* Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
|
|
|
906 |
*
|
|
|
907 |
* @return void
|
|
|
908 |
*/
|
|
|
909 |
public function testSecuritySubmitNestedNamed() {
|
|
|
910 |
$key = 'testKey';
|
|
|
911 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
912 |
|
|
|
913 |
$this->Form->create('Addresses');
|
|
|
914 |
$this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
|
|
|
915 |
$result = $this->Form->unlockField();
|
|
|
916 |
$this->assertEquals(array('Address.button'), $result);
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
/**
|
|
|
920 |
* Test that the correct fields are unlocked for image submits with no names.
|
|
|
921 |
*
|
|
|
922 |
* @return void
|
|
|
923 |
*/
|
|
|
924 |
public function testSecuritySubmitImageNoName() {
|
|
|
925 |
$key = 'testKey';
|
|
|
926 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
927 |
|
|
|
928 |
$this->Form->create('User');
|
|
|
929 |
$result = $this->Form->submit('save.png');
|
|
|
930 |
$expected = array(
|
|
|
931 |
'div' => array('class' => 'submit'),
|
|
|
932 |
'input' => array('type' => 'image', 'src' => 'img/save.png'),
|
|
|
933 |
'/div'
|
|
|
934 |
);
|
|
|
935 |
$this->assertTags($result, $expected);
|
|
|
936 |
$this->assertEquals(array('x', 'y'), $this->Form->unlockField());
|
|
|
937 |
}
|
|
|
938 |
|
|
|
939 |
/**
|
|
|
940 |
* Test that the correct fields are unlocked for image submits with names.
|
|
|
941 |
*
|
|
|
942 |
* @return void
|
|
|
943 |
*/
|
|
|
944 |
public function testSecuritySubmitImageName() {
|
|
|
945 |
$key = 'testKey';
|
|
|
946 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
947 |
|
|
|
948 |
$this->Form->create('User');
|
|
|
949 |
$result = $this->Form->submit('save.png', array('name' => 'test'));
|
|
|
950 |
$expected = array(
|
|
|
951 |
'div' => array('class' => 'submit'),
|
|
|
952 |
'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
|
|
|
953 |
'/div'
|
|
|
954 |
);
|
|
|
955 |
$this->assertTags($result, $expected);
|
|
|
956 |
$this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
/**
|
|
|
960 |
* testFormSecurityMultipleInputFields method
|
|
|
961 |
*
|
|
|
962 |
* Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
|
|
|
963 |
*
|
|
|
964 |
* @return void
|
|
|
965 |
*/
|
|
|
966 |
public function testFormSecurityMultipleInputFields() {
|
|
|
967 |
$key = 'testKey';
|
|
|
968 |
|
|
|
969 |
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
970 |
$this->Form->create('Addresses');
|
|
|
971 |
|
|
|
972 |
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
|
|
|
973 |
$this->Form->input('Addresses.0.title');
|
|
|
974 |
$this->Form->input('Addresses.0.first_name');
|
|
|
975 |
$this->Form->input('Addresses.0.last_name');
|
|
|
976 |
$this->Form->input('Addresses.0.address');
|
|
|
977 |
$this->Form->input('Addresses.0.city');
|
|
|
978 |
$this->Form->input('Addresses.0.phone');
|
|
|
979 |
$this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
|
|
|
980 |
|
|
|
981 |
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
|
|
|
982 |
$this->Form->input('Addresses.1.title');
|
|
|
983 |
$this->Form->input('Addresses.1.first_name');
|
|
|
984 |
$this->Form->input('Addresses.1.last_name');
|
|
|
985 |
$this->Form->input('Addresses.1.address');
|
|
|
986 |
$this->Form->input('Addresses.1.city');
|
|
|
987 |
$this->Form->input('Addresses.1.phone');
|
|
|
988 |
$this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
|
|
|
989 |
|
|
|
990 |
$result = $this->Form->secure($this->Form->fields);
|
|
|
991 |
|
|
|
992 |
$hash = 'c9118120e680a7201b543f562e5301006ccfcbe2%3AAddresses.0.id%7CAddresses.1.id';
|
|
|
993 |
|
|
|
994 |
$expected = array(
|
|
|
995 |
'div' => array('style' => 'display:none;'),
|
|
|
996 |
array('input' => array(
|
|
|
997 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
998 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
999 |
)),
|
|
|
1000 |
array('input' => array(
|
|
|
1001 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
1002 |
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
1003 |
)),
|
|
|
1004 |
'/div'
|
|
|
1005 |
);
|
|
|
1006 |
$this->assertTags($result, $expected);
|
|
|
1007 |
}
|
|
|
1008 |
|
|
|
1009 |
/**
|
|
|
1010 |
* Test form security with Model.field.0 style inputs
|
|
|
1011 |
*
|
|
|
1012 |
* @return void
|
|
|
1013 |
*/
|
|
|
1014 |
public function testFormSecurityArrayFields() {
|
|
|
1015 |
$key = 'testKey';
|
|
|
1016 |
|
|
|
1017 |
$this->Form->request->params['_Token']['key'] = $key;
|
|
|
1018 |
$this->Form->create('Address');
|
|
|
1019 |
$this->Form->input('Address.primary.1');
|
|
|
1020 |
$this->assertEquals('Address.primary', $this->Form->fields[0]);
|
|
|
1021 |
|
|
|
1022 |
$this->Form->input('Address.secondary.1.0');
|
|
|
1023 |
$this->assertEquals('Address.secondary', $this->Form->fields[1]);
|
|
|
1024 |
}
|
|
|
1025 |
|
|
|
1026 |
/**
|
|
|
1027 |
* testFormSecurityMultipleInputDisabledFields method
|
|
|
1028 |
*
|
|
|
1029 |
* test secure form generation with multiple records and disabled fields.
|
|
|
1030 |
*
|
|
|
1031 |
* @return void
|
|
|
1032 |
*/
|
|
|
1033 |
public function testFormSecurityMultipleInputDisabledFields() {
|
|
|
1034 |
$key = 'testKey';
|
|
|
1035 |
$this->Form->request->params['_Token'] = array(
|
|
|
1036 |
'key' => $key,
|
|
|
1037 |
'unlockedFields' => array('first_name', 'address')
|
|
|
1038 |
);
|
|
|
1039 |
$this->Form->create();
|
|
|
1040 |
|
|
|
1041 |
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
|
|
|
1042 |
$this->Form->input('Addresses.0.title');
|
|
|
1043 |
$this->Form->input('Addresses.0.first_name');
|
|
|
1044 |
$this->Form->input('Addresses.0.last_name');
|
|
|
1045 |
$this->Form->input('Addresses.0.address');
|
|
|
1046 |
$this->Form->input('Addresses.0.city');
|
|
|
1047 |
$this->Form->input('Addresses.0.phone');
|
|
|
1048 |
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
|
|
|
1049 |
$this->Form->input('Addresses.1.title');
|
|
|
1050 |
$this->Form->input('Addresses.1.first_name');
|
|
|
1051 |
$this->Form->input('Addresses.1.last_name');
|
|
|
1052 |
$this->Form->input('Addresses.1.address');
|
|
|
1053 |
$this->Form->input('Addresses.1.city');
|
|
|
1054 |
$this->Form->input('Addresses.1.phone');
|
|
|
1055 |
|
|
|
1056 |
$result = $this->Form->secure($this->Form->fields);
|
|
|
1057 |
$hash = '629b6536dcece48aa41a117045628ce602ccbbb2%3AAddresses.0.id%7CAddresses.1.id';
|
|
|
1058 |
|
|
|
1059 |
$expected = array(
|
|
|
1060 |
'div' => array('style' => 'display:none;'),
|
|
|
1061 |
array('input' => array(
|
|
|
1062 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
1063 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
1064 |
)),
|
|
|
1065 |
array('input' => array(
|
|
|
1066 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
1067 |
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
1068 |
)),
|
|
|
1069 |
'/div'
|
|
|
1070 |
);
|
|
|
1071 |
$this->assertTags($result, $expected);
|
|
|
1072 |
}
|
|
|
1073 |
|
|
|
1074 |
/**
|
|
|
1075 |
* testFormSecurityInputDisabledFields method
|
|
|
1076 |
*
|
|
|
1077 |
* Test single record form with disabled fields.
|
|
|
1078 |
*
|
|
|
1079 |
* @return void
|
|
|
1080 |
*/
|
|
|
1081 |
public function testFormSecurityInputUnlockedFields() {
|
|
|
1082 |
$key = 'testKey';
|
|
|
1083 |
$this->Form->request['_Token'] = array(
|
|
|
1084 |
'key' => $key,
|
|
|
1085 |
'unlockedFields' => array('first_name', 'address')
|
|
|
1086 |
);
|
|
|
1087 |
$this->Form->create();
|
|
|
1088 |
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
|
|
|
1089 |
|
|
|
1090 |
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
1091 |
$this->Form->input('Addresses.title');
|
|
|
1092 |
$this->Form->input('Addresses.first_name');
|
|
|
1093 |
$this->Form->input('Addresses.last_name');
|
|
|
1094 |
$this->Form->input('Addresses.address');
|
|
|
1095 |
$this->Form->input('Addresses.city');
|
|
|
1096 |
$this->Form->input('Addresses.phone');
|
|
|
1097 |
|
|
|
1098 |
$result = $this->Form->fields;
|
|
|
1099 |
$expected = array(
|
|
|
1100 |
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
|
|
|
1101 |
'Addresses.city', 'Addresses.phone'
|
|
|
1102 |
);
|
|
|
1103 |
$this->assertEquals($expected, $result);
|
|
|
1104 |
|
|
|
1105 |
$result = $this->Form->secure($expected);
|
|
|
1106 |
|
|
|
1107 |
$hash = '2981c38990f3f6ba935e6561dc77277966fabd6d%3AAddresses.id';
|
|
|
1108 |
$expected = array(
|
|
|
1109 |
'div' => array('style' => 'display:none;'),
|
|
|
1110 |
array('input' => array(
|
|
|
1111 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
1112 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
1113 |
)),
|
|
|
1114 |
array('input' => array(
|
|
|
1115 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
1116 |
'value' => 'address%7Cfirst_name', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
1117 |
)),
|
|
|
1118 |
'/div'
|
|
|
1119 |
);
|
|
|
1120 |
$this->assertTags($result, $expected);
|
|
|
1121 |
}
|
|
|
1122 |
|
|
|
1123 |
/**
|
|
|
1124 |
* test securing inputs with custom name attributes.
|
|
|
1125 |
*
|
|
|
1126 |
* @return void
|
|
|
1127 |
*/
|
|
|
1128 |
public function testFormSecureWithCustomNameAttribute() {
|
|
|
1129 |
$this->Form->request->params['_Token']['key'] = 'testKey';
|
|
|
1130 |
|
|
|
1131 |
$this->Form->text('UserForm.published', array('name' => 'data[User][custom]'));
|
|
|
1132 |
$this->assertEquals('User.custom', $this->Form->fields[0]);
|
|
|
1133 |
|
|
|
1134 |
$this->Form->text('UserForm.published', array('name' => 'data[User][custom][another][value]'));
|
|
|
1135 |
$this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
/**
|
|
|
1139 |
* testFormSecuredInput method
|
|
|
1140 |
*
|
|
|
1141 |
* Test generation of entire secure form, assertions made on input() output.
|
|
|
1142 |
*
|
|
|
1143 |
* @return void
|
|
|
1144 |
*/
|
|
|
1145 |
public function testFormSecuredInput() {
|
|
|
1146 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1147 |
|
|
|
1148 |
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
|
|
1149 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
1150 |
$expected = array(
|
|
|
1151 |
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
|
|
|
1152 |
'div' => array('style' => 'display:none;'),
|
|
|
1153 |
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
|
|
1154 |
array('input' => array(
|
|
|
1155 |
'type' => 'hidden', 'name' => 'data[_Token][key]',
|
|
|
1156 |
'value' => 'testKey', 'id' => 'preg:/Token\d+/'
|
|
|
1157 |
)),
|
|
|
1158 |
'/div'
|
|
|
1159 |
);
|
|
|
1160 |
$this->assertTags($result, $expected);
|
|
|
1161 |
|
|
|
1162 |
$result = $this->Form->input('UserForm.published', array('type' => 'text'));
|
|
|
1163 |
$expected = array(
|
|
|
1164 |
'div' => array('class' => 'input text'),
|
|
|
1165 |
'label' => array('for' => 'UserFormPublished'),
|
|
|
1166 |
'Published',
|
|
|
1167 |
'/label',
|
|
|
1168 |
array('input' => array(
|
|
|
1169 |
'type' => 'text', 'name' => 'data[UserForm][published]',
|
|
|
1170 |
'id' => 'UserFormPublished'
|
|
|
1171 |
)),
|
|
|
1172 |
'/div'
|
|
|
1173 |
);
|
|
|
1174 |
$this->assertTags($result, $expected);
|
|
|
1175 |
|
|
|
1176 |
$result = $this->Form->input('UserForm.other', array('type' => 'text'));
|
|
|
1177 |
$expected = array(
|
|
|
1178 |
'div' => array('class' => 'input text'),
|
|
|
1179 |
'label' => array('for' => 'UserFormOther'),
|
|
|
1180 |
'Other',
|
|
|
1181 |
'/label',
|
|
|
1182 |
array('input' => array(
|
|
|
1183 |
'type' => 'text', 'name' => 'data[UserForm][other]',
|
|
|
1184 |
'id' => 'UserFormOther'
|
|
|
1185 |
)),
|
|
|
1186 |
'/div'
|
|
|
1187 |
);
|
|
|
1188 |
$this->assertTags($result, $expected);
|
|
|
1189 |
|
|
|
1190 |
$result = $this->Form->hidden('UserForm.stuff');
|
|
|
1191 |
$expected = array(
|
|
|
1192 |
'input' => array(
|
|
|
1193 |
'type' => 'hidden', 'name' => 'data[UserForm][stuff]',
|
|
|
1194 |
'id' => 'UserFormStuff'
|
|
|
1195 |
));
|
|
|
1196 |
$this->assertTags($result, $expected);
|
|
|
1197 |
|
|
|
1198 |
$result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
|
|
|
1199 |
$expected = array('input' => array(
|
|
|
1200 |
'type' => 'hidden', 'name' => 'data[UserForm][hidden]',
|
|
|
1201 |
'value' => '0', 'id' => 'UserFormHidden'
|
|
|
1202 |
));
|
|
|
1203 |
$this->assertTags($result, $expected);
|
|
|
1204 |
|
|
|
1205 |
$result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
|
|
|
1206 |
$expected = array(
|
|
|
1207 |
'div' => array('class' => 'input checkbox'),
|
|
|
1208 |
array('input' => array(
|
|
|
1209 |
'type' => 'hidden', 'name' => 'data[UserForm][something]',
|
|
|
1210 |
'value' => '0', 'id' => 'UserFormSomething_'
|
|
|
1211 |
)),
|
|
|
1212 |
array('input' => array(
|
|
|
1213 |
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
1214 |
'value' => '1', 'id' => 'UserFormSomething'
|
|
|
1215 |
)),
|
|
|
1216 |
'label' => array('for' => 'UserFormSomething'),
|
|
|
1217 |
'Something',
|
|
|
1218 |
'/label',
|
|
|
1219 |
'/div'
|
|
|
1220 |
);
|
|
|
1221 |
$this->assertTags($result, $expected);
|
|
|
1222 |
|
|
|
1223 |
$result = $this->Form->fields;
|
|
|
1224 |
$expected = array(
|
|
|
1225 |
'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
|
|
|
1226 |
'UserForm.hidden' => '0', 'UserForm.something'
|
|
|
1227 |
);
|
|
|
1228 |
$this->assertEquals($expected, $result);
|
|
|
1229 |
|
|
|
1230 |
$hash = 'bd7c4a654e5361f9a433a43f488ff9a1065d0aaf%3AUserForm.hidden%7CUserForm.stuff';
|
|
|
1231 |
|
|
|
1232 |
$result = $this->Form->secure($this->Form->fields);
|
|
|
1233 |
$expected = array(
|
|
|
1234 |
'div' => array('style' => 'display:none;'),
|
|
|
1235 |
array('input' => array(
|
|
|
1236 |
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
|
|
1237 |
'value' => $hash, 'id' => 'preg:/TokenFields\d+/'
|
|
|
1238 |
)),
|
|
|
1239 |
array('input' => array(
|
|
|
1240 |
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
|
|
1241 |
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/'
|
|
|
1242 |
)),
|
|
|
1243 |
'/div'
|
|
|
1244 |
);
|
|
|
1245 |
$this->assertTags($result, $expected);
|
|
|
1246 |
}
|
|
|
1247 |
|
|
|
1248 |
/**
|
|
|
1249 |
* Test secured inputs with custom names.
|
|
|
1250 |
*
|
|
|
1251 |
* @return void
|
|
|
1252 |
*/
|
|
|
1253 |
public function testSecuredInputCustomName() {
|
|
|
1254 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1255 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1256 |
|
|
|
1257 |
$this->Form->input('text_input', array(
|
|
|
1258 |
'name' => 'data[Option][General.default_role]',
|
|
|
1259 |
));
|
|
|
1260 |
$expected = array('Option.General.default_role');
|
|
|
1261 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1262 |
|
|
|
1263 |
$this->Form->input('select_box', array(
|
|
|
1264 |
'name' => 'data[Option][General.select_role]',
|
|
|
1265 |
'type' => 'select',
|
|
|
1266 |
'options' => array(1, 2),
|
|
|
1267 |
));
|
|
|
1268 |
$expected = array('Option.General.default_role', 'Option.General.select_role');
|
|
|
1269 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1270 |
}
|
|
|
1271 |
|
|
|
1272 |
/**
|
|
|
1273 |
* Tests that the correct keys are added to the field hash index
|
|
|
1274 |
*
|
|
|
1275 |
* @return void
|
|
|
1276 |
*/
|
|
|
1277 |
public function testFormSecuredFileInput() {
|
|
|
1278 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1279 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1280 |
|
|
|
1281 |
$this->Form->file('Attachment.file');
|
|
|
1282 |
$expected = array(
|
|
|
1283 |
'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
|
|
|
1284 |
'Attachment.file.error', 'Attachment.file.size'
|
|
|
1285 |
);
|
|
|
1286 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1287 |
}
|
|
|
1288 |
|
|
|
1289 |
/**
|
|
|
1290 |
* test that multiple selects keys are added to field hash
|
|
|
1291 |
*
|
|
|
1292 |
* @return void
|
|
|
1293 |
*/
|
|
|
1294 |
public function testFormSecuredMultipleSelect() {
|
|
|
1295 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1296 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1297 |
$options = array('1' => 'one', '2' => 'two');
|
|
|
1298 |
|
|
|
1299 |
$this->Form->select('Model.select', $options);
|
|
|
1300 |
$expected = array('Model.select');
|
|
|
1301 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1302 |
|
|
|
1303 |
$this->Form->fields = array();
|
|
|
1304 |
$this->Form->select('Model.select', $options, array('multiple' => true));
|
|
|
1305 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1306 |
}
|
|
|
1307 |
|
|
|
1308 |
/**
|
|
|
1309 |
* testFormSecuredRadio method
|
|
|
1310 |
*
|
|
|
1311 |
* @return void
|
|
|
1312 |
*/
|
|
|
1313 |
public function testFormSecuredRadio() {
|
|
|
1314 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1315 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1316 |
$options = array('1' => 'option1', '2' => 'option2');
|
|
|
1317 |
|
|
|
1318 |
$this->Form->radio('Test.test', $options);
|
|
|
1319 |
$expected = array('Test.test');
|
|
|
1320 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1321 |
}
|
|
|
1322 |
|
|
|
1323 |
/**
|
|
|
1324 |
* Test that when disabled is in a list based attribute array it works.
|
|
|
1325 |
*
|
|
|
1326 |
* @return void
|
|
|
1327 |
*/
|
|
|
1328 |
public function testFormSecuredAndDisabledNotAssoc() {
|
|
|
1329 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1330 |
|
|
|
1331 |
$this->Form->select('Model.select', array(1, 2), array('disabled'));
|
|
|
1332 |
$this->Form->checkbox('Model.checkbox', array('disabled'));
|
|
|
1333 |
$this->Form->text('Model.text', array('disabled'));
|
|
|
1334 |
$this->Form->textarea('Model.textarea', array('disabled'));
|
|
|
1335 |
$this->Form->password('Model.password', array('disabled'));
|
|
|
1336 |
$this->Form->radio('Model.radio', array(1, 2), array('disabled'));
|
|
|
1337 |
|
|
|
1338 |
$expected = array(
|
|
|
1339 |
'Model.radio' => ''
|
|
|
1340 |
);
|
|
|
1341 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1342 |
}
|
|
|
1343 |
|
|
|
1344 |
/**
|
|
|
1345 |
* test that forms with disabled inputs + secured forms leave off the inputs from the form
|
|
|
1346 |
* hashing.
|
|
|
1347 |
*
|
|
|
1348 |
* @return void
|
|
|
1349 |
*/
|
|
|
1350 |
public function testFormSecuredAndDisabled() {
|
|
|
1351 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
1352 |
|
|
|
1353 |
$this->Form->checkbox('Model.checkbox', array('disabled' => true));
|
|
|
1354 |
$this->Form->text('Model.text', array('disabled' => true));
|
|
|
1355 |
$this->Form->password('Model.text', array('disabled' => true));
|
|
|
1356 |
$this->Form->textarea('Model.textarea', array('disabled' => true));
|
|
|
1357 |
$this->Form->select('Model.select', array(1, 2), array('disabled' => true));
|
|
|
1358 |
$this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
|
|
|
1359 |
$this->Form->year('Model.year', null, null, array('disabled' => true));
|
|
|
1360 |
$this->Form->month('Model.month', array('disabled' => true));
|
|
|
1361 |
$this->Form->day('Model.day', array('disabled' => true));
|
|
|
1362 |
$this->Form->hour('Model.hour', false, array('disabled' => true));
|
|
|
1363 |
$this->Form->minute('Model.minute', array('disabled' => true));
|
|
|
1364 |
$this->Form->meridian('Model.meridian', array('disabled' => true));
|
|
|
1365 |
|
|
|
1366 |
$expected = array(
|
|
|
1367 |
'Model.radio' => ''
|
|
|
1368 |
);
|
|
|
1369 |
$this->assertEquals($expected, $this->Form->fields);
|
|
|
1370 |
}
|
|
|
1371 |
|
|
|
1372 |
/**
|
|
|
1373 |
* testDisableSecurityUsingForm method
|
|
|
1374 |
*
|
|
|
1375 |
* @return void
|
|
|
1376 |
*/
|
|
|
1377 |
public function testDisableSecurityUsingForm() {
|
|
|
1378 |
$this->Form->request['_Token'] = array(
|
|
|
1379 |
'key' => 'testKey',
|
|
|
1380 |
'disabledFields' => array()
|
|
|
1381 |
);
|
|
|
1382 |
$this->Form->create();
|
|
|
1383 |
|
|
|
1384 |
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
1385 |
$this->Form->input('Addresses.title');
|
|
|
1386 |
$this->Form->input('Addresses.first_name', array('secure' => false));
|
|
|
1387 |
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
|
|
|
1388 |
$this->Form->input('Addresses.zip', array(
|
|
|
1389 |
'type' => 'select', 'options' => array(1, 2), 'secure' => false
|
|
|
1390 |
));
|
|
|
1391 |
|
|
|
1392 |
$result = $this->Form->fields;
|
|
|
1393 |
$expected = array(
|
|
|
1394 |
'Addresses.id' => '123456', 'Addresses.title',
|
|
|
1395 |
);
|
|
|
1396 |
$this->assertEquals($expected, $result);
|
|
|
1397 |
}
|
|
|
1398 |
|
|
|
1399 |
/**
|
|
|
1400 |
* test disableField
|
|
|
1401 |
*
|
|
|
1402 |
* @return void
|
|
|
1403 |
*/
|
|
|
1404 |
public function testUnlockFieldAddsToList() {
|
|
|
1405 |
$this->Form->request['_Token'] = array(
|
|
|
1406 |
'key' => 'testKey',
|
|
|
1407 |
'unlockedFields' => array()
|
|
|
1408 |
);
|
|
|
1409 |
$this->Form->create('Contact');
|
|
|
1410 |
$this->Form->unlockField('Contact.name');
|
|
|
1411 |
$this->Form->text('Contact.name');
|
|
|
1412 |
|
|
|
1413 |
$this->assertEquals(array('Contact.name'), $this->Form->unlockField());
|
|
|
1414 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1415 |
}
|
|
|
1416 |
|
|
|
1417 |
/**
|
|
|
1418 |
* test unlockField removing from fields array.
|
|
|
1419 |
*
|
|
|
1420 |
* @return void
|
|
|
1421 |
*/
|
|
|
1422 |
public function testUnlockFieldRemovingFromFields() {
|
|
|
1423 |
$this->Form->request['_Token'] = array(
|
|
|
1424 |
'key' => 'testKey',
|
|
|
1425 |
'unlockedFields' => array()
|
|
|
1426 |
);
|
|
|
1427 |
$this->Form->create('Contact');
|
|
|
1428 |
$this->Form->hidden('Contact.id', array('value' => 1));
|
|
|
1429 |
$this->Form->text('Contact.name');
|
|
|
1430 |
|
|
|
1431 |
$this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
|
|
|
1432 |
$this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
|
|
|
1433 |
|
|
|
1434 |
$this->Form->unlockField('Contact.name');
|
|
|
1435 |
$this->Form->unlockField('Contact.id');
|
|
|
1436 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
1437 |
}
|
|
|
1438 |
|
|
|
1439 |
/**
|
|
|
1440 |
* testTagIsInvalid method
|
|
|
1441 |
*
|
|
|
1442 |
* @return void
|
|
|
1443 |
*/
|
|
|
1444 |
public function testTagIsInvalid() {
|
|
|
1445 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
1446 |
$Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
|
|
|
1447 |
|
|
|
1448 |
$this->Form->setEntity('Contact.0.email');
|
|
|
1449 |
$result = $this->Form->tagIsInvalid();
|
|
|
1450 |
$this->assertEquals($expected, $result);
|
|
|
1451 |
|
|
|
1452 |
$this->Form->setEntity('Contact.1.email');
|
|
|
1453 |
$result = $this->Form->tagIsInvalid();
|
|
|
1454 |
$this->assertFalse($result);
|
|
|
1455 |
|
|
|
1456 |
$this->Form->setEntity('Contact.0.name');
|
|
|
1457 |
$result = $this->Form->tagIsInvalid();
|
|
|
1458 |
$this->assertFalse($result);
|
|
|
1459 |
}
|
|
|
1460 |
|
|
|
1461 |
/**
|
|
|
1462 |
* Test tagIsInvalid with validation errors from a saveMany
|
|
|
1463 |
*
|
|
|
1464 |
* @return void
|
|
|
1465 |
*/
|
|
|
1466 |
public function testTagIsInvalidSaveMany() {
|
|
|
1467 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
1468 |
$Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
|
|
|
1469 |
|
|
|
1470 |
$this->Form->create('Contact');
|
|
|
1471 |
|
|
|
1472 |
$this->Form->setEntity('0.email');
|
|
|
1473 |
$result = $this->Form->tagIsInvalid();
|
|
|
1474 |
$this->assertEquals($expected, $result);
|
|
|
1475 |
|
|
|
1476 |
$this->Form->setEntity('0.Contact.email');
|
|
|
1477 |
$result = $this->Form->tagIsInvalid();
|
|
|
1478 |
$this->assertEquals($expected, $result);
|
|
|
1479 |
}
|
|
|
1480 |
|
|
|
1481 |
/**
|
|
|
1482 |
* Test validation errors.
|
|
|
1483 |
*
|
|
|
1484 |
* @return void
|
|
|
1485 |
*/
|
|
|
1486 |
public function testPasswordValidation() {
|
|
|
1487 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
1488 |
$Contact->validationErrors['password'] = array('Please provide a password');
|
|
|
1489 |
|
|
|
1490 |
$result = $this->Form->input('Contact.password');
|
|
|
1491 |
$expected = array(
|
|
|
1492 |
'div' => array('class' => 'input password error'),
|
|
|
1493 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1494 |
'Password',
|
|
|
1495 |
'/label',
|
|
|
1496 |
'input' => array(
|
|
|
1497 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1498 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1499 |
),
|
|
|
1500 |
array('div' => array('class' => 'error-message')),
|
|
|
1501 |
'Please provide a password',
|
|
|
1502 |
'/div',
|
|
|
1503 |
'/div'
|
|
|
1504 |
);
|
|
|
1505 |
$this->assertTags($result, $expected);
|
|
|
1506 |
|
|
|
1507 |
$result = $this->Form->input('Contact.password', array('errorMessage' => false));
|
|
|
1508 |
$expected = array(
|
|
|
1509 |
'div' => array('class' => 'input password error'),
|
|
|
1510 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1511 |
'Password',
|
|
|
1512 |
'/label',
|
|
|
1513 |
'input' => array(
|
|
|
1514 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1515 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1516 |
),
|
|
|
1517 |
'/div'
|
|
|
1518 |
);
|
|
|
1519 |
$this->assertTags($result, $expected);
|
|
|
1520 |
}
|
|
|
1521 |
|
|
|
1522 |
/**
|
|
|
1523 |
* Test validation errors, when validation message is an empty string.
|
|
|
1524 |
*
|
|
|
1525 |
* @return void
|
|
|
1526 |
*/
|
|
|
1527 |
public function testEmptyErrorValidation() {
|
|
|
1528 |
$this->Form->validationErrors['Contact']['password'] = '';
|
|
|
1529 |
|
|
|
1530 |
$result = $this->Form->input('Contact.password');
|
|
|
1531 |
$expected = array(
|
|
|
1532 |
'div' => array('class' => 'input password error'),
|
|
|
1533 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1534 |
'Password',
|
|
|
1535 |
'/label',
|
|
|
1536 |
'input' => array(
|
|
|
1537 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1538 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1539 |
),
|
|
|
1540 |
array('div' => array('class' => 'error-message')),
|
|
|
1541 |
array(),
|
|
|
1542 |
'/div',
|
|
|
1543 |
'/div'
|
|
|
1544 |
);
|
|
|
1545 |
$this->assertTags($result, $expected);
|
|
|
1546 |
|
|
|
1547 |
$result = $this->Form->input('Contact.password', array('errorMessage' => false));
|
|
|
1548 |
$expected = array(
|
|
|
1549 |
'div' => array('class' => 'input password error'),
|
|
|
1550 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1551 |
'Password',
|
|
|
1552 |
'/label',
|
|
|
1553 |
'input' => array(
|
|
|
1554 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1555 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1556 |
),
|
|
|
1557 |
'/div'
|
|
|
1558 |
);
|
|
|
1559 |
$this->assertTags($result, $expected);
|
|
|
1560 |
}
|
|
|
1561 |
|
|
|
1562 |
/**
|
|
|
1563 |
* Test validation errors, when calling input() overriding validation message by an empty string.
|
|
|
1564 |
*
|
|
|
1565 |
* @return void
|
|
|
1566 |
*/
|
|
|
1567 |
public function testEmptyInputErrorValidation() {
|
|
|
1568 |
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
|
|
|
1569 |
|
|
|
1570 |
$result = $this->Form->input('Contact.password', array('error' => ''));
|
|
|
1571 |
$expected = array(
|
|
|
1572 |
'div' => array('class' => 'input password error'),
|
|
|
1573 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1574 |
'Password',
|
|
|
1575 |
'/label',
|
|
|
1576 |
'input' => array(
|
|
|
1577 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1578 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1579 |
),
|
|
|
1580 |
array('div' => array('class' => 'error-message')),
|
|
|
1581 |
array(),
|
|
|
1582 |
'/div',
|
|
|
1583 |
'/div'
|
|
|
1584 |
);
|
|
|
1585 |
$this->assertTags($result, $expected);
|
|
|
1586 |
|
|
|
1587 |
$result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
|
|
|
1588 |
$expected = array(
|
|
|
1589 |
'div' => array('class' => 'input password error'),
|
|
|
1590 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1591 |
'Password',
|
|
|
1592 |
'/label',
|
|
|
1593 |
'input' => array(
|
|
|
1594 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1595 |
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
1596 |
),
|
|
|
1597 |
'/div'
|
|
|
1598 |
);
|
|
|
1599 |
$this->assertTags($result, $expected);
|
|
|
1600 |
}
|
|
|
1601 |
|
|
|
1602 |
/**
|
|
|
1603 |
* testFormValidationAssociated method
|
|
|
1604 |
*
|
|
|
1605 |
* test display of form errors in conjunction with model::validates.
|
|
|
1606 |
*
|
|
|
1607 |
* @return void
|
|
|
1608 |
*/
|
|
|
1609 |
public function testFormValidationAssociated() {
|
|
|
1610 |
$this->UserForm = ClassRegistry::getObject('UserForm');
|
|
|
1611 |
$this->UserForm->OpenidUrl = ClassRegistry::getObject('OpenidUrl');
|
|
|
1612 |
|
|
|
1613 |
$data = array(
|
|
|
1614 |
'UserForm' => array('name' => 'user'),
|
|
|
1615 |
'OpenidUrl' => array('url' => 'http://www.cakephp.org')
|
|
|
1616 |
);
|
|
|
1617 |
|
|
|
1618 |
$result = $this->UserForm->OpenidUrl->create($data);
|
|
|
1619 |
$this->assertFalse(empty($result));
|
|
|
1620 |
$this->assertFalse($this->UserForm->OpenidUrl->validates());
|
|
|
1621 |
|
|
|
1622 |
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
|
|
|
1623 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
1624 |
$expected = array(
|
|
|
1625 |
'form' => array(
|
|
|
1626 |
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
|
|
|
1627 |
'accept-charset' => $encoding
|
|
|
1628 |
),
|
|
|
1629 |
'div' => array('style' => 'display:none;'),
|
|
|
1630 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
1631 |
'/div'
|
|
|
1632 |
);
|
|
|
1633 |
$this->assertTags($result, $expected);
|
|
|
1634 |
|
|
|
1635 |
$result = $this->Form->error(
|
|
|
1636 |
'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
|
|
|
1637 |
);
|
|
|
1638 |
$this->assertEquals('Error, not registered', $result);
|
|
|
1639 |
|
|
|
1640 |
unset($this->UserForm->OpenidUrl, $this->UserForm);
|
|
|
1641 |
}
|
|
|
1642 |
|
|
|
1643 |
/**
|
|
|
1644 |
* testFormValidationAssociatedFirstLevel method
|
|
|
1645 |
*
|
|
|
1646 |
* test form error display with associated model.
|
|
|
1647 |
*
|
|
|
1648 |
* @return void
|
|
|
1649 |
*/
|
|
|
1650 |
public function testFormValidationAssociatedFirstLevel() {
|
|
|
1651 |
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
1652 |
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
1653 |
|
|
|
1654 |
$data = array(
|
|
|
1655 |
'ValidateUser' => array('name' => 'mariano'),
|
|
|
1656 |
'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
|
|
|
1657 |
);
|
|
|
1658 |
|
|
|
1659 |
$result = $this->ValidateUser->create($data);
|
|
|
1660 |
$this->assertFalse(empty($result));
|
|
|
1661 |
$this->assertFalse($this->ValidateUser->validates());
|
|
|
1662 |
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
|
|
1663 |
|
|
|
1664 |
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
|
|
1665 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
1666 |
$expected = array(
|
|
|
1667 |
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
|
|
1668 |
'div' => array('style' => 'display:none;'),
|
|
|
1669 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
1670 |
'/div'
|
|
|
1671 |
);
|
|
|
1672 |
$this->assertTags($result, $expected);
|
|
|
1673 |
|
|
|
1674 |
$result = $this->Form->error(
|
|
|
1675 |
'ValidateUser.email', 'Invalid email', array('wrap' => false)
|
|
|
1676 |
);
|
|
|
1677 |
$this->assertEquals('Invalid email', $result);
|
|
|
1678 |
|
|
|
1679 |
$result = $this->Form->error(
|
|
|
1680 |
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
|
|
|
1681 |
);
|
|
|
1682 |
$this->assertEquals('Invalid name', $result);
|
|
|
1683 |
|
|
|
1684 |
$result = $this->Form->error(
|
|
|
1685 |
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
|
|
|
1686 |
);
|
|
|
1687 |
$this->assertEquals('Invalid city', $result);
|
|
|
1688 |
|
|
|
1689 |
unset($this->ValidateUser->ValidateProfile);
|
|
|
1690 |
unset($this->ValidateUser);
|
|
|
1691 |
}
|
|
|
1692 |
|
|
|
1693 |
/**
|
|
|
1694 |
* testFormValidationAssociatedSecondLevel method
|
|
|
1695 |
*
|
|
|
1696 |
* test form error display with associated model.
|
|
|
1697 |
*
|
|
|
1698 |
* @return void
|
|
|
1699 |
*/
|
|
|
1700 |
public function testFormValidationAssociatedSecondLevel() {
|
|
|
1701 |
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
1702 |
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
1703 |
$this->ValidateUser->ValidateProfile->ValidateItem = ClassRegistry::getObject('ValidateItem');
|
|
|
1704 |
|
|
|
1705 |
$data = array(
|
|
|
1706 |
'ValidateUser' => array('name' => 'mariano'),
|
|
|
1707 |
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
|
|
|
1708 |
'ValidateItem' => array('name' => 'Item')
|
|
|
1709 |
);
|
|
|
1710 |
|
|
|
1711 |
$result = $this->ValidateUser->create($data);
|
|
|
1712 |
$this->assertFalse(empty($result));
|
|
|
1713 |
$this->assertFalse($this->ValidateUser->validates());
|
|
|
1714 |
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
|
|
1715 |
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
|
|
1716 |
|
|
|
1717 |
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
|
|
1718 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
1719 |
$expected = array(
|
|
|
1720 |
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
|
|
1721 |
'div' => array('style' => 'display:none;'),
|
|
|
1722 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
1723 |
'/div'
|
|
|
1724 |
);
|
|
|
1725 |
$this->assertTags($result, $expected);
|
|
|
1726 |
|
|
|
1727 |
$result = $this->Form->error(
|
|
|
1728 |
'ValidateUser.email', 'Invalid email', array('wrap' => false)
|
|
|
1729 |
);
|
|
|
1730 |
$this->assertEquals('Invalid email', $result);
|
|
|
1731 |
|
|
|
1732 |
$result = $this->Form->error(
|
|
|
1733 |
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
|
|
|
1734 |
);
|
|
|
1735 |
$this->assertEquals('Invalid name', $result);
|
|
|
1736 |
|
|
|
1737 |
$result = $this->Form->error(
|
|
|
1738 |
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
|
|
|
1739 |
);
|
|
|
1740 |
|
|
|
1741 |
$result = $this->Form->error(
|
|
|
1742 |
'ValidateItem.description', 'Invalid description', array('wrap' => false)
|
|
|
1743 |
);
|
|
|
1744 |
$this->assertEquals('Invalid description', $result);
|
|
|
1745 |
|
|
|
1746 |
unset($this->ValidateUser->ValidateProfile->ValidateItem);
|
|
|
1747 |
unset($this->ValidateUser->ValidateProfile);
|
|
|
1748 |
unset($this->ValidateUser);
|
|
|
1749 |
}
|
|
|
1750 |
|
|
|
1751 |
/**
|
|
|
1752 |
* testFormValidationMultiRecord method
|
|
|
1753 |
*
|
|
|
1754 |
* test form error display with multiple records.
|
|
|
1755 |
*
|
|
|
1756 |
* @return void
|
|
|
1757 |
*/
|
|
|
1758 |
public function testFormValidationMultiRecord() {
|
|
|
1759 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
1760 |
$Contact->validationErrors[2] = array(
|
|
|
1761 |
'name' => array('This field cannot be left blank')
|
|
|
1762 |
);
|
|
|
1763 |
$result = $this->Form->input('Contact.2.name');
|
|
|
1764 |
$expected = array(
|
|
|
1765 |
'div' => array('class' => 'input text error'),
|
|
|
1766 |
'label' => array('for' => 'Contact2Name'),
|
|
|
1767 |
'Name',
|
|
|
1768 |
'/label',
|
|
|
1769 |
'input' => array(
|
|
|
1770 |
'type' => 'text', 'name' => 'data[Contact][2][name]', 'id' => 'Contact2Name',
|
|
|
1771 |
'class' => 'form-error', 'maxlength' => 255
|
|
|
1772 |
),
|
|
|
1773 |
array('div' => array('class' => 'error-message')),
|
|
|
1774 |
'This field cannot be left blank',
|
|
|
1775 |
'/div',
|
|
|
1776 |
'/div'
|
|
|
1777 |
);
|
|
|
1778 |
$this->assertTags($result, $expected);
|
|
|
1779 |
}
|
|
|
1780 |
|
|
|
1781 |
/**
|
|
|
1782 |
* testMultipleInputValidation method
|
|
|
1783 |
*
|
|
|
1784 |
* test multiple record form validation error display.
|
|
|
1785 |
*
|
|
|
1786 |
* @return void
|
|
|
1787 |
*/
|
|
|
1788 |
public function testMultipleInputValidation() {
|
|
|
1789 |
$Address = ClassRegistry::init(array('class' => 'Address', 'table' => false, 'ds' => 'test'));
|
|
|
1790 |
$Address->validationErrors[0] = array(
|
|
|
1791 |
'title' => array('This field cannot be empty'),
|
|
|
1792 |
'first_name' => array('This field cannot be empty')
|
|
|
1793 |
);
|
|
|
1794 |
$Address->validationErrors[1] = array(
|
|
|
1795 |
'last_name' => array('You must have a last name')
|
|
|
1796 |
);
|
|
|
1797 |
$this->Form->create();
|
|
|
1798 |
|
|
|
1799 |
$result = $this->Form->input('Address.0.title');
|
|
|
1800 |
$expected = array(
|
|
|
1801 |
'div' => array('class'),
|
|
|
1802 |
'label' => array('for'),
|
|
|
1803 |
'preg:/[^<]+/',
|
|
|
1804 |
'/label',
|
|
|
1805 |
'input' => array(
|
|
|
1806 |
'type' => 'text', 'name', 'id', 'class' => 'form-error'
|
|
|
1807 |
),
|
|
|
1808 |
array('div' => array('class' => 'error-message')),
|
|
|
1809 |
'This field cannot be empty',
|
|
|
1810 |
'/div',
|
|
|
1811 |
'/div'
|
|
|
1812 |
);
|
|
|
1813 |
$this->assertTags($result, $expected);
|
|
|
1814 |
|
|
|
1815 |
$result = $this->Form->input('Address.0.first_name');
|
|
|
1816 |
$expected = array(
|
|
|
1817 |
'div' => array('class'),
|
|
|
1818 |
'label' => array('for'),
|
|
|
1819 |
'preg:/[^<]+/',
|
|
|
1820 |
'/label',
|
|
|
1821 |
'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
|
|
|
1822 |
array('div' => array('class' => 'error-message')),
|
|
|
1823 |
'This field cannot be empty',
|
|
|
1824 |
'/div',
|
|
|
1825 |
'/div'
|
|
|
1826 |
);
|
|
|
1827 |
$this->assertTags($result, $expected);
|
|
|
1828 |
|
|
|
1829 |
$result = $this->Form->input('Address.0.last_name');
|
|
|
1830 |
$expected = array(
|
|
|
1831 |
'div' => array('class'),
|
|
|
1832 |
'label' => array('for'),
|
|
|
1833 |
'preg:/[^<]+/',
|
|
|
1834 |
'/label',
|
|
|
1835 |
'input' => array('type' => 'text', 'name', 'id'),
|
|
|
1836 |
'/div'
|
|
|
1837 |
);
|
|
|
1838 |
$this->assertTags($result, $expected);
|
|
|
1839 |
|
|
|
1840 |
$result = $this->Form->input('Address.1.last_name');
|
|
|
1841 |
$expected = array(
|
|
|
1842 |
'div' => array('class'),
|
|
|
1843 |
'label' => array('for'),
|
|
|
1844 |
'preg:/[^<]+/',
|
|
|
1845 |
'/label',
|
|
|
1846 |
'input' => array(
|
|
|
1847 |
'type' => 'text', 'name' => 'preg:/[^<]+/',
|
|
|
1848 |
'id' => 'preg:/[^<]+/', 'class' => 'form-error'
|
|
|
1849 |
),
|
|
|
1850 |
array('div' => array('class' => 'error-message')),
|
|
|
1851 |
'You must have a last name',
|
|
|
1852 |
'/div',
|
|
|
1853 |
'/div'
|
|
|
1854 |
);
|
|
|
1855 |
$this->assertTags($result, $expected);
|
|
|
1856 |
}
|
|
|
1857 |
|
|
|
1858 |
/**
|
|
|
1859 |
* testInput method
|
|
|
1860 |
*
|
|
|
1861 |
* Test various incarnations of input().
|
|
|
1862 |
*
|
|
|
1863 |
* @return void
|
|
|
1864 |
*/
|
|
|
1865 |
public function testInput() {
|
|
|
1866 |
$result = $this->Form->input('ValidateUser.balance');
|
|
|
1867 |
$expected = array(
|
|
|
1868 |
'div' => array('class'),
|
|
|
1869 |
'label' => array('for'),
|
|
|
1870 |
'Balance',
|
|
|
1871 |
'/label',
|
|
|
1872 |
'input' => array('name', 'type' => 'number', 'id'),
|
|
|
1873 |
'/div',
|
|
|
1874 |
);
|
|
|
1875 |
$this->assertTags($result, $expected);
|
|
|
1876 |
|
|
|
1877 |
$result = $this->Form->input('Contact.email', array('id' => 'custom'));
|
|
|
1878 |
$expected = array(
|
|
|
1879 |
'div' => array('class' => 'input email'),
|
|
|
1880 |
'label' => array('for' => 'custom'),
|
|
|
1881 |
'Email',
|
|
|
1882 |
'/label',
|
|
|
1883 |
array('input' => array(
|
|
|
1884 |
'type' => 'email', 'name' => 'data[Contact][email]',
|
|
|
1885 |
'id' => 'custom', 'maxlength' => 255
|
|
|
1886 |
)),
|
|
|
1887 |
'/div'
|
|
|
1888 |
);
|
|
|
1889 |
$this->assertTags($result, $expected);
|
|
|
1890 |
|
|
|
1891 |
$result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
|
|
|
1892 |
$expected = array(
|
|
|
1893 |
'<div',
|
|
|
1894 |
'label' => array('for' => 'ContactEmail'),
|
|
|
1895 |
'Email',
|
|
|
1896 |
'/label',
|
|
|
1897 |
array('input' => array(
|
|
|
1898 |
'type' => 'email', 'name' => 'data[Contact][email]',
|
|
|
1899 |
'id' => 'ContactEmail', 'maxlength' => 255
|
|
|
1900 |
)),
|
|
|
1901 |
'/div'
|
|
|
1902 |
);
|
|
|
1903 |
$this->assertTags($result, $expected);
|
|
|
1904 |
|
|
|
1905 |
$result = $this->Form->hidden('Contact.idontexist');
|
|
|
1906 |
$expected = array('input' => array(
|
|
|
1907 |
'type' => 'hidden', 'name' => 'data[Contact][idontexist]',
|
|
|
1908 |
'id' => 'ContactIdontexist'
|
|
|
1909 |
));
|
|
|
1910 |
$this->assertTags($result, $expected);
|
|
|
1911 |
|
|
|
1912 |
$result = $this->Form->input('Contact.email', array('type' => 'text'));
|
|
|
1913 |
$expected = array(
|
|
|
1914 |
'div' => array('class' => 'input text'),
|
|
|
1915 |
'label' => array('for' => 'ContactEmail'),
|
|
|
1916 |
'Email',
|
|
|
1917 |
'/label',
|
|
|
1918 |
array('input' => array(
|
|
|
1919 |
'type' => 'text', 'name' => 'data[Contact][email]',
|
|
|
1920 |
'id' => 'ContactEmail'
|
|
|
1921 |
)),
|
|
|
1922 |
'/div'
|
|
|
1923 |
);
|
|
|
1924 |
$this->assertTags($result, $expected);
|
|
|
1925 |
|
|
|
1926 |
$result = $this->Form->input('Contact.5.email', array('type' => 'text'));
|
|
|
1927 |
$expected = array(
|
|
|
1928 |
'div' => array('class' => 'input text'),
|
|
|
1929 |
'label' => array('for' => 'Contact5Email'),
|
|
|
1930 |
'Email',
|
|
|
1931 |
'/label',
|
|
|
1932 |
array('input' => array(
|
|
|
1933 |
'type' => 'text', 'name' => 'data[Contact][5][email]',
|
|
|
1934 |
'id' => 'Contact5Email'
|
|
|
1935 |
)),
|
|
|
1936 |
'/div'
|
|
|
1937 |
);
|
|
|
1938 |
$this->assertTags($result, $expected);
|
|
|
1939 |
|
|
|
1940 |
$result = $this->Form->input('Contact.password');
|
|
|
1941 |
$expected = array(
|
|
|
1942 |
'div' => array('class' => 'input password'),
|
|
|
1943 |
'label' => array('for' => 'ContactPassword'),
|
|
|
1944 |
'Password',
|
|
|
1945 |
'/label',
|
|
|
1946 |
array('input' => array(
|
|
|
1947 |
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
1948 |
'id' => 'ContactPassword'
|
|
|
1949 |
)),
|
|
|
1950 |
'/div'
|
|
|
1951 |
);
|
|
|
1952 |
$this->assertTags($result, $expected);
|
|
|
1953 |
|
|
|
1954 |
$result = $this->Form->input('Contact.email', array(
|
|
|
1955 |
'type' => 'file', 'class' => 'textbox'
|
|
|
1956 |
));
|
|
|
1957 |
$expected = array(
|
|
|
1958 |
'div' => array('class' => 'input file'),
|
|
|
1959 |
'label' => array('for' => 'ContactEmail'),
|
|
|
1960 |
'Email',
|
|
|
1961 |
'/label',
|
|
|
1962 |
array('input' => array(
|
|
|
1963 |
'type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox',
|
|
|
1964 |
'id' => 'ContactEmail'
|
|
|
1965 |
)),
|
|
|
1966 |
'/div'
|
|
|
1967 |
);
|
|
|
1968 |
$this->assertTags($result, $expected);
|
|
|
1969 |
|
|
|
1970 |
$this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
|
|
|
1971 |
$result = $this->Form->input('Contact.phone');
|
|
|
1972 |
$expected = array(
|
|
|
1973 |
'div' => array('class' => 'input tel'),
|
|
|
1974 |
'label' => array('for' => 'ContactPhone'),
|
|
|
1975 |
'Phone',
|
|
|
1976 |
'/label',
|
|
|
1977 |
array('input' => array(
|
|
|
1978 |
'type' => 'tel', 'name' => 'data[Contact][phone]',
|
|
|
1979 |
'value' => 'Hello & World > weird chars',
|
|
|
1980 |
'id' => 'ContactPhone', 'maxlength' => 255
|
|
|
1981 |
)),
|
|
|
1982 |
'/div'
|
|
|
1983 |
);
|
|
|
1984 |
$this->assertTags($result, $expected);
|
|
|
1985 |
|
|
|
1986 |
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
|
|
|
1987 |
$result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
|
|
|
1988 |
$expected = array(
|
|
|
1989 |
'div' => array('class' => 'input text'),
|
|
|
1990 |
'label' => array('for' => 'myId'),
|
|
|
1991 |
'Field',
|
|
|
1992 |
'/label',
|
|
|
1993 |
'input' => array(
|
|
|
1994 |
'type' => 'text', 'name' => 'data[Model][0][OtherModel][field]',
|
|
|
1995 |
'value' => 'My value', 'id' => 'myId'
|
|
|
1996 |
),
|
|
|
1997 |
'/div'
|
|
|
1998 |
);
|
|
|
1999 |
$this->assertTags($result, $expected);
|
|
|
2000 |
|
|
|
2001 |
unset($this->Form->request->data);
|
|
|
2002 |
|
|
|
2003 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
2004 |
$Contact->validationErrors['field'] = array('Badness!');
|
|
|
2005 |
$result = $this->Form->input('Contact.field');
|
|
|
2006 |
$expected = array(
|
|
|
2007 |
'div' => array('class' => 'input text error'),
|
|
|
2008 |
'label' => array('for' => 'ContactField'),
|
|
|
2009 |
'Field',
|
|
|
2010 |
'/label',
|
|
|
2011 |
'input' => array(
|
|
|
2012 |
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
2013 |
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
2014 |
),
|
|
|
2015 |
array('div' => array('class' => 'error-message')),
|
|
|
2016 |
'Badness!',
|
|
|
2017 |
'/div',
|
|
|
2018 |
'/div'
|
|
|
2019 |
);
|
|
|
2020 |
$this->assertTags($result, $expected);
|
|
|
2021 |
|
|
|
2022 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2023 |
'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
|
|
|
2024 |
));
|
|
|
2025 |
$expected = array(
|
|
|
2026 |
'label' => array('for' => 'ContactField'),
|
|
|
2027 |
'Field',
|
|
|
2028 |
'/label',
|
|
|
2029 |
'input' => array(
|
|
|
2030 |
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
2031 |
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
2032 |
),
|
|
|
2033 |
array('span' => array('class' => 'error-message')),
|
|
|
2034 |
'Badness!',
|
|
|
2035 |
'/span'
|
|
|
2036 |
);
|
|
|
2037 |
$this->assertTags($result, $expected);
|
|
|
2038 |
|
|
|
2039 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2040 |
'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
|
|
|
2041 |
));
|
|
|
2042 |
$expected = array(
|
|
|
2043 |
'div' => array('class' => 'input text error'),
|
|
|
2044 |
'label' => array('for' => 'ContactField'),
|
|
|
2045 |
'Field',
|
|
|
2046 |
'/label',
|
|
|
2047 |
'input' => array(
|
|
|
2048 |
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
2049 |
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
2050 |
),
|
|
|
2051 |
array('div' => array('class' => 'error')),
|
|
|
2052 |
'Badness!',
|
|
|
2053 |
'/div'
|
|
|
2054 |
);
|
|
|
2055 |
$this->assertTags($result, $expected);
|
|
|
2056 |
|
|
|
2057 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2058 |
'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
|
|
|
2059 |
));
|
|
|
2060 |
$expected = array(
|
|
|
2061 |
'span' => array('class' => 'input text error'),
|
|
|
2062 |
'label' => array('for' => 'ContactField'),
|
|
|
2063 |
'Field',
|
|
|
2064 |
'/label',
|
|
|
2065 |
'input' => array(
|
|
|
2066 |
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
2067 |
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
2068 |
),
|
|
|
2069 |
'Badness!',
|
|
|
2070 |
'/span'
|
|
|
2071 |
);
|
|
|
2072 |
$this->assertTags($result, $expected);
|
|
|
2073 |
|
|
|
2074 |
$result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
|
|
|
2075 |
$expected = array(
|
|
|
2076 |
'div' => array('class' => 'input text error'),
|
|
|
2077 |
'label' => array('for' => 'ContactField'),
|
|
|
2078 |
'Field',
|
|
|
2079 |
'/label',
|
|
|
2080 |
'input' => array(
|
|
|
2081 |
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
2082 |
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
2083 |
),
|
|
|
2084 |
'A message to you, Rudy',
|
|
|
2085 |
array('div' => array('class' => 'error-message')),
|
|
|
2086 |
'Badness!',
|
|
|
2087 |
'/div',
|
|
|
2088 |
'/div'
|
|
|
2089 |
);
|
|
|
2090 |
$this->assertTags($result, $expected);
|
|
|
2091 |
|
|
|
2092 |
$this->Form->setEntity(null);
|
|
|
2093 |
$this->Form->setEntity('Contact.field');
|
|
|
2094 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2095 |
'after' => 'A message to you, Rudy', 'error' => false
|
|
|
2096 |
));
|
|
|
2097 |
$expected = array(
|
|
|
2098 |
'div' => array('class' => 'input text'),
|
|
|
2099 |
'label' => array('for' => 'ContactField'),
|
|
|
2100 |
'Field',
|
|
|
2101 |
'/label',
|
|
|
2102 |
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
|
|
2103 |
'A message to you, Rudy',
|
|
|
2104 |
'/div'
|
|
|
2105 |
);
|
|
|
2106 |
$this->assertTags($result, $expected);
|
|
|
2107 |
|
|
|
2108 |
$result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
|
|
|
2109 |
$expected = array(
|
|
|
2110 |
'div' => array('class' => 'input text'),
|
|
|
2111 |
'label' => array('for' => 'ObjectField'),
|
|
|
2112 |
'Field',
|
|
|
2113 |
'/label',
|
|
|
2114 |
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
|
|
|
2115 |
'A message to you, Rudy',
|
|
|
2116 |
'/div'
|
|
|
2117 |
);
|
|
|
2118 |
$this->assertTags($result, $expected);
|
|
|
2119 |
|
|
|
2120 |
$Contact->validationErrors['field'] = array('minLength');
|
|
|
2121 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2122 |
'error' => array(
|
|
|
2123 |
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
|
|
2124 |
'maxLength' => 'login too large'
|
|
|
2125 |
)
|
|
|
2126 |
));
|
|
|
2127 |
$expected = array(
|
|
|
2128 |
'div' => array('class' => 'input text error'),
|
|
|
2129 |
'label' => array('for' => 'ContactField'),
|
|
|
2130 |
'Field',
|
|
|
2131 |
'/label',
|
|
|
2132 |
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
|
|
2133 |
array('div' => array('class' => 'error-message')),
|
|
|
2134 |
'Le login doit contenir au moins 2 caractères',
|
|
|
2135 |
'/div',
|
|
|
2136 |
'/div'
|
|
|
2137 |
);
|
|
|
2138 |
$this->assertTags($result, $expected);
|
|
|
2139 |
|
|
|
2140 |
$Contact->validationErrors['field'] = array('maxLength');
|
|
|
2141 |
$result = $this->Form->input('Contact.field', array(
|
|
|
2142 |
'error' => array(
|
|
|
2143 |
'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
|
|
|
2144 |
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
|
|
2145 |
'maxLength' => 'login too large',
|
|
|
2146 |
)
|
|
|
2147 |
));
|
|
|
2148 |
$expected = array(
|
|
|
2149 |
'div' => array('class' => 'input text error'),
|
|
|
2150 |
'label' => array('for' => 'ContactField'),
|
|
|
2151 |
'Field',
|
|
|
2152 |
'/label',
|
|
|
2153 |
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
|
|
2154 |
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
|
|
|
2155 |
'login too large',
|
|
|
2156 |
'/span',
|
|
|
2157 |
'/div'
|
|
|
2158 |
);
|
|
|
2159 |
$this->assertTags($result, $expected);
|
|
|
2160 |
}
|
|
|
2161 |
|
|
|
2162 |
/**
|
|
|
2163 |
* Test that inputs with 0 can be created.
|
|
|
2164 |
*
|
|
|
2165 |
* @return void
|
|
|
2166 |
*/
|
|
|
2167 |
public function testInputZero() {
|
|
|
2168 |
$this->Form->create('User');
|
|
|
2169 |
$result = $this->Form->input('0');
|
|
|
2170 |
$expected = array(
|
|
|
2171 |
'div' => array('class' => 'input text'),
|
|
|
2172 |
'label' => array('for' => 'User0'), '/label',
|
|
|
2173 |
'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
|
|
|
2174 |
'/div'
|
|
|
2175 |
);
|
|
|
2176 |
$this->assertTags($result, $expected);
|
|
|
2177 |
}
|
|
|
2178 |
|
|
|
2179 |
/**
|
|
|
2180 |
* test input() with checkbox creation
|
|
|
2181 |
*
|
|
|
2182 |
* @return void
|
|
|
2183 |
*/
|
|
|
2184 |
public function testInputCheckbox() {
|
|
|
2185 |
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
|
|
|
2186 |
$expected = array(
|
|
|
2187 |
'div' => array('class' => 'input checkbox'),
|
|
|
2188 |
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
2189 |
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
2190 |
'/div'
|
|
|
2191 |
);
|
|
|
2192 |
$this->assertTags($result, $expected);
|
|
|
2193 |
|
|
|
2194 |
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
|
|
|
2195 |
$expected = array(
|
|
|
2196 |
'div' => array('class' => 'input checkbox'),
|
|
|
2197 |
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
2198 |
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
2199 |
'/div'
|
|
|
2200 |
);
|
|
|
2201 |
$this->assertTags($result, $expected);
|
|
|
2202 |
|
|
|
2203 |
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
|
|
|
2204 |
$expected = array(
|
|
|
2205 |
'div' => array('class' => 'input checkbox'),
|
|
|
2206 |
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
2207 |
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
2208 |
'/div'
|
|
|
2209 |
);
|
|
|
2210 |
$this->assertTags($result, $expected);
|
|
|
2211 |
|
|
|
2212 |
$result = $this->Form->input('User.disabled', array(
|
|
|
2213 |
'label' => 'Disabled',
|
|
|
2214 |
'type' => 'checkbox',
|
|
|
2215 |
'data-foo' => 'disabled'
|
|
|
2216 |
));
|
|
|
2217 |
$expected = array(
|
|
|
2218 |
'div' => array('class' => 'input checkbox'),
|
|
|
2219 |
'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
|
|
|
2220 |
array('input' => array(
|
|
|
2221 |
'type' => 'checkbox',
|
|
|
2222 |
'name' => 'data[User][disabled]',
|
|
|
2223 |
'value' => '1',
|
|
|
2224 |
'id' => 'UserDisabled',
|
|
|
2225 |
'data-foo' => 'disabled'
|
|
|
2226 |
)),
|
|
|
2227 |
'label' => array('for' => 'UserDisabled'),
|
|
|
2228 |
'Disabled',
|
|
|
2229 |
'/label',
|
|
|
2230 |
'/div'
|
|
|
2231 |
);
|
|
|
2232 |
$this->assertTags($result, $expected);
|
|
|
2233 |
}
|
|
|
2234 |
|
|
|
2235 |
/**
|
|
|
2236 |
* test form->input() with time types.
|
|
|
2237 |
*
|
|
|
2238 |
*/
|
|
|
2239 |
public function testInputTime() {
|
|
|
2240 |
extract($this->dateRegex);
|
|
|
2241 |
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
|
|
|
2242 |
$result = explode(':', $result);
|
|
|
2243 |
$this->assertRegExp('/option value="23"/', $result[0]);
|
|
|
2244 |
$this->assertNotRegExp('/option value="24"/', $result[0]);
|
|
|
2245 |
|
|
|
2246 |
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
|
|
|
2247 |
$result = explode(':', $result);
|
|
|
2248 |
$this->assertRegExp('/option value="23"/', $result[0]);
|
|
|
2249 |
$this->assertNotRegExp('/option value="24"/', $result[0]);
|
|
|
2250 |
|
|
|
2251 |
$result = $this->Form->input('Model.field', array(
|
|
|
2252 |
'type' => 'time', 'timeFormat' => 24, 'interval' => 15
|
|
|
2253 |
));
|
|
|
2254 |
$result = explode(':', $result);
|
|
|
2255 |
$this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
2256 |
$this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
|
|
|
2257 |
$this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
2258 |
|
|
|
2259 |
$result = $this->Form->input('Model.field', array(
|
|
|
2260 |
'type' => 'time', 'timeFormat' => 12, 'interval' => 15
|
|
|
2261 |
));
|
|
|
2262 |
$result = explode(':', $result);
|
|
|
2263 |
$this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
2264 |
$this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
|
|
|
2265 |
$this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
2266 |
|
|
|
2267 |
$result = $this->Form->input('prueba', array(
|
|
|
2268 |
'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
|
|
|
2269 |
'maxYear' => date('Y') + 1, 'interval' => 15
|
|
|
2270 |
));
|
|
|
2271 |
$result = explode(':', $result);
|
|
|
2272 |
$this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
2273 |
$this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
|
|
|
2274 |
$this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
2275 |
$this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
|
|
|
2276 |
|
|
|
2277 |
$result = $this->Form->input('Random.start_time', array(
|
|
|
2278 |
'type' => 'time',
|
|
|
2279 |
'selected' => '18:15'
|
|
|
2280 |
));
|
|
|
2281 |
$this->assertContains('<option value="06" selected="selected">6</option>', $result);
|
|
|
2282 |
$this->assertContains('<option value="15" selected="selected">15</option>', $result);
|
|
|
2283 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2284 |
|
|
|
2285 |
$result = $this->Form->input('published', array('type' => 'time'));
|
|
|
2286 |
$now = strtotime('now');
|
|
|
2287 |
$this->assertContains('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
|
|
|
2288 |
|
|
|
2289 |
$now = strtotime('2013-03-09 00:42:21');
|
|
|
2290 |
$result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
|
|
|
2291 |
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
|
|
2292 |
$this->assertContains('<option value="42" selected="selected">42</option>', $result);
|
|
|
2293 |
}
|
|
|
2294 |
|
|
|
2295 |
/**
|
|
|
2296 |
* Test interval + selected near the hour roll over.
|
|
|
2297 |
*
|
|
|
2298 |
* @return void
|
|
|
2299 |
*/
|
|
|
2300 |
public function testTimeSelectedWithInterval() {
|
|
|
2301 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2302 |
'type' => 'time',
|
|
|
2303 |
'interval' => 15,
|
|
|
2304 |
'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
|
|
|
2305 |
));
|
|
|
2306 |
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
|
|
|
2307 |
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
|
|
2308 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2309 |
|
|
|
2310 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2311 |
'type' => 'time',
|
|
|
2312 |
'interval' => 15,
|
|
|
2313 |
'selected' => '2012-10-23 15:57:00'
|
|
|
2314 |
));
|
|
|
2315 |
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
|
|
|
2316 |
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
|
|
2317 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2318 |
|
|
|
2319 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2320 |
'timeFormat' => 24,
|
|
|
2321 |
'type' => 'time',
|
|
|
2322 |
'interval' => 15,
|
|
|
2323 |
'selected' => '15:57'
|
|
|
2324 |
));
|
|
|
2325 |
$this->assertContains('<option value="16" selected="selected">16</option>', $result);
|
|
|
2326 |
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
|
|
2327 |
|
|
|
2328 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2329 |
'timeFormat' => 24,
|
|
|
2330 |
'type' => 'time',
|
|
|
2331 |
'interval' => 15,
|
|
|
2332 |
'selected' => '23:57'
|
|
|
2333 |
));
|
|
|
2334 |
$this->assertContains('<option value="00" selected="selected">0</option>', $result);
|
|
|
2335 |
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
|
|
2336 |
|
|
|
2337 |
$result = $this->Form->input('Model.created', array(
|
|
|
2338 |
'timeFormat' => 24,
|
|
|
2339 |
'type' => 'datetime',
|
|
|
2340 |
'interval' => 15,
|
|
|
2341 |
'selected' => '2012-09-30 23:56'
|
|
|
2342 |
));
|
|
|
2343 |
$this->assertContains('<option value="2012" selected="selected">2012</option>', $result);
|
|
|
2344 |
$this->assertContains('<option value="10" selected="selected">October</option>', $result);
|
|
|
2345 |
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
|
|
|
2346 |
$this->assertContains('<option value="00" selected="selected">0</option>', $result);
|
|
|
2347 |
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
|
|
2348 |
}
|
|
|
2349 |
|
|
|
2350 |
/**
|
|
|
2351 |
* Test interval & timeFormat = 12
|
|
|
2352 |
*
|
|
|
2353 |
* @return void
|
|
|
2354 |
*/
|
|
|
2355 |
public function testInputTimeWithIntervalAnd12HourFormat() {
|
|
|
2356 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2357 |
'type' => 'time',
|
|
|
2358 |
'timeFormat' => 12,
|
|
|
2359 |
'interval' => 5,
|
|
|
2360 |
'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
|
|
|
2361 |
));
|
|
|
2362 |
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
|
|
|
2363 |
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
2364 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2365 |
|
|
|
2366 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2367 |
'type' => 'time',
|
|
|
2368 |
'timeFormat' => '12',
|
|
|
2369 |
'interval' => 5,
|
|
|
2370 |
'selected' => '2013-04-19 16:30:00'
|
|
|
2371 |
));
|
|
|
2372 |
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
|
|
|
2373 |
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
2374 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2375 |
|
|
|
2376 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2377 |
'type' => 'time',
|
|
|
2378 |
'timeFormat' => '12',
|
|
|
2379 |
'interval' => 10,
|
|
|
2380 |
'selected' => '2013-05-19 00:33:00'
|
|
|
2381 |
));
|
|
|
2382 |
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
|
|
2383 |
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
2384 |
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
|
|
|
2385 |
|
|
|
2386 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2387 |
'type' => 'time',
|
|
|
2388 |
'timeFormat' => '12',
|
|
|
2389 |
'interval' => 10,
|
|
|
2390 |
'selected' => '2013-05-19 13:33:00'
|
|
|
2391 |
));
|
|
|
2392 |
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
|
|
|
2393 |
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
2394 |
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
|
|
2395 |
|
|
|
2396 |
$result = $this->Form->input('Model.start_time', array(
|
|
|
2397 |
'type' => 'time',
|
|
|
2398 |
'timeFormat' => '12',
|
|
|
2399 |
'interval' => 10,
|
|
|
2400 |
'selected' => '2013-05-19 01:33:00'
|
|
|
2401 |
));
|
|
|
2402 |
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
|
|
|
2403 |
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
2404 |
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
|
|
|
2405 |
}
|
|
|
2406 |
|
|
|
2407 |
/**
|
|
|
2408 |
* test form->input() with datetime, date and time types
|
|
|
2409 |
*
|
|
|
2410 |
* @return void
|
|
|
2411 |
*/
|
|
|
2412 |
public function testInputDatetime() {
|
|
|
2413 |
extract($this->dateRegex);
|
|
|
2414 |
$result = $this->Form->input('prueba', array(
|
|
|
2415 |
'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
|
|
|
2416 |
'maxYear' => date('Y') + 1, 'interval' => 15
|
|
|
2417 |
));
|
|
|
2418 |
$result = explode(':', $result);
|
|
|
2419 |
$this->assertNotRegExp('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
2420 |
$this->assertNotRegExp('#<option value="50"[^>]*>50</option>#', $result[1]);
|
|
|
2421 |
$this->assertRegExp('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
2422 |
$this->assertRegExp('#<option value="30"[^>]*>30</option>#', $result[1]);
|
|
|
2423 |
|
|
|
2424 |
//related to ticket #5013
|
|
|
2425 |
$result = $this->Form->input('Contact.date', array(
|
|
|
2426 |
'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
|
|
|
2427 |
));
|
|
|
2428 |
$this->assertRegExp('/class="customClass"/', $result);
|
|
|
2429 |
$this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
|
|
|
2430 |
|
|
|
2431 |
$result = $this->Form->input('Contact.date', array(
|
|
|
2432 |
'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
|
|
|
2433 |
));
|
|
|
2434 |
$this->assertRegExp('/id="customIdDay"/', $result);
|
|
|
2435 |
$this->assertRegExp('/id="customIdMonth"/', $result);
|
|
|
2436 |
$this->assertRegExp('/onChange="function\(\)\{\}"/', $result);
|
|
|
2437 |
|
|
|
2438 |
$result = $this->Form->input('Model.field', array(
|
|
|
2439 |
'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
|
|
|
2440 |
));
|
|
|
2441 |
$this->assertRegExp('/id="customIDDay"/', $result);
|
|
|
2442 |
$this->assertRegExp('/id="customIDHour"/', $result);
|
|
|
2443 |
$result = explode('</select><select', $result);
|
|
|
2444 |
$result = explode(':', $result[1]);
|
|
|
2445 |
$this->assertRegExp('/option value="23"/', $result[0]);
|
|
|
2446 |
$this->assertNotRegExp('/option value="24"/', $result[0]);
|
|
|
2447 |
|
|
|
2448 |
$result = $this->Form->input('Model.field', array(
|
|
|
2449 |
'type' => 'datetime', 'timeFormat' => 12
|
|
|
2450 |
));
|
|
|
2451 |
$result = explode('</select><select', $result);
|
|
|
2452 |
$result = explode(':', $result[1]);
|
|
|
2453 |
$this->assertRegExp('/option value="12"/', $result[0]);
|
|
|
2454 |
$this->assertNotRegExp('/option value="13"/', $result[0]);
|
|
|
2455 |
|
|
|
2456 |
$this->Form->request->data = array('Contact' => array('created' => null));
|
|
|
2457 |
$result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
|
|
|
2458 |
$expected = array(
|
|
|
2459 |
'div' => array('class' => 'input date'),
|
|
|
2460 |
'label' => array('for' => 'ContactCreatedMonth'),
|
|
|
2461 |
'Created',
|
|
|
2462 |
'/label',
|
|
|
2463 |
array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
|
|
|
2464 |
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
2465 |
$monthsRegex,
|
|
|
2466 |
'/select', '-',
|
|
|
2467 |
array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
|
|
|
2468 |
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
2469 |
$daysRegex,
|
|
|
2470 |
'/select', '-',
|
|
|
2471 |
array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
|
|
|
2472 |
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
2473 |
$yearsRegex,
|
|
|
2474 |
'/select',
|
|
|
2475 |
'/div'
|
|
|
2476 |
);
|
|
|
2477 |
$this->assertTags($result, $expected);
|
|
|
2478 |
|
|
|
2479 |
$this->Form->request->data = array('Contact' => array('created' => null));
|
|
|
2480 |
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
|
|
|
2481 |
$this->assertRegExp('/for\="ContactCreatedHour"/', $result);
|
|
|
2482 |
|
|
|
2483 |
$this->Form->request->data = array('Contact' => array('created' => null));
|
|
|
2484 |
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
|
|
|
2485 |
$this->assertRegExp('/for\="ContactCreatedMonth"/', $result);
|
|
|
2486 |
|
|
|
2487 |
$result = $this->Form->input('Contact.created', array(
|
|
|
2488 |
'type' => 'date',
|
|
|
2489 |
'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
|
|
|
2490 |
'timeFormat' => 'NONE'
|
|
|
2491 |
));
|
|
|
2492 |
$this->assertRegExp('/for\="created-month"/', $result);
|
|
|
2493 |
}
|
|
|
2494 |
|
|
|
2495 |
/**
|
|
|
2496 |
* Test generating checkboxes in a loop.
|
|
|
2497 |
*
|
|
|
2498 |
* @return void
|
|
|
2499 |
*/
|
|
|
2500 |
public function testInputCheckboxesInLoop() {
|
|
|
2501 |
for ($i = 1; $i < 5; $i++) {
|
|
|
2502 |
$result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
|
|
|
2503 |
$expected = array(
|
|
|
2504 |
'div' => array('class' => 'input checkbox'),
|
|
|
2505 |
'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
|
|
|
2506 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
|
|
|
2507 |
'label' => array('for' => "Contact{$i}Email"),
|
|
|
2508 |
'Email',
|
|
|
2509 |
'/label',
|
|
|
2510 |
'/div'
|
|
|
2511 |
);
|
|
|
2512 |
$this->assertTags($result, $expected);
|
|
|
2513 |
}
|
|
|
2514 |
}
|
|
|
2515 |
|
|
|
2516 |
/**
|
|
|
2517 |
* Test generating checkboxes with disabled elements.
|
|
|
2518 |
*
|
|
|
2519 |
* @return void
|
|
|
2520 |
*/
|
|
|
2521 |
public function testInputCheckboxWithDisabledElements() {
|
|
|
2522 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
|
|
|
2523 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
|
|
|
2524 |
|
|
|
2525 |
$expected = array(
|
|
|
2526 |
array('div' => array('class' => 'input select')),
|
|
|
2527 |
array('label' => array('for' => "ContactMultiple")),
|
|
|
2528 |
'Multiple',
|
|
|
2529 |
'/label',
|
|
|
2530 |
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
|
|
|
2531 |
array('div' => array('class' => 'checkbox')),
|
|
|
2532 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
|
|
|
2533 |
array('label' => array('for' => "ContactMultiple1")),
|
|
|
2534 |
'One',
|
|
|
2535 |
'/label',
|
|
|
2536 |
'/div',
|
|
|
2537 |
array('div' => array('class' => 'checkbox')),
|
|
|
2538 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
|
|
|
2539 |
array('label' => array('for' => "ContactMultiple2")),
|
|
|
2540 |
'Two',
|
|
|
2541 |
'/label',
|
|
|
2542 |
'/div',
|
|
|
2543 |
array('div' => array('class' => 'checkbox')),
|
|
|
2544 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
|
|
|
2545 |
array('label' => array('for' => "ContactMultiple3")),
|
|
|
2546 |
'Three',
|
|
|
2547 |
'/label',
|
|
|
2548 |
'/div',
|
|
|
2549 |
'/div'
|
|
|
2550 |
);
|
|
|
2551 |
$this->assertTags($result, $expected);
|
|
|
2552 |
|
|
|
2553 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => true, 'options' => $options));
|
|
|
2554 |
$this->assertTags($result, $expected);
|
|
|
2555 |
|
|
|
2556 |
$disabled = array('2', 3);
|
|
|
2557 |
|
|
|
2558 |
$expected = array(
|
|
|
2559 |
array('div' => array('class' => 'input select')),
|
|
|
2560 |
array('label' => array('for' => "ContactMultiple")),
|
|
|
2561 |
'Multiple',
|
|
|
2562 |
'/label',
|
|
|
2563 |
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
|
|
|
2564 |
array('div' => array('class' => 'checkbox')),
|
|
|
2565 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
|
|
|
2566 |
array('label' => array('for' => "ContactMultiple1")),
|
|
|
2567 |
'One',
|
|
|
2568 |
'/label',
|
|
|
2569 |
'/div',
|
|
|
2570 |
array('div' => array('class' => 'checkbox')),
|
|
|
2571 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
|
|
|
2572 |
array('label' => array('for' => "ContactMultiple2")),
|
|
|
2573 |
'Two',
|
|
|
2574 |
'/label',
|
|
|
2575 |
'/div',
|
|
|
2576 |
array('div' => array('class' => 'checkbox')),
|
|
|
2577 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
|
|
|
2578 |
array('label' => array('for' => "ContactMultiple3")),
|
|
|
2579 |
'Three',
|
|
|
2580 |
'/label',
|
|
|
2581 |
'/div',
|
|
|
2582 |
'/div'
|
|
|
2583 |
);
|
|
|
2584 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
|
|
|
2585 |
$this->assertTags($result, $expected);
|
|
|
2586 |
|
|
|
2587 |
// make sure 50 does only disable 50, and not 50f5c0cf
|
|
|
2588 |
$options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
|
|
|
2589 |
$disabled = array(50);
|
|
|
2590 |
|
|
|
2591 |
$expected = array(
|
|
|
2592 |
array('div' => array('class' => 'input select')),
|
|
|
2593 |
array('label' => array('for' => "ContactMultiple")),
|
|
|
2594 |
'Multiple',
|
|
|
2595 |
'/label',
|
|
|
2596 |
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
|
|
|
2597 |
array('div' => array('class' => 'checkbox')),
|
|
|
2598 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
|
|
|
2599 |
array('label' => array('for' => "ContactMultiple50")),
|
|
|
2600 |
'Fifty',
|
|
|
2601 |
'/label',
|
|
|
2602 |
'/div',
|
|
|
2603 |
array('div' => array('class' => 'checkbox')),
|
|
|
2604 |
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
|
|
|
2605 |
array('label' => array('for' => "ContactMultiple50f5c0cf")),
|
|
|
2606 |
'Stringy',
|
|
|
2607 |
'/label',
|
|
|
2608 |
'/div',
|
|
|
2609 |
'/div'
|
|
|
2610 |
);
|
|
|
2611 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
|
|
|
2612 |
$this->assertTags($result, $expected);
|
|
|
2613 |
}
|
|
|
2614 |
|
|
|
2615 |
/**
|
|
|
2616 |
* test input name with leading integer, ensure attributes are generated correctly.
|
|
|
2617 |
*
|
|
|
2618 |
* @return void
|
|
|
2619 |
*/
|
|
|
2620 |
public function testInputWithLeadingInteger() {
|
|
|
2621 |
$result = $this->Form->text('0.Node.title');
|
|
|
2622 |
$expected = array(
|
|
|
2623 |
'input' => array('name' => 'data[0][Node][title]', 'id' => '0NodeTitle', 'type' => 'text')
|
|
|
2624 |
);
|
|
|
2625 |
$this->assertTags($result, $expected);
|
|
|
2626 |
}
|
|
|
2627 |
|
|
|
2628 |
/**
|
|
|
2629 |
* test form->input() with select type inputs.
|
|
|
2630 |
*
|
|
|
2631 |
* @return void
|
|
|
2632 |
*/
|
|
|
2633 |
public function testInputSelectType() {
|
|
|
2634 |
$result = $this->Form->input('email', array(
|
|
|
2635 |
'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
|
|
|
2636 |
);
|
|
|
2637 |
$expected = array(
|
|
|
2638 |
'div' => array('class' => 'input select'),
|
|
|
2639 |
'label' => array('for' => 'email'),
|
|
|
2640 |
'Email',
|
|
|
2641 |
'/label',
|
|
|
2642 |
array('select' => array('name' => 'data[email]', 'id' => 'email')),
|
|
|
2643 |
array('option' => array('value' => '')),
|
|
|
2644 |
'/option',
|
|
|
2645 |
array('option' => array('value' => 'è')),
|
|
|
2646 |
'Firést',
|
|
|
2647 |
'/option',
|
|
|
2648 |
array('option' => array('value' => 'é')),
|
|
|
2649 |
'Secoènd',
|
|
|
2650 |
'/option',
|
|
|
2651 |
'/select',
|
|
|
2652 |
'/div'
|
|
|
2653 |
);
|
|
|
2654 |
$this->assertTags($result, $expected);
|
|
|
2655 |
|
|
|
2656 |
$result = $this->Form->input('email', array(
|
|
|
2657 |
'options' => array('First', 'Second'), 'empty' => true)
|
|
|
2658 |
);
|
|
|
2659 |
$expected = array(
|
|
|
2660 |
'div' => array('class' => 'input select'),
|
|
|
2661 |
'label' => array('for' => 'email'),
|
|
|
2662 |
'Email',
|
|
|
2663 |
'/label',
|
|
|
2664 |
array('select' => array('name' => 'data[email]', 'id' => 'email')),
|
|
|
2665 |
array('option' => array('value' => '')),
|
|
|
2666 |
'/option',
|
|
|
2667 |
array('option' => array('value' => '0')),
|
|
|
2668 |
'First',
|
|
|
2669 |
'/option',
|
|
|
2670 |
array('option' => array('value' => '1')),
|
|
|
2671 |
'Second',
|
|
|
2672 |
'/option',
|
|
|
2673 |
'/select',
|
|
|
2674 |
'/div'
|
|
|
2675 |
);
|
|
|
2676 |
$this->assertTags($result, $expected);
|
|
|
2677 |
|
|
|
2678 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2679 |
$this->Form->request->data = array('Model' => array('user_id' => 'value'));
|
|
|
2680 |
|
|
|
2681 |
$result = $this->Form->input('Model.user_id', array('empty' => true));
|
|
|
2682 |
$expected = array(
|
|
|
2683 |
'div' => array('class' => 'input select'),
|
|
|
2684 |
'label' => array('for' => 'ModelUserId'),
|
|
|
2685 |
'User',
|
|
|
2686 |
'/label',
|
|
|
2687 |
'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),
|
|
|
2688 |
array('option' => array('value' => '')),
|
|
|
2689 |
'/option',
|
|
|
2690 |
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
2691 |
'good',
|
|
|
2692 |
'/option',
|
|
|
2693 |
array('option' => array('value' => 'other')),
|
|
|
2694 |
'bad',
|
|
|
2695 |
'/option',
|
|
|
2696 |
'/select',
|
|
|
2697 |
'/div'
|
|
|
2698 |
);
|
|
|
2699 |
$this->assertTags($result, $expected);
|
|
|
2700 |
|
|
|
2701 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2702 |
$this->Form->request->data = array('Thing' => array('user_id' => null));
|
|
|
2703 |
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
|
|
|
2704 |
$expected = array(
|
|
|
2705 |
'div' => array('class' => 'input select'),
|
|
|
2706 |
'label' => array('for' => 'ThingUserId'),
|
|
|
2707 |
'User',
|
|
|
2708 |
'/label',
|
|
|
2709 |
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
|
|
|
2710 |
array('option' => array('value' => '')),
|
|
|
2711 |
'Some Empty',
|
|
|
2712 |
'/option',
|
|
|
2713 |
array('option' => array('value' => 'value')),
|
|
|
2714 |
'good',
|
|
|
2715 |
'/option',
|
|
|
2716 |
array('option' => array('value' => 'other')),
|
|
|
2717 |
'bad',
|
|
|
2718 |
'/option',
|
|
|
2719 |
'/select',
|
|
|
2720 |
'/div'
|
|
|
2721 |
);
|
|
|
2722 |
$this->assertTags($result, $expected);
|
|
|
2723 |
|
|
|
2724 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2725 |
$this->Form->request->data = array('Thing' => array('user_id' => 'value'));
|
|
|
2726 |
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
|
|
|
2727 |
$expected = array(
|
|
|
2728 |
'div' => array('class' => 'input select'),
|
|
|
2729 |
'label' => array('for' => 'ThingUserId'),
|
|
|
2730 |
'User',
|
|
|
2731 |
'/label',
|
|
|
2732 |
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
|
|
|
2733 |
array('option' => array('value' => '')),
|
|
|
2734 |
'Some Empty',
|
|
|
2735 |
'/option',
|
|
|
2736 |
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
2737 |
'good',
|
|
|
2738 |
'/option',
|
|
|
2739 |
array('option' => array('value' => 'other')),
|
|
|
2740 |
'bad',
|
|
|
2741 |
'/option',
|
|
|
2742 |
'/select',
|
|
|
2743 |
'/div'
|
|
|
2744 |
);
|
|
|
2745 |
$this->assertTags($result, $expected);
|
|
|
2746 |
|
|
|
2747 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2748 |
$this->Form->request->data = array('User' => array('User' => array('value')));
|
|
|
2749 |
$result = $this->Form->input('User.User', array('empty' => true));
|
|
|
2750 |
$expected = array(
|
|
|
2751 |
'div' => array('class' => 'input select'),
|
|
|
2752 |
'label' => array('for' => 'UserUser'),
|
|
|
2753 |
'User',
|
|
|
2754 |
'/label',
|
|
|
2755 |
'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => '', 'id' => 'UserUser_'),
|
|
|
2756 |
'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
|
|
|
2757 |
array('option' => array('value' => '')),
|
|
|
2758 |
'/option',
|
|
|
2759 |
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
2760 |
'good',
|
|
|
2761 |
'/option',
|
|
|
2762 |
array('option' => array('value' => 'other')),
|
|
|
2763 |
'bad',
|
|
|
2764 |
'/option',
|
|
|
2765 |
'/select',
|
|
|
2766 |
'/div'
|
|
|
2767 |
);
|
|
|
2768 |
$this->assertTags($result, $expected);
|
|
|
2769 |
|
|
|
2770 |
$this->Form->data = array();
|
|
|
2771 |
$result = $this->Form->input('Publisher.id', array(
|
|
|
2772 |
'label' => 'Publisher',
|
|
|
2773 |
'type' => 'select',
|
|
|
2774 |
'multiple' => 'checkbox',
|
|
|
2775 |
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
|
|
|
2776 |
));
|
|
|
2777 |
$expected = array(
|
|
|
2778 |
array('div' => array('class' => 'input select')),
|
|
|
2779 |
array('label' => array('for' => 'PublisherId')),
|
|
|
2780 |
'Publisher',
|
|
|
2781 |
'/label',
|
|
|
2782 |
'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'),
|
|
|
2783 |
array('div' => array('class' => 'checkbox')),
|
|
|
2784 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
|
|
|
2785 |
array('label' => array('for' => 'PublisherIdValue1')),
|
|
|
2786 |
'Label 1',
|
|
|
2787 |
'/label',
|
|
|
2788 |
'/div',
|
|
|
2789 |
array('div' => array('class' => 'checkbox')),
|
|
|
2790 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
|
|
|
2791 |
array('label' => array('for' => 'PublisherIdValue2')),
|
|
|
2792 |
'Label 2',
|
|
|
2793 |
'/label',
|
|
|
2794 |
'/div',
|
|
|
2795 |
'/div'
|
|
|
2796 |
);
|
|
|
2797 |
$this->assertTags($result, $expected);
|
|
|
2798 |
}
|
|
|
2799 |
|
|
|
2800 |
/**
|
|
|
2801 |
* test that input() and a non standard primary key makes a hidden input by default.
|
|
|
2802 |
*
|
|
|
2803 |
* @return void
|
|
|
2804 |
*/
|
|
|
2805 |
public function testInputWithNonStandardPrimaryKeyMakesHidden() {
|
|
|
2806 |
$this->Form->create('User');
|
|
|
2807 |
$this->Form->fieldset = array(
|
|
|
2808 |
'User' => array(
|
|
|
2809 |
'fields' => array(
|
|
|
2810 |
'model_id' => array('type' => 'integer')
|
|
|
2811 |
),
|
|
|
2812 |
'validates' => array(),
|
|
|
2813 |
'key' => 'model_id'
|
|
|
2814 |
)
|
|
|
2815 |
);
|
|
|
2816 |
$result = $this->Form->input('model_id');
|
|
|
2817 |
$expected = array(
|
|
|
2818 |
'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
|
|
|
2819 |
);
|
|
|
2820 |
$this->assertTags($result, $expected);
|
|
|
2821 |
}
|
|
|
2822 |
|
|
|
2823 |
/**
|
|
|
2824 |
* test that overriding the magic select type widget is possible
|
|
|
2825 |
*
|
|
|
2826 |
* @return void
|
|
|
2827 |
*/
|
|
|
2828 |
public function testInputOverridingMagicSelectType() {
|
|
|
2829 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2830 |
$result = $this->Form->input('Model.user_id', array('type' => 'text'));
|
|
|
2831 |
$expected = array(
|
|
|
2832 |
'div' => array('class' => 'input text'),
|
|
|
2833 |
'label' => array('for' => 'ModelUserId'), 'User', '/label',
|
|
|
2834 |
'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
|
|
|
2835 |
'/div'
|
|
|
2836 |
);
|
|
|
2837 |
$this->assertTags($result, $expected);
|
|
|
2838 |
|
|
|
2839 |
//Check that magic types still work for plural/singular vars
|
|
|
2840 |
$this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2841 |
$result = $this->Form->input('Model.type');
|
|
|
2842 |
$expected = array(
|
|
|
2843 |
'div' => array('class' => 'input select'),
|
|
|
2844 |
'label' => array('for' => 'ModelType'), 'Type', '/label',
|
|
|
2845 |
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
|
|
|
2846 |
array('option' => array('value' => 'value')), 'good', '/option',
|
|
|
2847 |
array('option' => array('value' => 'other')), 'bad', '/option',
|
|
|
2848 |
'/select',
|
|
|
2849 |
'/div'
|
|
|
2850 |
);
|
|
|
2851 |
$this->assertTags($result, $expected);
|
|
|
2852 |
}
|
|
|
2853 |
|
|
|
2854 |
/**
|
|
|
2855 |
* Test that inferred types do not override developer input
|
|
|
2856 |
*
|
|
|
2857 |
* @return void
|
|
|
2858 |
*/
|
|
|
2859 |
public function testInputMagicTypeDoesNotOverride() {
|
|
|
2860 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2861 |
$result = $this->Form->input('Model.user', array('type' => 'checkbox'));
|
|
|
2862 |
$expected = array(
|
|
|
2863 |
'div' => array('class' => 'input checkbox'),
|
|
|
2864 |
array('input' => array(
|
|
|
2865 |
'type' => 'hidden',
|
|
|
2866 |
'name' => 'data[Model][user]',
|
|
|
2867 |
'id' => 'ModelUser_',
|
|
|
2868 |
'value' => 0,
|
|
|
2869 |
)),
|
|
|
2870 |
array('input' => array(
|
|
|
2871 |
'name' => 'data[Model][user]',
|
|
|
2872 |
'type' => 'checkbox',
|
|
|
2873 |
'id' => 'ModelUser',
|
|
|
2874 |
'value' => 1
|
|
|
2875 |
)),
|
|
|
2876 |
'label' => array('for' => 'ModelUser'), 'User', '/label',
|
|
|
2877 |
'/div'
|
|
|
2878 |
);
|
|
|
2879 |
$this->assertTags($result, $expected);
|
|
|
2880 |
}
|
|
|
2881 |
|
|
|
2882 |
/**
|
|
|
2883 |
* Test that magic input() selects are created for type=number
|
|
|
2884 |
*
|
|
|
2885 |
* @return void
|
|
|
2886 |
*/
|
|
|
2887 |
public function testInputMagicSelectForTypeNumber() {
|
|
|
2888 |
$this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
|
|
|
2889 |
$this->Form->request->data = array('ValidateUser' => array('balance' => 1));
|
|
|
2890 |
$result = $this->Form->input('ValidateUser.balance');
|
|
|
2891 |
$expected = array(
|
|
|
2892 |
'div' => array('class' => 'input select'),
|
|
|
2893 |
'label' => array('for' => 'ValidateUserBalance'),
|
|
|
2894 |
'Balance',
|
|
|
2895 |
'/label',
|
|
|
2896 |
'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'),
|
|
|
2897 |
array('option' => array('value' => '0')),
|
|
|
2898 |
'nothing',
|
|
|
2899 |
'/option',
|
|
|
2900 |
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
2901 |
'some',
|
|
|
2902 |
'/option',
|
|
|
2903 |
array('option' => array('value' => '100')),
|
|
|
2904 |
'a lot',
|
|
|
2905 |
'/option',
|
|
|
2906 |
'/select',
|
|
|
2907 |
'/div'
|
|
|
2908 |
);
|
|
|
2909 |
$this->assertTags($result, $expected);
|
|
|
2910 |
}
|
|
|
2911 |
|
|
|
2912 |
/**
|
|
|
2913 |
* Test that magic input() selects can easily be converted into radio types without error.
|
|
|
2914 |
*
|
|
|
2915 |
* @return void
|
|
|
2916 |
*/
|
|
|
2917 |
public function testInputMagicSelectChangeToRadio() {
|
|
|
2918 |
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
2919 |
$result = $this->Form->input('Model.user_id', array('type' => 'radio'));
|
|
|
2920 |
$this->assertRegExp('/input type="radio"/', $result);
|
|
|
2921 |
}
|
|
|
2922 |
|
|
|
2923 |
/**
|
|
|
2924 |
* fields with the same name as the model should work.
|
|
|
2925 |
*
|
|
|
2926 |
* @return void
|
|
|
2927 |
*/
|
|
|
2928 |
public function testInputWithMatchingFieldAndModelName() {
|
|
|
2929 |
$this->Form->create('User');
|
|
|
2930 |
$this->Form->fieldset = array(
|
|
|
2931 |
'User' => array(
|
|
|
2932 |
'fields' => array(
|
|
|
2933 |
'User' => array('type' => 'text')
|
|
|
2934 |
),
|
|
|
2935 |
'validates' => array(),
|
|
|
2936 |
'key' => 'id'
|
|
|
2937 |
)
|
|
|
2938 |
);
|
|
|
2939 |
$this->Form->request->data['User']['User'] = 'ABC, Inc.';
|
|
|
2940 |
$result = $this->Form->input('User', array('type' => 'text'));
|
|
|
2941 |
$expected = array(
|
|
|
2942 |
'div' => array('class' => 'input text'),
|
|
|
2943 |
'label' => array('for' => 'UserUser'), 'User', '/label',
|
|
|
2944 |
'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
|
|
|
2945 |
'/div'
|
|
|
2946 |
);
|
|
|
2947 |
$this->assertTags($result, $expected);
|
|
|
2948 |
}
|
|
|
2949 |
|
|
|
2950 |
/**
|
|
|
2951 |
* testFormInputs method
|
|
|
2952 |
*
|
|
|
2953 |
* test correct results from form::inputs().
|
|
|
2954 |
*
|
|
|
2955 |
* @return void
|
|
|
2956 |
*/
|
|
|
2957 |
public function testFormInputs() {
|
|
|
2958 |
$this->Form->create('Contact');
|
|
|
2959 |
$result = $this->Form->inputs('The Legend');
|
|
|
2960 |
$expected = array(
|
|
|
2961 |
'<fieldset',
|
|
|
2962 |
'<legend',
|
|
|
2963 |
'The Legend',
|
|
|
2964 |
'/legend',
|
|
|
2965 |
'*/fieldset',
|
|
|
2966 |
);
|
|
|
2967 |
$this->assertTags($result, $expected);
|
|
|
2968 |
|
|
|
2969 |
$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
|
|
|
2970 |
$expected = array(
|
|
|
2971 |
'fieldset' => array('class' => 'classy-stuff'),
|
|
|
2972 |
'<legend',
|
|
|
2973 |
'Field of Dreams',
|
|
|
2974 |
'/legend',
|
|
|
2975 |
'*/fieldset'
|
|
|
2976 |
);
|
|
|
2977 |
$this->assertTags($result, $expected);
|
|
|
2978 |
|
|
|
2979 |
$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
|
|
|
2980 |
$this->assertTags($result, $expected);
|
|
|
2981 |
|
|
|
2982 |
$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
|
|
|
2983 |
$this->assertTags($result, $expected);
|
|
|
2984 |
|
|
|
2985 |
$this->Form->create('Contact');
|
|
|
2986 |
$this->Form->request['prefix'] = 'admin';
|
|
|
2987 |
$this->Form->request['action'] = 'admin_edit';
|
|
|
2988 |
$result = $this->Form->inputs();
|
|
|
2989 |
$expected = array(
|
|
|
2990 |
'<fieldset',
|
|
|
2991 |
'<legend',
|
|
|
2992 |
'Edit Contact',
|
|
|
2993 |
'/legend',
|
|
|
2994 |
'*/fieldset',
|
|
|
2995 |
);
|
|
|
2996 |
$this->assertTags($result, $expected);
|
|
|
2997 |
|
|
|
2998 |
$this->Form->create('Contact');
|
|
|
2999 |
$result = $this->Form->inputs(false);
|
|
|
3000 |
$expected = array(
|
|
|
3001 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3002 |
array('div' => array('class' => 'input text')),
|
|
|
3003 |
'*/div',
|
|
|
3004 |
array('div' => array('class' => 'input email')),
|
|
|
3005 |
'*/div',
|
|
|
3006 |
array('div' => array('class' => 'input tel')),
|
|
|
3007 |
'*/div',
|
|
|
3008 |
array('div' => array('class' => 'input password')),
|
|
|
3009 |
'*/div',
|
|
|
3010 |
array('div' => array('class' => 'input date')),
|
|
|
3011 |
'*/div',
|
|
|
3012 |
array('div' => array('class' => 'input date')),
|
|
|
3013 |
'*/div',
|
|
|
3014 |
array('div' => array('class' => 'input datetime')),
|
|
|
3015 |
'*/div',
|
|
|
3016 |
array('div' => array('class' => 'input number')),
|
|
|
3017 |
'*/div',
|
|
|
3018 |
array('div' => array('class' => 'input select')),
|
|
|
3019 |
'*/div',
|
|
|
3020 |
);
|
|
|
3021 |
$this->assertTags($result, $expected);
|
|
|
3022 |
|
|
|
3023 |
$this->Form->create('Contact');
|
|
|
3024 |
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
|
|
|
3025 |
$expected = array(
|
|
|
3026 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3027 |
array('div' => array('class' => 'input text')),
|
|
|
3028 |
'*/div',
|
|
|
3029 |
array('div' => array('class' => 'input email')),
|
|
|
3030 |
'*/div',
|
|
|
3031 |
array('div' => array('class' => 'input tel')),
|
|
|
3032 |
'*/div',
|
|
|
3033 |
array('div' => array('class' => 'input password')),
|
|
|
3034 |
'*/div',
|
|
|
3035 |
array('div' => array('class' => 'input date')),
|
|
|
3036 |
'*/div',
|
|
|
3037 |
array('div' => array('class' => 'input date')),
|
|
|
3038 |
'*/div',
|
|
|
3039 |
array('div' => array('class' => 'input datetime')),
|
|
|
3040 |
'*/div',
|
|
|
3041 |
array('div' => array('class' => 'input number')),
|
|
|
3042 |
'*/div',
|
|
|
3043 |
array('div' => array('class' => 'input select')),
|
|
|
3044 |
'*/div',
|
|
|
3045 |
);
|
|
|
3046 |
$this->assertTags($result, $expected);
|
|
|
3047 |
|
|
|
3048 |
$this->Form->create('Contact');
|
|
|
3049 |
$result = $this->Form->inputs(null, null, array('fieldset' => false));
|
|
|
3050 |
$this->assertTags($result, $expected);
|
|
|
3051 |
|
|
|
3052 |
$this->Form->create('Contact');
|
|
|
3053 |
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
|
|
|
3054 |
$expected = array(
|
|
|
3055 |
'fieldset' => array(),
|
|
|
3056 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3057 |
array('div' => array('class' => 'input text')),
|
|
|
3058 |
'*/div',
|
|
|
3059 |
array('div' => array('class' => 'input email')),
|
|
|
3060 |
'*/div',
|
|
|
3061 |
array('div' => array('class' => 'input tel')),
|
|
|
3062 |
'*/div',
|
|
|
3063 |
array('div' => array('class' => 'input password')),
|
|
|
3064 |
'*/div',
|
|
|
3065 |
array('div' => array('class' => 'input date')),
|
|
|
3066 |
'*/div',
|
|
|
3067 |
array('div' => array('class' => 'input date')),
|
|
|
3068 |
'*/div',
|
|
|
3069 |
array('div' => array('class' => 'input datetime')),
|
|
|
3070 |
'*/div',
|
|
|
3071 |
array('div' => array('class' => 'input number')),
|
|
|
3072 |
'*/div',
|
|
|
3073 |
array('div' => array('class' => 'input select')),
|
|
|
3074 |
'*/div',
|
|
|
3075 |
'/fieldset'
|
|
|
3076 |
);
|
|
|
3077 |
$this->assertTags($result, $expected);
|
|
|
3078 |
|
|
|
3079 |
$this->Form->create('Contact');
|
|
|
3080 |
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
|
|
|
3081 |
$expected = array(
|
|
|
3082 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3083 |
array('div' => array('class' => 'input text')),
|
|
|
3084 |
'*/div',
|
|
|
3085 |
array('div' => array('class' => 'input email')),
|
|
|
3086 |
'*/div',
|
|
|
3087 |
array('div' => array('class' => 'input tel')),
|
|
|
3088 |
'*/div',
|
|
|
3089 |
array('div' => array('class' => 'input password')),
|
|
|
3090 |
'*/div',
|
|
|
3091 |
array('div' => array('class' => 'input date')),
|
|
|
3092 |
'*/div',
|
|
|
3093 |
array('div' => array('class' => 'input date')),
|
|
|
3094 |
'*/div',
|
|
|
3095 |
array('div' => array('class' => 'input datetime')),
|
|
|
3096 |
'*/div',
|
|
|
3097 |
array('div' => array('class' => 'input number')),
|
|
|
3098 |
'*/div',
|
|
|
3099 |
array('div' => array('class' => 'input select')),
|
|
|
3100 |
'*/div',
|
|
|
3101 |
);
|
|
|
3102 |
$this->assertTags($result, $expected);
|
|
|
3103 |
|
|
|
3104 |
$this->Form->create('Contact');
|
|
|
3105 |
$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
|
|
|
3106 |
$this->assertTags($result, $expected);
|
|
|
3107 |
|
|
|
3108 |
$this->Form->create('Contact');
|
|
|
3109 |
$result = $this->Form->inputs('Hello');
|
|
|
3110 |
$expected = array(
|
|
|
3111 |
'fieldset' => array(),
|
|
|
3112 |
'legend' => array(),
|
|
|
3113 |
'Hello',
|
|
|
3114 |
'/legend',
|
|
|
3115 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3116 |
array('div' => array('class' => 'input text')),
|
|
|
3117 |
'*/div',
|
|
|
3118 |
array('div' => array('class' => 'input email')),
|
|
|
3119 |
'*/div',
|
|
|
3120 |
array('div' => array('class' => 'input tel')),
|
|
|
3121 |
'*/div',
|
|
|
3122 |
array('div' => array('class' => 'input password')),
|
|
|
3123 |
'*/div',
|
|
|
3124 |
array('div' => array('class' => 'input date')),
|
|
|
3125 |
'*/div',
|
|
|
3126 |
array('div' => array('class' => 'input date')),
|
|
|
3127 |
'*/div',
|
|
|
3128 |
array('div' => array('class' => 'input datetime')),
|
|
|
3129 |
'*/div',
|
|
|
3130 |
array('div' => array('class' => 'input number')),
|
|
|
3131 |
'*/div',
|
|
|
3132 |
array('div' => array('class' => 'input select')),
|
|
|
3133 |
'*/div',
|
|
|
3134 |
'/fieldset'
|
|
|
3135 |
);
|
|
|
3136 |
$this->assertTags($result, $expected);
|
|
|
3137 |
|
|
|
3138 |
$this->Form->create('Contact');
|
|
|
3139 |
$result = $this->Form->inputs(array('legend' => 'Hello'));
|
|
|
3140 |
$expected = array(
|
|
|
3141 |
'fieldset' => array(),
|
|
|
3142 |
'legend' => array(),
|
|
|
3143 |
'Hello',
|
|
|
3144 |
'/legend',
|
|
|
3145 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
|
|
3146 |
array('div' => array('class' => 'input text')),
|
|
|
3147 |
'*/div',
|
|
|
3148 |
array('div' => array('class' => 'input email')),
|
|
|
3149 |
'*/div',
|
|
|
3150 |
array('div' => array('class' => 'input tel')),
|
|
|
3151 |
'*/div',
|
|
|
3152 |
array('div' => array('class' => 'input password')),
|
|
|
3153 |
'*/div',
|
|
|
3154 |
array('div' => array('class' => 'input date')),
|
|
|
3155 |
'*/div',
|
|
|
3156 |
array('div' => array('class' => 'input date')),
|
|
|
3157 |
'*/div',
|
|
|
3158 |
array('div' => array('class' => 'input datetime')),
|
|
|
3159 |
'*/div',
|
|
|
3160 |
array('div' => array('class' => 'input number')),
|
|
|
3161 |
'*/div',
|
|
|
3162 |
array('div' => array('class' => 'input select')),
|
|
|
3163 |
'*/div',
|
|
|
3164 |
'/fieldset'
|
|
|
3165 |
);
|
|
|
3166 |
$this->assertTags($result, $expected);
|
|
|
3167 |
|
|
|
3168 |
$this->Form->create('Contact');
|
|
|
3169 |
$result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
|
|
|
3170 |
$this->assertTags($result, $expected);
|
|
|
3171 |
$this->Form->end();
|
|
|
3172 |
|
|
|
3173 |
$this->Form->create(false);
|
|
|
3174 |
$expected = array(
|
|
|
3175 |
'fieldset' => array(),
|
|
|
3176 |
array('div' => array('class' => 'input text')),
|
|
|
3177 |
'label' => array('for' => 'foo'),
|
|
|
3178 |
'Foo',
|
|
|
3179 |
'/label',
|
|
|
3180 |
'input' => array('type' => 'text', 'name' => 'data[foo]', 'id' => 'foo'),
|
|
|
3181 |
'*/div',
|
|
|
3182 |
'/fieldset'
|
|
|
3183 |
);
|
|
|
3184 |
$result = $this->Form->inputs(
|
|
|
3185 |
array('foo' => array('type' => 'text')),
|
|
|
3186 |
array(),
|
|
|
3187 |
array('legend' => false)
|
|
|
3188 |
);
|
|
|
3189 |
$this->assertTags($result, $expected);
|
|
|
3190 |
}
|
|
|
3191 |
|
|
|
3192 |
/**
|
|
|
3193 |
* Tests inputs() works with plugin models
|
|
|
3194 |
*
|
|
|
3195 |
* @return void
|
|
|
3196 |
*/
|
|
|
3197 |
public function testInputsPluginModel() {
|
|
|
3198 |
$this->loadFixtures('Post');
|
|
|
3199 |
App::build(array(
|
|
|
3200 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
3201 |
));
|
|
|
3202 |
CakePlugin::load('TestPlugin');
|
|
|
3203 |
$this->Form->request['models'] = array(
|
|
|
3204 |
'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
|
|
|
3205 |
);
|
|
|
3206 |
$this->Form->create('TestPlugin.TestPluginPost');
|
|
|
3207 |
$result = $this->Form->inputs();
|
|
|
3208 |
|
|
|
3209 |
$this->assertContains('data[TestPluginPost][id]', $result);
|
|
|
3210 |
$this->assertContains('data[TestPluginPost][author_id]', $result);
|
|
|
3211 |
$this->assertContains('data[TestPluginPost][title]', $result);
|
|
|
3212 |
$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
|
|
|
3213 |
$this->assertFalse(ClassRegistry::isKeySet('TestPlugin'));
|
|
|
3214 |
$this->assertEquals('TestPluginPost', $this->Form->model());
|
|
|
3215 |
}
|
|
|
3216 |
|
|
|
3217 |
/**
|
|
|
3218 |
* testSelectAsCheckbox method
|
|
|
3219 |
*
|
|
|
3220 |
* test multi-select widget with checkbox formatting.
|
|
|
3221 |
*
|
|
|
3222 |
* @return void
|
|
|
3223 |
*/
|
|
|
3224 |
public function testSelectAsCheckbox() {
|
|
|
3225 |
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
|
|
|
3226 |
$expected = array(
|
|
|
3227 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
3228 |
array('div' => array('class' => 'checkbox')),
|
|
|
3229 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
3230 |
array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
|
|
|
3231 |
'first',
|
|
|
3232 |
'/label',
|
|
|
3233 |
'/div',
|
|
|
3234 |
array('div' => array('class' => 'checkbox')),
|
|
|
3235 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
3236 |
array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
|
|
|
3237 |
'second',
|
|
|
3238 |
'/label',
|
|
|
3239 |
'/div',
|
|
|
3240 |
array('div' => array('class' => 'checkbox')),
|
|
|
3241 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
3242 |
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
3243 |
'third',
|
|
|
3244 |
'/label',
|
|
|
3245 |
'/div',
|
|
|
3246 |
);
|
|
|
3247 |
$this->assertTags($result, $expected);
|
|
|
3248 |
|
|
|
3249 |
$result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
|
|
|
3250 |
$expected = array(
|
|
|
3251 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
3252 |
array('div' => array('class' => 'checkbox')),
|
|
|
3253 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
|
|
|
3254 |
array('label' => array('for' => 'ModelMultiField12')),
|
|
|
3255 |
'half',
|
|
|
3256 |
'/label',
|
|
|
3257 |
'/div',
|
|
|
3258 |
);
|
|
|
3259 |
$this->assertTags($result, $expected);
|
|
|
3260 |
}
|
|
|
3261 |
|
|
|
3262 |
/**
|
|
|
3263 |
* testLabel method
|
|
|
3264 |
*
|
|
|
3265 |
* test label generation.
|
|
|
3266 |
*
|
|
|
3267 |
* @return void
|
|
|
3268 |
*/
|
|
|
3269 |
public function testLabel() {
|
|
|
3270 |
$this->Form->text('Person.name');
|
|
|
3271 |
$result = $this->Form->label();
|
|
|
3272 |
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
|
|
|
3273 |
|
|
|
3274 |
$this->Form->text('Person.name');
|
|
|
3275 |
$result = $this->Form->label();
|
|
|
3276 |
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
|
|
|
3277 |
|
|
|
3278 |
$result = $this->Form->label('Person.first_name');
|
|
|
3279 |
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));
|
|
|
3280 |
|
|
|
3281 |
$result = $this->Form->label('Person.first_name', 'Your first name');
|
|
|
3282 |
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));
|
|
|
3283 |
|
|
|
3284 |
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
|
|
|
3285 |
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));
|
|
|
3286 |
|
|
|
3287 |
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
|
|
|
3288 |
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
|
|
|
3289 |
|
|
|
3290 |
$result = $this->Form->label('Person.first_name', '');
|
|
|
3291 |
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));
|
|
|
3292 |
|
|
|
3293 |
$result = $this->Form->label('Person.2.name', '');
|
|
|
3294 |
$this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));
|
|
|
3295 |
}
|
|
|
3296 |
|
|
|
3297 |
/**
|
|
|
3298 |
* testTextbox method
|
|
|
3299 |
*
|
|
|
3300 |
* test textbox element generation
|
|
|
3301 |
*
|
|
|
3302 |
* @return void
|
|
|
3303 |
*/
|
|
|
3304 |
public function testTextbox() {
|
|
|
3305 |
$result = $this->Form->text('Model.field');
|
|
|
3306 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
|
|
|
3307 |
|
|
|
3308 |
$result = $this->Form->text('Model.field', array('type' => 'password'));
|
|
|
3309 |
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
|
|
|
3310 |
|
|
|
3311 |
$result = $this->Form->text('Model.field', array('id' => 'theID'));
|
|
|
3312 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'theID')));
|
|
|
3313 |
|
|
|
3314 |
$this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
|
|
|
3315 |
$result = $this->Form->text('Model.text');
|
|
|
3316 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText')));
|
|
|
3317 |
|
|
|
3318 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
3319 |
$Contact->validationErrors['text'] = array(true);
|
|
|
3320 |
$this->Form->request->data['Contact']['text'] = 'test';
|
|
|
3321 |
$result = $this->Form->text('Contact.text', array('id' => 'theID'));
|
|
|
3322 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Contact][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
|
|
3323 |
|
|
|
3324 |
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
|
|
|
3325 |
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
|
|
|
3326 |
$expected = array(
|
|
|
3327 |
'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId')
|
|
|
3328 |
);
|
|
|
3329 |
$this->assertTags($result, $expected);
|
|
|
3330 |
}
|
|
|
3331 |
|
|
|
3332 |
/**
|
|
|
3333 |
* testDefaultValue method
|
|
|
3334 |
*
|
|
|
3335 |
* Test default value setting
|
|
|
3336 |
*
|
|
|
3337 |
* @return void
|
|
|
3338 |
*/
|
|
|
3339 |
public function testDefaultValue() {
|
|
|
3340 |
$this->Form->request->data['Model']['field'] = 'test';
|
|
|
3341 |
$result = $this->Form->text('Model.field', array('default' => 'default value'));
|
|
|
3342 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
|
|
|
3343 |
|
|
|
3344 |
unset($this->Form->request->data['Model']['field']);
|
|
|
3345 |
$result = $this->Form->text('Model.field', array('default' => 'default value'));
|
|
|
3346 |
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
|
|
|
3347 |
}
|
|
|
3348 |
|
|
|
3349 |
/**
|
|
|
3350 |
* testCheckboxDefaultValue method
|
|
|
3351 |
*
|
|
|
3352 |
* Test default value setting on checkbox() method
|
|
|
3353 |
*
|
|
|
3354 |
* @return void
|
|
|
3355 |
*/
|
|
|
3356 |
public function testCheckboxDefaultValue() {
|
|
|
3357 |
$this->Form->request->data['Model']['field'] = false;
|
|
|
3358 |
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
|
|
|
3359 |
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
|
|
|
3360 |
|
|
|
3361 |
unset($this->Form->request->data['Model']['field']);
|
|
|
3362 |
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
|
|
|
3363 |
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
|
|
|
3364 |
|
|
|
3365 |
$this->Form->request->data['Model']['field'] = true;
|
|
|
3366 |
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
|
|
|
3367 |
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
|
|
|
3368 |
|
|
|
3369 |
unset($this->Form->request->data['Model']['field']);
|
|
|
3370 |
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
|
|
|
3371 |
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
|
|
|
3372 |
}
|
|
|
3373 |
|
|
|
3374 |
/**
|
|
|
3375 |
* testError method
|
|
|
3376 |
*
|
|
|
3377 |
* Test field error generation
|
|
|
3378 |
*
|
|
|
3379 |
* @return void
|
|
|
3380 |
*/
|
|
|
3381 |
public function testError() {
|
|
|
3382 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
3383 |
$Contact->validationErrors['field'] = array(1);
|
|
|
3384 |
$result = $this->Form->error('Contact.field');
|
|
|
3385 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
|
|
|
3386 |
|
|
|
3387 |
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
|
|
|
3388 |
$this->assertEquals('Error in field Field', $result);
|
|
|
3389 |
|
|
|
3390 |
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
|
|
3391 |
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
|
|
|
3392 |
$this->assertEquals('This field contains invalid input', $result);
|
|
|
3393 |
|
|
|
3394 |
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
|
|
3395 |
$result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
|
|
|
3396 |
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
|
|
|
3397 |
|
|
|
3398 |
$result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
|
|
|
3399 |
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
|
|
|
3400 |
|
|
|
3401 |
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
|
|
|
3402 |
$this->assertEquals('<strong>Badness!</strong>', $result);
|
|
|
3403 |
|
|
|
3404 |
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
|
|
|
3405 |
$this->assertEquals('<strong>Badness!</strong>', $result);
|
|
|
3406 |
|
|
|
3407 |
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
|
|
|
3408 |
$this->assertEquals('<strong>Badness!</strong>', $result);
|
|
|
3409 |
|
|
|
3410 |
$Contact->validationErrors['field'] = array("email");
|
|
|
3411 |
$result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
|
|
|
3412 |
$expected = array(
|
|
|
3413 |
'div' => array('class' => 'field-error'),
|
|
|
3414 |
'No good!',
|
|
|
3415 |
'/div'
|
|
|
3416 |
);
|
|
|
3417 |
$this->assertTags($result, $expected);
|
|
|
3418 |
|
|
|
3419 |
$Contact->validationErrors['field'] = array('notEmpty', 'email', 'Something else');
|
|
|
3420 |
$result = $this->Form->error('Contact.field', array(
|
|
|
3421 |
'notEmpty' => 'Cannot be empty',
|
|
|
3422 |
'email' => 'No good!'
|
|
|
3423 |
));
|
|
|
3424 |
$expected = array(
|
|
|
3425 |
'div' => array('class' => 'error-message'),
|
|
|
3426 |
'ul' => array(),
|
|
|
3427 |
'<li', 'Cannot be empty', '/li',
|
|
|
3428 |
'<li', 'No good!', '/li',
|
|
|
3429 |
'<li', 'Something else', '/li',
|
|
|
3430 |
'/ul',
|
|
|
3431 |
'/div'
|
|
|
3432 |
);
|
|
|
3433 |
$this->assertTags($result, $expected);
|
|
|
3434 |
|
|
|
3435 |
// Testing error messages list options
|
|
|
3436 |
$Contact->validationErrors['field'] = array('notEmpty', 'email');
|
|
|
3437 |
|
|
|
3438 |
$result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
|
|
|
3439 |
$expected = array(
|
|
|
3440 |
'div' => array('class' => 'error-message'),
|
|
|
3441 |
'ol' => array(),
|
|
|
3442 |
'<li', 'notEmpty', '/li',
|
|
|
3443 |
'<li', 'email', '/li',
|
|
|
3444 |
'/ol',
|
|
|
3445 |
'/div'
|
|
|
3446 |
);
|
|
|
3447 |
$this->assertTags($result, $expected);
|
|
|
3448 |
|
|
|
3449 |
$result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
|
|
|
3450 |
$expected = array(
|
|
|
3451 |
'div' => array('class' => 'error-message'),
|
|
|
3452 |
'ol' => array(),
|
|
|
3453 |
'<li', 'notEmpty', '/li',
|
|
|
3454 |
'<li', 'email', '/li',
|
|
|
3455 |
'/ol',
|
|
|
3456 |
'/div'
|
|
|
3457 |
);
|
|
|
3458 |
$this->assertTags($result, $expected);
|
|
|
3459 |
|
|
|
3460 |
$result = $this->Form->error('Contact.field', null, array(
|
|
|
3461 |
'listOptions' => array(
|
|
|
3462 |
'class' => 'ul-class',
|
|
|
3463 |
'itemOptions' => array(
|
|
|
3464 |
'class' => 'li-class'
|
|
|
3465 |
)
|
|
|
3466 |
)
|
|
|
3467 |
));
|
|
|
3468 |
$expected = array(
|
|
|
3469 |
'div' => array('class' => 'error-message'),
|
|
|
3470 |
'ul' => array('class' => 'ul-class'),
|
|
|
3471 |
array('li' => array('class' => 'li-class')), 'notEmpty', '/li',
|
|
|
3472 |
array('li' => array('class' => 'li-class')), 'email', '/li',
|
|
|
3473 |
'/ul',
|
|
|
3474 |
'/div'
|
|
|
3475 |
);
|
|
|
3476 |
$this->assertTags($result, $expected);
|
|
|
3477 |
}
|
|
|
3478 |
|
|
|
3479 |
/**
|
|
|
3480 |
* test error options when using form->input();
|
|
|
3481 |
*
|
|
|
3482 |
* @return void
|
|
|
3483 |
*/
|
|
|
3484 |
public function testInputErrorEscape() {
|
|
|
3485 |
$this->Form->create('ValidateProfile');
|
|
|
3486 |
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
3487 |
$ValidateProfile->validationErrors['city'] = array('required<br>');
|
|
|
3488 |
$result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
|
|
|
3489 |
$this->assertRegExp('/required<br>/', $result);
|
|
|
3490 |
|
|
|
3491 |
$result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
|
|
|
3492 |
$this->assertRegExp('/required<br>/', $result);
|
|
|
3493 |
}
|
|
|
3494 |
|
|
|
3495 |
/**
|
|
|
3496 |
* testPassword method
|
|
|
3497 |
*
|
|
|
3498 |
* Test password element generation
|
|
|
3499 |
*
|
|
|
3500 |
* @return void
|
|
|
3501 |
*/
|
|
|
3502 |
public function testPassword() {
|
|
|
3503 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
3504 |
$result = $this->Form->password('Contact.field');
|
|
|
3505 |
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][field]', 'id' => 'ContactField')));
|
|
|
3506 |
|
|
|
3507 |
$Contact->validationErrors['passwd'] = 1;
|
|
|
3508 |
$this->Form->request->data['Contact']['passwd'] = 'test';
|
|
|
3509 |
$result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
|
|
|
3510 |
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
|
|
3511 |
}
|
|
|
3512 |
|
|
|
3513 |
/**
|
|
|
3514 |
* testRadio method
|
|
|
3515 |
*
|
|
|
3516 |
* Test radio element set generation
|
|
|
3517 |
*
|
|
|
3518 |
* @return void
|
|
|
3519 |
*/
|
|
|
3520 |
public function testRadio() {
|
|
|
3521 |
$result = $this->Form->radio('Model.field', array('option A'));
|
|
|
3522 |
$expected = array(
|
|
|
3523 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3524 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3525 |
'label' => array('for' => 'ModelField0'),
|
|
|
3526 |
'option A',
|
|
|
3527 |
'/label'
|
|
|
3528 |
);
|
|
|
3529 |
$this->assertTags($result, $expected);
|
|
|
3530 |
|
|
|
3531 |
$result = $this->Form->radio('Model.field', array('1/2' => 'half'));
|
|
|
3532 |
$expected = array(
|
|
|
3533 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3534 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
|
|
|
3535 |
'label' => array('for' => 'ModelField12'),
|
|
|
3536 |
'half',
|
|
|
3537 |
'/label'
|
|
|
3538 |
);
|
|
|
3539 |
$this->assertTags($result, $expected);
|
|
|
3540 |
|
|
|
3541 |
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
|
|
|
3542 |
$expected = array(
|
|
|
3543 |
'fieldset' => array(),
|
|
|
3544 |
'legend' => array(),
|
|
|
3545 |
'Field',
|
|
|
3546 |
'/legend',
|
|
|
3547 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3548 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3549 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3550 |
'option A',
|
|
|
3551 |
'/label',
|
|
|
3552 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3553 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3554 |
'option B',
|
|
|
3555 |
'/label',
|
|
|
3556 |
'/fieldset'
|
|
|
3557 |
);
|
|
|
3558 |
$this->assertTags($result, $expected);
|
|
|
3559 |
|
|
|
3560 |
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>'));
|
|
|
3561 |
$expected = array(
|
|
|
3562 |
'fieldset' => array(),
|
|
|
3563 |
'legend' => array(),
|
|
|
3564 |
'Field',
|
|
|
3565 |
'/legend',
|
|
|
3566 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3567 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3568 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3569 |
'option A',
|
|
|
3570 |
'/label',
|
|
|
3571 |
'br' => array(),
|
|
|
3572 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3573 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3574 |
'option B',
|
|
|
3575 |
'/label',
|
|
|
3576 |
'/fieldset'
|
|
|
3577 |
);
|
|
|
3578 |
$this->assertTags($result, $expected);
|
|
|
3579 |
|
|
|
3580 |
$result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female'));
|
|
|
3581 |
$expected = array(
|
|
|
3582 |
'fieldset' => array(),
|
|
|
3583 |
'legend' => array(),
|
|
|
3584 |
'Gender',
|
|
|
3585 |
'/legend',
|
|
|
3586 |
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'),
|
|
|
3587 |
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')),
|
|
|
3588 |
array('label' => array('for' => 'EmployeeGenderMale')),
|
|
|
3589 |
'Male',
|
|
|
3590 |
'/label',
|
|
|
3591 |
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')),
|
|
|
3592 |
array('label' => array('for' => 'EmployeeGenderFemale')),
|
|
|
3593 |
'Female',
|
|
|
3594 |
'/label',
|
|
|
3595 |
'/fieldset',
|
|
|
3596 |
);
|
|
|
3597 |
$this->assertTags($result, $expected);
|
|
|
3598 |
|
|
|
3599 |
$result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female'));
|
|
|
3600 |
$expected = array(
|
|
|
3601 |
'fieldset' => array(),
|
|
|
3602 |
'legend' => array(),
|
|
|
3603 |
'Gender',
|
|
|
3604 |
'/legend',
|
|
|
3605 |
'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'),
|
|
|
3606 |
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')),
|
|
|
3607 |
array('label' => array('for' => 'OfficerGenderMale')),
|
|
|
3608 |
'Male',
|
|
|
3609 |
'/label',
|
|
|
3610 |
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')),
|
|
|
3611 |
array('label' => array('for' => 'OfficerGenderFemale')),
|
|
|
3612 |
'Female',
|
|
|
3613 |
'/label',
|
|
|
3614 |
'/fieldset',
|
|
|
3615 |
);
|
|
|
3616 |
$this->assertTags($result, $expected);
|
|
|
3617 |
|
|
|
3618 |
$result = $this->Form->radio('Contact.1.imrequired', array('option A'));
|
|
|
3619 |
$expected = array(
|
|
|
3620 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][1][imrequired]', 'value' => '', 'id' => 'Contact1Imrequired_'),
|
|
|
3621 |
array('input' => array(
|
|
|
3622 |
'type' => 'radio',
|
|
|
3623 |
'name' => 'data[Contact][1][imrequired]',
|
|
|
3624 |
'value' => '0',
|
|
|
3625 |
'id' => 'Contact1Imrequired0',
|
|
|
3626 |
'required' => 'required'
|
|
|
3627 |
)),
|
|
|
3628 |
'label' => array('for' => 'Contact1Imrequired0'),
|
|
|
3629 |
'option A',
|
|
|
3630 |
'/label'
|
|
|
3631 |
);
|
|
|
3632 |
$this->assertTags($result, $expected);
|
|
|
3633 |
|
|
|
3634 |
$result = $this->Form->radio('Model.1.field', array('option A'));
|
|
|
3635 |
$expected = array(
|
|
|
3636 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field_'),
|
|
|
3637 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
3638 |
'label' => array('for' => 'Model1Field0'),
|
|
|
3639 |
'option A',
|
|
|
3640 |
'/label'
|
|
|
3641 |
);
|
|
|
3642 |
$this->assertTags($result, $expected);
|
|
|
3643 |
|
|
|
3644 |
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
|
|
|
3645 |
$expected = array(
|
|
|
3646 |
'fieldset' => array(),
|
|
|
3647 |
'legend' => array(),
|
|
|
3648 |
'Field',
|
|
|
3649 |
'/legend',
|
|
|
3650 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][custom]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3651 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3652 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3653 |
'option A',
|
|
|
3654 |
'/label',
|
|
|
3655 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3656 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3657 |
'option B',
|
|
|
3658 |
'/label',
|
|
|
3659 |
'/fieldset'
|
|
|
3660 |
);
|
|
|
3661 |
$this->assertTags($result, $expected);
|
|
|
3662 |
}
|
|
|
3663 |
|
|
|
3664 |
/**
|
|
|
3665 |
* Test radio inputs with between as string or array. Also ensure
|
|
|
3666 |
* that an array with less between elements works.
|
|
|
3667 |
*
|
|
|
3668 |
* @return void
|
|
|
3669 |
*/
|
|
|
3670 |
public function testRadioBetween() {
|
|
|
3671 |
$result = $this->Form->radio(
|
|
|
3672 |
'Model.field',
|
|
|
3673 |
array('option A', 'option B'),
|
|
|
3674 |
array('between' => 'I am between')
|
|
|
3675 |
);
|
|
|
3676 |
$expected = array(
|
|
|
3677 |
'fieldset' => array(),
|
|
|
3678 |
'legend' => array(),
|
|
|
3679 |
'Field',
|
|
|
3680 |
'/legend',
|
|
|
3681 |
'I am between',
|
|
|
3682 |
'input' => array(
|
|
|
3683 |
'type' => 'hidden', 'name' => 'data[Model][field]',
|
|
|
3684 |
'value' => '', 'id' => 'ModelField_'
|
|
|
3685 |
),
|
|
|
3686 |
array('input' => array(
|
|
|
3687 |
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
3688 |
'value' => '0', 'id' => 'ModelField0'
|
|
|
3689 |
)),
|
|
|
3690 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3691 |
'option A',
|
|
|
3692 |
'/label',
|
|
|
3693 |
array('input' => array(
|
|
|
3694 |
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
3695 |
'value' => '1', 'id' => 'ModelField1'
|
|
|
3696 |
)),
|
|
|
3697 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3698 |
'option B',
|
|
|
3699 |
'/label',
|
|
|
3700 |
'/fieldset'
|
|
|
3701 |
);
|
|
|
3702 |
$this->assertTags($result, $expected);
|
|
|
3703 |
|
|
|
3704 |
$result = $this->Form->radio(
|
|
|
3705 |
'Model.field',
|
|
|
3706 |
array('option A', 'option B', 'option C'),
|
|
|
3707 |
array('separator' => '--separator--', 'between' => array('between A', 'between B', 'between C'))
|
|
|
3708 |
);
|
|
|
3709 |
|
|
|
3710 |
$expected = array(
|
|
|
3711 |
'fieldset' => array(),
|
|
|
3712 |
'legend' => array(),
|
|
|
3713 |
'Field',
|
|
|
3714 |
'/legend',
|
|
|
3715 |
'input' => array(
|
|
|
3716 |
'type' => 'hidden', 'name' => 'data[Model][field]',
|
|
|
3717 |
'value' => '', 'id' => 'ModelField_'
|
|
|
3718 |
),
|
|
|
3719 |
array('input' => array(
|
|
|
3720 |
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
3721 |
'value' => '0', 'id' => 'ModelField0'
|
|
|
3722 |
)),
|
|
|
3723 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3724 |
'option A',
|
|
|
3725 |
'/label',
|
|
|
3726 |
'between A',
|
|
|
3727 |
'--separator--',
|
|
|
3728 |
array('input' => array(
|
|
|
3729 |
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
3730 |
'value' => '1', 'id' => 'ModelField1'
|
|
|
3731 |
)),
|
|
|
3732 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3733 |
'option B',
|
|
|
3734 |
'/label',
|
|
|
3735 |
'between B',
|
|
|
3736 |
'--separator--',
|
|
|
3737 |
array('input' => array(
|
|
|
3738 |
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
3739 |
'value' => '2', 'id' => 'ModelField2'
|
|
|
3740 |
)),
|
|
|
3741 |
array('label' => array('for' => 'ModelField2')),
|
|
|
3742 |
'option C',
|
|
|
3743 |
'/label',
|
|
|
3744 |
'between C',
|
|
|
3745 |
'/fieldset'
|
|
|
3746 |
);
|
|
|
3747 |
$this->assertTags($result, $expected);
|
|
|
3748 |
|
|
|
3749 |
$result = $this->Form->input('Model.field', array(
|
|
|
3750 |
'options' => array('1' => 'first', '2' => 'second'),
|
|
|
3751 |
'type' => 'radio',
|
|
|
3752 |
'before' => '--before--',
|
|
|
3753 |
'after' => '--after--',
|
|
|
3754 |
'separator' => '--separator--',
|
|
|
3755 |
'between' => array('--between first--', '--between second--')
|
|
|
3756 |
));
|
|
|
3757 |
|
|
|
3758 |
$expected = array(
|
|
|
3759 |
'div' => array('class' => 'input radio'),
|
|
|
3760 |
'--before--',
|
|
|
3761 |
'fieldset' => array(),
|
|
|
3762 |
'legend' => array(),
|
|
|
3763 |
'Field',
|
|
|
3764 |
'/legend',
|
|
|
3765 |
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
3766 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3767 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3768 |
'first',
|
|
|
3769 |
'/label',
|
|
|
3770 |
'--between first--',
|
|
|
3771 |
'--separator--',
|
|
|
3772 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
|
|
|
3773 |
array('label' => array('for' => 'ModelField2')),
|
|
|
3774 |
'second',
|
|
|
3775 |
'/label',
|
|
|
3776 |
'--between second--',
|
|
|
3777 |
'/fieldset',
|
|
|
3778 |
'--after--',
|
|
|
3779 |
'/div'
|
|
|
3780 |
);
|
|
|
3781 |
$this->assertTags($result, $expected);
|
|
|
3782 |
|
|
|
3783 |
$result = $this->Form->input('Model.field', array(
|
|
|
3784 |
'options' => array('1' => 'first', '2' => 'second'),
|
|
|
3785 |
'type' => 'radio',
|
|
|
3786 |
'before' => '--before--',
|
|
|
3787 |
'after' => '--after--',
|
|
|
3788 |
'separator' => '--separator--',
|
|
|
3789 |
'between' => array('--between first--')
|
|
|
3790 |
));
|
|
|
3791 |
|
|
|
3792 |
$expected = array(
|
|
|
3793 |
'div' => array('class' => 'input radio'),
|
|
|
3794 |
'--before--',
|
|
|
3795 |
'fieldset' => array(),
|
|
|
3796 |
'legend' => array(),
|
|
|
3797 |
'Field',
|
|
|
3798 |
'/legend',
|
|
|
3799 |
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
3800 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3801 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3802 |
'first',
|
|
|
3803 |
'/label',
|
|
|
3804 |
'--between first--',
|
|
|
3805 |
'--separator--',
|
|
|
3806 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
|
|
|
3807 |
array('label' => array('for' => 'ModelField2')),
|
|
|
3808 |
'second',
|
|
|
3809 |
'/label',
|
|
|
3810 |
'/fieldset',
|
|
|
3811 |
'--after--',
|
|
|
3812 |
'/div'
|
|
|
3813 |
);
|
|
|
3814 |
$this->assertTags($result, $expected);
|
|
|
3815 |
}
|
|
|
3816 |
|
|
|
3817 |
/**
|
|
|
3818 |
* Test that radios with a 0 value are selected under the correct conditions.
|
|
|
3819 |
* Also ensure that values that are booleanish are handled correctly.
|
|
|
3820 |
*
|
|
|
3821 |
* @return void
|
|
|
3822 |
*/
|
|
|
3823 |
public function testRadioOptionWithBooleanishValues() {
|
|
|
3824 |
$expected = array(
|
|
|
3825 |
'fieldset' => array(),
|
|
|
3826 |
'legend' => array(),
|
|
|
3827 |
'Field',
|
|
|
3828 |
'/legend',
|
|
|
3829 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3830 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3831 |
'Yes',
|
|
|
3832 |
'/label',
|
|
|
3833 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
|
|
|
3834 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3835 |
'No',
|
|
|
3836 |
'/label',
|
|
|
3837 |
'/fieldset'
|
|
|
3838 |
);
|
|
|
3839 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
|
|
|
3840 |
$this->assertTags($result, $expected);
|
|
|
3841 |
|
|
|
3842 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 0));
|
|
|
3843 |
$this->assertTags($result, $expected);
|
|
|
3844 |
|
|
|
3845 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => false));
|
|
|
3846 |
$this->assertTags($result, $expected);
|
|
|
3847 |
|
|
|
3848 |
$expected = array(
|
|
|
3849 |
'fieldset' => array(),
|
|
|
3850 |
'legend' => array(),
|
|
|
3851 |
'Field',
|
|
|
3852 |
'/legend',
|
|
|
3853 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
3854 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3855 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3856 |
'Yes',
|
|
|
3857 |
'/label',
|
|
|
3858 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3859 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3860 |
'No',
|
|
|
3861 |
'/label',
|
|
|
3862 |
'/fieldset'
|
|
|
3863 |
);
|
|
|
3864 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
|
|
|
3865 |
$this->assertTags($result, $expected);
|
|
|
3866 |
|
|
|
3867 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => ''));
|
|
|
3868 |
$this->assertTags($result, $expected);
|
|
|
3869 |
|
|
|
3870 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
|
|
|
3871 |
$this->assertTags($result, $expected);
|
|
|
3872 |
|
|
|
3873 |
$expected = array(
|
|
|
3874 |
'fieldset' => array(),
|
|
|
3875 |
'legend' => array(),
|
|
|
3876 |
'Field',
|
|
|
3877 |
'/legend',
|
|
|
3878 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3879 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3880 |
'Yes',
|
|
|
3881 |
'/label',
|
|
|
3882 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
3883 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3884 |
'No',
|
|
|
3885 |
'/label',
|
|
|
3886 |
'/fieldset'
|
|
|
3887 |
);
|
|
|
3888 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 1));
|
|
|
3889 |
$this->assertTags($result, $expected);
|
|
|
3890 |
|
|
|
3891 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
|
|
|
3892 |
$this->assertTags($result, $expected);
|
|
|
3893 |
|
|
|
3894 |
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => true));
|
|
|
3895 |
$this->assertTags($result, $expected);
|
|
|
3896 |
}
|
|
|
3897 |
|
|
|
3898 |
/**
|
|
|
3899 |
* test disabled radio options
|
|
|
3900 |
*
|
|
|
3901 |
* @return void
|
|
|
3902 |
*/
|
|
|
3903 |
public function testRadioDisabled() {
|
|
|
3904 |
$result = $this->Form->radio(
|
|
|
3905 |
'Model.field',
|
|
|
3906 |
array('option A', 'option B'),
|
|
|
3907 |
array('disabled' => array(0), 'value' => '0')
|
|
|
3908 |
);
|
|
|
3909 |
$expected = array(
|
|
|
3910 |
'fieldset' => array(),
|
|
|
3911 |
'legend' => array(),
|
|
|
3912 |
'Field',
|
|
|
3913 |
'/legend',
|
|
|
3914 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
3915 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3916 |
'option A',
|
|
|
3917 |
'/label',
|
|
|
3918 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3919 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3920 |
'option B',
|
|
|
3921 |
'/label',
|
|
|
3922 |
'/fieldset'
|
|
|
3923 |
);
|
|
|
3924 |
$this->assertTags($result, $expected);
|
|
|
3925 |
|
|
|
3926 |
$result = $this->Form->radio(
|
|
|
3927 |
'Model.field',
|
|
|
3928 |
array('option A', 'option B'),
|
|
|
3929 |
array('disabled' => true, 'value' => '0')
|
|
|
3930 |
);
|
|
|
3931 |
$expected = array(
|
|
|
3932 |
'fieldset' => array(),
|
|
|
3933 |
'legend' => array(),
|
|
|
3934 |
'Field',
|
|
|
3935 |
'/legend',
|
|
|
3936 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
3937 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3938 |
'option A',
|
|
|
3939 |
'/label',
|
|
|
3940 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
|
|
|
3941 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3942 |
'option B',
|
|
|
3943 |
'/label',
|
|
|
3944 |
'/fieldset'
|
|
|
3945 |
);
|
|
|
3946 |
$this->assertTags($result, $expected);
|
|
|
3947 |
|
|
|
3948 |
$result = $this->Form->radio(
|
|
|
3949 |
'Model.field',
|
|
|
3950 |
array('option A', 'option B'),
|
|
|
3951 |
array('disabled' => 'disabled', 'value' => '0')
|
|
|
3952 |
);
|
|
|
3953 |
$expected = array(
|
|
|
3954 |
'fieldset' => array(),
|
|
|
3955 |
'legend' => array(),
|
|
|
3956 |
'Field',
|
|
|
3957 |
'/legend',
|
|
|
3958 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
3959 |
array('label' => array('for' => 'ModelField0')),
|
|
|
3960 |
'option A',
|
|
|
3961 |
'/label',
|
|
|
3962 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
|
|
|
3963 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3964 |
'option B',
|
|
|
3965 |
'/label',
|
|
|
3966 |
'/fieldset'
|
|
|
3967 |
);
|
|
|
3968 |
$this->assertTags($result, $expected);
|
|
|
3969 |
|
|
|
3970 |
$result = $this->Form->input('Model.field', array(
|
|
|
3971 |
'options' => array(1 => 'first', 2 => 'second', '2x' => '2x', '3' => 'third', '3x' => '3x'),
|
|
|
3972 |
'type' => 'radio',
|
|
|
3973 |
'disabled' => array(2, '3x'),
|
|
|
3974 |
));
|
|
|
3975 |
|
|
|
3976 |
$expected = array(
|
|
|
3977 |
'div' => array('class' => 'input radio'),
|
|
|
3978 |
'fieldset' => array(),
|
|
|
3979 |
'legend' => array(),
|
|
|
3980 |
'Field',
|
|
|
3981 |
'/legend',
|
|
|
3982 |
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
3983 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
3984 |
array('label' => array('for' => 'ModelField1')),
|
|
|
3985 |
'first',
|
|
|
3986 |
'/label',
|
|
|
3987 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '2', 'id' => 'ModelField2')),
|
|
|
3988 |
array('label' => array('for' => 'ModelField2')),
|
|
|
3989 |
'second',
|
|
|
3990 |
'/label',
|
|
|
3991 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2x', 'id' => 'ModelField2x')),
|
|
|
3992 |
array('label' => array('for' => 'ModelField2x')),
|
|
|
3993 |
'2x',
|
|
|
3994 |
'/label',
|
|
|
3995 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '3', 'id' => 'ModelField3')),
|
|
|
3996 |
array('label' => array('for' => 'ModelField3')),
|
|
|
3997 |
'third',
|
|
|
3998 |
'/label',
|
|
|
3999 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '3x', 'id' => 'ModelField3x')),
|
|
|
4000 |
array('label' => array('for' => 'ModelField3x')),
|
|
|
4001 |
'3x',
|
|
|
4002 |
'/label',
|
|
|
4003 |
'/fieldset',
|
|
|
4004 |
'/div'
|
|
|
4005 |
);
|
|
|
4006 |
$this->assertTags($result, $expected);
|
|
|
4007 |
|
|
|
4008 |
$result = $this->Form->input('Model.field', array(
|
|
|
4009 |
'type' => 'radio',
|
|
|
4010 |
'options' => array(
|
|
|
4011 |
1 => 'A',
|
|
|
4012 |
2 => 'B',
|
|
|
4013 |
3 => 'C'
|
|
|
4014 |
),
|
|
|
4015 |
'disabled' => array(1)
|
|
|
4016 |
));
|
|
|
4017 |
|
|
|
4018 |
$expected = array(
|
|
|
4019 |
'div' => array('class' => 'input radio'),
|
|
|
4020 |
'fieldset' => array(),
|
|
|
4021 |
'legend' => array(),
|
|
|
4022 |
'Field',
|
|
|
4023 |
'/legend',
|
|
|
4024 |
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
4025 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField1', 'disabled' => 'disabled', 'value' => '1')),
|
|
|
4026 |
array('label' => array('for' => 'ModelField1')),
|
|
|
4027 |
'A',
|
|
|
4028 |
'/label',
|
|
|
4029 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField2', 'value' => '2')),
|
|
|
4030 |
array('label' => array('for' => 'ModelField2')),
|
|
|
4031 |
'B',
|
|
|
4032 |
'/label',
|
|
|
4033 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField3', 'value' => '3')),
|
|
|
4034 |
array('label' => array('for' => 'ModelField3')),
|
|
|
4035 |
'C',
|
|
|
4036 |
'/label',
|
|
|
4037 |
'/fieldset',
|
|
|
4038 |
'/div'
|
|
|
4039 |
);
|
|
|
4040 |
$this->assertTags($result, $expected);
|
|
|
4041 |
}
|
|
|
4042 |
|
|
|
4043 |
/**
|
|
|
4044 |
* test disabling the hidden input for radio buttons
|
|
|
4045 |
*
|
|
|
4046 |
* @return void
|
|
|
4047 |
*/
|
|
|
4048 |
public function testRadioHiddenInputDisabling() {
|
|
|
4049 |
$result = $this->Form->input('Model.1.field', array(
|
|
|
4050 |
'type' => 'radio',
|
|
|
4051 |
'options' => array('option A'),
|
|
|
4052 |
'hiddenField' => false
|
|
|
4053 |
)
|
|
|
4054 |
);
|
|
|
4055 |
$expected = array(
|
|
|
4056 |
'div' => array('class' => 'input radio'),
|
|
|
4057 |
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
|
|
|
4058 |
'label' => array('for' => 'Model1Field0'),
|
|
|
4059 |
'option A',
|
|
|
4060 |
'/label',
|
|
|
4061 |
'/div'
|
|
|
4062 |
);
|
|
|
4063 |
$this->assertTags($result, $expected);
|
|
|
4064 |
|
|
|
4065 |
$result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
|
|
|
4066 |
$expected = array(
|
|
|
4067 |
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
|
|
|
4068 |
'label' => array('for' => 'Model1Field0'),
|
|
|
4069 |
'option A',
|
|
|
4070 |
'/label'
|
|
|
4071 |
);
|
|
|
4072 |
$this->assertTags($result, $expected);
|
|
|
4073 |
}
|
|
|
4074 |
|
|
|
4075 |
/**
|
|
|
4076 |
* test adding an empty option for radio buttons
|
|
|
4077 |
*
|
|
|
4078 |
* @return void
|
|
|
4079 |
*/
|
|
|
4080 |
public function testRadioAddEmptyOption() {
|
|
|
4081 |
$result = $this->Form->input('Model.1.field', array(
|
|
|
4082 |
'type' => 'radio',
|
|
|
4083 |
'options' => array('option A'),
|
|
|
4084 |
'empty' => true,
|
|
|
4085 |
'hiddenField' => false
|
|
|
4086 |
));
|
|
|
4087 |
$expected = array(
|
|
|
4088 |
'div' => array('class' => 'input radio'),
|
|
|
4089 |
'fieldset' => array(),
|
|
|
4090 |
'legend' => array(),
|
|
|
4091 |
'Field',
|
|
|
4092 |
'/legend',
|
|
|
4093 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
|
|
|
4094 |
array('label' => array('for' => 'Model1Field')),
|
|
|
4095 |
__('empty'),
|
|
|
4096 |
'/label',
|
|
|
4097 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
4098 |
array('label' => array('for' => 'Model1Field0')),
|
|
|
4099 |
'option A',
|
|
|
4100 |
'/label',
|
|
|
4101 |
'/fieldset',
|
|
|
4102 |
'/div'
|
|
|
4103 |
);
|
|
|
4104 |
$this->assertTags($result, $expected);
|
|
|
4105 |
|
|
|
4106 |
$result = $this->Form->input('Model.1.field', array(
|
|
|
4107 |
'type' => 'radio',
|
|
|
4108 |
'options' => array('option A'),
|
|
|
4109 |
'empty' => 'CustomEmptyLabel',
|
|
|
4110 |
'hiddenField' => false
|
|
|
4111 |
));
|
|
|
4112 |
$expected = array(
|
|
|
4113 |
'div' => array('class' => 'input radio'),
|
|
|
4114 |
'fieldset' => array(),
|
|
|
4115 |
'legend' => array(),
|
|
|
4116 |
'Field',
|
|
|
4117 |
'/legend',
|
|
|
4118 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
|
|
|
4119 |
array('label' => array('for' => 'Model1Field')),
|
|
|
4120 |
'CustomEmptyLabel',
|
|
|
4121 |
'/label',
|
|
|
4122 |
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
4123 |
array('label' => array('for' => 'Model1Field0')),
|
|
|
4124 |
'option A',
|
|
|
4125 |
'/label',
|
|
|
4126 |
'/fieldset',
|
|
|
4127 |
'/div'
|
|
|
4128 |
);
|
|
|
4129 |
$this->assertTags($result, $expected);
|
|
|
4130 |
|
|
|
4131 |
$result = $this->Form->input('Model.1.field', array(
|
|
|
4132 |
'type' => 'radio',
|
|
|
4133 |
'options' => array('option A'),
|
|
|
4134 |
'empty' => false,
|
|
|
4135 |
'hiddenField' => false
|
|
|
4136 |
));
|
|
|
4137 |
$this->assertTextNotContains('"Model1Field"', $result);
|
|
|
4138 |
}
|
|
|
4139 |
|
|
|
4140 |
/**
|
|
|
4141 |
* Test that radio() accepts an array for label
|
|
|
4142 |
*
|
|
|
4143 |
* @return void
|
|
|
4144 |
*/
|
|
|
4145 |
public function testRadioLabelArray() {
|
|
|
4146 |
$result = $this->Form->input('Model.field', array(
|
|
|
4147 |
'type' => 'radio',
|
|
|
4148 |
'legend' => false,
|
|
|
4149 |
'label' => array(
|
|
|
4150 |
'class' => 'checkbox float-left',
|
|
|
4151 |
),
|
|
|
4152 |
'options' => array('1' => 'Option A', '2' => 'Option B.')
|
|
|
4153 |
));
|
|
|
4154 |
$this->assertTextContains(
|
|
|
4155 |
'<label for="ModelField1" class="checkbox float-left">Option A</label>',
|
|
|
4156 |
$result
|
|
|
4157 |
);
|
|
|
4158 |
}
|
|
|
4159 |
|
|
|
4160 |
/**
|
|
|
4161 |
* Test that label id's match the input element id's when radio is called after create().
|
|
|
4162 |
*
|
|
|
4163 |
* @return void
|
|
|
4164 |
*/
|
|
|
4165 |
public function testRadioWithCreate() {
|
|
|
4166 |
$this->Form->create('Model');
|
|
|
4167 |
$result = $this->Form->radio('recipient',
|
|
|
4168 |
array('1' => '1', '2' => '2', '3' => '3'),
|
|
|
4169 |
array('legend' => false, 'value' => '1')
|
|
|
4170 |
);
|
|
|
4171 |
$this->assertTextNotContains(
|
|
|
4172 |
'<label for="ModelModelRecipient1">1</label>',
|
|
|
4173 |
$result
|
|
|
4174 |
);
|
|
|
4175 |
$this->assertTextContains(
|
|
|
4176 |
'<label for="ModelRecipient1">1</label>',
|
|
|
4177 |
$result
|
|
|
4178 |
);
|
|
|
4179 |
}
|
|
|
4180 |
|
|
|
4181 |
/**
|
|
|
4182 |
* testSelect method
|
|
|
4183 |
*
|
|
|
4184 |
* Test select element generation.
|
|
|
4185 |
*
|
|
|
4186 |
* @return void
|
|
|
4187 |
*/
|
|
|
4188 |
public function testSelect() {
|
|
|
4189 |
$result = $this->Form->select('Model.field', array());
|
|
|
4190 |
$expected = array(
|
|
|
4191 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4192 |
array('option' => array('value' => '')),
|
|
|
4193 |
'/option',
|
|
|
4194 |
'/select'
|
|
|
4195 |
);
|
|
|
4196 |
$this->assertTags($result, $expected);
|
|
|
4197 |
|
|
|
4198 |
$this->Form->request->data = array('Model' => array('field' => 'value'));
|
|
|
4199 |
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
|
|
|
4200 |
$expected = array(
|
|
|
4201 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4202 |
array('option' => array('value' => '')),
|
|
|
4203 |
'/option',
|
|
|
4204 |
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
4205 |
'good',
|
|
|
4206 |
'/option',
|
|
|
4207 |
array('option' => array('value' => 'other')),
|
|
|
4208 |
'bad',
|
|
|
4209 |
'/option',
|
|
|
4210 |
'/select'
|
|
|
4211 |
);
|
|
|
4212 |
$this->assertTags($result, $expected);
|
|
|
4213 |
|
|
|
4214 |
$this->Form->request->data = array();
|
|
|
4215 |
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
|
|
|
4216 |
$expected = array(
|
|
|
4217 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4218 |
array('option' => array('value' => '')),
|
|
|
4219 |
'/option',
|
|
|
4220 |
array('option' => array('value' => 'value')),
|
|
|
4221 |
'good',
|
|
|
4222 |
'/option',
|
|
|
4223 |
array('option' => array('value' => 'other')),
|
|
|
4224 |
'bad',
|
|
|
4225 |
'/option',
|
|
|
4226 |
'/select'
|
|
|
4227 |
);
|
|
|
4228 |
$this->assertTags($result, $expected);
|
|
|
4229 |
|
|
|
4230 |
$result = $this->Form->select(
|
|
|
4231 |
'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
|
|
|
4232 |
array('empty' => false)
|
|
|
4233 |
);
|
|
|
4234 |
$expected = array(
|
|
|
4235 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4236 |
array('option' => array('value' => 'first')),
|
|
|
4237 |
'first "html" <chars>',
|
|
|
4238 |
'/option',
|
|
|
4239 |
array('option' => array('value' => 'second')),
|
|
|
4240 |
'value',
|
|
|
4241 |
'/option',
|
|
|
4242 |
'/select'
|
|
|
4243 |
);
|
|
|
4244 |
$this->assertTags($result, $expected);
|
|
|
4245 |
|
|
|
4246 |
$result = $this->Form->select(
|
|
|
4247 |
'Model.field',
|
|
|
4248 |
array('first' => 'first "html" <chars>', 'second' => 'value'),
|
|
|
4249 |
array('escape' => false, 'empty' => false)
|
|
|
4250 |
);
|
|
|
4251 |
$expected = array(
|
|
|
4252 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4253 |
array('option' => array('value' => 'first')),
|
|
|
4254 |
'first "html" <chars>',
|
|
|
4255 |
'/option',
|
|
|
4256 |
array('option' => array('value' => 'second')),
|
|
|
4257 |
'value',
|
|
|
4258 |
'/option',
|
|
|
4259 |
'/select'
|
|
|
4260 |
);
|
|
|
4261 |
$this->assertTags($result, $expected);
|
|
|
4262 |
|
|
|
4263 |
$options = array(
|
|
|
4264 |
array('value' => 'first', 'name' => 'First'),
|
|
|
4265 |
array('value' => 'first', 'name' => 'Another First'),
|
|
|
4266 |
);
|
|
|
4267 |
$result = $this->Form->select(
|
|
|
4268 |
'Model.field',
|
|
|
4269 |
$options,
|
|
|
4270 |
array('escape' => false, 'empty' => false)
|
|
|
4271 |
);
|
|
|
4272 |
$expected = array(
|
|
|
4273 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4274 |
array('option' => array('value' => 'first')),
|
|
|
4275 |
'First',
|
|
|
4276 |
'/option',
|
|
|
4277 |
array('option' => array('value' => 'first')),
|
|
|
4278 |
'Another First',
|
|
|
4279 |
'/option',
|
|
|
4280 |
'/select'
|
|
|
4281 |
);
|
|
|
4282 |
$this->assertTags($result, $expected);
|
|
|
4283 |
|
|
|
4284 |
$this->Form->request->data = array('Model' => array('contact_id' => 228));
|
|
|
4285 |
$result = $this->Form->select(
|
|
|
4286 |
'Model.contact_id',
|
|
|
4287 |
array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
|
|
|
4288 |
array('escape' => false, 'empty' => 'pick something')
|
|
|
4289 |
);
|
|
|
4290 |
|
|
|
4291 |
$expected = array(
|
|
|
4292 |
'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'),
|
|
|
4293 |
array('option' => array('value' => '')), 'pick something', '/option',
|
|
|
4294 |
array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
|
|
|
4295 |
array('option' => array('value' => '228-1')), '228-1 value', '/option',
|
|
|
4296 |
array('option' => array('value' => '228-2')), '228-2 value', '/option',
|
|
|
4297 |
'/select'
|
|
|
4298 |
);
|
|
|
4299 |
$this->assertTags($result, $expected);
|
|
|
4300 |
|
|
|
4301 |
$this->Form->request->data['Model']['field'] = 0;
|
|
|
4302 |
$result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
|
|
|
4303 |
$expected = array(
|
|
|
4304 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4305 |
array('option' => array('value' => '')), '/option',
|
|
|
4306 |
array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
|
|
|
4307 |
array('option' => array('value' => '1')), 'Yes', '/option',
|
|
|
4308 |
'/select'
|
|
|
4309 |
);
|
|
|
4310 |
$this->assertTags($result, $expected);
|
|
|
4311 |
|
|
|
4312 |
$this->Form->request->data['Model']['field'] = 50;
|
|
|
4313 |
$result = $this->Form->select('Model.field', array('50f5c0cf' => 'Stringy', '50' => 'fifty'));
|
|
|
4314 |
$expected = array(
|
|
|
4315 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4316 |
array('option' => array('value' => '')), '/option',
|
|
|
4317 |
array('option' => array('value' => '50f5c0cf')), 'Stringy', '/option',
|
|
|
4318 |
array('option' => array('value' => '50', 'selected' => 'selected')), 'fifty', '/option',
|
|
|
4319 |
'/select'
|
|
|
4320 |
);
|
|
|
4321 |
$this->assertTags($result, $expected);
|
|
|
4322 |
|
|
|
4323 |
$result = $this->Form->select('Contact.required_one', array('option A'));
|
|
|
4324 |
$expected = array(
|
|
|
4325 |
'select' => array(
|
|
|
4326 |
'name' => 'data[Contact][required_one]',
|
|
|
4327 |
'id' => 'ContactRequiredOne',
|
|
|
4328 |
'required' => 'required'
|
|
|
4329 |
),
|
|
|
4330 |
array('option' => array('value' => '')), '/option',
|
|
|
4331 |
array('option' => array('value' => '0')), 'option A', '/option',
|
|
|
4332 |
'/select'
|
|
|
4333 |
);
|
|
|
4334 |
$this->assertTags($result, $expected);
|
|
|
4335 |
|
|
|
4336 |
$result = $this->Form->select('Contact.required_one', array('option A'), array('disabled' => true));
|
|
|
4337 |
$expected = array(
|
|
|
4338 |
'select' => array(
|
|
|
4339 |
'name' => 'data[Contact][required_one]',
|
|
|
4340 |
'id' => 'ContactRequiredOne',
|
|
|
4341 |
'disabled' => 'disabled'
|
|
|
4342 |
),
|
|
|
4343 |
array('option' => array('value' => '')), '/option',
|
|
|
4344 |
array('option' => array('value' => '0')), 'option A', '/option',
|
|
|
4345 |
'/select'
|
|
|
4346 |
);
|
|
|
4347 |
$this->assertTags($result, $expected);
|
|
|
4348 |
}
|
|
|
4349 |
|
|
|
4350 |
/**
|
|
|
4351 |
* test that select() with optiongroups listens to the escape param.
|
|
|
4352 |
*
|
|
|
4353 |
* @return void
|
|
|
4354 |
*/
|
|
|
4355 |
public function testSelectOptionGroupEscaping() {
|
|
|
4356 |
$options = array(
|
|
|
4357 |
'>< Key' => array(
|
|
|
4358 |
1 => 'One',
|
|
|
4359 |
2 => 'Two'
|
|
|
4360 |
)
|
|
|
4361 |
);
|
|
|
4362 |
$result = $this->Form->select('Model.field', $options, array('empty' => false));
|
|
|
4363 |
$expected = array(
|
|
|
4364 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4365 |
'optgroup' => array('label' => '>< Key'),
|
|
|
4366 |
array('option' => array('value' => '1')), 'One', '/option',
|
|
|
4367 |
array('option' => array('value' => '2')), 'Two', '/option',
|
|
|
4368 |
'/optgroup',
|
|
|
4369 |
'/select'
|
|
|
4370 |
);
|
|
|
4371 |
$this->assertTags($result, $expected);
|
|
|
4372 |
|
|
|
4373 |
$options = array(
|
|
|
4374 |
'>< Key' => array(
|
|
|
4375 |
1 => 'One',
|
|
|
4376 |
2 => 'Two'
|
|
|
4377 |
)
|
|
|
4378 |
);
|
|
|
4379 |
$result = $this->Form->select('Model.field', $options, array('empty' => false, 'escape' => false));
|
|
|
4380 |
$expected = array(
|
|
|
4381 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4382 |
'optgroup' => array('label' => '>< Key'),
|
|
|
4383 |
array('option' => array('value' => '1')), 'One', '/option',
|
|
|
4384 |
array('option' => array('value' => '2')), 'Two', '/option',
|
|
|
4385 |
'/optgroup',
|
|
|
4386 |
'/select'
|
|
|
4387 |
);
|
|
|
4388 |
$this->assertTags($result, $expected);
|
|
|
4389 |
}
|
|
|
4390 |
|
|
|
4391 |
/**
|
|
|
4392 |
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
|
|
|
4393 |
*
|
|
|
4394 |
* @return void
|
|
|
4395 |
*/
|
|
|
4396 |
public function testSelectWithNullAttributes() {
|
|
|
4397 |
$result = $this->Form->select('Model.field', array('first', 'second'), array('empty' => false));
|
|
|
4398 |
$expected = array(
|
|
|
4399 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4400 |
array('option' => array('value' => '0')),
|
|
|
4401 |
'first',
|
|
|
4402 |
'/option',
|
|
|
4403 |
array('option' => array('value' => '1')),
|
|
|
4404 |
'second',
|
|
|
4405 |
'/option',
|
|
|
4406 |
'/select'
|
|
|
4407 |
);
|
|
|
4408 |
$this->assertTags($result, $expected);
|
|
|
4409 |
}
|
|
|
4410 |
|
|
|
4411 |
/**
|
|
|
4412 |
* testNestedSelect method
|
|
|
4413 |
*
|
|
|
4414 |
* test select element generation with optgroups
|
|
|
4415 |
*
|
|
|
4416 |
* @return void
|
|
|
4417 |
*/
|
|
|
4418 |
public function testNestedSelect() {
|
|
|
4419 |
$result = $this->Form->select(
|
|
|
4420 |
'Model.field',
|
|
|
4421 |
array(1 => 'One', 2 => 'Two', 'Three' => array(
|
|
|
4422 |
3 => 'Three', 4 => 'Four', 5 => 'Five'
|
|
|
4423 |
)), array('empty' => false)
|
|
|
4424 |
);
|
|
|
4425 |
$expected = array(
|
|
|
4426 |
'select' => array('name' => 'data[Model][field]',
|
|
|
4427 |
'id' => 'ModelField'),
|
|
|
4428 |
array('option' => array('value' => 1)),
|
|
|
4429 |
'One',
|
|
|
4430 |
'/option',
|
|
|
4431 |
array('option' => array('value' => 2)),
|
|
|
4432 |
'Two',
|
|
|
4433 |
'/option',
|
|
|
4434 |
array('optgroup' => array('label' => 'Three')),
|
|
|
4435 |
array('option' => array('value' => 4)),
|
|
|
4436 |
'Four',
|
|
|
4437 |
'/option',
|
|
|
4438 |
array('option' => array('value' => 5)),
|
|
|
4439 |
'Five',
|
|
|
4440 |
'/option',
|
|
|
4441 |
'/optgroup',
|
|
|
4442 |
'/select'
|
|
|
4443 |
);
|
|
|
4444 |
$this->assertTags($result, $expected);
|
|
|
4445 |
|
|
|
4446 |
$result = $this->Form->select(
|
|
|
4447 |
'Model.field',
|
|
|
4448 |
array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')),
|
|
|
4449 |
array('showParents' => true, 'empty' => false)
|
|
|
4450 |
);
|
|
|
4451 |
|
|
|
4452 |
$expected = array(
|
|
|
4453 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
4454 |
array('option' => array('value' => 1)),
|
|
|
4455 |
'One',
|
|
|
4456 |
'/option',
|
|
|
4457 |
array('option' => array('value' => 2)),
|
|
|
4458 |
'Two',
|
|
|
4459 |
'/option',
|
|
|
4460 |
array('optgroup' => array('label' => 'Three')),
|
|
|
4461 |
array('option' => array('value' => 3)),
|
|
|
4462 |
'Three',
|
|
|
4463 |
'/option',
|
|
|
4464 |
array('option' => array('value' => 4)),
|
|
|
4465 |
'Four',
|
|
|
4466 |
'/option',
|
|
|
4467 |
'/optgroup',
|
|
|
4468 |
'/select'
|
|
|
4469 |
);
|
|
|
4470 |
$this->assertTags($result, $expected);
|
|
|
4471 |
}
|
|
|
4472 |
|
|
|
4473 |
/**
|
|
|
4474 |
* testSelectMultiple method
|
|
|
4475 |
*
|
|
|
4476 |
* test generation of multiple select elements
|
|
|
4477 |
*
|
|
|
4478 |
* @return void
|
|
|
4479 |
*/
|
|
|
4480 |
public function testSelectMultiple() {
|
|
|
4481 |
$options = array('first', 'second', 'third');
|
|
|
4482 |
$result = $this->Form->select(
|
|
|
4483 |
'Model.multi_field', $options, array('multiple' => true)
|
|
|
4484 |
);
|
|
|
4485 |
$expected = array(
|
|
|
4486 |
'input' => array(
|
|
|
4487 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
|
|
4488 |
),
|
|
|
4489 |
'select' => array(
|
|
|
4490 |
'name' => 'data[Model][multi_field][]',
|
|
|
4491 |
'id' => 'ModelMultiField', 'multiple' => 'multiple'
|
|
|
4492 |
),
|
|
|
4493 |
array('option' => array('value' => '0')),
|
|
|
4494 |
'first',
|
|
|
4495 |
'/option',
|
|
|
4496 |
array('option' => array('value' => '1')),
|
|
|
4497 |
'second',
|
|
|
4498 |
'/option',
|
|
|
4499 |
array('option' => array('value' => '2')),
|
|
|
4500 |
'third',
|
|
|
4501 |
'/option',
|
|
|
4502 |
'/select'
|
|
|
4503 |
);
|
|
|
4504 |
$this->assertTags($result, $expected);
|
|
|
4505 |
|
|
|
4506 |
$result = $this->Form->select(
|
|
|
4507 |
'Model.multi_field', $options, array('multiple' => 'multiple')
|
|
|
4508 |
);
|
|
|
4509 |
$expected = array(
|
|
|
4510 |
'input' => array(
|
|
|
4511 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
|
|
4512 |
),
|
|
|
4513 |
'select' => array(
|
|
|
4514 |
'name' => 'data[Model][multi_field][]',
|
|
|
4515 |
'id' => 'ModelMultiField', 'multiple' => 'multiple'
|
|
|
4516 |
),
|
|
|
4517 |
array('option' => array('value' => '0')),
|
|
|
4518 |
'first',
|
|
|
4519 |
'/option',
|
|
|
4520 |
array('option' => array('value' => '1')),
|
|
|
4521 |
'second',
|
|
|
4522 |
'/option',
|
|
|
4523 |
array('option' => array('value' => '2')),
|
|
|
4524 |
'third',
|
|
|
4525 |
'/option',
|
|
|
4526 |
'/select'
|
|
|
4527 |
);
|
|
|
4528 |
$this->assertTags($result, $expected);
|
|
|
4529 |
|
|
|
4530 |
$result = $this->Form->select(
|
|
|
4531 |
'Model.multi_field', $options, array('multiple' => true, 'value' => array(0, 1))
|
|
|
4532 |
);
|
|
|
4533 |
$expected = array(
|
|
|
4534 |
'input' => array(
|
|
|
4535 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
|
|
4536 |
),
|
|
|
4537 |
'select' => array(
|
|
|
4538 |
'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField',
|
|
|
4539 |
'multiple' => 'multiple'
|
|
|
4540 |
),
|
|
|
4541 |
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
4542 |
'first',
|
|
|
4543 |
'/option',
|
|
|
4544 |
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
4545 |
'second',
|
|
|
4546 |
'/option',
|
|
|
4547 |
array('option' => array('value' => '2')),
|
|
|
4548 |
'third',
|
|
|
4549 |
'/option',
|
|
|
4550 |
'/select'
|
|
|
4551 |
);
|
|
|
4552 |
$this->assertTags($result, $expected);
|
|
|
4553 |
|
|
|
4554 |
$result = $this->Form->select(
|
|
|
4555 |
'Model.multi_field', $options, array('multiple' => false, 'value' => array(0, 1))
|
|
|
4556 |
);
|
|
|
4557 |
$expected = array(
|
|
|
4558 |
'select' => array(
|
|
|
4559 |
'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField'
|
|
|
4560 |
),
|
|
|
4561 |
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
4562 |
'first',
|
|
|
4563 |
'/option',
|
|
|
4564 |
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
4565 |
'second',
|
|
|
4566 |
'/option',
|
|
|
4567 |
array('option' => array('value' => '2')),
|
|
|
4568 |
'third',
|
|
|
4569 |
'/option',
|
|
|
4570 |
'/select'
|
|
|
4571 |
);
|
|
|
4572 |
$this->assertTags($result, $expected);
|
|
|
4573 |
|
|
|
4574 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4575 |
$selected = array('2', '3x');
|
|
|
4576 |
$result = $this->Form->select(
|
|
|
4577 |
'Model.multi_field', $options, array('multiple' => true, 'value' => $selected)
|
|
|
4578 |
);
|
|
|
4579 |
$expected = array(
|
|
|
4580 |
'input' => array(
|
|
|
4581 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
|
|
4582 |
),
|
|
|
4583 |
'select' => array(
|
|
|
4584 |
'name' => 'data[Model][multi_field][]', 'multiple' => 'multiple', 'id' => 'ModelMultiField'
|
|
|
4585 |
),
|
|
|
4586 |
array('option' => array('value' => '1')),
|
|
|
4587 |
'One',
|
|
|
4588 |
'/option',
|
|
|
4589 |
array('option' => array('value' => '2', 'selected' => 'selected')),
|
|
|
4590 |
'Two',
|
|
|
4591 |
'/option',
|
|
|
4592 |
array('option' => array('value' => '3')),
|
|
|
4593 |
'Three',
|
|
|
4594 |
'/option',
|
|
|
4595 |
array('option' => array('value' => '3x', 'selected' => 'selected')),
|
|
|
4596 |
'Stringy',
|
|
|
4597 |
'/option',
|
|
|
4598 |
'/select'
|
|
|
4599 |
);
|
|
|
4600 |
$this->assertTags($result, $expected);
|
|
|
4601 |
|
|
|
4602 |
$result = $this->Form->select('Contact.required_one', array(
|
|
|
4603 |
'1' => 'option A',
|
|
|
4604 |
'2' => 'option B'
|
|
|
4605 |
), array('multiple' => true));
|
|
|
4606 |
$expected = array(
|
|
|
4607 |
'input' => array(
|
|
|
4608 |
'type' => 'hidden', 'name' => 'data[Contact][required_one]', 'value' => '', 'id' => 'ContactRequiredOne_'
|
|
|
4609 |
),
|
|
|
4610 |
'select' => array(
|
|
|
4611 |
'name' => 'data[Contact][required_one][]',
|
|
|
4612 |
'id' => 'ContactRequiredOne',
|
|
|
4613 |
'required' => 'required',
|
|
|
4614 |
'multiple' => 'multiple'
|
|
|
4615 |
),
|
|
|
4616 |
array('option' => array('value' => '1')), 'option A', '/option',
|
|
|
4617 |
array('option' => array('value' => '2')), 'option B', '/option',
|
|
|
4618 |
'/select'
|
|
|
4619 |
);
|
|
|
4620 |
$this->assertTags($result, $expected);
|
|
|
4621 |
}
|
|
|
4622 |
|
|
|
4623 |
/**
|
|
|
4624 |
* Test generating multiple select with disabled elements.
|
|
|
4625 |
*
|
|
|
4626 |
* @return void
|
|
|
4627 |
*/
|
|
|
4628 |
public function testSelectMultipleWithDisabledElements() {
|
|
|
4629 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4630 |
$disabled = array(2, 3);
|
|
|
4631 |
$result = $this->Form->select('Contact.multiple', $options, array('multiple' => 'multiple', 'disabled' => $disabled));
|
|
|
4632 |
$expected = array(
|
|
|
4633 |
'input' => array(
|
|
|
4634 |
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
|
|
|
4635 |
),
|
|
|
4636 |
'select' => array(
|
|
|
4637 |
'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
4638 |
),
|
|
|
4639 |
array('option' => array('value' => '1')),
|
|
|
4640 |
'One',
|
|
|
4641 |
'/option',
|
|
|
4642 |
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
4643 |
'Two',
|
|
|
4644 |
'/option',
|
|
|
4645 |
array('option' => array('value' => '3', 'disabled' => 'disabled')),
|
|
|
4646 |
'Three',
|
|
|
4647 |
'/option',
|
|
|
4648 |
array('option' => array('value' => '3x')),
|
|
|
4649 |
'Stringy',
|
|
|
4650 |
'/option',
|
|
|
4651 |
'/select'
|
|
|
4652 |
);
|
|
|
4653 |
$this->assertTags($result, $expected);
|
|
|
4654 |
|
|
|
4655 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4656 |
$disabled = array('2', '3x');
|
|
|
4657 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
|
|
|
4658 |
$expected = array(
|
|
|
4659 |
array('div' => array('class' => 'input select')),
|
|
|
4660 |
array('label' => array('for' => 'ContactMultiple')),
|
|
|
4661 |
'Multiple',
|
|
|
4662 |
'/label',
|
|
|
4663 |
'input' => array(
|
|
|
4664 |
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
|
|
|
4665 |
),
|
|
|
4666 |
'select' => array(
|
|
|
4667 |
'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
4668 |
),
|
|
|
4669 |
array('option' => array('value' => '1')),
|
|
|
4670 |
'One',
|
|
|
4671 |
'/option',
|
|
|
4672 |
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
4673 |
'Two',
|
|
|
4674 |
'/option',
|
|
|
4675 |
array('option' => array('value' => '3')),
|
|
|
4676 |
'Three',
|
|
|
4677 |
'/option',
|
|
|
4678 |
array('option' => array('value' => '3x', 'disabled' => 'disabled')),
|
|
|
4679 |
'Stringy',
|
|
|
4680 |
'/option',
|
|
|
4681 |
'/select',
|
|
|
4682 |
'/div'
|
|
|
4683 |
);
|
|
|
4684 |
$this->assertTags($result, $expected);
|
|
|
4685 |
|
|
|
4686 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4687 |
$disabled = true;
|
|
|
4688 |
$result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
|
|
|
4689 |
$expected = array(
|
|
|
4690 |
array('div' => array('class' => 'input select')),
|
|
|
4691 |
array('label' => array('for' => 'ContactMultiple')),
|
|
|
4692 |
'Multiple',
|
|
|
4693 |
'/label',
|
|
|
4694 |
'input' => array(
|
|
|
4695 |
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
|
|
|
4696 |
),
|
|
|
4697 |
'select' => array(
|
|
|
4698 |
'name' => 'data[Contact][multiple][]', 'disabled' => 'disabled', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
4699 |
),
|
|
|
4700 |
array('option' => array('value' => '1')),
|
|
|
4701 |
'One',
|
|
|
4702 |
'/option',
|
|
|
4703 |
array('option' => array('value' => '2')),
|
|
|
4704 |
'Two',
|
|
|
4705 |
'/option',
|
|
|
4706 |
array('option' => array('value' => '3')),
|
|
|
4707 |
'Three',
|
|
|
4708 |
'/option',
|
|
|
4709 |
array('option' => array('value' => '3x')),
|
|
|
4710 |
'Stringy',
|
|
|
4711 |
'/option',
|
|
|
4712 |
'/select',
|
|
|
4713 |
'/div'
|
|
|
4714 |
);
|
|
|
4715 |
$this->assertTags($result, $expected);
|
|
|
4716 |
}
|
|
|
4717 |
|
|
|
4718 |
/**
|
|
|
4719 |
* Test generating select with disabled elements.
|
|
|
4720 |
*
|
|
|
4721 |
* @return void
|
|
|
4722 |
*/
|
|
|
4723 |
public function testSelectWithDisabledElements() {
|
|
|
4724 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4725 |
$disabled = array(2, 3);
|
|
|
4726 |
$result = $this->Form->select('Model.field', $options, array('disabled' => $disabled));
|
|
|
4727 |
$expected = array(
|
|
|
4728 |
'select' => array(
|
|
|
4729 |
'name' => 'data[Model][field]', 'id' => 'ModelField'
|
|
|
4730 |
),
|
|
|
4731 |
array('option' => array('value' => '')),
|
|
|
4732 |
'/option',
|
|
|
4733 |
array('option' => array('value' => '1')),
|
|
|
4734 |
'One',
|
|
|
4735 |
'/option',
|
|
|
4736 |
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
4737 |
'Two',
|
|
|
4738 |
'/option',
|
|
|
4739 |
array('option' => array('value' => '3', 'disabled' => 'disabled')),
|
|
|
4740 |
'Three',
|
|
|
4741 |
'/option',
|
|
|
4742 |
array('option' => array('value' => '3x')),
|
|
|
4743 |
'Stringy',
|
|
|
4744 |
'/option',
|
|
|
4745 |
'/select'
|
|
|
4746 |
);
|
|
|
4747 |
$this->assertTags($result, $expected);
|
|
|
4748 |
|
|
|
4749 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4750 |
$disabled = array('2', '3x');
|
|
|
4751 |
$result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
|
|
|
4752 |
$expected = array(
|
|
|
4753 |
array('div' => array('class' => 'input select')),
|
|
|
4754 |
array('label' => array('for' => 'ModelField')),
|
|
|
4755 |
'Field',
|
|
|
4756 |
'/label',
|
|
|
4757 |
'select' => array(
|
|
|
4758 |
'name' => 'data[Model][field]', 'id' => 'ModelField'
|
|
|
4759 |
),
|
|
|
4760 |
array('option' => array('value' => '1')),
|
|
|
4761 |
'One',
|
|
|
4762 |
'/option',
|
|
|
4763 |
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
4764 |
'Two',
|
|
|
4765 |
'/option',
|
|
|
4766 |
array('option' => array('value' => '3')),
|
|
|
4767 |
'Three',
|
|
|
4768 |
'/option',
|
|
|
4769 |
array('option' => array('value' => '3x', 'disabled' => 'disabled')),
|
|
|
4770 |
'Stringy',
|
|
|
4771 |
'/option',
|
|
|
4772 |
'/select',
|
|
|
4773 |
'/div'
|
|
|
4774 |
);
|
|
|
4775 |
$this->assertTags($result, $expected);
|
|
|
4776 |
|
|
|
4777 |
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
4778 |
$disabled = true;
|
|
|
4779 |
$result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
|
|
|
4780 |
$expected = array(
|
|
|
4781 |
array('div' => array('class' => 'input select')),
|
|
|
4782 |
array('label' => array('for' => 'ModelField')),
|
|
|
4783 |
'Field',
|
|
|
4784 |
'/label',
|
|
|
4785 |
'select' => array(
|
|
|
4786 |
'name' => 'data[Model][field]', 'id' => 'ModelField', 'disabled' => 'disabled'
|
|
|
4787 |
),
|
|
|
4788 |
array('option' => array('value' => '1')),
|
|
|
4789 |
'One',
|
|
|
4790 |
'/option',
|
|
|
4791 |
array('option' => array('value' => '2')),
|
|
|
4792 |
'Two',
|
|
|
4793 |
'/option',
|
|
|
4794 |
array('option' => array('value' => '3')),
|
|
|
4795 |
'Three',
|
|
|
4796 |
'/option',
|
|
|
4797 |
array('option' => array('value' => '3x')),
|
|
|
4798 |
'Stringy',
|
|
|
4799 |
'/option',
|
|
|
4800 |
'/select',
|
|
|
4801 |
'/div'
|
|
|
4802 |
);
|
|
|
4803 |
$this->assertTags($result, $expected);
|
|
|
4804 |
}
|
|
|
4805 |
|
|
|
4806 |
/**
|
|
|
4807 |
* test generation of habtm select boxes.
|
|
|
4808 |
*
|
|
|
4809 |
* @return void
|
|
|
4810 |
*/
|
|
|
4811 |
public function testHabtmSelectBox() {
|
|
|
4812 |
$this->View->viewVars['contactTags'] = array(
|
|
|
4813 |
1 => 'blue',
|
|
|
4814 |
2 => 'red',
|
|
|
4815 |
3 => 'green'
|
|
|
4816 |
);
|
|
|
4817 |
$this->Form->request->data = array(
|
|
|
4818 |
'Contact' => array(),
|
|
|
4819 |
'ContactTag' => array(
|
|
|
4820 |
array(
|
|
|
4821 |
'id' => '1',
|
|
|
4822 |
'name' => 'blue'
|
|
|
4823 |
),
|
|
|
4824 |
array(
|
|
|
4825 |
'id' => 3,
|
|
|
4826 |
'name' => 'green'
|
|
|
4827 |
)
|
|
|
4828 |
)
|
|
|
4829 |
);
|
|
|
4830 |
$this->Form->create('Contact');
|
|
|
4831 |
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
|
|
|
4832 |
$expected = array(
|
|
|
4833 |
'input' => array(
|
|
|
4834 |
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
|
|
|
4835 |
),
|
|
|
4836 |
'select' => array(
|
|
|
4837 |
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
|
|
|
4838 |
'multiple' => 'multiple'
|
|
|
4839 |
),
|
|
|
4840 |
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
4841 |
'blue',
|
|
|
4842 |
'/option',
|
|
|
4843 |
array('option' => array('value' => '2')),
|
|
|
4844 |
'red',
|
|
|
4845 |
'/option',
|
|
|
4846 |
array('option' => array('value' => '3', 'selected' => 'selected')),
|
|
|
4847 |
'green',
|
|
|
4848 |
'/option',
|
|
|
4849 |
'/select'
|
|
|
4850 |
);
|
|
|
4851 |
$this->assertTags($result, $expected);
|
|
|
4852 |
|
|
|
4853 |
// make sure only 50 is selected, and not 50f5c0cf
|
|
|
4854 |
$this->View->viewVars['contactTags'] = array(
|
|
|
4855 |
'1' => 'blue',
|
|
|
4856 |
'50f5c0cf' => 'red',
|
|
|
4857 |
'50' => 'green'
|
|
|
4858 |
);
|
|
|
4859 |
$this->Form->request->data = array(
|
|
|
4860 |
'Contact' => array(),
|
|
|
4861 |
'ContactTag' => array(
|
|
|
4862 |
array(
|
|
|
4863 |
'id' => 1,
|
|
|
4864 |
'name' => 'blue'
|
|
|
4865 |
),
|
|
|
4866 |
array(
|
|
|
4867 |
'id' => 50,
|
|
|
4868 |
'name' => 'green'
|
|
|
4869 |
)
|
|
|
4870 |
)
|
|
|
4871 |
);
|
|
|
4872 |
$this->Form->create('Contact');
|
|
|
4873 |
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
|
|
|
4874 |
$expected = array(
|
|
|
4875 |
'input' => array(
|
|
|
4876 |
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
|
|
|
4877 |
),
|
|
|
4878 |
'select' => array(
|
|
|
4879 |
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
|
|
|
4880 |
'multiple' => 'multiple'
|
|
|
4881 |
),
|
|
|
4882 |
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
4883 |
'blue',
|
|
|
4884 |
'/option',
|
|
|
4885 |
array('option' => array('value' => '50f5c0cf')),
|
|
|
4886 |
'red',
|
|
|
4887 |
'/option',
|
|
|
4888 |
array('option' => array('value' => '50', 'selected' => 'selected')),
|
|
|
4889 |
'green',
|
|
|
4890 |
'/option',
|
|
|
4891 |
'/select'
|
|
|
4892 |
);
|
|
|
4893 |
$this->assertTags($result, $expected);
|
|
|
4894 |
}
|
|
|
4895 |
|
|
|
4896 |
/**
|
|
|
4897 |
* test generation of multi select elements in checkbox format
|
|
|
4898 |
*
|
|
|
4899 |
* @return void
|
|
|
4900 |
*/
|
|
|
4901 |
public function testSelectMultipleCheckboxes() {
|
|
|
4902 |
$result = $this->Form->select(
|
|
|
4903 |
'Model.multi_field',
|
|
|
4904 |
array('first', 'second', 'third'),
|
|
|
4905 |
array('multiple' => 'checkbox')
|
|
|
4906 |
);
|
|
|
4907 |
|
|
|
4908 |
$expected = array(
|
|
|
4909 |
'input' => array(
|
|
|
4910 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
|
|
4911 |
),
|
|
|
4912 |
array('div' => array('class' => 'checkbox')),
|
|
|
4913 |
array('input' => array(
|
|
|
4914 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4915 |
'value' => '0', 'id' => 'ModelMultiField0'
|
|
|
4916 |
)),
|
|
|
4917 |
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
4918 |
'first',
|
|
|
4919 |
'/label',
|
|
|
4920 |
'/div',
|
|
|
4921 |
array('div' => array('class' => 'checkbox')),
|
|
|
4922 |
array('input' => array(
|
|
|
4923 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4924 |
'value' => '1', 'id' => 'ModelMultiField1'
|
|
|
4925 |
)),
|
|
|
4926 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
4927 |
'second',
|
|
|
4928 |
'/label',
|
|
|
4929 |
'/div',
|
|
|
4930 |
array('div' => array('class' => 'checkbox')),
|
|
|
4931 |
array('input' => array(
|
|
|
4932 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4933 |
'value' => '2', 'id' => 'ModelMultiField2'
|
|
|
4934 |
)),
|
|
|
4935 |
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
4936 |
'third',
|
|
|
4937 |
'/label',
|
|
|
4938 |
'/div'
|
|
|
4939 |
);
|
|
|
4940 |
$this->assertTags($result, $expected);
|
|
|
4941 |
|
|
|
4942 |
$result = $this->Form->select(
|
|
|
4943 |
'Model.multi_field',
|
|
|
4944 |
array('a' => 'first', 'b' => 'second', 'c' => 'third'),
|
|
|
4945 |
array('multiple' => 'checkbox')
|
|
|
4946 |
);
|
|
|
4947 |
$expected = array(
|
|
|
4948 |
'input' => array(
|
|
|
4949 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
|
|
4950 |
),
|
|
|
4951 |
array('div' => array('class' => 'checkbox')),
|
|
|
4952 |
array('input' => array(
|
|
|
4953 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4954 |
'value' => 'a', 'id' => 'ModelMultiFieldA'
|
|
|
4955 |
)),
|
|
|
4956 |
array('label' => array('for' => 'ModelMultiFieldA')),
|
|
|
4957 |
'first',
|
|
|
4958 |
'/label',
|
|
|
4959 |
'/div',
|
|
|
4960 |
array('div' => array('class' => 'checkbox')),
|
|
|
4961 |
array('input' => array(
|
|
|
4962 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4963 |
'value' => 'b', 'id' => 'ModelMultiFieldB'
|
|
|
4964 |
)),
|
|
|
4965 |
array('label' => array('for' => 'ModelMultiFieldB')),
|
|
|
4966 |
'second',
|
|
|
4967 |
'/label',
|
|
|
4968 |
'/div',
|
|
|
4969 |
array('div' => array('class' => 'checkbox')),
|
|
|
4970 |
array('input' => array(
|
|
|
4971 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4972 |
'value' => 'c', 'id' => 'ModelMultiFieldC'
|
|
|
4973 |
)),
|
|
|
4974 |
array('label' => array('for' => 'ModelMultiFieldC')),
|
|
|
4975 |
'third',
|
|
|
4976 |
'/label',
|
|
|
4977 |
'/div'
|
|
|
4978 |
);
|
|
|
4979 |
$this->assertTags($result, $expected);
|
|
|
4980 |
|
|
|
4981 |
$result = $this->Form->select(
|
|
|
4982 |
'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
|
|
|
4983 |
);
|
|
|
4984 |
$expected = array(
|
|
|
4985 |
'input' => array(
|
|
|
4986 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
|
|
4987 |
),
|
|
|
4988 |
array('div' => array('class' => 'checkbox')),
|
|
|
4989 |
array('input' => array(
|
|
|
4990 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
4991 |
'value' => '1', 'id' => 'ModelMultiField1'
|
|
|
4992 |
)),
|
|
|
4993 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
4994 |
'first',
|
|
|
4995 |
'/label',
|
|
|
4996 |
'/div'
|
|
|
4997 |
);
|
|
|
4998 |
$this->assertTags($result, $expected);
|
|
|
4999 |
|
|
|
5000 |
$this->Form->request->data = array('Model' => array('tags' => array(1)));
|
|
|
5001 |
$result = $this->Form->select(
|
|
|
5002 |
'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
|
|
|
5003 |
);
|
|
|
5004 |
$expected = array(
|
|
|
5005 |
'input' => array(
|
|
|
5006 |
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
|
|
|
5007 |
),
|
|
|
5008 |
array('div' => array('class' => 'checkbox')),
|
|
|
5009 |
array('input' => array(
|
|
|
5010 |
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
5011 |
'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
|
|
|
5012 |
)),
|
|
|
5013 |
array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
|
|
|
5014 |
'first',
|
|
|
5015 |
'/label',
|
|
|
5016 |
'/div',
|
|
|
5017 |
|
|
|
5018 |
array('div' => array('class' => 'checkbox')),
|
|
|
5019 |
array('input' => array(
|
|
|
5020 |
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
5021 |
'value' => 'Array', 'id' => 'ModelTagsArray'
|
|
|
5022 |
)),
|
|
|
5023 |
array('label' => array('for' => 'ModelTagsArray')),
|
|
|
5024 |
'Array',
|
|
|
5025 |
'/label',
|
|
|
5026 |
'/div'
|
|
|
5027 |
);
|
|
|
5028 |
$this->assertTags($result, $expected);
|
|
|
5029 |
}
|
|
|
5030 |
|
|
|
5031 |
/**
|
|
|
5032 |
* test multiple checkboxes with div styles.
|
|
|
5033 |
*
|
|
|
5034 |
* @return void
|
|
|
5035 |
*/
|
|
|
5036 |
public function testSelectMultipleCheckboxDiv() {
|
|
|
5037 |
$result = $this->Form->select(
|
|
|
5038 |
'Model.tags',
|
|
|
5039 |
array('first', 'second'),
|
|
|
5040 |
array('multiple' => 'checkbox', 'class' => 'my-class')
|
|
|
5041 |
);
|
|
|
5042 |
$expected = array(
|
|
|
5043 |
'input' => array(
|
|
|
5044 |
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
|
|
|
5045 |
),
|
|
|
5046 |
array('div' => array('class' => 'my-class')),
|
|
|
5047 |
array('input' => array(
|
|
|
5048 |
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
5049 |
'value' => '0', 'id' => 'ModelTags0'
|
|
|
5050 |
)),
|
|
|
5051 |
array('label' => array('for' => 'ModelTags0')), 'first', '/label',
|
|
|
5052 |
'/div',
|
|
|
5053 |
|
|
|
5054 |
array('div' => array('class' => 'my-class')),
|
|
|
5055 |
array('input' => array(
|
|
|
5056 |
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
5057 |
'value' => '1', 'id' => 'ModelTags1'
|
|
|
5058 |
)),
|
|
|
5059 |
array('label' => array('for' => 'ModelTags1')), 'second', '/label',
|
|
|
5060 |
'/div'
|
|
|
5061 |
);
|
|
|
5062 |
$this->assertTags($result, $expected);
|
|
|
5063 |
|
|
|
5064 |
$result = $this->Form->input('Model.tags', array(
|
|
|
5065 |
'options' => array('first', 'second'),
|
|
|
5066 |
'multiple' => 'checkbox',
|
|
|
5067 |
'class' => 'my-class',
|
|
|
5068 |
'div' => false,
|
|
|
5069 |
'label' => false
|
|
|
5070 |
));
|
|
|
5071 |
$this->assertTags($result, $expected);
|
|
|
5072 |
|
|
|
5073 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
5074 |
$Contact->validationErrors['tags'] = 'Select atleast one option';
|
|
|
5075 |
$result = $this->Form->input('Contact.tags', array(
|
|
|
5076 |
'options' => array('one'),
|
|
|
5077 |
'multiple' => 'checkbox',
|
|
|
5078 |
'label' => false,
|
|
|
5079 |
'div' => false
|
|
|
5080 |
));
|
|
|
5081 |
$expected = array(
|
|
|
5082 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
|
|
|
5083 |
array('div' => array('class' => 'checkbox form-error')),
|
|
|
5084 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
|
|
5085 |
array('label' => array('for' => 'ContactTags0')),
|
|
|
5086 |
'one',
|
|
|
5087 |
'/label',
|
|
|
5088 |
'/div'
|
|
|
5089 |
);
|
|
|
5090 |
$this->assertTags($result, $expected);
|
|
|
5091 |
|
|
|
5092 |
$result = $this->Form->input('Contact.tags', array(
|
|
|
5093 |
'options' => array('one'),
|
|
|
5094 |
'multiple' => 'checkbox',
|
|
|
5095 |
'class' => 'mycheckbox',
|
|
|
5096 |
'label' => false,
|
|
|
5097 |
'div' => false
|
|
|
5098 |
));
|
|
|
5099 |
$expected = array(
|
|
|
5100 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
|
|
|
5101 |
array('div' => array('class' => 'mycheckbox form-error')),
|
|
|
5102 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
|
|
5103 |
array('label' => array('for' => 'ContactTags0')),
|
|
|
5104 |
'one',
|
|
|
5105 |
'/label',
|
|
|
5106 |
'/div'
|
|
|
5107 |
);
|
|
|
5108 |
$this->assertTags($result, $expected);
|
|
|
5109 |
}
|
|
|
5110 |
|
|
|
5111 |
/**
|
|
|
5112 |
* Checks the security hash array generated for multiple-input checkbox elements
|
|
|
5113 |
*
|
|
|
5114 |
* @return void
|
|
|
5115 |
*/
|
|
|
5116 |
public function testSelectMultipleCheckboxSecurity() {
|
|
|
5117 |
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
5118 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
5119 |
|
|
|
5120 |
$result = $this->Form->select(
|
|
|
5121 |
'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
|
|
|
5122 |
array('multiple' => 'checkbox')
|
|
|
5123 |
);
|
|
|
5124 |
$this->assertEquals(array('Model.multi_field'), $this->Form->fields);
|
|
|
5125 |
|
|
|
5126 |
$result = $this->Form->secure($this->Form->fields);
|
|
|
5127 |
$key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
|
|
|
5128 |
$this->assertRegExp('/"' . $key . '"/', $result);
|
|
|
5129 |
}
|
|
|
5130 |
|
|
|
5131 |
/**
|
|
|
5132 |
* Multiple select elements should always be secured as they always participate
|
|
|
5133 |
* in the POST data.
|
|
|
5134 |
*
|
|
|
5135 |
* @return void
|
|
|
5136 |
*/
|
|
|
5137 |
public function testSelectMultipleSecureWithNoOptions() {
|
|
|
5138 |
$this->Form->request['_Token'] = array('key' => 'testkey');
|
|
|
5139 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
5140 |
|
|
|
5141 |
$this->Form->select(
|
|
|
5142 |
'Model.select',
|
|
|
5143 |
array(),
|
|
|
5144 |
array('multiple' => true)
|
|
|
5145 |
);
|
|
|
5146 |
$this->assertEquals(array('Model.select'), $this->Form->fields);
|
|
|
5147 |
}
|
|
|
5148 |
/**
|
|
|
5149 |
* When a select box has no options it should not be added to the fields list
|
|
|
5150 |
* as it always fail post validation.
|
|
|
5151 |
*
|
|
|
5152 |
* @return void
|
|
|
5153 |
*/
|
|
|
5154 |
public function testSelectNoSecureWithNoOptions() {
|
|
|
5155 |
$this->Form->request['_Token'] = array('key' => 'testkey');
|
|
|
5156 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
5157 |
|
|
|
5158 |
$this->Form->select(
|
|
|
5159 |
'Model.select',
|
|
|
5160 |
array()
|
|
|
5161 |
);
|
|
|
5162 |
$this->assertEquals(array(), $this->Form->fields);
|
|
|
5163 |
|
|
|
5164 |
$this->Form->select(
|
|
|
5165 |
'Model.select',
|
|
|
5166 |
array(),
|
|
|
5167 |
array('empty' => true)
|
|
|
5168 |
);
|
|
|
5169 |
$this->assertEquals(array('Model.select'), $this->Form->fields);
|
|
|
5170 |
}
|
|
|
5171 |
|
|
|
5172 |
/**
|
|
|
5173 |
* testInputMultipleCheckboxes method
|
|
|
5174 |
*
|
|
|
5175 |
* test input() resulting in multi select elements being generated.
|
|
|
5176 |
*
|
|
|
5177 |
* @return void
|
|
|
5178 |
*/
|
|
|
5179 |
public function testInputMultipleCheckboxes() {
|
|
|
5180 |
$result = $this->Form->input('Model.multi_field', array(
|
|
|
5181 |
'options' => array('first', 'second', 'third'),
|
|
|
5182 |
'multiple' => 'checkbox'
|
|
|
5183 |
));
|
|
|
5184 |
$expected = array(
|
|
|
5185 |
array('div' => array('class' => 'input select')),
|
|
|
5186 |
array('label' => array('for' => 'ModelMultiField')),
|
|
|
5187 |
'Multi Field',
|
|
|
5188 |
'/label',
|
|
|
5189 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
5190 |
array('div' => array('class' => 'checkbox')),
|
|
|
5191 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
5192 |
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
5193 |
'first',
|
|
|
5194 |
'/label',
|
|
|
5195 |
'/div',
|
|
|
5196 |
array('div' => array('class' => 'checkbox')),
|
|
|
5197 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
5198 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
5199 |
'second',
|
|
|
5200 |
'/label',
|
|
|
5201 |
'/div',
|
|
|
5202 |
array('div' => array('class' => 'checkbox')),
|
|
|
5203 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
5204 |
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
5205 |
'third',
|
|
|
5206 |
'/label',
|
|
|
5207 |
'/div',
|
|
|
5208 |
'/div'
|
|
|
5209 |
);
|
|
|
5210 |
$this->assertTags($result, $expected);
|
|
|
5211 |
|
|
|
5212 |
$result = $this->Form->input('Model.multi_field', array(
|
|
|
5213 |
'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
|
|
|
5214 |
'multiple' => 'checkbox'
|
|
|
5215 |
));
|
|
|
5216 |
$expected = array(
|
|
|
5217 |
array('div' => array('class' => 'input select')),
|
|
|
5218 |
array('label' => array('for' => 'ModelMultiField')),
|
|
|
5219 |
'Multi Field',
|
|
|
5220 |
'/label',
|
|
|
5221 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
5222 |
array('div' => array('class' => 'checkbox')),
|
|
|
5223 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
|
|
|
5224 |
array('label' => array('for' => 'ModelMultiFieldA')),
|
|
|
5225 |
'first',
|
|
|
5226 |
'/label',
|
|
|
5227 |
'/div',
|
|
|
5228 |
array('div' => array('class' => 'checkbox')),
|
|
|
5229 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
|
|
|
5230 |
array('label' => array('for' => 'ModelMultiFieldB')),
|
|
|
5231 |
'second',
|
|
|
5232 |
'/label',
|
|
|
5233 |
'/div',
|
|
|
5234 |
array('div' => array('class' => 'checkbox')),
|
|
|
5235 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
|
|
|
5236 |
array('label' => array('for' => 'ModelMultiFieldC')),
|
|
|
5237 |
'third',
|
|
|
5238 |
'/label',
|
|
|
5239 |
'/div',
|
|
|
5240 |
'/div'
|
|
|
5241 |
);
|
|
|
5242 |
$this->assertTags($result, $expected);
|
|
|
5243 |
|
|
|
5244 |
$result = $this->Form->input('Model.multi_field', array(
|
|
|
5245 |
'options' => array('1' => 'first'),
|
|
|
5246 |
'multiple' => 'checkbox',
|
|
|
5247 |
'label' => false,
|
|
|
5248 |
'div' => false
|
|
|
5249 |
));
|
|
|
5250 |
$expected = array(
|
|
|
5251 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
5252 |
array('div' => array('class' => 'checkbox')),
|
|
|
5253 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
5254 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
5255 |
'first',
|
|
|
5256 |
'/label',
|
|
|
5257 |
'/div'
|
|
|
5258 |
);
|
|
|
5259 |
$this->assertTags($result, $expected);
|
|
|
5260 |
|
|
|
5261 |
$result = $this->Form->input('Model.multi_field', array(
|
|
|
5262 |
'options' => array('2' => 'second'),
|
|
|
5263 |
'multiple' => 'checkbox',
|
|
|
5264 |
'label' => false,
|
|
|
5265 |
'div' => false
|
|
|
5266 |
));
|
|
|
5267 |
$expected = array(
|
|
|
5268 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
5269 |
array('div' => array('class' => 'checkbox')),
|
|
|
5270 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
5271 |
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
5272 |
'second',
|
|
|
5273 |
'/label',
|
|
|
5274 |
'/div'
|
|
|
5275 |
);
|
|
|
5276 |
$this->assertTags($result, $expected);
|
|
|
5277 |
}
|
|
|
5278 |
|
|
|
5279 |
/**
|
|
|
5280 |
* testSelectHiddenFieldOmission method
|
|
|
5281 |
*
|
|
|
5282 |
* test that select() with 'hiddenField' => false omits the hidden field
|
|
|
5283 |
*
|
|
|
5284 |
* @return void
|
|
|
5285 |
*/
|
|
|
5286 |
public function testSelectHiddenFieldOmission() {
|
|
|
5287 |
$result = $this->Form->select('Model.multi_field',
|
|
|
5288 |
array('first', 'second'),
|
|
|
5289 |
array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
|
|
|
5290 |
);
|
|
|
5291 |
$expected = array(
|
|
|
5292 |
array('div' => array('class' => 'checkbox')),
|
|
|
5293 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
5294 |
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
5295 |
'first',
|
|
|
5296 |
'/label',
|
|
|
5297 |
'/div',
|
|
|
5298 |
array('div' => array('class' => 'checkbox')),
|
|
|
5299 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
5300 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
5301 |
'second',
|
|
|
5302 |
'/label',
|
|
|
5303 |
'/div'
|
|
|
5304 |
);
|
|
|
5305 |
$this->assertTags($result, $expected);
|
|
|
5306 |
|
|
|
5307 |
$result = $this->Form->input('Model.multi_field', array(
|
|
|
5308 |
'options' => array('first', 'second'),
|
|
|
5309 |
'multiple' => 'checkbox',
|
|
|
5310 |
'hiddenField' => false
|
|
|
5311 |
));
|
|
|
5312 |
$expected = array(
|
|
|
5313 |
array('div' => array('class' => 'input select')),
|
|
|
5314 |
array('label' => array('for' => 'ModelMultiField')),
|
|
|
5315 |
'Multi Field',
|
|
|
5316 |
'/label',
|
|
|
5317 |
array('div' => array('class' => 'checkbox')),
|
|
|
5318 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
5319 |
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
5320 |
'first',
|
|
|
5321 |
'/label',
|
|
|
5322 |
'/div',
|
|
|
5323 |
array('div' => array('class' => 'checkbox')),
|
|
|
5324 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
5325 |
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
5326 |
'second',
|
|
|
5327 |
'/label',
|
|
|
5328 |
'/div',
|
|
|
5329 |
'/div'
|
|
|
5330 |
);
|
|
|
5331 |
$this->assertTags($result, $expected);
|
|
|
5332 |
}
|
|
|
5333 |
|
|
|
5334 |
/**
|
|
|
5335 |
* test that select() with multiple = checkbox works with overriding name attribute.
|
|
|
5336 |
*
|
|
|
5337 |
* @return void
|
|
|
5338 |
*/
|
|
|
5339 |
public function testSelectCheckboxMultipleOverrideName() {
|
|
|
5340 |
$result = $this->Form->input('category', array(
|
|
|
5341 |
'type' => 'select',
|
|
|
5342 |
'multiple' => 'checkbox',
|
|
|
5343 |
'name' => 'data[fish]',
|
|
|
5344 |
'options' => array('1', '2'),
|
|
|
5345 |
'div' => false,
|
|
|
5346 |
'label' => false,
|
|
|
5347 |
));
|
|
|
5348 |
$expected = array(
|
|
|
5349 |
'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'),
|
|
|
5350 |
array('div' => array('class' => 'checkbox')),
|
|
|
5351 |
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')),
|
|
|
5352 |
array('label' => array('for' => 'Category0')), '1', '/label',
|
|
|
5353 |
'/div',
|
|
|
5354 |
array('div' => array('class' => 'checkbox')),
|
|
|
5355 |
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')),
|
|
|
5356 |
array('label' => array('for' => 'Category1')), '2', '/label',
|
|
|
5357 |
'/div'
|
|
|
5358 |
);
|
|
|
5359 |
$this->assertTags($result, $expected);
|
|
|
5360 |
}
|
|
|
5361 |
|
|
|
5362 |
/**
|
|
|
5363 |
* Test that 'id' overrides all the checkbox id's as well.
|
|
|
5364 |
*
|
|
|
5365 |
* @return void
|
|
|
5366 |
*/
|
|
|
5367 |
public function testSelectCheckboxMultipleId() {
|
|
|
5368 |
$result = $this->Form->select(
|
|
|
5369 |
'Model.multi_field',
|
|
|
5370 |
array('first', 'second', 'third'),
|
|
|
5371 |
array('multiple' => 'checkbox', 'id' => 'CustomId')
|
|
|
5372 |
);
|
|
|
5373 |
|
|
|
5374 |
$expected = array(
|
|
|
5375 |
'input' => array(
|
|
|
5376 |
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'CustomId'
|
|
|
5377 |
),
|
|
|
5378 |
array('div' => array('class' => 'checkbox')),
|
|
|
5379 |
array('input' => array(
|
|
|
5380 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
5381 |
'value' => '0', 'id' => 'CustomId0'
|
|
|
5382 |
)),
|
|
|
5383 |
array('label' => array('for' => 'CustomId0')),
|
|
|
5384 |
'first',
|
|
|
5385 |
'/label',
|
|
|
5386 |
'/div',
|
|
|
5387 |
array('div' => array('class' => 'checkbox')),
|
|
|
5388 |
array('input' => array(
|
|
|
5389 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
5390 |
'value' => '1', 'id' => 'CustomId1'
|
|
|
5391 |
)),
|
|
|
5392 |
array('label' => array('for' => 'CustomId1')),
|
|
|
5393 |
'second',
|
|
|
5394 |
'/label',
|
|
|
5395 |
'/div',
|
|
|
5396 |
array('div' => array('class' => 'checkbox')),
|
|
|
5397 |
array('input' => array(
|
|
|
5398 |
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
5399 |
'value' => '2', 'id' => 'CustomId2'
|
|
|
5400 |
)),
|
|
|
5401 |
array('label' => array('for' => 'CustomId2')),
|
|
|
5402 |
'third',
|
|
|
5403 |
'/label',
|
|
|
5404 |
'/div'
|
|
|
5405 |
);
|
|
|
5406 |
$this->assertTags($result, $expected);
|
|
|
5407 |
}
|
|
|
5408 |
|
|
|
5409 |
/**
|
|
|
5410 |
* testCheckbox method
|
|
|
5411 |
*
|
|
|
5412 |
* Test generation of checkboxes
|
|
|
5413 |
*
|
|
|
5414 |
* @return void
|
|
|
5415 |
*/
|
|
|
5416 |
public function testCheckbox() {
|
|
|
5417 |
$result = $this->Form->checkbox('Model.field');
|
|
|
5418 |
$expected = array(
|
|
|
5419 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5420 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
5421 |
);
|
|
|
5422 |
$this->assertTags($result, $expected);
|
|
|
5423 |
|
|
|
5424 |
$result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue'));
|
|
|
5425 |
$expected = array(
|
|
|
5426 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'),
|
|
|
5427 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID'))
|
|
|
5428 |
);
|
|
|
5429 |
$this->assertTags($result, $expected);
|
|
|
5430 |
|
|
|
5431 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
5432 |
$Contact->validationErrors['field'] = 1;
|
|
|
5433 |
$this->Form->request->data['Contact']['field'] = 'myvalue';
|
|
|
5434 |
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
|
|
|
5435 |
$expected = array(
|
|
|
5436 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
|
|
|
5437 |
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
|
|
|
5438 |
);
|
|
|
5439 |
$this->assertTags($result, $expected);
|
|
|
5440 |
|
|
|
5441 |
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
|
|
5442 |
$expected = array(
|
|
|
5443 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
|
|
5444 |
array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
|
|
|
5445 |
);
|
|
|
5446 |
$this->assertTags($result, $expected);
|
|
|
5447 |
|
|
|
5448 |
$this->Form->request->data['Contact']['field'] = '';
|
|
|
5449 |
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
|
|
|
5450 |
$expected = array(
|
|
|
5451 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
|
|
|
5452 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
|
|
|
5453 |
);
|
|
|
5454 |
$this->assertTags($result, $expected);
|
|
|
5455 |
|
|
|
5456 |
$Contact->validationErrors = array();
|
|
|
5457 |
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
|
|
5458 |
$expected = array(
|
|
|
5459 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
|
|
5460 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
|
|
|
5461 |
);
|
|
|
5462 |
$this->assertTags($result, $expected);
|
|
|
5463 |
|
|
|
5464 |
$this->Form->request->data['Contact']['published'] = 1;
|
|
|
5465 |
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
|
|
|
5466 |
$expected = array(
|
|
|
5467 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
|
|
|
5468 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked'))
|
|
|
5469 |
);
|
|
|
5470 |
$this->assertTags($result, $expected);
|
|
|
5471 |
|
|
|
5472 |
$this->Form->request->data['Contact']['published'] = 0;
|
|
|
5473 |
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
|
|
|
5474 |
$expected = array(
|
|
|
5475 |
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
|
|
|
5476 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID'))
|
|
|
5477 |
);
|
|
|
5478 |
$this->assertTags($result, $expected);
|
|
|
5479 |
|
|
|
5480 |
$result = $this->Form->checkbox('Model.CustomField.1.value');
|
|
|
5481 |
$expected = array(
|
|
|
5482 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][CustomField][1][value]', 'value' => '0', 'id' => 'ModelCustomField1Value_'),
|
|
|
5483 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][CustomField][1][value]', 'value' => '1', 'id' => 'ModelCustomField1Value'))
|
|
|
5484 |
);
|
|
|
5485 |
$this->assertTags($result, $expected);
|
|
|
5486 |
|
|
|
5487 |
$result = $this->Form->checkbox('CustomField.1.value');
|
|
|
5488 |
$expected = array(
|
|
|
5489 |
'input' => array('type' => 'hidden', 'name' => 'data[CustomField][1][value]', 'value' => '0', 'id' => 'CustomField1Value_'),
|
|
|
5490 |
array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value'))
|
|
|
5491 |
);
|
|
|
5492 |
$this->assertTags($result, $expected);
|
|
|
5493 |
}
|
|
|
5494 |
|
|
|
5495 |
/**
|
|
|
5496 |
* test checkbox() with a custom name attribute
|
|
|
5497 |
*
|
|
|
5498 |
* @return void
|
|
|
5499 |
*/
|
|
|
5500 |
public function testCheckboxCustomNameAttribute() {
|
|
|
5501 |
$result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
|
|
|
5502 |
$expected = array(
|
|
|
5503 |
'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'),
|
|
|
5504 |
array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1', 'id' => 'TestTest'))
|
|
|
5505 |
);
|
|
|
5506 |
$this->assertTags($result, $expected);
|
|
|
5507 |
}
|
|
|
5508 |
|
|
|
5509 |
/**
|
|
|
5510 |
* test the checked option for checkboxes.
|
|
|
5511 |
*
|
|
|
5512 |
* @return void
|
|
|
5513 |
*/
|
|
|
5514 |
public function testCheckboxCheckedOption() {
|
|
|
5515 |
$result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
|
|
|
5516 |
$expected = array(
|
|
|
5517 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5518 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
5519 |
);
|
|
|
5520 |
$this->assertTags($result, $expected);
|
|
|
5521 |
|
|
|
5522 |
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
|
|
|
5523 |
$expected = array(
|
|
|
5524 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5525 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
5526 |
);
|
|
|
5527 |
$this->assertTags($result, $expected);
|
|
|
5528 |
|
|
|
5529 |
$result = $this->Form->checkbox('Model.field', array('checked' => true));
|
|
|
5530 |
$expected = array(
|
|
|
5531 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5532 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
5533 |
);
|
|
|
5534 |
$this->assertTags($result, $expected);
|
|
|
5535 |
|
|
|
5536 |
$result = $this->Form->checkbox('Model.field', array('checked' => false));
|
|
|
5537 |
$expected = array(
|
|
|
5538 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5539 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
5540 |
);
|
|
|
5541 |
$this->assertTags($result, $expected);
|
|
|
5542 |
|
|
|
5543 |
$this->Form->request->data['Model']['field'] = 1;
|
|
|
5544 |
$result = $this->Form->checkbox('Model.field', array('checked' => false));
|
|
|
5545 |
$expected = array(
|
|
|
5546 |
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
5547 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
5548 |
);
|
|
|
5549 |
$this->assertTags($result, $expected);
|
|
|
5550 |
}
|
|
|
5551 |
|
|
|
5552 |
/**
|
|
|
5553 |
* Test that disabled attribute works on both the checkbox and hidden input.
|
|
|
5554 |
*
|
|
|
5555 |
* @return void
|
|
|
5556 |
*/
|
|
|
5557 |
public function testCheckboxDisabling() {
|
|
|
5558 |
$result = $this->Form->checkbox('Account.show_name', array('disabled' => 'disabled'));
|
|
|
5559 |
$expected = array(
|
|
|
5560 |
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')),
|
|
|
5561 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled'))
|
|
|
5562 |
);
|
|
|
5563 |
$this->assertTags($result, $expected);
|
|
|
5564 |
|
|
|
5565 |
$result = $this->Form->checkbox('Account.show_name', array('disabled' => false));
|
|
|
5566 |
$expected = array(
|
|
|
5567 |
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')),
|
|
|
5568 |
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName'))
|
|
|
5569 |
);
|
|
|
5570 |
$this->assertTags($result, $expected);
|
|
|
5571 |
}
|
|
|
5572 |
|
|
|
5573 |
/**
|
|
|
5574 |
* Test that the hidden input for checkboxes can be omitted or set to a
|
|
|
5575 |
* specific value.
|
|
|
5576 |
*
|
|
|
5577 |
* @return void
|
|
|
5578 |
*/
|
|
|
5579 |
public function testCheckboxHiddenField() {
|
|
|
5580 |
$result = $this->Form->input('UserForm.something', array(
|
|
|
5581 |
'type' => 'checkbox',
|
|
|
5582 |
'hiddenField' => false
|
|
|
5583 |
));
|
|
|
5584 |
$expected = array(
|
|
|
5585 |
'div' => array('class' => 'input checkbox'),
|
|
|
5586 |
array('input' => array(
|
|
|
5587 |
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
5588 |
'value' => '1', 'id' => 'UserFormSomething'
|
|
|
5589 |
)),
|
|
|
5590 |
'label' => array('for' => 'UserFormSomething'),
|
|
|
5591 |
'Something',
|
|
|
5592 |
'/label',
|
|
|
5593 |
'/div'
|
|
|
5594 |
);
|
|
|
5595 |
$this->assertTags($result, $expected);
|
|
|
5596 |
|
|
|
5597 |
$result = $this->Form->input('UserForm.something', array(
|
|
|
5598 |
'type' => 'checkbox',
|
|
|
5599 |
'value' => 'Y',
|
|
|
5600 |
'hiddenField' => 'N',
|
|
|
5601 |
));
|
|
|
5602 |
$expected = array(
|
|
|
5603 |
'div' => array('class' => 'input checkbox'),
|
|
|
5604 |
array('input' => array(
|
|
|
5605 |
'type' => 'hidden', 'name' => 'data[UserForm][something]',
|
|
|
5606 |
'value' => 'N', 'id' => 'UserFormSomething_'
|
|
|
5607 |
)),
|
|
|
5608 |
array('input' => array(
|
|
|
5609 |
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
5610 |
'value' => 'Y', 'id' => 'UserFormSomething'
|
|
|
5611 |
)),
|
|
|
5612 |
'label' => array('for' => 'UserFormSomething'),
|
|
|
5613 |
'Something',
|
|
|
5614 |
'/label',
|
|
|
5615 |
'/div'
|
|
|
5616 |
);
|
|
|
5617 |
$this->assertTags($result, $expected);
|
|
|
5618 |
}
|
|
|
5619 |
|
|
|
5620 |
/**
|
|
|
5621 |
* testDateTime method
|
|
|
5622 |
*
|
|
|
5623 |
* Test generation of date/time select elements
|
|
|
5624 |
*
|
|
|
5625 |
* @return void
|
|
|
5626 |
*/
|
|
|
5627 |
public function testDateTime() {
|
|
|
5628 |
extract($this->dateRegex);
|
|
|
5629 |
|
|
|
5630 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
|
|
|
5631 |
$now = strtotime('now');
|
|
|
5632 |
$expected = array(
|
|
|
5633 |
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
5634 |
$daysRegex,
|
|
|
5635 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
5636 |
date('j', $now),
|
|
|
5637 |
'/option',
|
|
|
5638 |
'*/select',
|
|
|
5639 |
'-',
|
|
|
5640 |
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
5641 |
$monthsRegex,
|
|
|
5642 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
5643 |
date('F', $now),
|
|
|
5644 |
'/option',
|
|
|
5645 |
'*/select',
|
|
|
5646 |
'-',
|
|
|
5647 |
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
5648 |
$yearsRegex,
|
|
|
5649 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
5650 |
date('Y', $now),
|
|
|
5651 |
'/option',
|
|
|
5652 |
'*/select',
|
|
|
5653 |
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
5654 |
$hoursRegex,
|
|
|
5655 |
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
|
|
|
5656 |
date('g', $now),
|
|
|
5657 |
'/option',
|
|
|
5658 |
'*/select',
|
|
|
5659 |
':',
|
|
|
5660 |
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
5661 |
$minutesRegex,
|
|
|
5662 |
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
|
|
|
5663 |
date('i', $now),
|
|
|
5664 |
'/option',
|
|
|
5665 |
'*/select',
|
|
|
5666 |
' ',
|
|
|
5667 |
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
5668 |
$meridianRegex,
|
|
|
5669 |
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
|
|
|
5670 |
date('a', $now),
|
|
|
5671 |
'/option',
|
|
|
5672 |
'*/select'
|
|
|
5673 |
);
|
|
|
5674 |
$this->assertTags($result, $expected);
|
|
|
5675 |
|
|
|
5676 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
|
|
|
5677 |
$expected = array(
|
|
|
5678 |
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
5679 |
$daysRegex,
|
|
|
5680 |
array('option' => array('value' => '')),
|
|
|
5681 |
'/option',
|
|
|
5682 |
'*/select',
|
|
|
5683 |
'-',
|
|
|
5684 |
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
5685 |
$monthsRegex,
|
|
|
5686 |
array('option' => array('value' => '')),
|
|
|
5687 |
'/option',
|
|
|
5688 |
'*/select',
|
|
|
5689 |
'-',
|
|
|
5690 |
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
5691 |
$yearsRegex,
|
|
|
5692 |
array('option' => array('value' => '')),
|
|
|
5693 |
'/option',
|
|
|
5694 |
'*/select',
|
|
|
5695 |
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
5696 |
$hoursRegex,
|
|
|
5697 |
array('option' => array('value' => '')),
|
|
|
5698 |
'/option',
|
|
|
5699 |
'*/select',
|
|
|
5700 |
':',
|
|
|
5701 |
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
5702 |
$minutesRegex,
|
|
|
5703 |
array('option' => array('value' => '')),
|
|
|
5704 |
'/option',
|
|
|
5705 |
'*/select',
|
|
|
5706 |
' ',
|
|
|
5707 |
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
5708 |
$meridianRegex,
|
|
|
5709 |
array('option' => array('value' => '')),
|
|
|
5710 |
'/option',
|
|
|
5711 |
'*/select'
|
|
|
5712 |
);
|
|
|
5713 |
$this->assertTags($result, $expected);
|
|
|
5714 |
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
|
|
5715 |
|
|
|
5716 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
|
|
|
5717 |
$this->assertTags($result, $expected);
|
|
|
5718 |
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
|
|
5719 |
|
|
|
5720 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
|
|
|
5721 |
$this->assertTags($result, $expected);
|
|
|
5722 |
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
|
|
5723 |
|
|
|
5724 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
|
|
|
5725 |
$expected = array(
|
|
|
5726 |
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
5727 |
$daysRegex,
|
|
|
5728 |
array('option' => array('value' => '')),
|
|
|
5729 |
'/option',
|
|
|
5730 |
'*/select',
|
|
|
5731 |
'-',
|
|
|
5732 |
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
5733 |
$monthsRegex,
|
|
|
5734 |
array('option' => array('value' => '')),
|
|
|
5735 |
'/option',
|
|
|
5736 |
'*/select',
|
|
|
5737 |
'-',
|
|
|
5738 |
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
5739 |
$yearsRegex,
|
|
|
5740 |
array('option' => array('value' => '')),
|
|
|
5741 |
'/option',
|
|
|
5742 |
'*/select',
|
|
|
5743 |
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
5744 |
$hoursRegex,
|
|
|
5745 |
array('option' => array('value' => '')),
|
|
|
5746 |
'/option',
|
|
|
5747 |
'*/select',
|
|
|
5748 |
':',
|
|
|
5749 |
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
5750 |
$minutesRegex,
|
|
|
5751 |
array('option' => array('value' => '')),
|
|
|
5752 |
'/option',
|
|
|
5753 |
array('option' => array('value' => '00')),
|
|
|
5754 |
'00',
|
|
|
5755 |
'/option',
|
|
|
5756 |
array('option' => array('value' => '05')),
|
|
|
5757 |
'05',
|
|
|
5758 |
'/option',
|
|
|
5759 |
array('option' => array('value' => '10')),
|
|
|
5760 |
'10',
|
|
|
5761 |
'/option',
|
|
|
5762 |
'*/select',
|
|
|
5763 |
' ',
|
|
|
5764 |
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
5765 |
$meridianRegex,
|
|
|
5766 |
array('option' => array('value' => '')),
|
|
|
5767 |
'/option',
|
|
|
5768 |
'*/select'
|
|
|
5769 |
);
|
|
|
5770 |
$this->assertTags($result, $expected);
|
|
|
5771 |
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
|
|
5772 |
|
|
|
5773 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
|
|
|
5774 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
|
|
|
5775 |
|
|
|
5776 |
$this->Form->request->data['Contact']['data'] = null;
|
|
|
5777 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
|
|
|
5778 |
$expected = array(
|
|
|
5779 |
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
5780 |
$daysRegex,
|
|
|
5781 |
array('option' => array('value' => '')),
|
|
|
5782 |
'/option',
|
|
|
5783 |
'*/select',
|
|
|
5784 |
'-',
|
|
|
5785 |
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
5786 |
$monthsRegex,
|
|
|
5787 |
array('option' => array('value' => '')),
|
|
|
5788 |
'/option',
|
|
|
5789 |
'*/select',
|
|
|
5790 |
'-',
|
|
|
5791 |
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
5792 |
$yearsRegex,
|
|
|
5793 |
array('option' => array('value' => '')),
|
|
|
5794 |
'/option',
|
|
|
5795 |
'*/select',
|
|
|
5796 |
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
5797 |
$hoursRegex,
|
|
|
5798 |
array('option' => array('value' => '')),
|
|
|
5799 |
'/option',
|
|
|
5800 |
'*/select',
|
|
|
5801 |
':',
|
|
|
5802 |
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
5803 |
$minutesRegex,
|
|
|
5804 |
array('option' => array('value' => '')),
|
|
|
5805 |
'/option',
|
|
|
5806 |
'*/select',
|
|
|
5807 |
' ',
|
|
|
5808 |
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
5809 |
$meridianRegex,
|
|
|
5810 |
array('option' => array('value' => '')),
|
|
|
5811 |
'/option',
|
|
|
5812 |
'*/select'
|
|
|
5813 |
);
|
|
|
5814 |
$this->assertTags($result, $expected);
|
|
|
5815 |
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
|
|
5816 |
|
|
|
5817 |
$this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
|
|
|
5818 |
$now = strtotime($this->Form->data['Model']['field']);
|
|
|
5819 |
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
|
|
|
5820 |
$expected = array(
|
|
|
5821 |
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
5822 |
$daysRegex,
|
|
|
5823 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
5824 |
date('j', $now),
|
|
|
5825 |
'/option',
|
|
|
5826 |
'*/select',
|
|
|
5827 |
'-',
|
|
|
5828 |
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
5829 |
$monthsRegex,
|
|
|
5830 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
5831 |
date('F', $now),
|
|
|
5832 |
'/option',
|
|
|
5833 |
'*/select',
|
|
|
5834 |
'-',
|
|
|
5835 |
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
5836 |
$yearsRegex,
|
|
|
5837 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
5838 |
date('Y', $now),
|
|
|
5839 |
'/option',
|
|
|
5840 |
'*/select',
|
|
|
5841 |
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
5842 |
$hoursRegex,
|
|
|
5843 |
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
|
|
|
5844 |
date('g', $now),
|
|
|
5845 |
'/option',
|
|
|
5846 |
'*/select',
|
|
|
5847 |
':',
|
|
|
5848 |
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
5849 |
$minutesRegex,
|
|
|
5850 |
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
|
|
|
5851 |
date('i', $now),
|
|
|
5852 |
'/option',
|
|
|
5853 |
'*/select',
|
|
|
5854 |
' ',
|
|
|
5855 |
array('select' => array('name' => 'data[Model][field][meridian]', 'id' => 'ModelFieldMeridian')),
|
|
|
5856 |
$meridianRegex,
|
|
|
5857 |
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
|
|
|
5858 |
date('a', $now),
|
|
|
5859 |
'/option',
|
|
|
5860 |
'*/select'
|
|
|
5861 |
);
|
|
|
5862 |
$this->assertTags($result, $expected);
|
|
|
5863 |
|
|
|
5864 |
$selected = strtotime('2008-10-26 12:33:00');
|
|
|
5865 |
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
|
|
|
5866 |
$this->assertRegExp('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
|
|
|
5867 |
$this->assertRegExp('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
|
|
|
5868 |
$this->assertRegExp('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
|
|
|
5869 |
$this->assertRegExp('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
|
|
|
5870 |
$this->assertRegExp('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
|
|
|
5871 |
$this->assertRegExp('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
|
|
|
5872 |
|
|
|
5873 |
$this->Form->create('Contact');
|
|
|
5874 |
$result = $this->Form->input('published');
|
|
|
5875 |
$now = strtotime('now');
|
|
|
5876 |
$expected = array(
|
|
|
5877 |
'div' => array('class' => 'input date'),
|
|
|
5878 |
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
5879 |
'Published',
|
|
|
5880 |
'/label',
|
|
|
5881 |
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
|
|
|
5882 |
$monthsRegex,
|
|
|
5883 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
5884 |
date('F', $now),
|
|
|
5885 |
'/option',
|
|
|
5886 |
'*/select',
|
|
|
5887 |
'-',
|
|
|
5888 |
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
|
|
|
5889 |
$daysRegex,
|
|
|
5890 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
5891 |
date('j', $now),
|
|
|
5892 |
'/option',
|
|
|
5893 |
'*/select',
|
|
|
5894 |
'-',
|
|
|
5895 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
5896 |
$yearsRegex,
|
|
|
5897 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
5898 |
date('Y', $now),
|
|
|
5899 |
'/option',
|
|
|
5900 |
'*/select',
|
|
|
5901 |
'/div'
|
|
|
5902 |
);
|
|
|
5903 |
$this->assertTags($result, $expected);
|
|
|
5904 |
|
|
|
5905 |
$result = $this->Form->input('published2', array('type' => 'date'));
|
|
|
5906 |
$now = strtotime('now');
|
|
|
5907 |
$expected = array(
|
|
|
5908 |
'div' => array('class' => 'input date'),
|
|
|
5909 |
'label' => array('for' => 'ContactPublished2Month'),
|
|
|
5910 |
'Published2',
|
|
|
5911 |
'/label',
|
|
|
5912 |
array('select' => array('name' => 'data[Contact][published2][month]', 'id' => 'ContactPublished2Month')),
|
|
|
5913 |
$monthsRegex,
|
|
|
5914 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
5915 |
date('F', $now),
|
|
|
5916 |
'/option',
|
|
|
5917 |
'*/select',
|
|
|
5918 |
'-',
|
|
|
5919 |
array('select' => array('name' => 'data[Contact][published2][day]', 'id' => 'ContactPublished2Day')),
|
|
|
5920 |
$daysRegex,
|
|
|
5921 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
5922 |
date('j', $now),
|
|
|
5923 |
'/option',
|
|
|
5924 |
'*/select',
|
|
|
5925 |
'-',
|
|
|
5926 |
array('select' => array('name' => 'data[Contact][published2][year]', 'id' => 'ContactPublished2Year')),
|
|
|
5927 |
$yearsRegex,
|
|
|
5928 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
5929 |
date('Y', $now),
|
|
|
5930 |
'/option',
|
|
|
5931 |
'*/select',
|
|
|
5932 |
'/div'
|
|
|
5933 |
);
|
|
|
5934 |
$this->assertTags($result, $expected);
|
|
|
5935 |
|
|
|
5936 |
$this->Form->create('Contact');
|
|
|
5937 |
$result = $this->Form->input('published', array('monthNames' => false));
|
|
|
5938 |
$now = strtotime('now');
|
|
|
5939 |
$expected = array(
|
|
|
5940 |
'div' => array('class' => 'input date'),
|
|
|
5941 |
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
5942 |
'Published',
|
|
|
5943 |
'/label',
|
|
|
5944 |
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
|
|
|
5945 |
'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
|
|
|
5946 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
5947 |
date('m', $now),
|
|
|
5948 |
'/option',
|
|
|
5949 |
'*/select',
|
|
|
5950 |
'-',
|
|
|
5951 |
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
|
|
|
5952 |
$daysRegex,
|
|
|
5953 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
5954 |
date('j', $now),
|
|
|
5955 |
'/option',
|
|
|
5956 |
'*/select',
|
|
|
5957 |
'-',
|
|
|
5958 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
5959 |
$yearsRegex,
|
|
|
5960 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
5961 |
date('Y', $now),
|
|
|
5962 |
'/option',
|
|
|
5963 |
'*/select',
|
|
|
5964 |
'/div'
|
|
|
5965 |
);
|
|
|
5966 |
$this->assertTags($result, $expected);
|
|
|
5967 |
|
|
|
5968 |
$result = $this->Form->input('published', array(
|
|
|
5969 |
'timeFormat' => 24,
|
|
|
5970 |
'interval' => 5,
|
|
|
5971 |
'selected' => strtotime('2009-09-03 13:37:00'),
|
|
|
5972 |
'type' => 'datetime'
|
|
|
5973 |
));
|
|
|
5974 |
$this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
5975 |
$this->assertRegExp('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
|
|
|
5976 |
$this->assertRegExp('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
|
|
|
5977 |
$this->assertRegExp('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
|
|
|
5978 |
$this->assertRegExp('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
|
|
|
5979 |
}
|
|
|
5980 |
|
|
|
5981 |
/**
|
|
|
5982 |
* Test dateTime with rounding
|
|
|
5983 |
*
|
|
|
5984 |
* @return void
|
|
|
5985 |
*/
|
|
|
5986 |
public function testDateTimeRounding() {
|
|
|
5987 |
$this->Form->request->data['Contact'] = array(
|
|
|
5988 |
'date' => array(
|
|
|
5989 |
'day' => '13',
|
|
|
5990 |
'month' => '12',
|
|
|
5991 |
'year' => '2010',
|
|
|
5992 |
'hour' => '04',
|
|
|
5993 |
'min' => '19',
|
|
|
5994 |
'meridian' => 'AM'
|
|
|
5995 |
)
|
|
|
5996 |
);
|
|
|
5997 |
|
|
|
5998 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
|
|
|
5999 |
$this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
|
|
|
6000 |
|
|
|
6001 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
|
|
|
6002 |
$this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
6003 |
|
|
|
6004 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
|
|
|
6005 |
$this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
|
|
|
6006 |
}
|
|
|
6007 |
|
|
|
6008 |
/**
|
|
|
6009 |
* Test that empty values don't trigger errors.
|
|
|
6010 |
*
|
|
|
6011 |
* @return void
|
|
|
6012 |
*/
|
|
|
6013 |
public function testDateTimeNoErrorsOnEmptyData() {
|
|
|
6014 |
$this->Form->request->data['Contact'] = array(
|
|
|
6015 |
'date' => array(
|
|
|
6016 |
'day' => '',
|
|
|
6017 |
'month' => '',
|
|
|
6018 |
'year' => '',
|
|
|
6019 |
'hour' => '',
|
|
|
6020 |
'min' => '',
|
|
|
6021 |
'meridian' => ''
|
|
|
6022 |
)
|
|
|
6023 |
);
|
|
|
6024 |
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
|
|
|
6025 |
$this->assertNotEmpty($result);
|
|
|
6026 |
}
|
|
|
6027 |
|
|
|
6028 |
/**
|
|
|
6029 |
* test that datetime() and default values work.
|
|
|
6030 |
*
|
|
|
6031 |
* @return void
|
|
|
6032 |
*/
|
|
|
6033 |
public function testDatetimeWithDefault() {
|
|
|
6034 |
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
|
|
|
6035 |
$this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
6036 |
$this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
|
|
|
6037 |
$this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
|
|
|
6038 |
|
|
|
6039 |
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
|
|
|
6040 |
'default' => '2009-06-01 11:15:30'
|
|
|
6041 |
));
|
|
|
6042 |
$this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
6043 |
$this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
|
|
|
6044 |
$this->assertRegExp('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
|
|
|
6045 |
}
|
|
|
6046 |
|
|
|
6047 |
/**
|
|
|
6048 |
* test that bogus non-date time data doesn't cause errors.
|
|
|
6049 |
*
|
|
|
6050 |
* @return void
|
|
|
6051 |
*/
|
|
|
6052 |
public function testDateTimeWithBogusData() {
|
|
|
6053 |
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
|
|
|
6054 |
$this->assertNotRegExp('/selected="selected">\d/', $result);
|
|
|
6055 |
}
|
|
|
6056 |
|
|
|
6057 |
/**
|
|
|
6058 |
* testDateTimeEmptyAsArray
|
|
|
6059 |
*
|
|
|
6060 |
* @return void
|
|
|
6061 |
*/
|
|
|
6062 |
public function testDateTimeEmptyAsArray() {
|
|
|
6063 |
$result = $this->Form->dateTime('Contact.date',
|
|
|
6064 |
'DMY',
|
|
|
6065 |
'12',
|
|
|
6066 |
array(
|
|
|
6067 |
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
|
|
|
6068 |
'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
|
|
|
6069 |
)
|
|
|
6070 |
)
|
|
|
6071 |
);
|
|
|
6072 |
|
|
|
6073 |
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
|
|
|
6074 |
$this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
|
|
|
6075 |
$this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
|
|
|
6076 |
$this->assertRegExp('/<option value="">HOUR<\/option>/', $result);
|
|
|
6077 |
$this->assertRegExp('/<option value="">MINUTE<\/option>/', $result);
|
|
|
6078 |
$this->assertNotRegExp('/<option value=""><\/option>/', $result);
|
|
|
6079 |
|
|
|
6080 |
$result = $this->Form->dateTime('Contact.date',
|
|
|
6081 |
'DMY',
|
|
|
6082 |
'12',
|
|
|
6083 |
array(
|
|
|
6084 |
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
|
|
|
6085 |
)
|
|
|
6086 |
);
|
|
|
6087 |
|
|
|
6088 |
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
|
|
|
6089 |
$this->assertRegExp('/<option value="">MONTH<\/option>/', $result);
|
|
|
6090 |
$this->assertRegExp('/<option value="">YEAR<\/option>/', $result);
|
|
|
6091 |
$this->assertRegExp('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
|
|
|
6092 |
$this->assertRegExp('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
|
|
|
6093 |
$this->assertRegExp('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
|
|
|
6094 |
}
|
|
|
6095 |
|
|
|
6096 |
/**
|
|
|
6097 |
* testFormDateTimeMulti method
|
|
|
6098 |
*
|
|
|
6099 |
* test multiple datetime element generation
|
|
|
6100 |
*
|
|
|
6101 |
* @return void
|
|
|
6102 |
*/
|
|
|
6103 |
public function testFormDateTimeMulti() {
|
|
|
6104 |
extract($this->dateRegex);
|
|
|
6105 |
|
|
|
6106 |
$result = $this->Form->dateTime('Contact.1.updated');
|
|
|
6107 |
$expected = array(
|
|
|
6108 |
array('select' => array('name' => 'data[Contact][1][updated][day]', 'id' => 'Contact1UpdatedDay')),
|
|
|
6109 |
$daysRegex,
|
|
|
6110 |
array('option' => array('value' => '')),
|
|
|
6111 |
'/option',
|
|
|
6112 |
'*/select',
|
|
|
6113 |
'-',
|
|
|
6114 |
array('select' => array('name' => 'data[Contact][1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
|
|
|
6115 |
$monthsRegex,
|
|
|
6116 |
array('option' => array('value' => '')),
|
|
|
6117 |
'/option',
|
|
|
6118 |
'*/select',
|
|
|
6119 |
'-',
|
|
|
6120 |
array('select' => array('name' => 'data[Contact][1][updated][year]', 'id' => 'Contact1UpdatedYear')),
|
|
|
6121 |
$yearsRegex,
|
|
|
6122 |
array('option' => array('value' => '')),
|
|
|
6123 |
'/option',
|
|
|
6124 |
'*/select',
|
|
|
6125 |
array('select' => array('name' => 'data[Contact][1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
|
|
|
6126 |
$hoursRegex,
|
|
|
6127 |
array('option' => array('value' => '')),
|
|
|
6128 |
'/option',
|
|
|
6129 |
'*/select',
|
|
|
6130 |
':',
|
|
|
6131 |
array('select' => array('name' => 'data[Contact][1][updated][min]', 'id' => 'Contact1UpdatedMin')),
|
|
|
6132 |
$minutesRegex,
|
|
|
6133 |
array('option' => array('value' => '')),
|
|
|
6134 |
'/option',
|
|
|
6135 |
'*/select',
|
|
|
6136 |
' ',
|
|
|
6137 |
array('select' => array('name' => 'data[Contact][1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
|
|
|
6138 |
$meridianRegex,
|
|
|
6139 |
array('option' => array('value' => '')),
|
|
|
6140 |
'/option',
|
|
|
6141 |
'*/select'
|
|
|
6142 |
);
|
|
|
6143 |
$this->assertTags($result, $expected);
|
|
|
6144 |
|
|
|
6145 |
$result = $this->Form->dateTime('Contact.2.updated');
|
|
|
6146 |
$expected = array(
|
|
|
6147 |
array('select' => array('name' => 'data[Contact][2][updated][day]', 'id' => 'Contact2UpdatedDay')),
|
|
|
6148 |
$daysRegex,
|
|
|
6149 |
array('option' => array('value' => '')),
|
|
|
6150 |
'/option',
|
|
|
6151 |
'*/select',
|
|
|
6152 |
'-',
|
|
|
6153 |
array('select' => array('name' => 'data[Contact][2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
|
|
|
6154 |
$monthsRegex,
|
|
|
6155 |
array('option' => array('value' => '')),
|
|
|
6156 |
'/option',
|
|
|
6157 |
'*/select',
|
|
|
6158 |
'-',
|
|
|
6159 |
array('select' => array('name' => 'data[Contact][2][updated][year]', 'id' => 'Contact2UpdatedYear')),
|
|
|
6160 |
$yearsRegex,
|
|
|
6161 |
array('option' => array('value' => '')),
|
|
|
6162 |
'/option',
|
|
|
6163 |
'*/select',
|
|
|
6164 |
array('select' => array('name' => 'data[Contact][2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
|
|
|
6165 |
$hoursRegex,
|
|
|
6166 |
array('option' => array('value' => '')),
|
|
|
6167 |
'/option',
|
|
|
6168 |
'*/select',
|
|
|
6169 |
':',
|
|
|
6170 |
array('select' => array('name' => 'data[Contact][2][updated][min]', 'id' => 'Contact2UpdatedMin')),
|
|
|
6171 |
$minutesRegex,
|
|
|
6172 |
array('option' => array('value' => '')),
|
|
|
6173 |
'/option',
|
|
|
6174 |
'*/select',
|
|
|
6175 |
' ',
|
|
|
6176 |
array('select' => array('name' => 'data[Contact][2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
|
|
|
6177 |
$meridianRegex,
|
|
|
6178 |
array('option' => array('value' => '')),
|
|
|
6179 |
'/option',
|
|
|
6180 |
'*/select'
|
|
|
6181 |
);
|
|
|
6182 |
$this->assertTags($result, $expected);
|
|
|
6183 |
}
|
|
|
6184 |
|
|
|
6185 |
/**
|
|
|
6186 |
* When changing the date format, the label should always focus the first select box when
|
|
|
6187 |
* clicked.
|
|
|
6188 |
*
|
|
|
6189 |
* @return void
|
|
|
6190 |
*/
|
|
|
6191 |
public function testDateTimeLabelIdMatchesFirstInput() {
|
|
|
6192 |
$result = $this->Form->input('Model.date', array('type' => 'date'));
|
|
|
6193 |
$this->assertContains('label for="ModelDateMonth"', $result);
|
|
|
6194 |
|
|
|
6195 |
$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
|
|
|
6196 |
$this->assertContains('label for="ModelDateDay"', $result);
|
|
|
6197 |
|
|
|
6198 |
$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
|
|
|
6199 |
$this->assertContains('label for="ModelDateYear"', $result);
|
|
|
6200 |
}
|
|
|
6201 |
|
|
|
6202 |
/**
|
|
|
6203 |
* testMonth method
|
|
|
6204 |
*
|
|
|
6205 |
* @return void
|
|
|
6206 |
*/
|
|
|
6207 |
public function testMonth() {
|
|
|
6208 |
$result = $this->Form->month('Model.field');
|
|
|
6209 |
$expected = array(
|
|
|
6210 |
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
6211 |
array('option' => array('value' => '')),
|
|
|
6212 |
'/option',
|
|
|
6213 |
array('option' => array('value' => '01')),
|
|
|
6214 |
date('F', strtotime('2008-01-01 00:00:00')),
|
|
|
6215 |
'/option',
|
|
|
6216 |
array('option' => array('value' => '02')),
|
|
|
6217 |
date('F', strtotime('2008-02-01 00:00:00')),
|
|
|
6218 |
'/option',
|
|
|
6219 |
'*/select',
|
|
|
6220 |
);
|
|
|
6221 |
$this->assertTags($result, $expected);
|
|
|
6222 |
|
|
|
6223 |
$result = $this->Form->month('Model.field', array('empty' => true));
|
|
|
6224 |
$expected = array(
|
|
|
6225 |
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
6226 |
array('option' => array('value' => '')),
|
|
|
6227 |
'/option',
|
|
|
6228 |
array('option' => array('value' => '01')),
|
|
|
6229 |
date('F', strtotime('2008-01-01 00:00:00')),
|
|
|
6230 |
'/option',
|
|
|
6231 |
array('option' => array('value' => '02')),
|
|
|
6232 |
date('F', strtotime('2008-02-01 00:00:00')),
|
|
|
6233 |
'/option',
|
|
|
6234 |
'*/select',
|
|
|
6235 |
);
|
|
|
6236 |
$this->assertTags($result, $expected);
|
|
|
6237 |
|
|
|
6238 |
$result = $this->Form->month('Model.field', array('monthNames' => false));
|
|
|
6239 |
$expected = array(
|
|
|
6240 |
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
6241 |
array('option' => array('value' => '')),
|
|
|
6242 |
'/option',
|
|
|
6243 |
array('option' => array('value' => '01')),
|
|
|
6244 |
'01',
|
|
|
6245 |
'/option',
|
|
|
6246 |
array('option' => array('value' => '02')),
|
|
|
6247 |
'02',
|
|
|
6248 |
'/option',
|
|
|
6249 |
'*/select',
|
|
|
6250 |
);
|
|
|
6251 |
$this->assertTags($result, $expected);
|
|
|
6252 |
|
|
|
6253 |
$monthNames = array(
|
|
|
6254 |
'01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
|
|
|
6255 |
'07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
|
|
|
6256 |
$result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
|
|
|
6257 |
$expected = array(
|
|
|
6258 |
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
6259 |
array('option' => array('value' => '')),
|
|
|
6260 |
'/option',
|
|
|
6261 |
array('option' => array('value' => '01')),
|
|
|
6262 |
'Jan',
|
|
|
6263 |
'/option',
|
|
|
6264 |
array('option' => array('value' => '02')),
|
|
|
6265 |
'Feb',
|
|
|
6266 |
'/option',
|
|
|
6267 |
'*/select',
|
|
|
6268 |
);
|
|
|
6269 |
$this->assertTags($result, $expected);
|
|
|
6270 |
|
|
|
6271 |
$this->Form->request->data['Project']['release'] = '2050-02-10';
|
|
|
6272 |
$result = $this->Form->month('Project.release');
|
|
|
6273 |
|
|
|
6274 |
$expected = array(
|
|
|
6275 |
array('select' => array('name' => 'data[Project][release][month]', 'id' => 'ProjectReleaseMonth')),
|
|
|
6276 |
array('option' => array('value' => '')),
|
|
|
6277 |
'/option',
|
|
|
6278 |
array('option' => array('value' => '01')),
|
|
|
6279 |
'January',
|
|
|
6280 |
'/option',
|
|
|
6281 |
array('option' => array('value' => '02', 'selected' => 'selected')),
|
|
|
6282 |
'February',
|
|
|
6283 |
'/option',
|
|
|
6284 |
'*/select',
|
|
|
6285 |
);
|
|
|
6286 |
$this->assertTags($result, $expected);
|
|
|
6287 |
}
|
|
|
6288 |
|
|
|
6289 |
/**
|
|
|
6290 |
* testDay method
|
|
|
6291 |
*
|
|
|
6292 |
* @return void
|
|
|
6293 |
*/
|
|
|
6294 |
public function testDay() {
|
|
|
6295 |
extract($this->dateRegex);
|
|
|
6296 |
|
|
|
6297 |
$result = $this->Form->day('Model.field', array('value' => false));
|
|
|
6298 |
$expected = array(
|
|
|
6299 |
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
6300 |
array('option' => array('value' => '')),
|
|
|
6301 |
'/option',
|
|
|
6302 |
array('option' => array('value' => '01')),
|
|
|
6303 |
'1',
|
|
|
6304 |
'/option',
|
|
|
6305 |
array('option' => array('value' => '02')),
|
|
|
6306 |
'2',
|
|
|
6307 |
'/option',
|
|
|
6308 |
$daysRegex,
|
|
|
6309 |
'/select',
|
|
|
6310 |
);
|
|
|
6311 |
$this->assertTags($result, $expected);
|
|
|
6312 |
|
|
|
6313 |
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
|
|
|
6314 |
$result = $this->Form->day('Model.field');
|
|
|
6315 |
$expected = array(
|
|
|
6316 |
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
6317 |
array('option' => array('value' => '')),
|
|
|
6318 |
'/option',
|
|
|
6319 |
array('option' => array('value' => '01')),
|
|
|
6320 |
'1',
|
|
|
6321 |
'/option',
|
|
|
6322 |
array('option' => array('value' => '02')),
|
|
|
6323 |
'2',
|
|
|
6324 |
'/option',
|
|
|
6325 |
$daysRegex,
|
|
|
6326 |
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
6327 |
'10',
|
|
|
6328 |
'/option',
|
|
|
6329 |
$daysRegex,
|
|
|
6330 |
'/select',
|
|
|
6331 |
);
|
|
|
6332 |
$this->assertTags($result, $expected);
|
|
|
6333 |
|
|
|
6334 |
$this->Form->request->data['Model']['field'] = '';
|
|
|
6335 |
$result = $this->Form->day('Model.field', array('value' => '10'));
|
|
|
6336 |
$expected = array(
|
|
|
6337 |
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
6338 |
array('option' => array('value' => '')),
|
|
|
6339 |
'/option',
|
|
|
6340 |
array('option' => array('value' => '01')),
|
|
|
6341 |
'1',
|
|
|
6342 |
'/option',
|
|
|
6343 |
array('option' => array('value' => '02')),
|
|
|
6344 |
'2',
|
|
|
6345 |
'/option',
|
|
|
6346 |
$daysRegex,
|
|
|
6347 |
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
6348 |
'10',
|
|
|
6349 |
'/option',
|
|
|
6350 |
$daysRegex,
|
|
|
6351 |
'/select',
|
|
|
6352 |
);
|
|
|
6353 |
$this->assertTags($result, $expected);
|
|
|
6354 |
|
|
|
6355 |
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
|
|
|
6356 |
$result = $this->Form->day('Model.field', array('value' => true));
|
|
|
6357 |
$expected = array(
|
|
|
6358 |
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
6359 |
array('option' => array('value' => '')),
|
|
|
6360 |
'/option',
|
|
|
6361 |
array('option' => array('value' => '01')),
|
|
|
6362 |
'1',
|
|
|
6363 |
'/option',
|
|
|
6364 |
array('option' => array('value' => '02')),
|
|
|
6365 |
'2',
|
|
|
6366 |
'/option',
|
|
|
6367 |
$daysRegex,
|
|
|
6368 |
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
6369 |
'10',
|
|
|
6370 |
'/option',
|
|
|
6371 |
$daysRegex,
|
|
|
6372 |
'/select',
|
|
|
6373 |
);
|
|
|
6374 |
$this->assertTags($result, $expected);
|
|
|
6375 |
|
|
|
6376 |
$this->Form->request->data['Project']['release'] = '2050-10-10';
|
|
|
6377 |
$result = $this->Form->day('Project.release');
|
|
|
6378 |
|
|
|
6379 |
$expected = array(
|
|
|
6380 |
array('select' => array('name' => 'data[Project][release][day]', 'id' => 'ProjectReleaseDay')),
|
|
|
6381 |
array('option' => array('value' => '')),
|
|
|
6382 |
'/option',
|
|
|
6383 |
array('option' => array('value' => '01')),
|
|
|
6384 |
'1',
|
|
|
6385 |
'/option',
|
|
|
6386 |
array('option' => array('value' => '02')),
|
|
|
6387 |
'2',
|
|
|
6388 |
'/option',
|
|
|
6389 |
$daysRegex,
|
|
|
6390 |
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
6391 |
'10',
|
|
|
6392 |
'/option',
|
|
|
6393 |
$daysRegex,
|
|
|
6394 |
'/select',
|
|
|
6395 |
);
|
|
|
6396 |
$this->assertTags($result, $expected);
|
|
|
6397 |
}
|
|
|
6398 |
|
|
|
6399 |
/**
|
|
|
6400 |
* testMinute method
|
|
|
6401 |
*
|
|
|
6402 |
* @return void
|
|
|
6403 |
*/
|
|
|
6404 |
public function testMinute() {
|
|
|
6405 |
extract($this->dateRegex);
|
|
|
6406 |
|
|
|
6407 |
$result = $this->Form->minute('Model.field');
|
|
|
6408 |
$expected = array(
|
|
|
6409 |
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
6410 |
array('option' => array('value' => '')),
|
|
|
6411 |
'/option',
|
|
|
6412 |
array('option' => array('value' => '00')),
|
|
|
6413 |
'00',
|
|
|
6414 |
'/option',
|
|
|
6415 |
array('option' => array('value' => '01')),
|
|
|
6416 |
'01',
|
|
|
6417 |
'/option',
|
|
|
6418 |
array('option' => array('value' => '02')),
|
|
|
6419 |
'02',
|
|
|
6420 |
'/option',
|
|
|
6421 |
$minutesRegex,
|
|
|
6422 |
'/select',
|
|
|
6423 |
);
|
|
|
6424 |
$this->assertTags($result, $expected);
|
|
|
6425 |
|
|
|
6426 |
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
|
|
6427 |
$result = $this->Form->minute('Model.field');
|
|
|
6428 |
$expected = array(
|
|
|
6429 |
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
6430 |
array('option' => array('value' => '')),
|
|
|
6431 |
'/option',
|
|
|
6432 |
array('option' => array('value' => '00')),
|
|
|
6433 |
'00',
|
|
|
6434 |
'/option',
|
|
|
6435 |
array('option' => array('value' => '01')),
|
|
|
6436 |
'01',
|
|
|
6437 |
'/option',
|
|
|
6438 |
array('option' => array('value' => '02')),
|
|
|
6439 |
'02',
|
|
|
6440 |
'/option',
|
|
|
6441 |
$minutesRegex,
|
|
|
6442 |
array('option' => array('value' => '12', 'selected' => 'selected')),
|
|
|
6443 |
'12',
|
|
|
6444 |
'/option',
|
|
|
6445 |
$minutesRegex,
|
|
|
6446 |
'/select',
|
|
|
6447 |
);
|
|
|
6448 |
$this->assertTags($result, $expected);
|
|
|
6449 |
|
|
|
6450 |
$this->Form->request->data['Model']['field'] = '';
|
|
|
6451 |
$result = $this->Form->minute('Model.field', array('interval' => 5));
|
|
|
6452 |
$expected = array(
|
|
|
6453 |
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
6454 |
array('option' => array('value' => '')),
|
|
|
6455 |
'/option',
|
|
|
6456 |
array('option' => array('value' => '00')),
|
|
|
6457 |
'00',
|
|
|
6458 |
'/option',
|
|
|
6459 |
array('option' => array('value' => '05')),
|
|
|
6460 |
'05',
|
|
|
6461 |
'/option',
|
|
|
6462 |
array('option' => array('value' => '10')),
|
|
|
6463 |
'10',
|
|
|
6464 |
'/option',
|
|
|
6465 |
$minutesRegex,
|
|
|
6466 |
'/select',
|
|
|
6467 |
);
|
|
|
6468 |
$this->assertTags($result, $expected);
|
|
|
6469 |
|
|
|
6470 |
$this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
|
|
|
6471 |
$result = $this->Form->minute('Model.field', array('interval' => 5));
|
|
|
6472 |
$expected = array(
|
|
|
6473 |
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
6474 |
array('option' => array('value' => '')),
|
|
|
6475 |
'/option',
|
|
|
6476 |
array('option' => array('value' => '00')),
|
|
|
6477 |
'00',
|
|
|
6478 |
'/option',
|
|
|
6479 |
array('option' => array('value' => '05')),
|
|
|
6480 |
'05',
|
|
|
6481 |
'/option',
|
|
|
6482 |
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
6483 |
'10',
|
|
|
6484 |
'/option',
|
|
|
6485 |
$minutesRegex,
|
|
|
6486 |
'/select',
|
|
|
6487 |
);
|
|
|
6488 |
$this->assertTags($result, $expected);
|
|
|
6489 |
}
|
|
|
6490 |
|
|
|
6491 |
/**
|
|
|
6492 |
* testHour method
|
|
|
6493 |
*
|
|
|
6494 |
* @return void
|
|
|
6495 |
*/
|
|
|
6496 |
public function testHour() {
|
|
|
6497 |
extract($this->dateRegex);
|
|
|
6498 |
|
|
|
6499 |
$result = $this->Form->hour('Model.field', false);
|
|
|
6500 |
$expected = array(
|
|
|
6501 |
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
6502 |
array('option' => array('value' => '')),
|
|
|
6503 |
'/option',
|
|
|
6504 |
array('option' => array('value' => '01')),
|
|
|
6505 |
'1',
|
|
|
6506 |
'/option',
|
|
|
6507 |
array('option' => array('value' => '02')),
|
|
|
6508 |
'2',
|
|
|
6509 |
'/option',
|
|
|
6510 |
$hoursRegex,
|
|
|
6511 |
'/select',
|
|
|
6512 |
);
|
|
|
6513 |
$this->assertTags($result, $expected);
|
|
|
6514 |
|
|
|
6515 |
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
|
|
6516 |
$result = $this->Form->hour('Model.field', false);
|
|
|
6517 |
$expected = array(
|
|
|
6518 |
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
6519 |
array('option' => array('value' => '')),
|
|
|
6520 |
'/option',
|
|
|
6521 |
array('option' => array('value' => '01')),
|
|
|
6522 |
'1',
|
|
|
6523 |
'/option',
|
|
|
6524 |
array('option' => array('value' => '02')),
|
|
|
6525 |
'2',
|
|
|
6526 |
'/option',
|
|
|
6527 |
$hoursRegex,
|
|
|
6528 |
array('option' => array('value' => '12', 'selected' => 'selected')),
|
|
|
6529 |
'12',
|
|
|
6530 |
'/option',
|
|
|
6531 |
'/select',
|
|
|
6532 |
);
|
|
|
6533 |
$this->assertTags($result, $expected);
|
|
|
6534 |
|
|
|
6535 |
$this->Form->request->data['Model']['field'] = '';
|
|
|
6536 |
$result = $this->Form->hour('Model.field', true, array('value' => '23'));
|
|
|
6537 |
$this->assertContains('<option value="23" selected="selected">23</option>', $result);
|
|
|
6538 |
|
|
|
6539 |
$result = $this->Form->hour('Model.field', false, array('value' => '23'));
|
|
|
6540 |
$this->assertContains('<option value="11" selected="selected">11</option>', $result);
|
|
|
6541 |
|
|
|
6542 |
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
|
|
6543 |
$result = $this->Form->hour('Model.field', true);
|
|
|
6544 |
$expected = array(
|
|
|
6545 |
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
6546 |
array('option' => array('value' => '')),
|
|
|
6547 |
'/option',
|
|
|
6548 |
array('option' => array('value' => '00', 'selected' => 'selected')),
|
|
|
6549 |
'0',
|
|
|
6550 |
'/option',
|
|
|
6551 |
array('option' => array('value' => '01')),
|
|
|
6552 |
'1',
|
|
|
6553 |
'/option',
|
|
|
6554 |
array('option' => array('value' => '02')),
|
|
|
6555 |
'2',
|
|
|
6556 |
'/option',
|
|
|
6557 |
$hoursRegex,
|
|
|
6558 |
'/select',
|
|
|
6559 |
);
|
|
|
6560 |
$this->assertTags($result, $expected);
|
|
|
6561 |
|
|
|
6562 |
unset($this->Form->request->data['Model']['field']);
|
|
|
6563 |
$result = $this->Form->hour('Model.field', true, array('value' => 'now'));
|
|
|
6564 |
$thisHour = date('H');
|
|
|
6565 |
$optValue = date('G');
|
|
|
6566 |
$this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
|
|
|
6567 |
|
|
|
6568 |
$this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
|
|
|
6569 |
$result = $this->Form->hour('Model.field', true);
|
|
|
6570 |
$expected = array(
|
|
|
6571 |
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
6572 |
array('option' => array('value' => '')),
|
|
|
6573 |
'/option',
|
|
|
6574 |
array('option' => array('value' => '00')),
|
|
|
6575 |
'0',
|
|
|
6576 |
'/option',
|
|
|
6577 |
array('option' => array('value' => '01', 'selected' => 'selected')),
|
|
|
6578 |
'1',
|
|
|
6579 |
'/option',
|
|
|
6580 |
array('option' => array('value' => '02')),
|
|
|
6581 |
'2',
|
|
|
6582 |
'/option',
|
|
|
6583 |
$hoursRegex,
|
|
|
6584 |
'/select',
|
|
|
6585 |
);
|
|
|
6586 |
$this->assertTags($result, $expected);
|
|
|
6587 |
}
|
|
|
6588 |
|
|
|
6589 |
/**
|
|
|
6590 |
* testYear method
|
|
|
6591 |
*
|
|
|
6592 |
* @return void
|
|
|
6593 |
*/
|
|
|
6594 |
public function testYear() {
|
|
|
6595 |
$result = $this->Form->year('Model.field', 2006, 2007);
|
|
|
6596 |
$expected = array(
|
|
|
6597 |
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
6598 |
array('option' => array('value' => '')),
|
|
|
6599 |
'/option',
|
|
|
6600 |
array('option' => array('value' => '2007')),
|
|
|
6601 |
'2007',
|
|
|
6602 |
'/option',
|
|
|
6603 |
array('option' => array('value' => '2006')),
|
|
|
6604 |
'2006',
|
|
|
6605 |
'/option',
|
|
|
6606 |
'/select',
|
|
|
6607 |
);
|
|
|
6608 |
$this->assertTags($result, $expected);
|
|
|
6609 |
|
|
|
6610 |
$result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
|
|
|
6611 |
$expected = array(
|
|
|
6612 |
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
6613 |
array('option' => array('value' => '')),
|
|
|
6614 |
'/option',
|
|
|
6615 |
array('option' => array('value' => '2006')),
|
|
|
6616 |
'2006',
|
|
|
6617 |
'/option',
|
|
|
6618 |
array('option' => array('value' => '2007')),
|
|
|
6619 |
'2007',
|
|
|
6620 |
'/option',
|
|
|
6621 |
'/select',
|
|
|
6622 |
);
|
|
|
6623 |
$this->assertTags($result, $expected);
|
|
|
6624 |
|
|
|
6625 |
$this->request->data['Contact']['published'] = '';
|
|
|
6626 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
|
|
|
6627 |
$expected = array(
|
|
|
6628 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
|
|
|
6629 |
array('option' => array('value' => '')),
|
|
|
6630 |
'/option',
|
|
|
6631 |
array('option' => array('value' => '2007')),
|
|
|
6632 |
'2007',
|
|
|
6633 |
'/option',
|
|
|
6634 |
array('option' => array('value' => '2006')),
|
|
|
6635 |
'2006',
|
|
|
6636 |
'/option',
|
|
|
6637 |
'/select',
|
|
|
6638 |
);
|
|
|
6639 |
$this->assertTags($result, $expected);
|
|
|
6640 |
|
|
|
6641 |
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
|
|
6642 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
|
|
|
6643 |
$expected = array(
|
|
|
6644 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6645 |
array('option' => array('value' => '2007')),
|
|
|
6646 |
'2007',
|
|
|
6647 |
'/option',
|
|
|
6648 |
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
6649 |
'2006',
|
|
|
6650 |
'/option',
|
|
|
6651 |
'/select',
|
|
|
6652 |
);
|
|
|
6653 |
$this->assertTags($result, $expected);
|
|
|
6654 |
|
|
|
6655 |
$this->Form->request->data['Contact']['published'] = '';
|
|
|
6656 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
|
|
|
6657 |
$expected = array(
|
|
|
6658 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6659 |
array('option' => array('value' => '')),
|
|
|
6660 |
'/option',
|
|
|
6661 |
array('option' => array('value' => '2007')),
|
|
|
6662 |
'2007',
|
|
|
6663 |
'/option',
|
|
|
6664 |
array('option' => array('value' => '2006')),
|
|
|
6665 |
'2006',
|
|
|
6666 |
'/option',
|
|
|
6667 |
'/select',
|
|
|
6668 |
);
|
|
|
6669 |
$this->assertTags($result, $expected);
|
|
|
6670 |
|
|
|
6671 |
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
|
|
6672 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
|
|
|
6673 |
$expected = array(
|
|
|
6674 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6675 |
array('option' => array('value' => '2007')),
|
|
|
6676 |
'2007',
|
|
|
6677 |
'/option',
|
|
|
6678 |
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
6679 |
'2006',
|
|
|
6680 |
'/option',
|
|
|
6681 |
'/select',
|
|
|
6682 |
);
|
|
|
6683 |
$this->assertTags($result, $expected);
|
|
|
6684 |
|
|
|
6685 |
$this->Form->request->data['Contact']['published'] = '';
|
|
|
6686 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
|
|
|
6687 |
$expected = array(
|
|
|
6688 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6689 |
array('option' => array('value' => '')),
|
|
|
6690 |
'/option',
|
|
|
6691 |
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
6692 |
'2007',
|
|
|
6693 |
'/option',
|
|
|
6694 |
array('option' => array('value' => '2006')),
|
|
|
6695 |
'2006',
|
|
|
6696 |
'/option',
|
|
|
6697 |
'/select',
|
|
|
6698 |
);
|
|
|
6699 |
$this->assertTags($result, $expected);
|
|
|
6700 |
|
|
|
6701 |
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
|
|
6702 |
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
|
|
|
6703 |
$expected = array(
|
|
|
6704 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6705 |
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
6706 |
'2007',
|
|
|
6707 |
'/option',
|
|
|
6708 |
array('option' => array('value' => '2006')),
|
|
|
6709 |
'2006',
|
|
|
6710 |
'/option',
|
|
|
6711 |
'/select',
|
|
|
6712 |
);
|
|
|
6713 |
$this->assertTags($result, $expected);
|
|
|
6714 |
|
|
|
6715 |
$this->Form->request->data['Contact']['published'] = '';
|
|
|
6716 |
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
|
|
|
6717 |
$expected = array(
|
|
|
6718 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6719 |
array('option' => array('value' => '2008')),
|
|
|
6720 |
'2008',
|
|
|
6721 |
'/option',
|
|
|
6722 |
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
6723 |
'2007',
|
|
|
6724 |
'/option',
|
|
|
6725 |
array('option' => array('value' => '2006')),
|
|
|
6726 |
'2006',
|
|
|
6727 |
'/option',
|
|
|
6728 |
'/select',
|
|
|
6729 |
);
|
|
|
6730 |
$this->assertTags($result, $expected);
|
|
|
6731 |
|
|
|
6732 |
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
|
|
6733 |
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
|
|
|
6734 |
$expected = array(
|
|
|
6735 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6736 |
array('option' => array('value' => '2008')),
|
|
|
6737 |
'2008',
|
|
|
6738 |
'/option',
|
|
|
6739 |
array('option' => array('value' => '2007')),
|
|
|
6740 |
'2007',
|
|
|
6741 |
'/option',
|
|
|
6742 |
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
6743 |
'2006',
|
|
|
6744 |
'/option',
|
|
|
6745 |
'/select',
|
|
|
6746 |
);
|
|
|
6747 |
$this->assertTags($result, $expected);
|
|
|
6748 |
|
|
|
6749 |
$this->Form->request->data = array();
|
|
|
6750 |
$this->Form->create('Contact');
|
|
|
6751 |
$result = $this->Form->year('published', 2006, 2008, array('empty' => false));
|
|
|
6752 |
$expected = array(
|
|
|
6753 |
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
6754 |
array('option' => array('value' => '2008')),
|
|
|
6755 |
'2008',
|
|
|
6756 |
'/option',
|
|
|
6757 |
array('option' => array('value' => '2007')),
|
|
|
6758 |
'2007',
|
|
|
6759 |
'/option',
|
|
|
6760 |
array('option' => array('value' => '2006')),
|
|
|
6761 |
'2006',
|
|
|
6762 |
'/option',
|
|
|
6763 |
'/select',
|
|
|
6764 |
);
|
|
|
6765 |
$this->assertTags($result, $expected);
|
|
|
6766 |
|
|
|
6767 |
$result = $this->Form->year('published', array(), array(), array('empty' => false));
|
|
|
6768 |
$this->assertContains('data[Contact][published][year]', $result);
|
|
|
6769 |
}
|
|
|
6770 |
|
|
|
6771 |
/**
|
|
|
6772 |
* testYearAutoExpandRange method
|
|
|
6773 |
*
|
|
|
6774 |
* @return void
|
|
|
6775 |
*/
|
|
|
6776 |
public function testYearAutoExpandRange() {
|
|
|
6777 |
$this->Form->request->data['User']['birthday'] = '1930-10-10';
|
|
|
6778 |
$result = $this->Form->year('User.birthday');
|
|
|
6779 |
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
6780 |
|
|
|
6781 |
$result = $matches[1];
|
|
|
6782 |
$expected = range(date('Y') + 20, 1930);
|
|
|
6783 |
$this->assertEquals($expected, $result);
|
|
|
6784 |
|
|
|
6785 |
$this->Form->request->data['Project']['release'] = '2050-10-10';
|
|
|
6786 |
$result = $this->Form->year('Project.release');
|
|
|
6787 |
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
6788 |
|
|
|
6789 |
$result = $matches[1];
|
|
|
6790 |
$expected = range(2050, date('Y') - 20);
|
|
|
6791 |
$this->assertEquals($expected, $result);
|
|
|
6792 |
|
|
|
6793 |
$this->Form->request->data['Project']['release'] = '1881-10-10';
|
|
|
6794 |
$result = $this->Form->year('Project.release', 1890, 1900);
|
|
|
6795 |
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
6796 |
|
|
|
6797 |
$result = $matches[1];
|
|
|
6798 |
$expected = range(1900, 1881);
|
|
|
6799 |
$this->assertEquals($expected, $result);
|
|
|
6800 |
}
|
|
|
6801 |
|
|
|
6802 |
/**
|
|
|
6803 |
* testInputDate method
|
|
|
6804 |
*
|
|
|
6805 |
* Test various inputs with type date and different dateFormat values.
|
|
|
6806 |
* Failing to provide a dateFormat key should not error.
|
|
|
6807 |
* It should simply not pre-select any value then.
|
|
|
6808 |
*
|
|
|
6809 |
* @return void
|
|
|
6810 |
*/
|
|
|
6811 |
public function testInputDate() {
|
|
|
6812 |
$this->Form->request->data = array(
|
|
|
6813 |
'User' => array(
|
|
|
6814 |
'month_year' => array('month' => date('m')),
|
|
|
6815 |
'just_year' => array('month' => date('m')),
|
|
|
6816 |
'just_month' => array('year' => date('Y')),
|
|
|
6817 |
'just_day' => array('month' => date('m')),
|
|
|
6818 |
)
|
|
|
6819 |
);
|
|
|
6820 |
$this->Form->create('User');
|
|
|
6821 |
$result = $this->Form->input('month_year',
|
|
|
6822 |
array(
|
|
|
6823 |
'label' => false,
|
|
|
6824 |
'div' => false,
|
|
|
6825 |
'type' => 'date',
|
|
|
6826 |
'dateFormat' => 'MY',
|
|
|
6827 |
'minYear' => 2006,
|
|
|
6828 |
'maxYear' => 2008
|
|
|
6829 |
)
|
|
|
6830 |
);
|
|
|
6831 |
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
|
|
|
6832 |
$this->assertNotContains('value="2008" selected="selected"', $result);
|
|
|
6833 |
|
|
|
6834 |
$result = $this->Form->input('just_year',
|
|
|
6835 |
array(
|
|
|
6836 |
'type' => 'date',
|
|
|
6837 |
'label' => false,
|
|
|
6838 |
'dateFormat' => 'Y',
|
|
|
6839 |
'minYear' => date('Y'),
|
|
|
6840 |
'maxYear' => date('Y', strtotime('+20 years'))
|
|
|
6841 |
)
|
|
|
6842 |
);
|
|
|
6843 |
$this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
|
|
|
6844 |
|
|
|
6845 |
$result = $this->Form->input('just_month',
|
|
|
6846 |
array(
|
|
|
6847 |
'type' => 'date',
|
|
|
6848 |
'label' => false,
|
|
|
6849 |
'dateFormat' => 'M',
|
|
|
6850 |
'empty' => false,
|
|
|
6851 |
)
|
|
|
6852 |
);
|
|
|
6853 |
$this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
|
|
|
6854 |
|
|
|
6855 |
$result = $this->Form->input('just_day',
|
|
|
6856 |
array(
|
|
|
6857 |
'type' => 'date',
|
|
|
6858 |
'label' => false,
|
|
|
6859 |
'dateFormat' => 'D',
|
|
|
6860 |
'empty' => false,
|
|
|
6861 |
)
|
|
|
6862 |
);
|
|
|
6863 |
$this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
|
|
|
6864 |
}
|
|
|
6865 |
|
|
|
6866 |
/**
|
|
|
6867 |
* testInputDateMaxYear method
|
|
|
6868 |
*
|
|
|
6869 |
* Let's say we want to only allow users born from 2006 to 2008 to register
|
|
|
6870 |
* This being the first singup page, we still don't have any data
|
|
|
6871 |
*
|
|
|
6872 |
* @return void
|
|
|
6873 |
*/
|
|
|
6874 |
public function testInputDateMaxYear() {
|
|
|
6875 |
$this->Form->request->data = array();
|
|
|
6876 |
$this->Form->create('User');
|
|
|
6877 |
$result = $this->Form->input('birthday',
|
|
|
6878 |
array(
|
|
|
6879 |
'label' => false,
|
|
|
6880 |
'div' => false,
|
|
|
6881 |
'type' => 'date',
|
|
|
6882 |
'dateFormat' => 'DMY',
|
|
|
6883 |
'minYear' => 2006,
|
|
|
6884 |
'maxYear' => 2008
|
|
|
6885 |
)
|
|
|
6886 |
);
|
|
|
6887 |
$this->assertContains('value="2008" selected="selected"', $result);
|
|
|
6888 |
}
|
|
|
6889 |
|
|
|
6890 |
/**
|
|
|
6891 |
* testTextArea method
|
|
|
6892 |
*
|
|
|
6893 |
* @return void
|
|
|
6894 |
*/
|
|
|
6895 |
public function testTextArea() {
|
|
|
6896 |
$this->Form->request->data = array('Model' => array('field' => 'some test data'));
|
|
|
6897 |
$result = $this->Form->textarea('Model.field');
|
|
|
6898 |
$expected = array(
|
|
|
6899 |
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
6900 |
'some test data',
|
|
|
6901 |
'/textarea',
|
|
|
6902 |
);
|
|
|
6903 |
$this->assertTags($result, $expected);
|
|
|
6904 |
|
|
|
6905 |
$result = $this->Form->textarea('Model.tmp');
|
|
|
6906 |
$expected = array(
|
|
|
6907 |
'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'),
|
|
|
6908 |
'/textarea',
|
|
|
6909 |
);
|
|
|
6910 |
$this->assertTags($result, $expected);
|
|
|
6911 |
|
|
|
6912 |
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
|
|
|
6913 |
$result = $this->Form->textarea('Model.field');
|
|
|
6914 |
$expected = array(
|
|
|
6915 |
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
6916 |
htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
|
|
|
6917 |
'/textarea',
|
|
|
6918 |
);
|
|
|
6919 |
$this->assertTags($result, $expected);
|
|
|
6920 |
|
|
|
6921 |
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
|
|
|
6922 |
$result = $this->Form->textarea('Model.field', array('escape' => false));
|
|
|
6923 |
$expected = array(
|
|
|
6924 |
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
6925 |
'some <strong>test</strong> data with <a href="#">HTML</a> chars',
|
|
|
6926 |
'/textarea',
|
|
|
6927 |
);
|
|
|
6928 |
$this->assertTags($result, $expected);
|
|
|
6929 |
|
|
|
6930 |
$this->Form->request->data['Model']['0']['OtherModel']['field'] = null;
|
|
|
6931 |
$result = $this->Form->textarea('Model.0.OtherModel.field');
|
|
|
6932 |
$expected = array(
|
|
|
6933 |
'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
|
|
|
6934 |
'/textarea'
|
|
|
6935 |
);
|
|
|
6936 |
$this->assertTags($result, $expected);
|
|
|
6937 |
}
|
|
|
6938 |
|
|
|
6939 |
/**
|
|
|
6940 |
* testTextAreaWithStupidCharacters method
|
|
|
6941 |
*
|
|
|
6942 |
* test text area with non-ascii characters
|
|
|
6943 |
*
|
|
|
6944 |
* @return void
|
|
|
6945 |
*/
|
|
|
6946 |
public function testTextAreaWithStupidCharacters() {
|
|
|
6947 |
$this->loadFixtures('Post');
|
|
|
6948 |
$result = $this->Form->input('Post.content', array(
|
|
|
6949 |
'label' => 'Current Text', 'value' => "GREAT®", 'rows' => '15', 'cols' => '75'
|
|
|
6950 |
));
|
|
|
6951 |
$expected = array(
|
|
|
6952 |
'div' => array('class' => 'input textarea'),
|
|
|
6953 |
'label' => array('for' => 'PostContent'),
|
|
|
6954 |
'Current Text',
|
|
|
6955 |
'/label',
|
|
|
6956 |
'textarea' => array('name' => 'data[Post][content]', 'id' => 'PostContent', 'rows' => '15', 'cols' => '75'),
|
|
|
6957 |
'GREAT®',
|
|
|
6958 |
'/textarea',
|
|
|
6959 |
'/div'
|
|
|
6960 |
);
|
|
|
6961 |
$this->assertTags($result, $expected);
|
|
|
6962 |
}
|
|
|
6963 |
|
|
|
6964 |
/**
|
|
|
6965 |
* testHiddenField method
|
|
|
6966 |
*
|
|
|
6967 |
* @return void
|
|
|
6968 |
*/
|
|
|
6969 |
public function testHiddenField() {
|
|
|
6970 |
$Contact = ClassRegistry::getObject('Contact');
|
|
|
6971 |
$Contact->validationErrors['field'] = 1;
|
|
|
6972 |
$this->Form->request->data['Contact']['field'] = 'test';
|
|
|
6973 |
$result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
|
|
|
6974 |
$this->assertTags($result, array(
|
|
|
6975 |
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'id' => 'theID', 'value' => 'test'))
|
|
|
6976 |
);
|
|
|
6977 |
}
|
|
|
6978 |
|
|
|
6979 |
/**
|
|
|
6980 |
* testFileUploadField method
|
|
|
6981 |
*
|
|
|
6982 |
* @return void
|
|
|
6983 |
*/
|
|
|
6984 |
public function testFileUploadField() {
|
|
|
6985 |
$result = $this->Form->file('Model.upload');
|
|
|
6986 |
$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
|
|
|
6987 |
|
|
|
6988 |
$this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
|
|
|
6989 |
$result = $this->Form->input('Model.upload', array('type' => 'file'));
|
|
|
6990 |
$expected = array(
|
|
|
6991 |
'div' => array('class' => 'input file'),
|
|
|
6992 |
'label' => array('for' => 'ModelUpload'),
|
|
|
6993 |
'Upload',
|
|
|
6994 |
'/label',
|
|
|
6995 |
'input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'),
|
|
|
6996 |
'/div'
|
|
|
6997 |
);
|
|
|
6998 |
$this->assertTags($result, $expected);
|
|
|
6999 |
|
|
|
7000 |
$this->Form->request->data['Model']['upload'] = 'no data should be set in value';
|
|
|
7001 |
$result = $this->Form->file('Model.upload');
|
|
|
7002 |
$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
|
|
|
7003 |
}
|
|
|
7004 |
|
|
|
7005 |
/**
|
|
|
7006 |
* test File upload input on a model not used in create();
|
|
|
7007 |
*
|
|
|
7008 |
* @return void
|
|
|
7009 |
*/
|
|
|
7010 |
public function testFileUploadOnOtherModel() {
|
|
|
7011 |
$this->Form->create('ValidateUser', array('type' => 'file'));
|
|
|
7012 |
$result = $this->Form->file('ValidateProfile.city');
|
|
|
7013 |
$expected = array(
|
|
|
7014 |
'input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity')
|
|
|
7015 |
);
|
|
|
7016 |
$this->assertTags($result, $expected);
|
|
|
7017 |
}
|
|
|
7018 |
|
|
|
7019 |
/**
|
|
|
7020 |
* testButton method
|
|
|
7021 |
*
|
|
|
7022 |
* @return void
|
|
|
7023 |
*/
|
|
|
7024 |
public function testButton() {
|
|
|
7025 |
$result = $this->Form->button('Hi');
|
|
|
7026 |
$this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
|
|
|
7027 |
|
|
|
7028 |
$result = $this->Form->button('Clear Form >', array('type' => 'reset'));
|
|
|
7029 |
$this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
|
|
|
7030 |
|
|
|
7031 |
$result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
|
|
|
7032 |
$this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
|
|
|
7033 |
|
|
|
7034 |
$result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
|
|
|
7035 |
$this->assertTags($result, array('button' => array('type' => 'reset'), '<Clear Form>', '/button'));
|
|
|
7036 |
|
|
|
7037 |
$result = $this->Form->button('No type', array('type' => false));
|
|
|
7038 |
$this->assertTags($result, array('button' => array(), 'No type', '/button'));
|
|
|
7039 |
|
|
|
7040 |
$result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false));
|
|
|
7041 |
$this->assertNotRegExp('/\&039/', $result);
|
|
|
7042 |
}
|
|
|
7043 |
|
|
|
7044 |
/**
|
|
|
7045 |
* Test that button() makes unlocked fields by default.
|
|
|
7046 |
*
|
|
|
7047 |
* @return void
|
|
|
7048 |
*/
|
|
|
7049 |
public function testButtonUnlockedByDefault() {
|
|
|
7050 |
$this->Form->request->params['_Token']['key'] = 'secured';
|
|
|
7051 |
$this->Form->button('Save', array('name' => 'save'));
|
|
|
7052 |
$this->Form->button('Clear');
|
|
|
7053 |
|
|
|
7054 |
$result = $this->Form->unlockField();
|
|
|
7055 |
$this->assertEquals(array('save'), $result);
|
|
|
7056 |
}
|
|
|
7057 |
|
|
|
7058 |
/**
|
|
|
7059 |
* testPostButton method
|
|
|
7060 |
*
|
|
|
7061 |
* @return void
|
|
|
7062 |
*/
|
|
|
7063 |
public function testPostButton() {
|
|
|
7064 |
$result = $this->Form->postButton('Hi', '/controller/action');
|
|
|
7065 |
$this->assertTags($result, array(
|
|
|
7066 |
'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
|
|
|
7067 |
'div' => array('style' => 'display:none;'),
|
|
|
7068 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7069 |
'/div',
|
|
|
7070 |
'button' => array('type' => 'submit'),
|
|
|
7071 |
'Hi',
|
|
|
7072 |
'/button',
|
|
|
7073 |
'/form'
|
|
|
7074 |
));
|
|
|
7075 |
|
|
|
7076 |
$result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
|
|
|
7077 |
$this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false);
|
|
|
7078 |
}
|
|
|
7079 |
|
|
|
7080 |
/**
|
|
|
7081 |
* Test that postButton adds _Token fields.
|
|
|
7082 |
*
|
|
|
7083 |
* @return void
|
|
|
7084 |
*/
|
|
|
7085 |
public function testSecurePostButton() {
|
|
|
7086 |
$this->Form->request->params['_Token'] = array('key' => 'testkey');
|
|
|
7087 |
|
|
|
7088 |
$result = $this->Form->postButton('Delete', '/posts/delete/1');
|
|
|
7089 |
$expected = array(
|
|
|
7090 |
'form' => array(
|
|
|
7091 |
'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
|
|
|
7092 |
),
|
|
|
7093 |
array('div' => array('style' => 'display:none;')),
|
|
|
7094 |
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
|
|
7095 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
|
|
|
7096 |
'/div',
|
|
|
7097 |
'button' => array('type' => 'submit'),
|
|
|
7098 |
'Delete',
|
|
|
7099 |
'/button',
|
|
|
7100 |
array('div' => array('style' => 'display:none;')),
|
|
|
7101 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
|
|
|
7102 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
|
|
|
7103 |
'/div',
|
|
|
7104 |
'/form',
|
|
|
7105 |
);
|
|
|
7106 |
$this->assertTags($result, $expected);
|
|
|
7107 |
}
|
|
|
7108 |
|
|
|
7109 |
/**
|
|
|
7110 |
* testPostLink method
|
|
|
7111 |
*
|
|
|
7112 |
* @return void
|
|
|
7113 |
*/
|
|
|
7114 |
public function testPostLink() {
|
|
|
7115 |
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
|
|
7116 |
$this->assertTags($result, array(
|
|
|
7117 |
'form' => array(
|
|
|
7118 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7119 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7120 |
),
|
|
|
7121 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7122 |
'/form',
|
|
|
7123 |
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
7124 |
'Delete',
|
|
|
7125 |
'/a'
|
|
|
7126 |
));
|
|
|
7127 |
|
|
|
7128 |
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
|
|
|
7129 |
$this->assertTags($result, array(
|
|
|
7130 |
'form' => array(
|
|
|
7131 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7132 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7133 |
),
|
|
|
7134 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
|
|
|
7135 |
'/form',
|
|
|
7136 |
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
7137 |
'Delete',
|
|
|
7138 |
'/a'
|
|
|
7139 |
));
|
|
|
7140 |
|
|
|
7141 |
$result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
|
|
|
7142 |
$this->assertTags($result, array(
|
|
|
7143 |
'form' => array(
|
|
|
7144 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7145 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7146 |
),
|
|
|
7147 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7148 |
'/form',
|
|
|
7149 |
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
|
|
7150 |
'Delete',
|
|
|
7151 |
'/a'
|
|
|
7152 |
));
|
|
|
7153 |
|
|
|
7154 |
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
|
|
|
7155 |
$this->assertTags($result, array(
|
|
|
7156 |
'form' => array(
|
|
|
7157 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7158 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7159 |
),
|
|
|
7160 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7161 |
'/form',
|
|
|
7162 |
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("'Confirm' this \\\\"deletion\\\\"\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
|
|
7163 |
'Delete',
|
|
|
7164 |
'/a'
|
|
|
7165 |
));
|
|
|
7166 |
|
|
|
7167 |
$result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
|
|
|
7168 |
$this->assertContains('<input type="hidden" name="data[id]" value="1"/>', $result);
|
|
|
7169 |
|
|
|
7170 |
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
|
|
|
7171 |
$this->assertTags($result, array(
|
|
|
7172 |
'form' => array(
|
|
|
7173 |
'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
|
|
|
7174 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7175 |
),
|
|
|
7176 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7177 |
'/form',
|
|
|
7178 |
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
7179 |
'Delete',
|
|
|
7180 |
'/a'
|
|
|
7181 |
));
|
|
|
7182 |
|
|
|
7183 |
$result = $this->Form->postLink(
|
|
|
7184 |
'',
|
|
|
7185 |
array('controller' => 'items', 'action' => 'delete', 10),
|
|
|
7186 |
array('class' => 'btn btn-danger', 'escape' => false),
|
|
|
7187 |
'Confirm thing'
|
|
|
7188 |
);
|
|
|
7189 |
$this->assertTags($result, array(
|
|
|
7190 |
'form' => array(
|
|
|
7191 |
'method' => 'post', 'action' => '/items/delete/10',
|
|
|
7192 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7193 |
),
|
|
|
7194 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7195 |
'/form',
|
|
|
7196 |
'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\"\;Confirm thing\"\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
|
|
7197 |
'/a'
|
|
|
7198 |
));
|
|
|
7199 |
}
|
|
|
7200 |
|
|
|
7201 |
/**
|
|
|
7202 |
* test creating postLinks after a GET form.
|
|
|
7203 |
*
|
|
|
7204 |
* @return void
|
|
|
7205 |
*/
|
|
|
7206 |
public function testPostLinkAfterGetForm() {
|
|
|
7207 |
$this->Form->request->params['_Token']['key'] = 'testkey';
|
|
|
7208 |
$this->Form->create('User', array('type' => 'get'));
|
|
|
7209 |
$this->Form->end();
|
|
|
7210 |
|
|
|
7211 |
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
|
|
7212 |
$this->assertTags($result, array(
|
|
|
7213 |
'form' => array(
|
|
|
7214 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7215 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7216 |
),
|
|
|
7217 |
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
|
|
7218 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
|
|
|
7219 |
'div' => array('style' => 'display:none;'),
|
|
|
7220 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
|
|
|
7221 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
|
|
|
7222 |
'/div',
|
|
|
7223 |
'/form',
|
|
|
7224 |
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
7225 |
'Delete',
|
|
|
7226 |
'/a'
|
|
|
7227 |
));
|
|
|
7228 |
}
|
|
|
7229 |
|
|
|
7230 |
/**
|
|
|
7231 |
* Test that postLink adds _Token fields.
|
|
|
7232 |
*
|
|
|
7233 |
* @return void
|
|
|
7234 |
*/
|
|
|
7235 |
public function testSecurePostLink() {
|
|
|
7236 |
$this->Form->request->params['_Token'] = array('key' => 'testkey');
|
|
|
7237 |
|
|
|
7238 |
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
|
|
7239 |
$expected = array(
|
|
|
7240 |
'form' => array(
|
|
|
7241 |
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
7242 |
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
7243 |
),
|
|
|
7244 |
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
|
|
7245 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/')),
|
|
|
7246 |
'div' => array('style' => 'display:none;'),
|
|
|
7247 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/')),
|
|
|
7248 |
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/')),
|
|
|
7249 |
'/div',
|
|
|
7250 |
'/form',
|
|
|
7251 |
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
7252 |
'Delete',
|
|
|
7253 |
'/a'
|
|
|
7254 |
);
|
|
|
7255 |
$this->assertTags($result, $expected);
|
|
|
7256 |
}
|
|
|
7257 |
|
|
|
7258 |
/**
|
|
|
7259 |
* testSubmitButton method
|
|
|
7260 |
*
|
|
|
7261 |
* @return void
|
|
|
7262 |
*/
|
|
|
7263 |
public function testSubmitButton() {
|
|
|
7264 |
$result = $this->Form->submit('');
|
|
|
7265 |
$expected = array(
|
|
|
7266 |
'div' => array('class' => 'submit'),
|
|
|
7267 |
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
7268 |
'/div'
|
|
|
7269 |
);
|
|
|
7270 |
$this->assertTags($result, $expected);
|
|
|
7271 |
|
|
|
7272 |
$result = $this->Form->submit('Test Submit');
|
|
|
7273 |
$expected = array(
|
|
|
7274 |
'div' => array('class' => 'submit'),
|
|
|
7275 |
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
7276 |
'/div'
|
|
|
7277 |
);
|
|
|
7278 |
$this->assertTags($result, $expected);
|
|
|
7279 |
|
|
|
7280 |
$result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
|
|
|
7281 |
$expected = array(
|
|
|
7282 |
'span' => array('class' => 'submit'),
|
|
|
7283 |
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
7284 |
'/span'
|
|
|
7285 |
);
|
|
|
7286 |
$this->assertTags($result, $expected);
|
|
|
7287 |
|
|
|
7288 |
$result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
|
|
|
7289 |
$expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
|
|
|
7290 |
$this->assertTags($result, $expected);
|
|
|
7291 |
|
|
|
7292 |
$result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
|
|
|
7293 |
$expected = array(
|
|
|
7294 |
'div' => array('class' => 'submit', 'id' => 'SaveButton'),
|
|
|
7295 |
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
7296 |
'/div'
|
|
|
7297 |
);
|
|
|
7298 |
$this->assertTags($result, $expected);
|
|
|
7299 |
|
|
|
7300 |
$result = $this->Form->submit('Next >');
|
|
|
7301 |
$expected = array(
|
|
|
7302 |
'div' => array('class' => 'submit'),
|
|
|
7303 |
'input' => array('type' => 'submit', 'value' => 'Next >'),
|
|
|
7304 |
'/div'
|
|
|
7305 |
);
|
|
|
7306 |
$this->assertTags($result, $expected);
|
|
|
7307 |
|
|
|
7308 |
$result = $this->Form->submit('Next >', array('escape' => false));
|
|
|
7309 |
$expected = array(
|
|
|
7310 |
'div' => array('class' => 'submit'),
|
|
|
7311 |
'input' => array('type' => 'submit', 'value' => 'Next >'),
|
|
|
7312 |
'/div'
|
|
|
7313 |
);
|
|
|
7314 |
$this->assertTags($result, $expected);
|
|
|
7315 |
|
|
|
7316 |
$result = $this->Form->submit('Reset!', array('type' => 'reset'));
|
|
|
7317 |
$expected = array(
|
|
|
7318 |
'div' => array('class' => 'submit'),
|
|
|
7319 |
'input' => array('type' => 'reset', 'value' => 'Reset!'),
|
|
|
7320 |
'/div'
|
|
|
7321 |
);
|
|
|
7322 |
$this->assertTags($result, $expected);
|
|
|
7323 |
|
|
|
7324 |
$before = '--before--';
|
|
|
7325 |
$after = '--after--';
|
|
|
7326 |
$result = $this->Form->submit('Test', array('before' => $before));
|
|
|
7327 |
$expected = array(
|
|
|
7328 |
'div' => array('class' => 'submit'),
|
|
|
7329 |
'--before--',
|
|
|
7330 |
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
7331 |
'/div'
|
|
|
7332 |
);
|
|
|
7333 |
$this->assertTags($result, $expected);
|
|
|
7334 |
|
|
|
7335 |
$result = $this->Form->submit('Test', array('after' => $after));
|
|
|
7336 |
$expected = array(
|
|
|
7337 |
'div' => array('class' => 'submit'),
|
|
|
7338 |
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
7339 |
'--after--',
|
|
|
7340 |
'/div'
|
|
|
7341 |
);
|
|
|
7342 |
$this->assertTags($result, $expected);
|
|
|
7343 |
|
|
|
7344 |
$result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
|
|
|
7345 |
$expected = array(
|
|
|
7346 |
'div' => array('class' => 'submit'),
|
|
|
7347 |
'--before--',
|
|
|
7348 |
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
7349 |
'--after--',
|
|
|
7350 |
'/div'
|
|
|
7351 |
);
|
|
|
7352 |
$this->assertTags($result, $expected);
|
|
|
7353 |
}
|
|
|
7354 |
|
|
|
7355 |
/**
|
|
|
7356 |
* test image submit types.
|
|
|
7357 |
*
|
|
|
7358 |
* @return void
|
|
|
7359 |
*/
|
|
|
7360 |
public function testSubmitImage() {
|
|
|
7361 |
$result = $this->Form->submit('http://example.com/cake.power.gif');
|
|
|
7362 |
$expected = array(
|
|
|
7363 |
'div' => array('class' => 'submit'),
|
|
|
7364 |
'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
|
|
|
7365 |
'/div'
|
|
|
7366 |
);
|
|
|
7367 |
$this->assertTags($result, $expected);
|
|
|
7368 |
|
|
|
7369 |
$result = $this->Form->submit('/relative/cake.power.gif');
|
|
|
7370 |
$expected = array(
|
|
|
7371 |
'div' => array('class' => 'submit'),
|
|
|
7372 |
'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
|
|
|
7373 |
'/div'
|
|
|
7374 |
);
|
|
|
7375 |
$this->assertTags($result, $expected);
|
|
|
7376 |
|
|
|
7377 |
$result = $this->Form->submit('cake.power.gif');
|
|
|
7378 |
$expected = array(
|
|
|
7379 |
'div' => array('class' => 'submit'),
|
|
|
7380 |
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
7381 |
'/div'
|
|
|
7382 |
);
|
|
|
7383 |
$this->assertTags($result, $expected);
|
|
|
7384 |
|
|
|
7385 |
$result = $this->Form->submit('Not.an.image');
|
|
|
7386 |
$expected = array(
|
|
|
7387 |
'div' => array('class' => 'submit'),
|
|
|
7388 |
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
|
|
|
7389 |
'/div'
|
|
|
7390 |
);
|
|
|
7391 |
$this->assertTags($result, $expected);
|
|
|
7392 |
|
|
|
7393 |
$after = '--after--';
|
|
|
7394 |
$before = '--before--';
|
|
|
7395 |
$result = $this->Form->submit('cake.power.gif', array('after' => $after));
|
|
|
7396 |
$expected = array(
|
|
|
7397 |
'div' => array('class' => 'submit'),
|
|
|
7398 |
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
7399 |
'--after--',
|
|
|
7400 |
'/div'
|
|
|
7401 |
);
|
|
|
7402 |
$this->assertTags($result, $expected);
|
|
|
7403 |
|
|
|
7404 |
$result = $this->Form->submit('cake.power.gif', array('before' => $before));
|
|
|
7405 |
$expected = array(
|
|
|
7406 |
'div' => array('class' => 'submit'),
|
|
|
7407 |
'--before--',
|
|
|
7408 |
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
7409 |
'/div'
|
|
|
7410 |
);
|
|
|
7411 |
$this->assertTags($result, $expected);
|
|
|
7412 |
|
|
|
7413 |
$result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
|
|
|
7414 |
$expected = array(
|
|
|
7415 |
'div' => array('class' => 'submit'),
|
|
|
7416 |
'--before--',
|
|
|
7417 |
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
7418 |
'--after--',
|
|
|
7419 |
'/div'
|
|
|
7420 |
);
|
|
|
7421 |
$this->assertTags($result, $expected);
|
|
|
7422 |
|
|
|
7423 |
$result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
|
|
|
7424 |
$expected = array(
|
|
|
7425 |
'div' => array('class' => 'submit'),
|
|
|
7426 |
'--before--',
|
|
|
7427 |
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
|
|
|
7428 |
'--after--',
|
|
|
7429 |
'/div'
|
|
|
7430 |
);
|
|
|
7431 |
$this->assertTags($result, $expected);
|
|
|
7432 |
}
|
|
|
7433 |
|
|
|
7434 |
/**
|
|
|
7435 |
* Submit buttons should be unlocked by default as there could be multiples, and only one will
|
|
|
7436 |
* be submitted at a time.
|
|
|
7437 |
*
|
|
|
7438 |
* @return void
|
|
|
7439 |
*/
|
|
|
7440 |
public function testSubmitUnlockedByDefault() {
|
|
|
7441 |
$this->Form->request->params['_Token']['key'] = 'secured';
|
|
|
7442 |
$this->Form->submit('Go go');
|
|
|
7443 |
$this->Form->submit('Save', array('name' => 'save'));
|
|
|
7444 |
|
|
|
7445 |
$result = $this->Form->unlockField();
|
|
|
7446 |
$this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
|
|
|
7447 |
}
|
|
|
7448 |
|
|
|
7449 |
/**
|
|
|
7450 |
* Test submit image with timestamps.
|
|
|
7451 |
*
|
|
|
7452 |
* @return void
|
|
|
7453 |
*/
|
|
|
7454 |
public function testSubmitImageTimestamp() {
|
|
|
7455 |
Configure::write('Asset.timestamp', 'force');
|
|
|
7456 |
|
|
|
7457 |
$result = $this->Form->submit('cake.power.gif');
|
|
|
7458 |
$expected = array(
|
|
|
7459 |
'div' => array('class' => 'submit'),
|
|
|
7460 |
'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
|
|
|
7461 |
'/div'
|
|
|
7462 |
);
|
|
|
7463 |
$this->assertTags($result, $expected);
|
|
|
7464 |
}
|
|
|
7465 |
|
|
|
7466 |
/**
|
|
|
7467 |
* test the create() method
|
|
|
7468 |
*
|
|
|
7469 |
* @return void
|
|
|
7470 |
*/
|
|
|
7471 |
public function testCreate() {
|
|
|
7472 |
$result = $this->Form->create('Contact');
|
|
|
7473 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7474 |
$expected = array(
|
|
|
7475 |
'form' => array(
|
|
|
7476 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
7477 |
'accept-charset' => $encoding
|
|
|
7478 |
),
|
|
|
7479 |
'div' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
|
|
|
7480 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7481 |
'/div'
|
|
|
7482 |
);
|
|
|
7483 |
$this->assertTags($result, $expected);
|
|
|
7484 |
|
|
|
7485 |
$result = $this->Form->create('Contact', array('type' => 'GET'));
|
|
|
7486 |
$expected = array('form' => array(
|
|
|
7487 |
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
|
|
7488 |
'accept-charset' => $encoding
|
|
|
7489 |
));
|
|
|
7490 |
$this->assertTags($result, $expected);
|
|
|
7491 |
|
|
|
7492 |
$result = $this->Form->create('Contact', array('type' => 'get'));
|
|
|
7493 |
$expected = array('form' => array(
|
|
|
7494 |
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
|
|
7495 |
'accept-charset' => $encoding
|
|
|
7496 |
));
|
|
|
7497 |
$this->assertTags($result, $expected);
|
|
|
7498 |
|
|
|
7499 |
$result = $this->Form->create('Contact', array('type' => 'put'));
|
|
|
7500 |
$expected = array(
|
|
|
7501 |
'form' => array(
|
|
|
7502 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
7503 |
'accept-charset' => $encoding
|
|
|
7504 |
),
|
|
|
7505 |
'div' => array('style' => 'display:none;'),
|
|
|
7506 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
|
|
7507 |
'/div'
|
|
|
7508 |
);
|
|
|
7509 |
$this->assertTags($result, $expected);
|
|
|
7510 |
|
|
|
7511 |
$result = $this->Form->create('Contact', array('type' => 'file'));
|
|
|
7512 |
$expected = array(
|
|
|
7513 |
'form' => array(
|
|
|
7514 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
7515 |
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
|
|
|
7516 |
),
|
|
|
7517 |
'div' => array('style' => 'display:none;'),
|
|
|
7518 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7519 |
'/div'
|
|
|
7520 |
);
|
|
|
7521 |
$this->assertTags($result, $expected);
|
|
|
7522 |
|
|
|
7523 |
$this->Form->request->data['Contact']['id'] = 1;
|
|
|
7524 |
$this->Form->request->here = '/contacts/edit/1';
|
|
|
7525 |
$this->Form->request['action'] = 'edit';
|
|
|
7526 |
$result = $this->Form->create('Contact');
|
|
|
7527 |
$expected = array(
|
|
|
7528 |
'form' => array(
|
|
|
7529 |
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
7530 |
'accept-charset' => $encoding
|
|
|
7531 |
),
|
|
|
7532 |
'div' => array('style' => 'display:none;'),
|
|
|
7533 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
|
|
7534 |
'/div'
|
|
|
7535 |
);
|
|
|
7536 |
$this->assertTags($result, $expected);
|
|
|
7537 |
|
|
|
7538 |
$this->Form->request->data['Contact']['id'] = 1;
|
|
|
7539 |
$this->Form->request->here = '/contacts/edit/1';
|
|
|
7540 |
$this->Form->request['action'] = 'edit';
|
|
|
7541 |
$result = $this->Form->create('Contact', array('type' => 'file'));
|
|
|
7542 |
$expected = array(
|
|
|
7543 |
'form' => array(
|
|
|
7544 |
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
7545 |
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
|
|
|
7546 |
),
|
|
|
7547 |
'div' => array('style' => 'display:none;'),
|
|
|
7548 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
|
|
7549 |
'/div'
|
|
|
7550 |
);
|
|
|
7551 |
$this->assertTags($result, $expected);
|
|
|
7552 |
|
|
|
7553 |
$this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
|
|
|
7554 |
$result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
|
|
|
7555 |
$expected = array(
|
|
|
7556 |
'form' => array(
|
|
|
7557 |
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
|
|
|
7558 |
'action' => '/contact_non_standard_pks/edit/1', 'accept-charset' => $encoding
|
|
|
7559 |
),
|
|
|
7560 |
'div' => array('style' => 'display:none;'),
|
|
|
7561 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
|
|
7562 |
'/div'
|
|
|
7563 |
);
|
|
|
7564 |
$this->assertTags($result, $expected);
|
|
|
7565 |
|
|
|
7566 |
$result = $this->Form->create('Contact', array('id' => 'TestId'));
|
|
|
7567 |
$expected = array(
|
|
|
7568 |
'form' => array(
|
|
|
7569 |
'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
7570 |
'accept-charset' => $encoding
|
|
|
7571 |
),
|
|
|
7572 |
'div' => array('style' => 'display:none;'),
|
|
|
7573 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
|
|
7574 |
'/div'
|
|
|
7575 |
);
|
|
|
7576 |
$this->assertTags($result, $expected);
|
|
|
7577 |
|
|
|
7578 |
$this->Form->request['action'] = 'add';
|
|
|
7579 |
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
|
|
7580 |
$expected = array(
|
|
|
7581 |
'form' => array(
|
|
|
7582 |
'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login',
|
|
|
7583 |
'accept-charset' => $encoding
|
|
|
7584 |
),
|
|
|
7585 |
'div' => array('style' => 'display:none;'),
|
|
|
7586 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7587 |
'/div'
|
|
|
7588 |
);
|
|
|
7589 |
$this->assertTags($result, $expected);
|
|
|
7590 |
|
|
|
7591 |
$result = $this->Form->create('User', array('action' => 'login'));
|
|
|
7592 |
$expected = array(
|
|
|
7593 |
'form' => array(
|
|
|
7594 |
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
|
|
|
7595 |
'accept-charset' => $encoding
|
|
|
7596 |
),
|
|
|
7597 |
'div' => array('style' => 'display:none;'),
|
|
|
7598 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7599 |
'/div'
|
|
|
7600 |
);
|
|
|
7601 |
$this->assertTags($result, $expected);
|
|
|
7602 |
|
|
|
7603 |
$result = $this->Form->create('User', array('url' => '/users/login'));
|
|
|
7604 |
$expected = array(
|
|
|
7605 |
'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'),
|
|
|
7606 |
'div' => array('style' => 'display:none;'),
|
|
|
7607 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7608 |
'/div'
|
|
|
7609 |
);
|
|
|
7610 |
$this->assertTags($result, $expected);
|
|
|
7611 |
|
|
|
7612 |
$this->Form->request['controller'] = 'pages';
|
|
|
7613 |
$result = $this->Form->create('User', array('action' => 'signup'));
|
|
|
7614 |
$expected = array(
|
|
|
7615 |
'form' => array(
|
|
|
7616 |
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
|
|
|
7617 |
'accept-charset' => $encoding
|
|
|
7618 |
),
|
|
|
7619 |
'div' => array('style' => 'display:none;'),
|
|
|
7620 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7621 |
'/div'
|
|
|
7622 |
);
|
|
|
7623 |
$this->assertTags($result, $expected);
|
|
|
7624 |
|
|
|
7625 |
$this->Form->request->data = array();
|
|
|
7626 |
$this->Form->request['controller'] = 'contacts';
|
|
|
7627 |
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
|
|
7628 |
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
|
|
|
7629 |
$expected = array(
|
|
|
7630 |
'form' => array(
|
|
|
7631 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param',
|
|
|
7632 |
'accept-charset' => 'utf-8'
|
|
|
7633 |
),
|
|
|
7634 |
'div' => array('style' => 'display:none;'),
|
|
|
7635 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7636 |
'/div'
|
|
|
7637 |
);
|
|
|
7638 |
$this->assertTags($result, $expected);
|
|
|
7639 |
}
|
|
|
7640 |
|
|
|
7641 |
/**
|
|
|
7642 |
* Test the onsubmit option for create()
|
|
|
7643 |
*
|
|
|
7644 |
* @return void
|
|
|
7645 |
*/
|
|
|
7646 |
public function testCreateOnSubmit() {
|
|
|
7647 |
$this->Form->request->data = array();
|
|
|
7648 |
$this->Form->request['controller'] = 'contacts';
|
|
|
7649 |
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
|
|
7650 |
$result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
|
|
|
7651 |
$expected = array(
|
|
|
7652 |
'form' => array(
|
|
|
7653 |
'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
|
|
|
7654 |
'accept-charset' => 'utf-8'
|
|
|
7655 |
),
|
|
|
7656 |
'div' => array('style' => 'display:none;'),
|
|
|
7657 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7658 |
'/div'
|
|
|
7659 |
);
|
|
|
7660 |
$this->assertTags($result, $expected);
|
|
|
7661 |
|
|
|
7662 |
$this->Form->request->data = array();
|
|
|
7663 |
$this->Form->request['controller'] = 'contacts';
|
|
|
7664 |
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
|
|
7665 |
$result = $this->Form->create(array(
|
|
|
7666 |
'url' => array('action' => 'index', 'param'),
|
|
|
7667 |
'default' => false,
|
|
|
7668 |
'onsubmit' => 'someFunction();'
|
|
|
7669 |
));
|
|
|
7670 |
|
|
|
7671 |
$expected = array(
|
|
|
7672 |
'form' => array(
|
|
|
7673 |
'id' => 'ContactAddForm', 'method' => 'post',
|
|
|
7674 |
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
|
|
|
7675 |
'action' => '/contacts/index/param',
|
|
|
7676 |
'accept-charset' => 'utf-8'
|
|
|
7677 |
),
|
|
|
7678 |
'div' => array('style' => 'display:none;'),
|
|
|
7679 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7680 |
'/div'
|
|
|
7681 |
);
|
|
|
7682 |
$this->assertTags($result, $expected);
|
|
|
7683 |
}
|
|
|
7684 |
|
|
|
7685 |
/**
|
|
|
7686 |
* test create() with automatic url generation
|
|
|
7687 |
*
|
|
|
7688 |
* @return void
|
|
|
7689 |
*/
|
|
|
7690 |
public function testCreateAutoUrl() {
|
|
|
7691 |
Router::setRequestInfo(array(array(), array('base' => '/base_url')));
|
|
|
7692 |
$this->Form->request->here = '/base_url/contacts/add/Contact:1';
|
|
|
7693 |
$this->Form->request->base = '/base_url';
|
|
|
7694 |
$result = $this->Form->create('Contact');
|
|
|
7695 |
$expected = array(
|
|
|
7696 |
'form' => array(
|
|
|
7697 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/base_url/contacts/add/Contact:1',
|
|
|
7698 |
'accept-charset' => 'utf-8'
|
|
|
7699 |
),
|
|
|
7700 |
'div' => array('style' => 'display:none;'),
|
|
|
7701 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7702 |
'/div'
|
|
|
7703 |
);
|
|
|
7704 |
$this->assertTags($result, $expected);
|
|
|
7705 |
|
|
|
7706 |
$this->Form->request['action'] = 'delete';
|
|
|
7707 |
$this->Form->request->here = '/base_url/contacts/delete/10/User:42';
|
|
|
7708 |
$this->Form->request->base = '/base_url';
|
|
|
7709 |
$result = $this->Form->create('Contact');
|
|
|
7710 |
$expected = array(
|
|
|
7711 |
'form' => array(
|
|
|
7712 |
'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/base_url/contacts/delete/10/User:42',
|
|
|
7713 |
'accept-charset' => 'utf-8'
|
|
|
7714 |
),
|
|
|
7715 |
'div' => array('style' => 'display:none;'),
|
|
|
7716 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7717 |
'/div'
|
|
|
7718 |
);
|
|
|
7719 |
$this->assertTags($result, $expected);
|
|
|
7720 |
}
|
|
|
7721 |
|
|
|
7722 |
/**
|
|
|
7723 |
* test create() with a custom route
|
|
|
7724 |
*
|
|
|
7725 |
* @return void
|
|
|
7726 |
*/
|
|
|
7727 |
public function testCreateCustomRoute() {
|
|
|
7728 |
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
|
|
|
7729 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7730 |
|
|
|
7731 |
$result = $this->Form->create('User', array('action' => 'login'));
|
|
|
7732 |
$expected = array(
|
|
|
7733 |
'form' => array(
|
|
|
7734 |
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
|
|
|
7735 |
'accept-charset' => $encoding
|
|
|
7736 |
),
|
|
|
7737 |
'div' => array('style' => 'display:none;'),
|
|
|
7738 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7739 |
'/div'
|
|
|
7740 |
);
|
|
|
7741 |
$this->assertTags($result, $expected);
|
|
|
7742 |
}
|
|
|
7743 |
|
|
|
7744 |
/**
|
|
|
7745 |
* test that inputDefaults are stored and used.
|
|
|
7746 |
*
|
|
|
7747 |
* @return void
|
|
|
7748 |
*/
|
|
|
7749 |
public function testCreateWithInputDefaults() {
|
|
|
7750 |
$this->Form->create('User', array(
|
|
|
7751 |
'inputDefaults' => array(
|
|
|
7752 |
'div' => false,
|
|
|
7753 |
'label' => false,
|
|
|
7754 |
'error' => array('attributes' => array('wrap' => 'small', 'class' => 'error')),
|
|
|
7755 |
'format' => array('before', 'label', 'between', 'input', 'after', 'error')
|
|
|
7756 |
)
|
|
|
7757 |
));
|
|
|
7758 |
$result = $this->Form->input('username');
|
|
|
7759 |
$expected = array(
|
|
|
7760 |
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
|
|
|
7761 |
);
|
|
|
7762 |
$this->assertTags($result, $expected);
|
|
|
7763 |
|
|
|
7764 |
$result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
|
|
|
7765 |
$expected = array(
|
|
|
7766 |
'div' => array('class' => 'input text'),
|
|
|
7767 |
'label' => array('for' => 'UserUsername'), 'username', '/label',
|
|
|
7768 |
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
|
|
7769 |
'/div'
|
|
|
7770 |
);
|
|
|
7771 |
$this->assertTags($result, $expected);
|
|
|
7772 |
|
|
|
7773 |
$result = $this->Form->input('username', array('label' => 'Username', 'format' => array('input', 'label')));
|
|
|
7774 |
$expected = array(
|
|
|
7775 |
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
|
|
7776 |
'label' => array('for' => 'UserUsername'), 'Username', '/label',
|
|
|
7777 |
);
|
|
|
7778 |
$this->assertTags($result, $expected);
|
|
|
7779 |
|
|
|
7780 |
$this->Form->create('User', array(
|
|
|
7781 |
'inputDefaults' => array(
|
|
|
7782 |
'div' => false,
|
|
|
7783 |
'label' => array('class' => 'nice', 'for' => 'changed'),
|
|
|
7784 |
)
|
|
|
7785 |
));
|
|
|
7786 |
$result = $this->Form->input('username', array('div' => true));
|
|
|
7787 |
$expected = array(
|
|
|
7788 |
'div' => array('class' => 'input text'),
|
|
|
7789 |
'label' => array('for' => 'changed', 'class' => 'nice'), 'Username', '/label',
|
|
|
7790 |
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
|
|
7791 |
'/div'
|
|
|
7792 |
);
|
|
|
7793 |
$this->assertTags($result, $expected);
|
|
|
7794 |
}
|
|
|
7795 |
|
|
|
7796 |
/**
|
|
|
7797 |
* test automatic accept-charset overriding
|
|
|
7798 |
*
|
|
|
7799 |
* @return void
|
|
|
7800 |
*/
|
|
|
7801 |
public function testCreateWithAcceptCharset() {
|
|
|
7802 |
$result = $this->Form->create('UserForm', array(
|
|
|
7803 |
'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
|
|
|
7804 |
)
|
|
|
7805 |
);
|
|
|
7806 |
$expected = array(
|
|
|
7807 |
'form' => array(
|
|
|
7808 |
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
|
|
|
7809 |
'accept-charset' => 'iso-8859-1'
|
|
|
7810 |
),
|
|
|
7811 |
'div' => array('style' => 'display:none;'),
|
|
|
7812 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7813 |
'/div'
|
|
|
7814 |
);
|
|
|
7815 |
$this->assertTags($result, $expected);
|
|
|
7816 |
}
|
|
|
7817 |
|
|
|
7818 |
/**
|
|
|
7819 |
* Test base form URL when url param is passed with multiple parameters (&)
|
|
|
7820 |
*
|
|
|
7821 |
*/
|
|
|
7822 |
public function testCreateQuerystringrequest() {
|
|
|
7823 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7824 |
$result = $this->Form->create('Contact', array(
|
|
|
7825 |
'type' => 'post',
|
|
|
7826 |
'escape' => false,
|
|
|
7827 |
'url' => array(
|
|
|
7828 |
'controller' => 'controller',
|
|
|
7829 |
'action' => 'action',
|
|
|
7830 |
'?' => array('param1' => 'value1', 'param2' => 'value2')
|
|
|
7831 |
)
|
|
|
7832 |
));
|
|
|
7833 |
$expected = array(
|
|
|
7834 |
'form' => array(
|
|
|
7835 |
'id' => 'ContactAddForm',
|
|
|
7836 |
'method' => 'post',
|
|
|
7837 |
'action' => '/controller/action?param1=value1&param2=value2',
|
|
|
7838 |
'accept-charset' => $encoding
|
|
|
7839 |
),
|
|
|
7840 |
'div' => array('style' => 'display:none;'),
|
|
|
7841 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7842 |
'/div'
|
|
|
7843 |
);
|
|
|
7844 |
$this->assertTags($result, $expected);
|
|
|
7845 |
|
|
|
7846 |
$result = $this->Form->create('Contact', array(
|
|
|
7847 |
'type' => 'post',
|
|
|
7848 |
'url' => array(
|
|
|
7849 |
'controller' => 'controller',
|
|
|
7850 |
'action' => 'action',
|
|
|
7851 |
'?' => array('param1' => 'value1', 'param2' => 'value2')
|
|
|
7852 |
)
|
|
|
7853 |
));
|
|
|
7854 |
$expected = array(
|
|
|
7855 |
'form' => array(
|
|
|
7856 |
'id' => 'ContactAddForm',
|
|
|
7857 |
'method' => 'post',
|
|
|
7858 |
'action' => '/controller/action?param1=value1&param2=value2',
|
|
|
7859 |
'accept-charset' => $encoding
|
|
|
7860 |
),
|
|
|
7861 |
'div' => array('style' => 'display:none;'),
|
|
|
7862 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7863 |
'/div'
|
|
|
7864 |
);
|
|
|
7865 |
$this->assertTags($result, $expected);
|
|
|
7866 |
}
|
|
|
7867 |
|
|
|
7868 |
/**
|
|
|
7869 |
* test that create() doesn't cause errors by multiple id's being in the primary key
|
|
|
7870 |
* as could happen with multiple select or checkboxes.
|
|
|
7871 |
*
|
|
|
7872 |
* @return void
|
|
|
7873 |
*/
|
|
|
7874 |
public function testCreateWithMultipleIdInData() {
|
|
|
7875 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7876 |
|
|
|
7877 |
$this->Form->request->data['Contact']['id'] = array(1, 2);
|
|
|
7878 |
$result = $this->Form->create('Contact');
|
|
|
7879 |
$expected = array(
|
|
|
7880 |
'form' => array(
|
|
|
7881 |
'id' => 'ContactAddForm',
|
|
|
7882 |
'method' => 'post',
|
|
|
7883 |
'action' => '/contacts/add',
|
|
|
7884 |
'accept-charset' => $encoding
|
|
|
7885 |
),
|
|
|
7886 |
'div' => array('style' => 'display:none;'),
|
|
|
7887 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7888 |
'/div'
|
|
|
7889 |
);
|
|
|
7890 |
$this->assertTags($result, $expected);
|
|
|
7891 |
}
|
|
|
7892 |
|
|
|
7893 |
/**
|
|
|
7894 |
* test that create() doesn't add in extra passed params.
|
|
|
7895 |
*
|
|
|
7896 |
* @return void
|
|
|
7897 |
*/
|
|
|
7898 |
public function testCreatePassedArgs() {
|
|
|
7899 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7900 |
$this->Form->request->data['Contact']['id'] = 1;
|
|
|
7901 |
$result = $this->Form->create('Contact', array(
|
|
|
7902 |
'type' => 'post',
|
|
|
7903 |
'escape' => false,
|
|
|
7904 |
'url' => array(
|
|
|
7905 |
'action' => 'edit',
|
|
|
7906 |
'myparam'
|
|
|
7907 |
)
|
|
|
7908 |
));
|
|
|
7909 |
$expected = array(
|
|
|
7910 |
'form' => array(
|
|
|
7911 |
'id' => 'ContactAddForm',
|
|
|
7912 |
'method' => 'post',
|
|
|
7913 |
'action' => '/contacts/edit/myparam',
|
|
|
7914 |
'accept-charset' => $encoding
|
|
|
7915 |
),
|
|
|
7916 |
'div' => array('style' => 'display:none;'),
|
|
|
7917 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
7918 |
'/div'
|
|
|
7919 |
);
|
|
|
7920 |
$this->assertTags($result, $expected);
|
|
|
7921 |
}
|
|
|
7922 |
|
|
|
7923 |
/**
|
|
|
7924 |
* test creating a get form, and get form inputs.
|
|
|
7925 |
*
|
|
|
7926 |
* @return void
|
|
|
7927 |
*/
|
|
|
7928 |
public function testGetFormCreate() {
|
|
|
7929 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7930 |
$result = $this->Form->create('Contact', array('type' => 'get'));
|
|
|
7931 |
$this->assertTags($result, array('form' => array(
|
|
|
7932 |
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
|
|
7933 |
'accept-charset' => $encoding
|
|
|
7934 |
)));
|
|
|
7935 |
|
|
|
7936 |
$result = $this->Form->text('Contact.name');
|
|
|
7937 |
$this->assertTags($result, array('input' => array(
|
|
|
7938 |
'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
|
|
|
7939 |
)));
|
|
|
7940 |
|
|
|
7941 |
$result = $this->Form->password('password');
|
|
|
7942 |
$this->assertTags($result, array('input' => array(
|
|
|
7943 |
'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
|
|
|
7944 |
)));
|
|
|
7945 |
$this->assertNotRegExp('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
|
|
|
7946 |
|
|
|
7947 |
$result = $this->Form->text('user_form');
|
|
|
7948 |
$this->assertTags($result, array('input' => array(
|
|
|
7949 |
'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
|
|
|
7950 |
)));
|
|
|
7951 |
}
|
|
|
7952 |
|
|
|
7953 |
/**
|
|
|
7954 |
* test get form, and inputs when the model param is false
|
|
|
7955 |
*
|
|
|
7956 |
* @return void
|
|
|
7957 |
*/
|
|
|
7958 |
public function testGetFormWithFalseModel() {
|
|
|
7959 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
7960 |
$this->Form->request['controller'] = 'contact_test';
|
|
|
7961 |
$result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
|
|
|
7962 |
|
|
|
7963 |
$expected = array('form' => array(
|
|
|
7964 |
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
|
|
|
7965 |
'accept-charset' => $encoding
|
|
|
7966 |
));
|
|
|
7967 |
$this->assertTags($result, $expected);
|
|
|
7968 |
|
|
|
7969 |
$result = $this->Form->text('reason');
|
|
|
7970 |
$expected = array(
|
|
|
7971 |
'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
|
|
|
7972 |
);
|
|
|
7973 |
$this->assertTags($result, $expected);
|
|
|
7974 |
}
|
|
|
7975 |
|
|
|
7976 |
/**
|
|
|
7977 |
* test that datetime() works with GET style forms.
|
|
|
7978 |
*
|
|
|
7979 |
* @return void
|
|
|
7980 |
*/
|
|
|
7981 |
public function testDateTimeWithGetForms() {
|
|
|
7982 |
extract($this->dateRegex);
|
|
|
7983 |
$this->Form->create('Contact', array('type' => 'get'));
|
|
|
7984 |
$result = $this->Form->datetime('created');
|
|
|
7985 |
|
|
|
7986 |
$this->assertRegExp('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
|
|
|
7987 |
$this->assertRegExp('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
|
|
|
7988 |
$this->assertRegExp('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
|
|
|
7989 |
$this->assertRegExp('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
|
|
|
7990 |
$this->assertRegExp('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
|
|
|
7991 |
$this->assertRegExp('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
|
|
|
7992 |
}
|
|
|
7993 |
|
|
|
7994 |
/**
|
|
|
7995 |
* testEditFormWithData method
|
|
|
7996 |
*
|
|
|
7997 |
* test auto populating form elements from submitted data.
|
|
|
7998 |
*
|
|
|
7999 |
* @return void
|
|
|
8000 |
*/
|
|
|
8001 |
public function testEditFormWithData() {
|
|
|
8002 |
$this->Form->request->data = array('Person' => array(
|
|
|
8003 |
'id' => 1,
|
|
|
8004 |
'first_name' => 'Nate',
|
|
|
8005 |
'last_name' => 'Abele',
|
|
|
8006 |
'email' => 'nate@example.com'
|
|
|
8007 |
));
|
|
|
8008 |
$this->Form->request->addParams(array(
|
|
|
8009 |
'models' => array('Person'),
|
|
|
8010 |
'controller' => 'people',
|
|
|
8011 |
'action' => 'add'
|
|
|
8012 |
));
|
|
|
8013 |
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
|
|
|
8014 |
|
|
|
8015 |
$this->Form->create();
|
|
|
8016 |
$result = $this->Form->select('People.People', $options, array('multiple' => true));
|
|
|
8017 |
$expected = array(
|
|
|
8018 |
'input' => array('type' => 'hidden', 'name' => 'data[People][People]', 'value' => '', 'id' => 'PeoplePeople_'),
|
|
|
8019 |
'select' => array(
|
|
|
8020 |
'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
|
|
|
8021 |
),
|
|
|
8022 |
array('option' => array('value' => 1)), 'Nate', '/option',
|
|
|
8023 |
array('option' => array('value' => 2)), 'Garrett', '/option',
|
|
|
8024 |
array('option' => array('value' => 3)), 'Larry', '/option',
|
|
|
8025 |
'/select'
|
|
|
8026 |
);
|
|
|
8027 |
$this->assertTags($result, $expected);
|
|
|
8028 |
}
|
|
|
8029 |
|
|
|
8030 |
/**
|
|
|
8031 |
* Test that required fields are created for various types of validation.
|
|
|
8032 |
*
|
|
|
8033 |
* @return void
|
|
|
8034 |
*/
|
|
|
8035 |
public function testFormInputRequiredDetection() {
|
|
|
8036 |
$this->Form->create('Contact');
|
|
|
8037 |
|
|
|
8038 |
$result = $this->Form->input('Contact.non_existing');
|
|
|
8039 |
$expected = array(
|
|
|
8040 |
'div' => array('class' => 'input text'),
|
|
|
8041 |
'label' => array('for' => 'ContactNonExisting'),
|
|
|
8042 |
'Non Existing',
|
|
|
8043 |
'/label',
|
|
|
8044 |
'input' => array(
|
|
|
8045 |
'type' => 'text', 'name' => 'data[Contact][non_existing]',
|
|
|
8046 |
'id' => 'ContactNonExisting'
|
|
|
8047 |
),
|
|
|
8048 |
'/div'
|
|
|
8049 |
);
|
|
|
8050 |
$this->assertTags($result, $expected);
|
|
|
8051 |
|
|
|
8052 |
$result = $this->Form->input('Contact.imrequired');
|
|
|
8053 |
$expected = array(
|
|
|
8054 |
'div' => array('class' => 'input text required'),
|
|
|
8055 |
'label' => array('for' => 'ContactImrequired'),
|
|
|
8056 |
'Imrequired',
|
|
|
8057 |
'/label',
|
|
|
8058 |
'input' => array(
|
|
|
8059 |
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
8060 |
'id' => 'ContactImrequired',
|
|
|
8061 |
'required' => 'required'
|
|
|
8062 |
),
|
|
|
8063 |
'/div'
|
|
|
8064 |
);
|
|
|
8065 |
$this->assertTags($result, $expected);
|
|
|
8066 |
|
|
|
8067 |
$result = $this->Form->input('Contact.imalsorequired');
|
|
|
8068 |
$expected = array(
|
|
|
8069 |
'div' => array('class' => 'input text required'),
|
|
|
8070 |
'label' => array('for' => 'ContactImalsorequired'),
|
|
|
8071 |
'Imalsorequired',
|
|
|
8072 |
'/label',
|
|
|
8073 |
'input' => array(
|
|
|
8074 |
'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
|
|
|
8075 |
'id' => 'ContactImalsorequired',
|
|
|
8076 |
'required' => 'required'
|
|
|
8077 |
),
|
|
|
8078 |
'/div'
|
|
|
8079 |
);
|
|
|
8080 |
$this->assertTags($result, $expected);
|
|
|
8081 |
|
|
|
8082 |
$result = $this->Form->input('Contact.imrequiredtoo');
|
|
|
8083 |
$expected = array(
|
|
|
8084 |
'div' => array('class' => 'input text required'),
|
|
|
8085 |
'label' => array('for' => 'ContactImrequiredtoo'),
|
|
|
8086 |
'Imrequiredtoo',
|
|
|
8087 |
'/label',
|
|
|
8088 |
'input' => array(
|
|
|
8089 |
'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
|
|
|
8090 |
'id' => 'ContactImrequiredtoo',
|
|
|
8091 |
'required' => 'required'
|
|
|
8092 |
),
|
|
|
8093 |
'/div'
|
|
|
8094 |
);
|
|
|
8095 |
$this->assertTags($result, $expected);
|
|
|
8096 |
|
|
|
8097 |
$result = $this->Form->input('Contact.required_one');
|
|
|
8098 |
$expected = array(
|
|
|
8099 |
'div' => array('class' => 'input text required'),
|
|
|
8100 |
'label' => array('for' => 'ContactRequiredOne'),
|
|
|
8101 |
'Required One',
|
|
|
8102 |
'/label',
|
|
|
8103 |
'input' => array(
|
|
|
8104 |
'type' => 'text', 'name' => 'data[Contact][required_one]',
|
|
|
8105 |
'id' => 'ContactRequiredOne',
|
|
|
8106 |
'required' => 'required'
|
|
|
8107 |
),
|
|
|
8108 |
'/div'
|
|
|
8109 |
);
|
|
|
8110 |
$this->assertTags($result, $expected);
|
|
|
8111 |
|
|
|
8112 |
$result = $this->Form->input('Contact.string_required');
|
|
|
8113 |
$expected = array(
|
|
|
8114 |
'div' => array('class' => 'input text required'),
|
|
|
8115 |
'label' => array('for' => 'ContactStringRequired'),
|
|
|
8116 |
'String Required',
|
|
|
8117 |
'/label',
|
|
|
8118 |
'input' => array(
|
|
|
8119 |
'type' => 'text', 'name' => 'data[Contact][string_required]',
|
|
|
8120 |
'id' => 'ContactStringRequired',
|
|
|
8121 |
'required' => 'required'
|
|
|
8122 |
),
|
|
|
8123 |
'/div'
|
|
|
8124 |
);
|
|
|
8125 |
$this->assertTags($result, $expected);
|
|
|
8126 |
|
|
|
8127 |
$result = $this->Form->input('Contact.imnotrequired');
|
|
|
8128 |
$expected = array(
|
|
|
8129 |
'div' => array('class' => 'input text'),
|
|
|
8130 |
'label' => array('for' => 'ContactImnotrequired'),
|
|
|
8131 |
'Imnotrequired',
|
|
|
8132 |
'/label',
|
|
|
8133 |
'input' => array(
|
|
|
8134 |
'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
|
|
|
8135 |
'id' => 'ContactImnotrequired'
|
|
|
8136 |
),
|
|
|
8137 |
'/div'
|
|
|
8138 |
);
|
|
|
8139 |
$this->assertTags($result, $expected);
|
|
|
8140 |
|
|
|
8141 |
$result = $this->Form->input('Contact.imalsonotrequired');
|
|
|
8142 |
$expected = array(
|
|
|
8143 |
'div' => array('class' => 'input text'),
|
|
|
8144 |
'label' => array('for' => 'ContactImalsonotrequired'),
|
|
|
8145 |
'Imalsonotrequired',
|
|
|
8146 |
'/label',
|
|
|
8147 |
'input' => array(
|
|
|
8148 |
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
|
|
|
8149 |
'id' => 'ContactImalsonotrequired'
|
|
|
8150 |
),
|
|
|
8151 |
'/div'
|
|
|
8152 |
);
|
|
|
8153 |
$this->assertTags($result, $expected);
|
|
|
8154 |
|
|
|
8155 |
$result = $this->Form->input('Contact.imalsonotrequired2');
|
|
|
8156 |
$expected = array(
|
|
|
8157 |
'div' => array('class' => 'input text'),
|
|
|
8158 |
'label' => array('for' => 'ContactImalsonotrequired2'),
|
|
|
8159 |
'Imalsonotrequired2',
|
|
|
8160 |
'/label',
|
|
|
8161 |
'input' => array(
|
|
|
8162 |
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired2]',
|
|
|
8163 |
'id' => 'ContactImalsonotrequired2'
|
|
|
8164 |
),
|
|
|
8165 |
'/div'
|
|
|
8166 |
);
|
|
|
8167 |
$this->assertTags($result, $expected);
|
|
|
8168 |
|
|
|
8169 |
$result = $this->Form->input('Contact.imnotrequiredeither');
|
|
|
8170 |
$expected = array(
|
|
|
8171 |
'div' => array('class' => 'input text'),
|
|
|
8172 |
'label' => array('for' => 'ContactImnotrequiredeither'),
|
|
|
8173 |
'Imnotrequiredeither',
|
|
|
8174 |
'/label',
|
|
|
8175 |
'input' => array(
|
|
|
8176 |
'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
|
|
|
8177 |
'id' => 'ContactImnotrequiredeither'
|
|
|
8178 |
),
|
|
|
8179 |
'/div'
|
|
|
8180 |
);
|
|
|
8181 |
$this->assertTags($result, $expected);
|
|
|
8182 |
|
|
|
8183 |
$result = $this->Form->input('Contact.iamrequiredalways');
|
|
|
8184 |
$expected = array(
|
|
|
8185 |
'div' => array('class' => 'input text required'),
|
|
|
8186 |
'label' => array('for' => 'ContactIamrequiredalways'),
|
|
|
8187 |
'Iamrequiredalways',
|
|
|
8188 |
'/label',
|
|
|
8189 |
'input' => array(
|
|
|
8190 |
'type' => 'text', 'name' => 'data[Contact][iamrequiredalways]',
|
|
|
8191 |
'id' => 'ContactIamrequiredalways',
|
|
|
8192 |
'required' => 'required'
|
|
|
8193 |
),
|
|
|
8194 |
'/div'
|
|
|
8195 |
);
|
|
|
8196 |
$this->assertTags($result, $expected);
|
|
|
8197 |
|
|
|
8198 |
$result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
|
|
|
8199 |
$expected = array(
|
|
|
8200 |
'div' => array('class' => 'input checkbox required'),
|
|
|
8201 |
array('input' => array(
|
|
|
8202 |
'type' => 'hidden',
|
|
|
8203 |
'name' => 'data[Contact][boolean_field]',
|
|
|
8204 |
'id' => 'ContactBooleanField_',
|
|
|
8205 |
'value' => '0'
|
|
|
8206 |
)),
|
|
|
8207 |
array('input' => array(
|
|
|
8208 |
'type' => 'checkbox',
|
|
|
8209 |
'name' => 'data[Contact][boolean_field]',
|
|
|
8210 |
'value' => '1',
|
|
|
8211 |
'id' => 'ContactBooleanField'
|
|
|
8212 |
)),
|
|
|
8213 |
'label' => array('for' => 'ContactBooleanField'),
|
|
|
8214 |
'Boolean Field',
|
|
|
8215 |
'/label',
|
|
|
8216 |
'/div'
|
|
|
8217 |
);
|
|
|
8218 |
$this->assertTags($result, $expected);
|
|
|
8219 |
|
|
|
8220 |
$result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
|
|
|
8221 |
$expected = array(
|
|
|
8222 |
'div' => array('class' => 'input checkbox required'),
|
|
|
8223 |
array('input' => array(
|
|
|
8224 |
'type' => 'hidden',
|
|
|
8225 |
'name' => 'data[Contact][boolean_field]',
|
|
|
8226 |
'id' => 'ContactBooleanField_',
|
|
|
8227 |
'value' => '0'
|
|
|
8228 |
)),
|
|
|
8229 |
array('input' => array(
|
|
|
8230 |
'type' => 'checkbox',
|
|
|
8231 |
'name' => 'data[Contact][boolean_field]',
|
|
|
8232 |
'value' => '1',
|
|
|
8233 |
'id' => 'ContactBooleanField',
|
|
|
8234 |
'required' => 'required'
|
|
|
8235 |
)),
|
|
|
8236 |
'label' => array('for' => 'ContactBooleanField'),
|
|
|
8237 |
'Boolean Field',
|
|
|
8238 |
'/label',
|
|
|
8239 |
'/div'
|
|
|
8240 |
);
|
|
|
8241 |
$this->assertTags($result, $expected);
|
|
|
8242 |
|
|
|
8243 |
$result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
|
|
|
8244 |
$expected = array(
|
|
|
8245 |
'div' => array('class' => 'input file required'),
|
|
|
8246 |
'label' => array('for' => 'ContactIamrequiredalways'),
|
|
|
8247 |
'Iamrequiredalways',
|
|
|
8248 |
'/label',
|
|
|
8249 |
'input' => array(
|
|
|
8250 |
'type' => 'file',
|
|
|
8251 |
'name' => 'data[Contact][iamrequiredalways]',
|
|
|
8252 |
'id' => 'ContactIamrequiredalways',
|
|
|
8253 |
'required' => 'required'
|
|
|
8254 |
),
|
|
|
8255 |
'/div'
|
|
|
8256 |
);
|
|
|
8257 |
$this->assertTags($result, $expected);
|
|
|
8258 |
}
|
|
|
8259 |
|
|
|
8260 |
/**
|
|
|
8261 |
* Test that required fields are created when only using ModelValidator::add().
|
|
|
8262 |
*
|
|
|
8263 |
* @return void
|
|
|
8264 |
*/
|
|
|
8265 |
public function testFormInputRequiredDetectionModelValidator() {
|
|
|
8266 |
ClassRegistry::getObject('ContactTag')->validator()->add('iwillberequired', 'required', array('rule' => 'notEmpty'));
|
|
|
8267 |
|
|
|
8268 |
$this->Form->create('ContactTag');
|
|
|
8269 |
$result = $this->Form->input('ContactTag.iwillberequired');
|
|
|
8270 |
$expected = array(
|
|
|
8271 |
'div' => array('class' => 'input text required'),
|
|
|
8272 |
'label' => array('for' => 'ContactTagIwillberequired'),
|
|
|
8273 |
'Iwillberequired',
|
|
|
8274 |
'/label',
|
|
|
8275 |
'input' => array(
|
|
|
8276 |
'name' => 'data[ContactTag][iwillberequired]',
|
|
|
8277 |
'type' => 'text',
|
|
|
8278 |
'id' => 'ContactTagIwillberequired',
|
|
|
8279 |
'required' => 'required'
|
|
|
8280 |
),
|
|
|
8281 |
'/div'
|
|
|
8282 |
);
|
|
|
8283 |
$this->assertTags($result, $expected);
|
|
|
8284 |
}
|
|
|
8285 |
|
|
|
8286 |
/**
|
|
|
8287 |
* testFormMagicInput method
|
|
|
8288 |
*
|
|
|
8289 |
* @return void
|
|
|
8290 |
*/
|
|
|
8291 |
public function testFormMagicInput() {
|
|
|
8292 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
8293 |
$result = $this->Form->create('Contact');
|
|
|
8294 |
$expected = array(
|
|
|
8295 |
'form' => array(
|
|
|
8296 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
8297 |
'accept-charset' => $encoding
|
|
|
8298 |
),
|
|
|
8299 |
'div' => array('style' => 'display:none;'),
|
|
|
8300 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
8301 |
'/div'
|
|
|
8302 |
);
|
|
|
8303 |
$this->assertTags($result, $expected);
|
|
|
8304 |
|
|
|
8305 |
$result = $this->Form->input('name');
|
|
|
8306 |
$expected = array(
|
|
|
8307 |
'div' => array('class' => 'input text'),
|
|
|
8308 |
'label' => array('for' => 'ContactName'),
|
|
|
8309 |
'Name',
|
|
|
8310 |
'/label',
|
|
|
8311 |
'input' => array(
|
|
|
8312 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8313 |
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
8314 |
),
|
|
|
8315 |
'/div'
|
|
|
8316 |
);
|
|
|
8317 |
$this->assertTags($result, $expected);
|
|
|
8318 |
|
|
|
8319 |
$result = $this->Form->input('non_existing_field_in_contact_model');
|
|
|
8320 |
$expected = array(
|
|
|
8321 |
'div' => array('class' => 'input text'),
|
|
|
8322 |
'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
|
|
|
8323 |
'Non Existing Field In Contact Model',
|
|
|
8324 |
'/label',
|
|
|
8325 |
'input' => array(
|
|
|
8326 |
'type' => 'text', 'name' => 'data[Contact][non_existing_field_in_contact_model]',
|
|
|
8327 |
'id' => 'ContactNonExistingFieldInContactModel'
|
|
|
8328 |
),
|
|
|
8329 |
'/div'
|
|
|
8330 |
);
|
|
|
8331 |
$this->assertTags($result, $expected);
|
|
|
8332 |
|
|
|
8333 |
$result = $this->Form->input('Address.street');
|
|
|
8334 |
$expected = array(
|
|
|
8335 |
'div' => array('class' => 'input text'),
|
|
|
8336 |
'label' => array('for' => 'AddressStreet'),
|
|
|
8337 |
'Street',
|
|
|
8338 |
'/label',
|
|
|
8339 |
'input' => array(
|
|
|
8340 |
'type' => 'text', 'name' => 'data[Address][street]',
|
|
|
8341 |
'id' => 'AddressStreet'
|
|
|
8342 |
),
|
|
|
8343 |
'/div'
|
|
|
8344 |
);
|
|
|
8345 |
$this->assertTags($result, $expected);
|
|
|
8346 |
|
|
|
8347 |
$result = $this->Form->input('Address.non_existing_field_in_model');
|
|
|
8348 |
$expected = array(
|
|
|
8349 |
'div' => array('class' => 'input text'),
|
|
|
8350 |
'label' => array('for' => 'AddressNonExistingFieldInModel'),
|
|
|
8351 |
'Non Existing Field In Model',
|
|
|
8352 |
'/label',
|
|
|
8353 |
'input' => array(
|
|
|
8354 |
'type' => 'text', 'name' => 'data[Address][non_existing_field_in_model]',
|
|
|
8355 |
'id' => 'AddressNonExistingFieldInModel'
|
|
|
8356 |
),
|
|
|
8357 |
'/div'
|
|
|
8358 |
);
|
|
|
8359 |
$this->assertTags($result, $expected);
|
|
|
8360 |
|
|
|
8361 |
$result = $this->Form->input('name', array('div' => false));
|
|
|
8362 |
$expected = array(
|
|
|
8363 |
'label' => array('for' => 'ContactName'),
|
|
|
8364 |
'Name',
|
|
|
8365 |
'/label',
|
|
|
8366 |
'input' => array(
|
|
|
8367 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8368 |
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
8369 |
)
|
|
|
8370 |
);
|
|
|
8371 |
$this->assertTags($result, $expected);
|
|
|
8372 |
|
|
|
8373 |
extract($this->dateRegex);
|
|
|
8374 |
$now = strtotime('now');
|
|
|
8375 |
|
|
|
8376 |
$result = $this->Form->input('Contact.published', array('div' => false));
|
|
|
8377 |
$expected = array(
|
|
|
8378 |
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
8379 |
'Published',
|
|
|
8380 |
'/label',
|
|
|
8381 |
array('select' => array(
|
|
|
8382 |
'name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth'
|
|
|
8383 |
)),
|
|
|
8384 |
$monthsRegex,
|
|
|
8385 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
8386 |
date('F', $now),
|
|
|
8387 |
'/option',
|
|
|
8388 |
'*/select',
|
|
|
8389 |
'-',
|
|
|
8390 |
array('select' => array(
|
|
|
8391 |
'name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay'
|
|
|
8392 |
)),
|
|
|
8393 |
$daysRegex,
|
|
|
8394 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
8395 |
date('j', $now),
|
|
|
8396 |
'/option',
|
|
|
8397 |
'*/select',
|
|
|
8398 |
'-',
|
|
|
8399 |
array('select' => array(
|
|
|
8400 |
'name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear'
|
|
|
8401 |
)),
|
|
|
8402 |
$yearsRegex,
|
|
|
8403 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
8404 |
date('Y', $now),
|
|
|
8405 |
'*/select'
|
|
|
8406 |
);
|
|
|
8407 |
$this->assertTags($result, $expected);
|
|
|
8408 |
|
|
|
8409 |
$result = $this->Form->input('Contact.updated', array('div' => false));
|
|
|
8410 |
$expected = array(
|
|
|
8411 |
'label' => array('for' => 'ContactUpdatedMonth'),
|
|
|
8412 |
'Updated',
|
|
|
8413 |
'/label',
|
|
|
8414 |
array('select' => array(
|
|
|
8415 |
'name' => 'data[Contact][updated][month]', 'id' => 'ContactUpdatedMonth'
|
|
|
8416 |
)),
|
|
|
8417 |
$monthsRegex,
|
|
|
8418 |
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
8419 |
date('F', $now),
|
|
|
8420 |
'/option',
|
|
|
8421 |
'*/select',
|
|
|
8422 |
'-',
|
|
|
8423 |
array('select' => array(
|
|
|
8424 |
'name' => 'data[Contact][updated][day]', 'id' => 'ContactUpdatedDay'
|
|
|
8425 |
)),
|
|
|
8426 |
$daysRegex,
|
|
|
8427 |
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
8428 |
date('j', $now),
|
|
|
8429 |
'/option',
|
|
|
8430 |
'*/select',
|
|
|
8431 |
'-',
|
|
|
8432 |
array('select' => array(
|
|
|
8433 |
'name' => 'data[Contact][updated][year]', 'id' => 'ContactUpdatedYear'
|
|
|
8434 |
)),
|
|
|
8435 |
$yearsRegex,
|
|
|
8436 |
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
8437 |
date('Y', $now),
|
|
|
8438 |
'*/select'
|
|
|
8439 |
);
|
|
|
8440 |
$this->assertTags($result, $expected);
|
|
|
8441 |
|
|
|
8442 |
$result = $this->Form->input('UserForm.stuff');
|
|
|
8443 |
$expected = array(
|
|
|
8444 |
'div' => array('class' => 'input text'),
|
|
|
8445 |
'label' => array('for' => 'UserFormStuff'),
|
|
|
8446 |
'Stuff',
|
|
|
8447 |
'/label',
|
|
|
8448 |
'input' => array(
|
|
|
8449 |
'type' => 'text', 'name' => 'data[UserForm][stuff]',
|
|
|
8450 |
'id' => 'UserFormStuff', 'maxlength' => 10
|
|
|
8451 |
),
|
|
|
8452 |
'/div'
|
|
|
8453 |
);
|
|
|
8454 |
$this->assertTags($result, $expected);
|
|
|
8455 |
}
|
|
|
8456 |
|
|
|
8457 |
/**
|
|
|
8458 |
* testForMagicInputNonExistingNorValidated method
|
|
|
8459 |
*
|
|
|
8460 |
* @return void
|
|
|
8461 |
*/
|
|
|
8462 |
public function testForMagicInputNonExistingNorValidated() {
|
|
|
8463 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
8464 |
$result = $this->Form->create('Contact');
|
|
|
8465 |
$expected = array(
|
|
|
8466 |
'form' => array(
|
|
|
8467 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
8468 |
'accept-charset' => $encoding
|
|
|
8469 |
),
|
|
|
8470 |
'div' => array('style' => 'display:none;'),
|
|
|
8471 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
8472 |
'/div'
|
|
|
8473 |
);
|
|
|
8474 |
$this->assertTags($result, $expected);
|
|
|
8475 |
|
|
|
8476 |
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
|
|
|
8477 |
$expected = array(
|
|
|
8478 |
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
8479 |
'Non Existing Nor Validated',
|
|
|
8480 |
'/label',
|
|
|
8481 |
'input' => array(
|
|
|
8482 |
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
|
|
8483 |
'id' => 'ContactNonExistingNorValidated'
|
|
|
8484 |
)
|
|
|
8485 |
);
|
|
|
8486 |
$this->assertTags($result, $expected);
|
|
|
8487 |
|
|
|
8488 |
$result = $this->Form->input('Contact.non_existing_nor_validated', array(
|
|
|
8489 |
'div' => false, 'value' => 'my value'
|
|
|
8490 |
));
|
|
|
8491 |
$expected = array(
|
|
|
8492 |
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
8493 |
'Non Existing Nor Validated',
|
|
|
8494 |
'/label',
|
|
|
8495 |
'input' => array(
|
|
|
8496 |
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
|
|
8497 |
'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
|
|
|
8498 |
)
|
|
|
8499 |
);
|
|
|
8500 |
$this->assertTags($result, $expected);
|
|
|
8501 |
|
|
|
8502 |
$this->Form->request->data = array(
|
|
|
8503 |
'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
|
|
|
8504 |
));
|
|
|
8505 |
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
|
|
|
8506 |
$expected = array(
|
|
|
8507 |
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
8508 |
'Non Existing Nor Validated',
|
|
|
8509 |
'/label',
|
|
|
8510 |
'input' => array(
|
|
|
8511 |
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
|
|
8512 |
'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
|
|
|
8513 |
)
|
|
|
8514 |
);
|
|
|
8515 |
$this->assertTags($result, $expected);
|
|
|
8516 |
}
|
|
|
8517 |
|
|
|
8518 |
/**
|
|
|
8519 |
* testFormMagicInputLabel method
|
|
|
8520 |
*
|
|
|
8521 |
* @return void
|
|
|
8522 |
*/
|
|
|
8523 |
public function testFormMagicInputLabel() {
|
|
|
8524 |
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
8525 |
$result = $this->Form->create('Contact');
|
|
|
8526 |
$expected = array(
|
|
|
8527 |
'form' => array(
|
|
|
8528 |
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
8529 |
'accept-charset' => $encoding
|
|
|
8530 |
),
|
|
|
8531 |
'div' => array('style' => 'display:none;'),
|
|
|
8532 |
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
8533 |
'/div'
|
|
|
8534 |
);
|
|
|
8535 |
$this->assertTags($result, $expected);
|
|
|
8536 |
|
|
|
8537 |
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
|
|
|
8538 |
$this->assertTags($result, array('input' => array(
|
|
|
8539 |
'name' => 'data[Contact][name]', 'type' => 'text',
|
|
|
8540 |
'id' => 'ContactName', 'maxlength' => '255')
|
|
|
8541 |
));
|
|
|
8542 |
|
|
|
8543 |
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
|
|
|
8544 |
$expected = array(
|
|
|
8545 |
'label' => array('for' => 'ContactName'),
|
|
|
8546 |
'My label',
|
|
|
8547 |
'/label',
|
|
|
8548 |
'input' => array(
|
|
|
8549 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8550 |
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
8551 |
)
|
|
|
8552 |
);
|
|
|
8553 |
$this->assertTags($result, $expected);
|
|
|
8554 |
|
|
|
8555 |
$result = $this->Form->input('Contact.name', array(
|
|
|
8556 |
'div' => false, 'label' => array('class' => 'mandatory')
|
|
|
8557 |
));
|
|
|
8558 |
$expected = array(
|
|
|
8559 |
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
|
|
|
8560 |
'Name',
|
|
|
8561 |
'/label',
|
|
|
8562 |
'input' => array(
|
|
|
8563 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8564 |
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
8565 |
)
|
|
|
8566 |
);
|
|
|
8567 |
$this->assertTags($result, $expected);
|
|
|
8568 |
|
|
|
8569 |
$result = $this->Form->input('Contact.name', array(
|
|
|
8570 |
'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
|
|
|
8571 |
));
|
|
|
8572 |
$expected = array(
|
|
|
8573 |
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
|
|
|
8574 |
'My label',
|
|
|
8575 |
'/label',
|
|
|
8576 |
'input' => array(
|
|
|
8577 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8578 |
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
8579 |
)
|
|
|
8580 |
);
|
|
|
8581 |
$this->assertTags($result, $expected);
|
|
|
8582 |
|
|
|
8583 |
$result = $this->Form->input('Contact.name', array(
|
|
|
8584 |
'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
|
|
|
8585 |
));
|
|
|
8586 |
$expected = array(
|
|
|
8587 |
'label' => array('for' => 'my_id'),
|
|
|
8588 |
'Name',
|
|
|
8589 |
'/label',
|
|
|
8590 |
'input' => array(
|
|
|
8591 |
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
8592 |
'id' => 'my_id', 'maxlength' => '255'
|
|
|
8593 |
)
|
|
|
8594 |
);
|
|
|
8595 |
$this->assertTags($result, $expected);
|
|
|
8596 |
|
|
|
8597 |
$result = $this->Form->input('1.id');
|
|
|
8598 |
$this->assertTags($result, array('input' => array(
|
|
|
8599 |
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
|
|
|
8600 |
'id' => 'Contact1Id'
|
|
|
8601 |
)));
|
|
|
8602 |
|
|
|
8603 |
$result = $this->Form->input("1.name");
|
|
|
8604 |
$expected = array(
|
|
|
8605 |
'div' => array('class' => 'input text'),
|
|
|
8606 |
'label' => array('for' => 'Contact1Name'),
|
|
|
8607 |
'Name',
|
|
|
8608 |
'/label',
|
|
|
8609 |
'input' => array(
|
|
|
8610 |
'type' => 'text', 'name' => 'data[Contact][1][name]',
|
|
|
8611 |
'id' => 'Contact1Name', 'maxlength' => '255'
|
|
|
8612 |
),
|
|
|
8613 |
'/div'
|
|
|
8614 |
);
|
|
|
8615 |
$this->assertTags($result, $expected);
|
|
|
8616 |
|
|
|
8617 |
$result = $this->Form->input('Contact.1.id');
|
|
|
8618 |
$this->assertTags($result, array(
|
|
|
8619 |
'input' => array(
|
|
|
8620 |
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
|
|
|
8621 |
'id' => 'Contact1Id'
|
|
|
8622 |
)
|
|
|
8623 |
));
|
|
|
8624 |
|
|
|
8625 |
$result = $this->Form->input("Model.1.name");
|
|
|
8626 |
$expected = array(
|
|
|
8627 |
'div' => array('class' => 'input text'),
|
|
|
8628 |
'label' => array('for' => 'Model1Name'),
|
|
|
8629 |
'Name',
|
|
|
8630 |
'/label',
|
|
|
8631 |
'input' => array(
|
|
|
8632 |
'type' => 'text', 'name' => 'data[Model][1][name]',
|
|
|
8633 |
'id' => 'Model1Name'
|
|
|
8634 |
),
|
|
|
8635 |
'/div'
|
|
|
8636 |
);
|
|
|
8637 |
$this->assertTags($result, $expected);
|
|
|
8638 |
}
|
|
|
8639 |
|
|
|
8640 |
/**
|
|
|
8641 |
* testFormEnd method
|
|
|
8642 |
*
|
|
|
8643 |
* @return void
|
|
|
8644 |
*/
|
|
|
8645 |
public function testFormEnd() {
|
|
|
8646 |
$this->assertEquals('</form>', $this->Form->end());
|
|
|
8647 |
|
|
|
8648 |
$result = $this->Form->end('');
|
|
|
8649 |
$expected = array(
|
|
|
8650 |
'div' => array('class' => 'submit'),
|
|
|
8651 |
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
8652 |
'/div',
|
|
|
8653 |
'/form'
|
|
|
8654 |
);
|
|
|
8655 |
$this->assertTags($result, $expected);
|
|
|
8656 |
|
|
|
8657 |
$result = $this->Form->end(array('label' => ''));
|
|
|
8658 |
$expected = array(
|
|
|
8659 |
'div' => array('class' => 'submit'),
|
|
|
8660 |
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
8661 |
'/div',
|
|
|
8662 |
'/form'
|
|
|
8663 |
);
|
|
|
8664 |
$this->assertTags($result, $expected);
|
|
|
8665 |
|
|
|
8666 |
$result = $this->Form->end('save');
|
|
|
8667 |
$expected = array(
|
|
|
8668 |
'div' => array('class' => 'submit'),
|
|
|
8669 |
'input' => array('type' => 'submit', 'value' => 'save'),
|
|
|
8670 |
'/div',
|
|
|
8671 |
'/form'
|
|
|
8672 |
);
|
|
|
8673 |
$this->assertTags($result, $expected);
|
|
|
8674 |
|
|
|
8675 |
$result = $this->Form->end(array('label' => 'save'));
|
|
|
8676 |
$expected = array(
|
|
|
8677 |
'div' => array('class' => 'submit'),
|
|
|
8678 |
'input' => array('type' => 'submit', 'value' => 'save'),
|
|
|
8679 |
'/div',
|
|
|
8680 |
'/form'
|
|
|
8681 |
);
|
|
|
8682 |
$this->assertTags($result, $expected);
|
|
|
8683 |
|
|
|
8684 |
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
|
|
|
8685 |
$expected = array(
|
|
|
8686 |
'div' => array('class' => 'submit'),
|
|
|
8687 |
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
8688 |
'/div',
|
|
|
8689 |
'/form'
|
|
|
8690 |
);
|
|
|
8691 |
$this->assertTags($result, $expected);
|
|
|
8692 |
|
|
|
8693 |
$result = $this->Form->end(array('name' => 'Whatever'));
|
|
|
8694 |
$expected = array(
|
|
|
8695 |
'div' => array('class' => 'submit'),
|
|
|
8696 |
'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
|
|
|
8697 |
'/div',
|
|
|
8698 |
'/form'
|
|
|
8699 |
);
|
|
|
8700 |
$this->assertTags($result, $expected);
|
|
|
8701 |
|
|
|
8702 |
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
|
|
|
8703 |
$expected = array(
|
|
|
8704 |
'div' => array('class' => 'good'),
|
|
|
8705 |
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
8706 |
'/div',
|
|
|
8707 |
'/form'
|
|
|
8708 |
);
|
|
|
8709 |
$this->assertTags($result, $expected);
|
|
|
8710 |
|
|
|
8711 |
$result = $this->Form->end(array(
|
|
|
8712 |
'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
|
|
|
8713 |
));
|
|
|
8714 |
$expected = array(
|
|
|
8715 |
'div' => array('class' => 'good'),
|
|
|
8716 |
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
8717 |
'/div',
|
|
|
8718 |
'/form'
|
|
|
8719 |
);
|
|
|
8720 |
$this->assertTags($result, $expected);
|
|
|
8721 |
}
|
|
|
8722 |
|
|
|
8723 |
/**
|
|
|
8724 |
* testMultipleFormWithIdFields method
|
|
|
8725 |
*
|
|
|
8726 |
* @return void
|
|
|
8727 |
*/
|
|
|
8728 |
public function testMultipleFormWithIdFields() {
|
|
|
8729 |
$this->Form->create('UserForm');
|
|
|
8730 |
|
|
|
8731 |
$result = $this->Form->input('id');
|
|
|
8732 |
$this->assertTags($result, array('input' => array(
|
|
|
8733 |
'type' => 'hidden', 'name' => 'data[UserForm][id]', 'id' => 'UserFormId'
|
|
|
8734 |
)));
|
|
|
8735 |
|
|
|
8736 |
$result = $this->Form->input('ValidateItem.id');
|
|
|
8737 |
$this->assertTags($result, array('input' => array(
|
|
|
8738 |
'type' => 'hidden', 'name' => 'data[ValidateItem][id]',
|
|
|
8739 |
'id' => 'ValidateItemId'
|
|
|
8740 |
)));
|
|
|
8741 |
|
|
|
8742 |
$result = $this->Form->input('ValidateUser.id');
|
|
|
8743 |
$this->assertTags($result, array('input' => array(
|
|
|
8744 |
'type' => 'hidden', 'name' => 'data[ValidateUser][id]',
|
|
|
8745 |
'id' => 'ValidateUserId'
|
|
|
8746 |
)));
|
|
|
8747 |
}
|
|
|
8748 |
|
|
|
8749 |
/**
|
|
|
8750 |
* testDbLessModel method
|
|
|
8751 |
*
|
|
|
8752 |
* @return void
|
|
|
8753 |
*/
|
|
|
8754 |
public function testDbLessModel() {
|
|
|
8755 |
$this->Form->create('TestMail');
|
|
|
8756 |
|
|
|
8757 |
$result = $this->Form->input('name');
|
|
|
8758 |
$expected = array(
|
|
|
8759 |
'div' => array('class' => 'input text'),
|
|
|
8760 |
'label' => array('for' => 'TestMailName'),
|
|
|
8761 |
'Name',
|
|
|
8762 |
'/label',
|
|
|
8763 |
'input' => array(
|
|
|
8764 |
'name' => 'data[TestMail][name]', 'type' => 'text',
|
|
|
8765 |
'id' => 'TestMailName'
|
|
|
8766 |
),
|
|
|
8767 |
'/div'
|
|
|
8768 |
);
|
|
|
8769 |
$this->assertTags($result, $expected);
|
|
|
8770 |
|
|
|
8771 |
ClassRegistry::init('TestMail');
|
|
|
8772 |
$this->Form->create('TestMail');
|
|
|
8773 |
$result = $this->Form->input('name');
|
|
|
8774 |
$expected = array(
|
|
|
8775 |
'div' => array('class' => 'input text'),
|
|
|
8776 |
'label' => array('for' => 'TestMailName'),
|
|
|
8777 |
'Name',
|
|
|
8778 |
'/label',
|
|
|
8779 |
'input' => array(
|
|
|
8780 |
'name' => 'data[TestMail][name]', 'type' => 'text',
|
|
|
8781 |
'id' => 'TestMailName'
|
|
|
8782 |
),
|
|
|
8783 |
'/div'
|
|
|
8784 |
);
|
|
|
8785 |
$this->assertTags($result, $expected);
|
|
|
8786 |
}
|
|
|
8787 |
|
|
|
8788 |
/**
|
|
|
8789 |
* testBrokenness method
|
|
|
8790 |
*
|
|
|
8791 |
* @return void
|
|
|
8792 |
*/
|
|
|
8793 |
public function testBrokenness() {
|
|
|
8794 |
/*
|
|
|
8795 |
* #4 This test has two parents and four children. By default (as of r7117) both
|
|
|
8796 |
* parents are show but the first parent is missing a child. This is the inconsistency
|
|
|
8797 |
* in the default behaviour - one parent has all children, the other does not - dependent
|
|
|
8798 |
* on the data values.
|
|
|
8799 |
*/
|
|
|
8800 |
$result = $this->Form->select('Model.field', array(
|
|
|
8801 |
'Fred' => array(
|
|
|
8802 |
'freds_son_1' => 'Fred',
|
|
|
8803 |
'freds_son_2' => 'Freddie'
|
|
|
8804 |
),
|
|
|
8805 |
'Bert' => array(
|
|
|
8806 |
'berts_son_1' => 'Albert',
|
|
|
8807 |
'berts_son_2' => 'Bertie')
|
|
|
8808 |
),
|
|
|
8809 |
array('showParents' => true, 'empty' => false)
|
|
|
8810 |
);
|
|
|
8811 |
|
|
|
8812 |
$expected = array(
|
|
|
8813 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
8814 |
array('optgroup' => array('label' => 'Fred')),
|
|
|
8815 |
array('option' => array('value' => 'freds_son_1')),
|
|
|
8816 |
'Fred',
|
|
|
8817 |
'/option',
|
|
|
8818 |
array('option' => array('value' => 'freds_son_2')),
|
|
|
8819 |
'Freddie',
|
|
|
8820 |
'/option',
|
|
|
8821 |
'/optgroup',
|
|
|
8822 |
array('optgroup' => array('label' => 'Bert')),
|
|
|
8823 |
array('option' => array('value' => 'berts_son_1')),
|
|
|
8824 |
'Albert',
|
|
|
8825 |
'/option',
|
|
|
8826 |
array('option' => array('value' => 'berts_son_2')),
|
|
|
8827 |
'Bertie',
|
|
|
8828 |
'/option',
|
|
|
8829 |
'/optgroup',
|
|
|
8830 |
'/select'
|
|
|
8831 |
);
|
|
|
8832 |
$this->assertTags($result, $expected);
|
|
|
8833 |
|
|
|
8834 |
/*
|
|
|
8835 |
* #2 This is structurally identical to the test above (#1) - only the parent name has
|
|
|
8836 |
* changed, so we should expect the same select list data, just with a different name
|
|
|
8837 |
* for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
|
|
|
8838 |
* This is where data corruption can occur, because when a select value is missing from
|
|
|
8839 |
* a list a form will substitute the first value in the list - without the user knowing.
|
|
|
8840 |
* If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
|
|
|
8841 |
* affect the availability of 3 => 'Three' as a valid option.
|
|
|
8842 |
*/
|
|
|
8843 |
$options = array(1 => 'One', 2 => 'Two', 'Three' => array(
|
|
|
8844 |
3 => 'Three', 4 => 'Four', 5 => 'Five'
|
|
|
8845 |
));
|
|
|
8846 |
$result = $this->Form->select(
|
|
|
8847 |
'Model.field', $options, array('showParents' => true, 'empty' => false)
|
|
|
8848 |
);
|
|
|
8849 |
|
|
|
8850 |
$expected = array(
|
|
|
8851 |
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
8852 |
array('option' => array('value' => 1)),
|
|
|
8853 |
'One',
|
|
|
8854 |
'/option',
|
|
|
8855 |
array('option' => array('value' => 2)),
|
|
|
8856 |
'Two',
|
|
|
8857 |
'/option',
|
|
|
8858 |
array('optgroup' => array('label' => 'Three')),
|
|
|
8859 |
array('option' => array('value' => 3)),
|
|
|
8860 |
'Three',
|
|
|
8861 |
'/option',
|
|
|
8862 |
array('option' => array('value' => 4)),
|
|
|
8863 |
'Four',
|
|
|
8864 |
'/option',
|
|
|
8865 |
array('option' => array('value' => 5)),
|
|
|
8866 |
'Five',
|
|
|
8867 |
'/option',
|
|
|
8868 |
'/optgroup',
|
|
|
8869 |
'/select'
|
|
|
8870 |
);
|
|
|
8871 |
$this->assertTags($result, $expected);
|
|
|
8872 |
}
|
|
|
8873 |
|
|
|
8874 |
/**
|
|
|
8875 |
* Test the generation of fields for a multi record form.
|
|
|
8876 |
*
|
|
|
8877 |
* @return void
|
|
|
8878 |
*/
|
|
|
8879 |
public function testMultiRecordForm() {
|
|
|
8880 |
$this->Form->create('ValidateProfile');
|
|
|
8881 |
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
|
|
|
8882 |
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
|
|
|
8883 |
$expected = array(
|
|
|
8884 |
'div' => array('class' => 'input textarea'),
|
|
|
8885 |
'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
|
|
|
8886 |
'Name',
|
|
|
8887 |
'/label',
|
|
|
8888 |
'textarea' => array(
|
|
|
8889 |
'id' => 'ValidateProfile1ValidateItem2Name',
|
|
|
8890 |
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
|
|
|
8891 |
'cols' => 30,
|
|
|
8892 |
'rows' => 6
|
|
|
8893 |
),
|
|
|
8894 |
'Value',
|
|
|
8895 |
'/textarea',
|
|
|
8896 |
'/div'
|
|
|
8897 |
);
|
|
|
8898 |
$this->assertTags($result, $expected);
|
|
|
8899 |
|
|
|
8900 |
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
|
|
|
8901 |
$expected = array(
|
|
|
8902 |
'div' => array('class' => 'input date'),
|
|
|
8903 |
'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
|
|
|
8904 |
'Created',
|
|
|
8905 |
'/label',
|
|
|
8906 |
array('select' => array(
|
|
|
8907 |
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][month]',
|
|
|
8908 |
'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
|
|
|
8909 |
)
|
|
|
8910 |
),
|
|
|
8911 |
array('option' => array('value' => '')), '/option',
|
|
|
8912 |
$this->dateRegex['monthsRegex'],
|
|
|
8913 |
'/select', '-',
|
|
|
8914 |
array('select' => array(
|
|
|
8915 |
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][day]',
|
|
|
8916 |
'id' => 'ValidateProfile1ValidateItem2CreatedDay'
|
|
|
8917 |
)
|
|
|
8918 |
),
|
|
|
8919 |
array('option' => array('value' => '')), '/option',
|
|
|
8920 |
$this->dateRegex['daysRegex'],
|
|
|
8921 |
'/select', '-',
|
|
|
8922 |
array('select' => array(
|
|
|
8923 |
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][year]',
|
|
|
8924 |
'id' => 'ValidateProfile1ValidateItem2CreatedYear'
|
|
|
8925 |
)
|
|
|
8926 |
),
|
|
|
8927 |
array('option' => array('value' => '')), '/option',
|
|
|
8928 |
$this->dateRegex['yearsRegex'],
|
|
|
8929 |
'/select',
|
|
|
8930 |
'/div'
|
|
|
8931 |
);
|
|
|
8932 |
$this->assertTags($result, $expected);
|
|
|
8933 |
|
|
|
8934 |
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
8935 |
$ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
|
|
|
8936 |
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
|
|
|
8937 |
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
|
|
|
8938 |
$expected = array(
|
|
|
8939 |
'div' => array('class' => 'input select error'),
|
|
|
8940 |
'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
|
|
|
8941 |
'Profile',
|
|
|
8942 |
'/label',
|
|
|
8943 |
'select' => array(
|
|
|
8944 |
'name' => 'data[ValidateProfile][1][ValidateItem][2][profile_id]',
|
|
|
8945 |
'id' => 'ValidateProfile1ValidateItem2ProfileId',
|
|
|
8946 |
'class' => 'form-error'
|
|
|
8947 |
),
|
|
|
8948 |
'/select',
|
|
|
8949 |
array('div' => array('class' => 'error-message')),
|
|
|
8950 |
'Error',
|
|
|
8951 |
'/div',
|
|
|
8952 |
'/div'
|
|
|
8953 |
);
|
|
|
8954 |
$this->assertTags($result, $expected);
|
|
|
8955 |
}
|
|
|
8956 |
|
|
|
8957 |
/**
|
|
|
8958 |
* test the correct display of multi-record form validation errors.
|
|
|
8959 |
*
|
|
|
8960 |
* @return void
|
|
|
8961 |
*/
|
|
|
8962 |
public function testMultiRecordFormValidationErrors() {
|
|
|
8963 |
$this->Form->create('ValidateProfile');
|
|
|
8964 |
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
8965 |
$ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
|
|
|
8966 |
$result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
|
|
|
8967 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
|
|
|
8968 |
|
|
|
8969 |
$ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
|
|
|
8970 |
$result = $this->Form->error('ValidateProfile.2.city');
|
|
|
8971 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
|
|
8972 |
|
|
|
8973 |
$result = $this->Form->error('2.city');
|
|
|
8974 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
|
|
8975 |
}
|
|
|
8976 |
|
|
|
8977 |
/**
|
|
|
8978 |
* test the correct display of multi-record form validation errors.
|
|
|
8979 |
*
|
|
|
8980 |
* @return void
|
|
|
8981 |
*/
|
|
|
8982 |
public function testSaveManyRecordFormValidationErrors() {
|
|
|
8983 |
$this->Form->create('ValidateUser');
|
|
|
8984 |
$ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
8985 |
$ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
|
|
|
8986 |
|
|
|
8987 |
$result = $this->Form->error('0.ValidateUser.ValidateItem.name');
|
|
|
8988 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
|
|
|
8989 |
|
|
|
8990 |
$ValidateUser->validationErrors[0]['city'] = array('Error in field city');
|
|
|
8991 |
$result = $this->Form->error('ValidateUser.0.city');
|
|
|
8992 |
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
|
|
8993 |
}
|
|
|
8994 |
|
|
|
8995 |
/**
|
|
|
8996 |
* tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
|
|
|
8997 |
*
|
|
|
8998 |
* @return void
|
|
|
8999 |
*/
|
|
|
9000 |
public function testInputTemplate() {
|
|
|
9001 |
$result = $this->Form->input('Contact.email', array(
|
|
|
9002 |
'type' => 'text', 'format' => array('input')
|
|
|
9003 |
));
|
|
|
9004 |
$expected = array(
|
|
|
9005 |
'div' => array('class' => 'input text'),
|
|
|
9006 |
'input' => array(
|
|
|
9007 |
'type' => 'text', 'name' => 'data[Contact][email]',
|
|
|
9008 |
'id' => 'ContactEmail'
|
|
|
9009 |
),
|
|
|
9010 |
'/div'
|
|
|
9011 |
);
|
|
|
9012 |
$this->assertTags($result, $expected);
|
|
|
9013 |
|
|
|
9014 |
$result = $this->Form->input('Contact.email', array(
|
|
|
9015 |
'type' => 'text', 'format' => array('input', 'label'),
|
|
|
9016 |
'label' => '<em>Email (required)</em>'
|
|
|
9017 |
));
|
|
|
9018 |
$expected = array(
|
|
|
9019 |
'div' => array('class' => 'input text'),
|
|
|
9020 |
array('input' => array(
|
|
|
9021 |
'type' => 'text', 'name' => 'data[Contact][email]',
|
|
|
9022 |
'id' => 'ContactEmail'
|
|
|
9023 |
)),
|
|
|
9024 |
'label' => array('for' => 'ContactEmail'),
|
|
|
9025 |
'em' => array(),
|
|
|
9026 |
'Email (required)',
|
|
|
9027 |
'/em',
|
|
|
9028 |
'/label',
|
|
|
9029 |
'/div'
|
|
|
9030 |
);
|
|
|
9031 |
$this->assertTags($result, $expected);
|
|
|
9032 |
|
|
|
9033 |
$result = $this->Form->input('Contact.email', array(
|
|
|
9034 |
'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
|
|
|
9035 |
'between' => '<div>Something in the middle</div>',
|
|
|
9036 |
'after' => '<span>Some text at the end</span>'
|
|
|
9037 |
));
|
|
|
9038 |
$expected = array(
|
|
|
9039 |
'div' => array('class' => 'input text'),
|
|
|
9040 |
array('input' => array(
|
|
|
9041 |
'type' => 'text', 'name' => 'data[Contact][email]',
|
|
|
9042 |
'id' => 'ContactEmail'
|
|
|
9043 |
)),
|
|
|
9044 |
array('div' => array()),
|
|
|
9045 |
'Something in the middle',
|
|
|
9046 |
'/div',
|
|
|
9047 |
'label' => array('for' => 'ContactEmail'),
|
|
|
9048 |
'Email',
|
|
|
9049 |
'/label',
|
|
|
9050 |
'span' => array(),
|
|
|
9051 |
'Some text at the end',
|
|
|
9052 |
'/span',
|
|
|
9053 |
'/div'
|
|
|
9054 |
);
|
|
|
9055 |
$this->assertTags($result, $expected);
|
|
|
9056 |
|
|
|
9057 |
$result = $this->Form->input('Contact.method', array(
|
|
|
9058 |
'type' => 'radio',
|
|
|
9059 |
'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
|
|
|
9060 |
'between' => 'I am between',
|
|
|
9061 |
));
|
|
|
9062 |
$expected = array(
|
|
|
9063 |
'div' => array('class' => 'input radio'),
|
|
|
9064 |
'fieldset' => array(),
|
|
|
9065 |
'legend' => array(),
|
|
|
9066 |
'Method',
|
|
|
9067 |
'/legend',
|
|
|
9068 |
'I am between',
|
|
|
9069 |
'input' => array(
|
|
|
9070 |
'type' => 'hidden', 'name' => 'data[Contact][method]',
|
|
|
9071 |
'value' => '', 'id' => 'ContactMethod_'
|
|
|
9072 |
),
|
|
|
9073 |
array('input' => array(
|
|
|
9074 |
'type' => 'radio', 'name' => 'data[Contact][method]',
|
|
|
9075 |
'value' => 'email', 'id' => 'ContactMethodEmail'
|
|
|
9076 |
)),
|
|
|
9077 |
array('label' => array('for' => 'ContactMethodEmail')),
|
|
|
9078 |
'Email',
|
|
|
9079 |
'/label',
|
|
|
9080 |
array('input' => array(
|
|
|
9081 |
'type' => 'radio', 'name' => 'data[Contact][method]',
|
|
|
9082 |
'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
|
|
|
9083 |
)),
|
|
|
9084 |
array('label' => array('for' => 'ContactMethodPigeon')),
|
|
|
9085 |
'Pigeon',
|
|
|
9086 |
'/label',
|
|
|
9087 |
'/fieldset',
|
|
|
9088 |
'/div',
|
|
|
9089 |
);
|
|
|
9090 |
$this->assertTags($result, $expected);
|
|
|
9091 |
}
|
|
|
9092 |
|
|
|
9093 |
/**
|
|
|
9094 |
* test that some html5 inputs + FormHelper::__call() work
|
|
|
9095 |
*
|
|
|
9096 |
* @return void
|
|
|
9097 |
*/
|
|
|
9098 |
public function testHtml5Inputs() {
|
|
|
9099 |
$result = $this->Form->email('User.email');
|
|
|
9100 |
$expected = array(
|
|
|
9101 |
'input' => array('type' => 'email', 'name' => 'data[User][email]', 'id' => 'UserEmail')
|
|
|
9102 |
);
|
|
|
9103 |
$this->assertTags($result, $expected);
|
|
|
9104 |
|
|
|
9105 |
$result = $this->Form->search('User.query');
|
|
|
9106 |
$expected = array(
|
|
|
9107 |
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery')
|
|
|
9108 |
);
|
|
|
9109 |
$this->assertTags($result, $expected);
|
|
|
9110 |
|
|
|
9111 |
$result = $this->Form->search('User.query', array('value' => 'test'));
|
|
|
9112 |
$expected = array(
|
|
|
9113 |
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
|
|
|
9114 |
);
|
|
|
9115 |
$this->assertTags($result, $expected);
|
|
|
9116 |
|
|
|
9117 |
$result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
|
|
|
9118 |
$expected = array(
|
|
|
9119 |
'input' => array('type' => 'text', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
|
|
|
9120 |
);
|
|
|
9121 |
$this->assertTags($result, $expected);
|
|
|
9122 |
|
|
|
9123 |
$result = $this->Form->input('User.website', array('type' => 'url', 'value' => 'http://domain.tld', 'div' => false, 'label' => false));
|
|
|
9124 |
$expected = array(
|
|
|
9125 |
'input' => array('type' => 'url', 'name' => 'data[User][website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
|
|
|
9126 |
);
|
|
|
9127 |
$this->assertTags($result, $expected);
|
|
|
9128 |
}
|
|
|
9129 |
|
|
|
9130 |
/**
|
|
|
9131 |
*
|
|
|
9132 |
* @expectedException CakeException
|
|
|
9133 |
* @return void
|
|
|
9134 |
*/
|
|
|
9135 |
public function testHtml5InputException() {
|
|
|
9136 |
$this->Form->email();
|
|
|
9137 |
}
|
|
|
9138 |
|
|
|
9139 |
/**
|
|
|
9140 |
* Tests that a model can be loaded from the model names passed in the request object
|
|
|
9141 |
*
|
|
|
9142 |
* @return void
|
|
|
9143 |
*/
|
|
|
9144 |
public function testIntrospectModelFromRequest() {
|
|
|
9145 |
$this->loadFixtures('Post');
|
|
|
9146 |
App::build(array(
|
|
|
9147 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
9148 |
));
|
|
|
9149 |
CakePlugin::load('TestPlugin');
|
|
|
9150 |
$this->Form->request['models'] = array('TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost'));
|
|
|
9151 |
|
|
|
9152 |
$this->assertFalse(ClassRegistry::isKeySet('TestPluginPost'));
|
|
|
9153 |
$this->Form->create('TestPluginPost');
|
|
|
9154 |
$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
|
|
|
9155 |
$this->assertInstanceOf('TestPluginPost', ClassRegistry::getObject('TestPluginPost'));
|
|
|
9156 |
|
|
|
9157 |
CakePlugin::unload();
|
|
|
9158 |
App::build();
|
|
|
9159 |
}
|
|
|
9160 |
|
|
|
9161 |
/**
|
|
|
9162 |
* Tests that it is possible to set the validation errors directly in the helper for a field
|
|
|
9163 |
*
|
|
|
9164 |
* @return void
|
|
|
9165 |
*/
|
|
|
9166 |
public function testCustomValidationErrors() {
|
|
|
9167 |
$this->Form->validationErrors['Thing']['field'] = 'Badness!';
|
|
|
9168 |
$result = $this->Form->error('Thing.field', null, array('wrap' => false));
|
|
|
9169 |
$this->assertEquals('Badness!', $result);
|
|
|
9170 |
}
|
|
|
9171 |
|
|
|
9172 |
/**
|
|
|
9173 |
* Tests that the 'on' key validates as expected on create
|
|
|
9174 |
*
|
|
|
9175 |
* @return void
|
|
|
9176 |
*/
|
|
|
9177 |
public function testRequiredOnCreate() {
|
|
|
9178 |
$this->Form->create('Contact');
|
|
|
9179 |
|
|
|
9180 |
$result = $this->Form->input('Contact.imrequiredonupdate');
|
|
|
9181 |
$expected = array(
|
|
|
9182 |
'div' => array('class' => 'input text'),
|
|
|
9183 |
'label' => array('for' => 'ContactImrequiredonupdate'),
|
|
|
9184 |
'Imrequiredonupdate',
|
|
|
9185 |
'/label',
|
|
|
9186 |
'input' => array(
|
|
|
9187 |
'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
|
|
|
9188 |
'id' => 'ContactImrequiredonupdate'
|
|
|
9189 |
),
|
|
|
9190 |
'/div'
|
|
|
9191 |
);
|
|
|
9192 |
$this->assertTags($result, $expected);
|
|
|
9193 |
|
|
|
9194 |
$result = $this->Form->input('Contact.imrequiredoncreate');
|
|
|
9195 |
$expected = array(
|
|
|
9196 |
'div' => array('class' => 'input text required'),
|
|
|
9197 |
'label' => array('for' => 'ContactImrequiredoncreate'),
|
|
|
9198 |
'Imrequiredoncreate',
|
|
|
9199 |
'/label',
|
|
|
9200 |
'input' => array(
|
|
|
9201 |
'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
|
|
|
9202 |
'id' => 'ContactImrequiredoncreate',
|
|
|
9203 |
'required' => 'required'
|
|
|
9204 |
),
|
|
|
9205 |
'/div'
|
|
|
9206 |
);
|
|
|
9207 |
$this->assertTags($result, $expected);
|
|
|
9208 |
|
|
|
9209 |
$result = $this->Form->input('Contact.imrequiredonboth');
|
|
|
9210 |
$expected = array(
|
|
|
9211 |
'div' => array('class' => 'input text required'),
|
|
|
9212 |
'label' => array('for' => 'ContactImrequiredonboth'),
|
|
|
9213 |
'Imrequiredonboth',
|
|
|
9214 |
'/label',
|
|
|
9215 |
'input' => array(
|
|
|
9216 |
'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
|
|
|
9217 |
'id' => 'ContactImrequiredonboth',
|
|
|
9218 |
'required' => 'required'
|
|
|
9219 |
),
|
|
|
9220 |
'/div'
|
|
|
9221 |
);
|
|
|
9222 |
$this->assertTags($result, $expected);
|
|
|
9223 |
|
|
|
9224 |
$this->Form->inputDefaults(array('required' => false));
|
|
|
9225 |
$result = $this->Form->input('Contact.imrequired');
|
|
|
9226 |
$expected = array(
|
|
|
9227 |
'div' => array('class' => 'input text'),
|
|
|
9228 |
'label' => array('for' => 'ContactImrequired'),
|
|
|
9229 |
'Imrequired',
|
|
|
9230 |
'/label',
|
|
|
9231 |
'input' => array(
|
|
|
9232 |
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
9233 |
'id' => 'ContactImrequired'
|
|
|
9234 |
),
|
|
|
9235 |
'/div'
|
|
|
9236 |
);
|
|
|
9237 |
$this->assertTags($result, $expected);
|
|
|
9238 |
|
|
|
9239 |
$result = $this->Form->input('Contact.imrequired', array('required' => false));
|
|
|
9240 |
$this->assertTags($result, $expected);
|
|
|
9241 |
|
|
|
9242 |
$result = $this->Form->input('Contact.imrequired', array('required' => true));
|
|
|
9243 |
$expected = array(
|
|
|
9244 |
'div' => array('class' => 'input text required'),
|
|
|
9245 |
'label' => array('for' => 'ContactImrequired'),
|
|
|
9246 |
'Imrequired',
|
|
|
9247 |
'/label',
|
|
|
9248 |
'input' => array(
|
|
|
9249 |
'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
9250 |
'id' => 'ContactImrequired'
|
|
|
9251 |
),
|
|
|
9252 |
'/div'
|
|
|
9253 |
);
|
|
|
9254 |
$this->assertTags($result, $expected);
|
|
|
9255 |
|
|
|
9256 |
$result = $this->Form->input('Contact.imrequired', array('required' => null));
|
|
|
9257 |
$this->assertTags($result, $expected);
|
|
|
9258 |
}
|
|
|
9259 |
|
|
|
9260 |
/**
|
|
|
9261 |
* Tests that the 'on' key validates as expected on update
|
|
|
9262 |
*
|
|
|
9263 |
* @return void
|
|
|
9264 |
*/
|
|
|
9265 |
public function testRequiredOnUpdate() {
|
|
|
9266 |
$this->Form->request->data['Contact']['id'] = 1;
|
|
|
9267 |
$this->Form->create('Contact');
|
|
|
9268 |
|
|
|
9269 |
$result = $this->Form->input('Contact.imrequiredonupdate');
|
|
|
9270 |
$expected = array(
|
|
|
9271 |
'div' => array('class' => 'input text required'),
|
|
|
9272 |
'label' => array('for' => 'ContactImrequiredonupdate'),
|
|
|
9273 |
'Imrequiredonupdate',
|
|
|
9274 |
'/label',
|
|
|
9275 |
'input' => array(
|
|
|
9276 |
'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
|
|
|
9277 |
'id' => 'ContactImrequiredonupdate',
|
|
|
9278 |
'required' => 'required'
|
|
|
9279 |
),
|
|
|
9280 |
'/div'
|
|
|
9281 |
);
|
|
|
9282 |
$this->assertTags($result, $expected);
|
|
|
9283 |
$result = $this->Form->input('Contact.imrequiredoncreate');
|
|
|
9284 |
$expected = array(
|
|
|
9285 |
'div' => array('class' => 'input text'),
|
|
|
9286 |
'label' => array('for' => 'ContactImrequiredoncreate'),
|
|
|
9287 |
'Imrequiredoncreate',
|
|
|
9288 |
'/label',
|
|
|
9289 |
'input' => array(
|
|
|
9290 |
'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
|
|
|
9291 |
'id' => 'ContactImrequiredoncreate'
|
|
|
9292 |
),
|
|
|
9293 |
'/div'
|
|
|
9294 |
);
|
|
|
9295 |
$this->assertTags($result, $expected);
|
|
|
9296 |
|
|
|
9297 |
$result = $this->Form->input('Contact.imrequiredonboth');
|
|
|
9298 |
$expected = array(
|
|
|
9299 |
'div' => array('class' => 'input text required'),
|
|
|
9300 |
'label' => array('for' => 'ContactImrequiredonboth'),
|
|
|
9301 |
'Imrequiredonboth',
|
|
|
9302 |
'/label',
|
|
|
9303 |
'input' => array(
|
|
|
9304 |
'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
|
|
|
9305 |
'id' => 'ContactImrequiredonboth',
|
|
|
9306 |
'required' => 'required'
|
|
|
9307 |
),
|
|
|
9308 |
'/div'
|
|
|
9309 |
);
|
|
|
9310 |
$this->assertTags($result, $expected);
|
|
|
9311 |
|
|
|
9312 |
$result = $this->Form->input('Contact.imrequired');
|
|
|
9313 |
$expected = array(
|
|
|
9314 |
'div' => array('class' => 'input text required'),
|
|
|
9315 |
'label' => array('for' => 'ContactImrequired'),
|
|
|
9316 |
'Imrequired',
|
|
|
9317 |
'/label',
|
|
|
9318 |
'input' => array(
|
|
|
9319 |
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
9320 |
'id' => 'ContactImrequired',
|
|
|
9321 |
'required' => 'required'
|
|
|
9322 |
),
|
|
|
9323 |
'/div'
|
|
|
9324 |
);
|
|
|
9325 |
$this->assertTags($result, $expected);
|
|
|
9326 |
}
|
|
|
9327 |
|
|
|
9328 |
/**
|
|
|
9329 |
* Test inputDefaults setter and getter
|
|
|
9330 |
*
|
|
|
9331 |
* @return void
|
|
|
9332 |
*/
|
|
|
9333 |
public function testInputDefaults() {
|
|
|
9334 |
$this->Form->create('Contact');
|
|
|
9335 |
|
|
|
9336 |
$this->Form->inputDefaults(array(
|
|
|
9337 |
'label' => false,
|
|
|
9338 |
'div' => array(
|
|
|
9339 |
'style' => 'color: #000;'
|
|
|
9340 |
)
|
|
|
9341 |
));
|
|
|
9342 |
$result = $this->Form->input('Contact.field1');
|
|
|
9343 |
$expected = array(
|
|
|
9344 |
'div' => array('class' => 'input text', 'style' => 'color: #000;'),
|
|
|
9345 |
'input' => array(
|
|
|
9346 |
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
9347 |
'id' => 'ContactField1'
|
|
|
9348 |
),
|
|
|
9349 |
'/div'
|
|
|
9350 |
);
|
|
|
9351 |
$this->assertTags($result, $expected);
|
|
|
9352 |
|
|
|
9353 |
$this->Form->inputDefaults(array(
|
|
|
9354 |
'div' => false,
|
|
|
9355 |
'label' => 'Label',
|
|
|
9356 |
));
|
|
|
9357 |
$result = $this->Form->input('Contact.field1');
|
|
|
9358 |
$expected = array(
|
|
|
9359 |
'label' => array('for' => 'ContactField1'),
|
|
|
9360 |
'Label',
|
|
|
9361 |
'/label',
|
|
|
9362 |
'input' => array(
|
|
|
9363 |
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
9364 |
'id' => 'ContactField1'
|
|
|
9365 |
),
|
|
|
9366 |
);
|
|
|
9367 |
$this->assertTags($result, $expected);
|
|
|
9368 |
|
|
|
9369 |
$this->Form->inputDefaults(array(
|
|
|
9370 |
'label' => false,
|
|
|
9371 |
), true);
|
|
|
9372 |
$result = $this->Form->input('Contact.field1');
|
|
|
9373 |
$expected = array(
|
|
|
9374 |
'input' => array(
|
|
|
9375 |
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
9376 |
'id' => 'ContactField1'
|
|
|
9377 |
),
|
|
|
9378 |
);
|
|
|
9379 |
$this->assertTags($result, $expected);
|
|
|
9380 |
|
|
|
9381 |
$result = $this->Form->inputDefaults();
|
|
|
9382 |
$expected = array(
|
|
|
9383 |
'div' => false,
|
|
|
9384 |
'label' => false,
|
|
|
9385 |
);
|
|
|
9386 |
$this->assertEquals($expected, $result);
|
|
|
9387 |
}
|
|
|
9388 |
|
|
|
9389 |
}
|