2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FormHelperTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('ClassRegistry', 'Utility');
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('Security', 'Utility');
|
|
|
|
App::uses('CakeRequest', 'Network');
|
|
|
|
App::uses('HtmlHelper', 'View/Helper');
|
|
|
|
App::uses('FormHelper', 'View/Helper');
|
2010-12-22 02:43:22 +00:00
|
|
|
App::uses('Router', 'Routing');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ContactTestController class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ContactTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var mixed
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* Contact class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class Contact extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-22 16:05:34 +00:00
|
|
|
/**
|
|
|
|
* Default schema
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-08-22 16:05:34 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
2016-05-02 15:13:22 +00:00
|
|
|
'lap_time' => array('type' => 'time', 'null' => '', 'default' => '', 'length' => '2'),
|
|
|
|
'last_seen' => array('type' => 'datetime', 'null' => '', 'default' => '', 'length' => '3'),
|
2008-08-22 16:05:34 +00:00
|
|
|
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
|
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
2011-07-26 09:19:41 +00:00
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null),
|
|
|
|
'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null)
|
2008-08-22 16:05:34 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* validate property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $validate = array(
|
2008-06-23 00:07:33 +00:00
|
|
|
'non_existing' => array(),
|
|
|
|
'idontexist' => array(),
|
2010-02-23 14:25:01 +00:00
|
|
|
'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false),
|
2015-05-17 20:27:16 +00:00
|
|
|
'imrequiredonupdate' => array('notBlank' => array('rule' => 'alphaNumeric', 'on' => 'update')),
|
2012-02-07 13:06:36 +00:00
|
|
|
'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')),
|
2012-03-20 02:53:58 +00:00
|
|
|
'imrequiredonboth' => array(
|
2012-09-12 01:59:46 +00:00
|
|
|
'required' => array('rule' => 'alphaNumeric'),
|
2012-03-20 02:53:58 +00:00
|
|
|
),
|
2015-05-17 20:27:16 +00:00
|
|
|
'string_required' => 'notBlank',
|
2010-02-23 14:25:01 +00:00
|
|
|
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
|
2015-05-17 20:27:16 +00:00
|
|
|
'imrequiredtoo' => array('rule' => 'notBlank'),
|
|
|
|
'required_one' => array('required' => array('rule' => array('notBlank'))),
|
2010-02-28 03:28:27 +00:00
|
|
|
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
|
2010-04-30 20:37:59 +00:00
|
|
|
'imalsonotrequired' => array(
|
2012-10-31 23:34:37 +00:00
|
|
|
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
|
|
|
|
'between' => array('rule' => array('between', 5, 30)),
|
|
|
|
),
|
|
|
|
'imalsonotrequired2' => array(
|
2012-03-20 02:53:58 +00:00
|
|
|
'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true),
|
|
|
|
'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true),
|
2010-04-30 20:37:59 +00:00
|
|
|
),
|
2010-04-30 19:49:52 +00:00
|
|
|
'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true),
|
2012-10-26 07:28:24 +00:00
|
|
|
'iamrequiredalways' => array(
|
|
|
|
'email' => array('rule' => 'email'),
|
|
|
|
'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'),
|
|
|
|
'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'),
|
|
|
|
),
|
2013-01-23 15:08:24 +00:00
|
|
|
'boolean_field' => array('rule' => 'boolean')
|
2010-04-30 21:12:59 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setSchema($schema) {
|
2008-08-22 16:05:34 +00:00
|
|
|
$this->_schema = $schema;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact'));
|
2010-04-22 21:07:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-23 02:52:56 +00:00
|
|
|
public $belongsTo = array('User' => array('className' => 'UserForm'));
|
2008-10-16 00:38:38 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* ContactTagsContact class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2008-10-16 00:38:38 +00:00
|
|
|
class ContactTagsContact extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 00:38:38 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-10-16 00:38:38 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 00:38:38 +00:00
|
|
|
/**
|
|
|
|
* Default schema
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-10-16 00:38:38 +00:00
|
|
|
'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
2008-12-25 22:13:06 +00:00
|
|
|
'contact_tag_id' => array(
|
|
|
|
'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'
|
|
|
|
)
|
2008-10-16 00:38:38 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-16 00:38:38 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setSchema($schema) {
|
2008-10-16 00:38:38 +00:00
|
|
|
$this->_schema = $schema;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* ContactNonStandardPk class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
|
|
|
class ContactNonStandardPk extends Contact {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* primaryKey property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $primaryKey = 'pk';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function schema($field = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->_schema = parent::schema();
|
|
|
|
$this->_schema['pk'] = $this->_schema['id'];
|
|
|
|
unset($this->_schema['id']);
|
|
|
|
return $this->_schema;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ContactTag class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ContactTag extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-12-25 22:13:06 +00:00
|
|
|
* schema definition
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-12-25 22:13:06 +00:00
|
|
|
* @var array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
|
|
|
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
|
|
|
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* UserForm class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class UserForm extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasMany property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id'
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-12-25 22:13:06 +00:00
|
|
|
* schema definition
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-12-25 22:13:06 +00:00
|
|
|
* @var array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null),
|
|
|
|
'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null),
|
2010-04-22 21:07:15 +00:00
|
|
|
'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10),
|
2008-12-25 22:13:06 +00:00
|
|
|
'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255),
|
2010-06-10 16:48:55 +00:00
|
|
|
'active' => array('type' => 'boolean', 'null' => false, 'default' => false),
|
2008-12-25 22:13:06 +00:00
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* OpenidUrl class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class OpenidUrl extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('UserForm' => array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'className' => 'UserForm', 'foreignKey' => 'user_form_id'
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* validate property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $validate = array('openid_not_registered' => array());
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-12-25 22:13:06 +00:00
|
|
|
* @var array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'user_form_id' => array(
|
|
|
|
'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8'
|
|
|
|
),
|
|
|
|
'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeValidate method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeValidate($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->invalidate('openid_not_registered');
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ValidateUser class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ValidateUser extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasOne property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasOne = array('ValidateProfile' => array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'className' => 'ValidateProfile', 'foreignKey' => 'user_id'
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* schema method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-12-25 22:13:06 +00:00
|
|
|
* @var array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
|
2013-09-29 14:40:35 +00:00
|
|
|
'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'),
|
2015-10-02 01:46:21 +00:00
|
|
|
'null_decimal' => array('type' => 'decimal', 'null' => false, 'length' => null),
|
2014-01-30 20:17:50 +00:00
|
|
|
'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'),
|
|
|
|
'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'),
|
2008-12-25 22:13:06 +00:00
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeValidate method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeValidate($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->invalidate('email');
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ValidateProfile class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ValidateProfile extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
/**
|
|
|
|
* schema property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* hasOne property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasOne = array('ValidateItem' => array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'className' => 'ValidateItem', 'foreignKey' => 'profile_id'
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('ValidateUser' => array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'className' => 'ValidateUser', 'foreignKey' => 'user_id'
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeValidate method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeValidate($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->invalidate('full_name');
|
|
|
|
$this->invalidate('city');
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ValidateItem class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ValidateItem extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-12-25 22:13:06 +00:00
|
|
|
* schema property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_schema = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
2009-10-21 21:17:12 +00:00
|
|
|
'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
2008-12-25 22:13:06 +00:00
|
|
|
'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
'description' => array(
|
|
|
|
'type' => 'string', 'null' => '', 'default' => '', 'length' => '255'
|
|
|
|
),
|
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-12-25 22:13:06 +00:00
|
|
|
* belongsTo property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-12-25 22:13:06 +00:00
|
|
|
* @var array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id'));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeValidate method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeValidate($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->invalidate('description');
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestMail class
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestMail extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FormHelperTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2013-05-30 22:11:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2012-02-07 13:06:36 +00:00
|
|
|
* @property FormHelper $Form
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class FormHelperTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-07-14 21:56:55 +00:00
|
|
|
/**
|
|
|
|
* Fixtures to be used
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $fixtures = array('core.post');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not load the fixtures by default
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2011-07-14 21:56:55 +00:00
|
|
|
*/
|
|
|
|
public $autoFixtures = false;
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2008-05-30 11:40:08 +00:00
|
|
|
parent::setUp();
|
2010-08-28 04:01:41 +00:00
|
|
|
|
2013-06-11 18:03:05 +00:00
|
|
|
Configure::write('Config.language', 'eng');
|
2011-03-03 02:47:11 +00:00
|
|
|
Configure::write('App.base', '');
|
2013-05-14 01:07:43 +00:00
|
|
|
Configure::delete('Asset');
|
2010-07-03 16:16:40 +00:00
|
|
|
$this->Controller = new ContactTestController();
|
|
|
|
$this->View = new View($this->Controller);
|
|
|
|
|
|
|
|
$this->Form = new FormHelper($this->View);
|
2010-08-28 04:01:41 +00:00
|
|
|
$this->Form->Html = new HtmlHelper($this->View);
|
2011-03-03 02:47:11 +00:00
|
|
|
$this->Form->request = new CakeRequest('contacts/add', false);
|
2011-03-02 01:31:02 +00:00
|
|
|
$this->Form->request->here = '/contacts/add';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['action'] = 'add';
|
|
|
|
$this->Form->request->webroot = '';
|
|
|
|
$this->Form->request->base = '';
|
2016-09-14 02:21:01 +00:00
|
|
|
Router::setRequestInfo($this->Form->request);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ClassRegistry::addObject('Contact', new Contact());
|
|
|
|
ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk());
|
|
|
|
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
|
2010-08-05 04:24:38 +00:00
|
|
|
ClassRegistry::addObject('User', new UserForm());
|
2008-05-30 11:40:08 +00:00
|
|
|
ClassRegistry::addObject('ValidateItem', new ValidateItem());
|
|
|
|
ClassRegistry::addObject('ValidateUser', new ValidateUser());
|
|
|
|
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
|
2008-09-24 23:02:14 +00:00
|
|
|
|
|
|
|
$this->oldSalt = Configure::read('Security.salt');
|
2008-11-29 00:28:31 +00:00
|
|
|
|
|
|
|
$this->dateRegex = array(
|
|
|
|
'daysRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
|
'monthsRegex' => 'preg:/(?:<option value="[\d]+">[\w]+<\/option>[\r\n]*)*/',
|
|
|
|
'yearsRegex' => 'preg:/(?:<option value="([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
|
'hoursRegex' => 'preg:/(?:<option value="0?([\d]+)">\\1<\/option>[\r\n]*)*/',
|
|
|
|
'minutesRegex' => 'preg:/(?:<option value="([\d]+)">0?\\1<\/option>[\r\n]*)*/',
|
|
|
|
'meridianRegex' => 'preg:/(?:<option value="(am|pm)">\\1<\/option>[\r\n]*)*/',
|
|
|
|
);
|
2009-01-21 01:15:29 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
Configure::write('Security.salt', 'foo!');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2011-02-03 02:52:41 +00:00
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
|
|
|
|
Configure::write('Security.salt', $this->oldSalt);
|
|
|
|
}
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormCreateWithSecurity method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test form->create() with security key.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateWithSecurity() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
|
|
|
$expected = array(
|
2011-03-16 01:19:15 +00:00
|
|
|
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testKey', 'id', 'autocomplete'
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('url' => '/contacts/add', 'id' => 'MyForm'));
|
|
|
|
$expected['form']['id'] = 'MyForm';
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-01-25 20:21:16 +00:00
|
|
|
/**
|
|
|
|
* testFormCreateGetNoSecurity method
|
|
|
|
*
|
|
|
|
* Test form->create() with no security key as its a get form
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreateEndGetNoSecurity() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
|
$result = $this->Form->create('Contact', array('type' => 'get', 'url' => '/contacts/add'));
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('Token', $result);
|
2013-01-25 20:21:16 +00:00
|
|
|
|
|
|
|
$result = $this->Form->end('Save');
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('Token', $result);
|
2013-01-25 20:21:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 02:50:09 +00:00
|
|
|
/**
|
|
|
|
* test that create() clears the fields property so it starts fresh
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateClearingFields() {
|
2010-06-13 02:50:09 +00:00
|
|
|
$this->Form->fields = array('model_id');
|
|
|
|
$this->Form->create('Contact');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
2010-06-13 02:50:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
/**
|
|
|
|
* Tests form hash generation with model-less data
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testValidateHashNoModel() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'foo');
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->secure(array('anything'));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/540ac9c60d323c22bafe997b72c0790f39a8bdef/', $result);
|
2008-09-24 23:02:14 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
/**
|
|
|
|
* Tests that models with identical field names get resolved properly
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDuplicateFieldNameResolution() {
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->create('ValidateUser');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('ValidateUser'), $this->Form->entity());
|
2008-12-25 22:13:06 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('ValidateItem.name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
|
2008-12-25 22:13:06 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('ValidateUser.name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/name="data\[ValidateUser\]\[name\]"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/type="text"/', $result);
|
2008-12-25 22:13:06 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('ValidateItem.name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('ValidateItem', 'name'), $this->Form->entity());
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/name="data\[ValidateItem\]\[name\]"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<textarea/', $result);
|
2008-12-25 22:13:06 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('name');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('ValidateUser', 'name'), $this->Form->entity());
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/name="data\[ValidateUser\]\[name\]"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/type="text"/', $result);
|
2008-12-25 22:13:06 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
/**
|
|
|
|
* Tests that hidden fields generated for checkboxes don't get locked
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNoCheckboxLocking() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'foo');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertSame(array(), $this->Form->fields);
|
2008-09-24 23:02:14 +00:00
|
|
|
|
|
|
|
$this->Form->checkbox('check', array('value' => '1'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Form->fields, array('check'));
|
2008-09-24 23:02:14 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityFields method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test generation of secure form hash generation.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecurityFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$key = 'testKey';
|
2008-09-24 23:02:14 +00:00
|
|
|
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
|
2013-12-30 15:28:10 +00:00
|
|
|
$secureAttributes = array('form' => 'MyTestForm');
|
2014-02-17 16:03:49 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
2013-12-30 15:28:10 +00:00
|
|
|
$result = $this->Form->secure($fields, $secureAttributes);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-09-03 14:04:19 +00:00
|
|
|
$hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
|
|
|
|
$hash .= ':' . 'Model.valid';
|
|
|
|
$hash = urlencode($hash);
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'',
|
|
|
|
$fields,
|
|
|
|
array()
|
|
|
|
)));
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2013-12-30 15:28:10 +00:00
|
|
|
'value' => $hash, 'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'form' => 'MyTestForm',
|
2017-04-05 17:02:17 +00:00
|
|
|
'autocomplete' => 'off',
|
2012-09-03 14:04:19 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2013-12-30 15:28:10 +00:00
|
|
|
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'form' => 'MyTestForm',
|
2017-04-05 17:02:17 +00:00
|
|
|
'autocomplete' => 'off',
|
2012-09-03 14:04:19 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
'form' => 'MyTestForm',
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFormSecurityFields method
|
|
|
|
*
|
|
|
|
* Test debug token is not generated if debug is false
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormSecurityFieldsNoDebugMode() {
|
|
|
|
Configure::write('debug', false);
|
|
|
|
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
|
|
|
|
|
|
|
|
$this->Form->request->params['_Token'] = 'testKey';
|
|
|
|
$result = $this->Form->secure($fields);
|
|
|
|
|
|
|
|
$hash = Security::hash(serialize($fields) . Configure::read('Security.salt'));
|
|
|
|
$hash .= ':' . 'Model.valid';
|
|
|
|
$hash = urlencode($hash);
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][fields]',
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => $hash,
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][unlocked]',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'value' => '',
|
2017-05-28 01:47:22 +00:00
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
2012-09-03 14:04:19 +00:00
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-08-22 16:05:34 +00:00
|
|
|
/**
|
2011-08-19 02:31:00 +00:00
|
|
|
* Tests correct generation of number fields for double and float fields
|
2008-08-22 16:05:34 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTextFieldGenerationForFloats() {
|
2008-08-22 16:05:34 +00:00
|
|
|
$model = ClassRegistry::getObject('Contact');
|
|
|
|
$model->setSchema(array('foo' => array(
|
|
|
|
'type' => 'float',
|
|
|
|
'null' => false,
|
|
|
|
'default' => null,
|
2013-04-11 15:36:52 +00:00
|
|
|
'length' => 10
|
2008-08-22 16:05:34 +00:00
|
|
|
)));
|
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('foo');
|
|
|
|
$expected = array(
|
2011-08-19 02:31:00 +00:00
|
|
|
'div' => array('class' => 'input number'),
|
2008-08-22 16:05:34 +00:00
|
|
|
'label' => array('for' => 'ContactFoo'),
|
|
|
|
'Foo',
|
|
|
|
'/label',
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
2011-08-19 02:31:00 +00:00
|
|
|
'type' => 'number',
|
|
|
|
'name' => 'data[Contact][foo]',
|
|
|
|
'id' => 'ContactFoo',
|
|
|
|
'step' => 'any'
|
2008-10-29 06:55:42 +00:00
|
|
|
)),
|
2008-08-22 16:05:34 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-08-19 02:31:00 +00:00
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('foo', array('step' => 0.5));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input number'),
|
|
|
|
'label' => array('for' => 'ContactFoo'),
|
|
|
|
'Foo',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'number',
|
|
|
|
'name' => 'data[Contact][foo]',
|
|
|
|
'id' => 'ContactFoo',
|
|
|
|
'step' => '0.5'
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-08-22 16:05:34 +00:00
|
|
|
}
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2015-02-06 03:28:02 +00:00
|
|
|
/**
|
|
|
|
* Tests correct generation of decimal fields as text inputs
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTextFieldGenerationForDecimalAsText() {
|
|
|
|
$this->Form->create('ValidateUser');
|
|
|
|
$result = $this->Form->input('cost_decimal', array(
|
|
|
|
'type' => 'text'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ValidateUserCostDecimal'),
|
|
|
|
'Cost Decimal',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'text',
|
|
|
|
'name' => 'data[ValidateUser][cost_decimal]',
|
|
|
|
'id' => 'ValidateUserCostDecimal',
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2011-07-26 09:19:41 +00:00
|
|
|
/**
|
2011-08-19 02:31:00 +00:00
|
|
|
* Tests correct generation of number fields for integer fields
|
2011-07-26 09:19:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTextFieldTypeNumberGenerationForIntegers() {
|
|
|
|
$model = ClassRegistry::getObject('Contact');
|
|
|
|
$model->setSchema(array('foo' => array(
|
|
|
|
'type' => 'integer',
|
|
|
|
'null' => false,
|
|
|
|
'default' => null,
|
|
|
|
'length' => null
|
|
|
|
)));
|
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('foo');
|
|
|
|
$expected = array(
|
2011-08-19 02:31:00 +00:00
|
|
|
'div' => array('class' => 'input number'),
|
2011-07-26 09:19:41 +00:00
|
|
|
'label' => array('for' => 'ContactFoo'),
|
|
|
|
'Foo',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'number', 'name' => 'data[Contact][foo]',
|
|
|
|
'id' => 'ContactFoo'
|
|
|
|
)),
|
|
|
|
'/div'
|
2008-08-22 16:05:34 +00:00
|
|
|
);
|
2011-08-19 02:31:00 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-10-15 20:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests correct generation of file upload fields for binary fields
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFileUploadFieldTypeGenerationForBinaries() {
|
|
|
|
$model = ClassRegistry::getObject('Contact');
|
|
|
|
$model->setSchema(array('foo' => array(
|
|
|
|
'type' => 'binary',
|
|
|
|
'null' => false,
|
|
|
|
'default' => null,
|
|
|
|
'length' => 1024
|
|
|
|
)));
|
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('foo');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input file'),
|
|
|
|
'label' => array('for' => 'ContactFoo'),
|
|
|
|
'Foo',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'file', 'name' => 'data[Contact][foo]',
|
|
|
|
'id' => 'ContactFoo'
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-08-22 16:05:34 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityMultipleFields method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test secure() with multiple row form. Ensure hash is correct.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecurityMultipleFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$key = 'testKey';
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$fields = array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'Model.0.password', 'Model.0.username', 'Model.0.hidden' => 'value',
|
|
|
|
'Model.0.valid' => '0', 'Model.1.password', 'Model.1.username',
|
|
|
|
'Model.1.hidden' => 'value', 'Model.1.valid' => '0'
|
2008-09-21 04:06:37 +00:00
|
|
|
);
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->secure($fields);
|
|
|
|
|
2012-11-21 14:39:03 +00:00
|
|
|
$hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid';
|
2010-11-21 05:09:45 +00:00
|
|
|
$hash .= '%7CModel.1.hidden%7CModel.1.valid';
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'',
|
|
|
|
$fields,
|
|
|
|
array()
|
|
|
|
)));
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => $hash, 'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
2011-06-14 01:39:49 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-29 01:58:27 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityMultipleSubmitButtons
|
|
|
|
*
|
|
|
|
* test form submit generation and ensure that _Token is only created on end()
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecurityMultipleSubmitButtons() {
|
2008-09-29 01:58:27 +00:00
|
|
|
$key = 'testKey';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
2008-09-29 01:58:27 +00:00
|
|
|
|
|
|
|
$this->Form->create('Addresses');
|
|
|
|
$this->Form->input('Address.title');
|
|
|
|
$this->Form->input('Address.first_name');
|
2008-10-07 16:57:22 +00:00
|
|
|
|
2008-09-29 01:58:27 +00:00
|
|
|
$result = $this->Form->submit('Save', array('name' => 'save'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'name' => 'save', 'value' => 'Save'),
|
|
|
|
'/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2014-03-22 01:57:06 +00:00
|
|
|
|
2008-09-29 01:58:27 +00:00
|
|
|
$result = $this->Form->submit('Cancel', array('name' => 'cancel'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'name' => 'cancel', 'value' => 'Cancel'),
|
|
|
|
'/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-09-29 01:58:27 +00:00
|
|
|
$result = $this->Form->end(null);
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
array(
|
|
|
|
'Address.title',
|
|
|
|
'Address.first_name',
|
|
|
|
),
|
|
|
|
array('save', 'cancel')
|
|
|
|
)));
|
2008-10-07 16:57:22 +00:00
|
|
|
|
2008-09-29 01:58:27 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2008-09-29 01:58:27 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => 'preg:/.+/', 'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
2011-06-14 01:39:49 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => 'cancel%7Csave', 'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-09-29 01:58:27 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-09-29 01:58:27 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-19 16:43:09 +00:00
|
|
|
/**
|
|
|
|
* Test that buttons created with foo[bar] name attributes are unlocked correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecurityButtonNestedNamed() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
|
|
|
|
|
$this->Form->create('Addresses');
|
|
|
|
$this->Form->button('Test', array('type' => 'submit', 'name' => 'Address[button]'));
|
|
|
|
$result = $this->Form->unlockField();
|
|
|
|
$this->assertEquals(array('Address.button'), $result);
|
|
|
|
}
|
|
|
|
|
2011-11-24 01:40:25 +00:00
|
|
|
/**
|
|
|
|
* Test that submit inputs created with foo[bar] name attributes are unlocked correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuritySubmitNestedNamed() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
|
|
|
|
|
$this->Form->create('Addresses');
|
|
|
|
$this->Form->submit('Test', array('type' => 'submit', 'name' => 'Address[button]'));
|
|
|
|
$result = $this->Form->unlockField();
|
|
|
|
$this->assertEquals(array('Address.button'), $result);
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2011-09-28 01:14:36 +00:00
|
|
|
/**
|
|
|
|
* Test that the correct fields are unlocked for image submits with no names.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuritySubmitImageNoName() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
|
|
|
|
|
$this->Form->create('User');
|
|
|
|
$result = $this->Form->submit('save.png');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'img/save.png'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
$this->assertEquals(array('x', 'y'), $this->Form->unlockField());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the correct fields are unlocked for image submits with names.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuritySubmitImageName() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
|
|
|
|
|
|
|
$this->Form->create('User');
|
|
|
|
$result = $this->Form->submit('save.png', array('name' => 'test'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'name' => 'test', 'src' => 'img/save.png'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
$this->assertEquals(array('test', 'test_x', 'test_y'), $this->Form->unlockField());
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityMultipleInputFields method
|
2008-10-07 16:57:22 +00:00
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* Test secure form creation with multiple row creation. Checks hidden, text, checkbox field types
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecurityMultipleInputFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$key = 'testKey';
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => $key);
|
2008-08-29 03:11:35 +00:00
|
|
|
$this->Form->create('Addresses');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.0.title');
|
|
|
|
$this->Form->input('Addresses.0.first_name');
|
|
|
|
$this->Form->input('Addresses.0.last_name');
|
|
|
|
$this->Form->input('Addresses.0.address');
|
|
|
|
$this->Form->input('Addresses.0.city');
|
|
|
|
$this->Form->input('Addresses.0.phone');
|
2008-08-29 03:11:35 +00:00
|
|
|
$this->Form->input('Addresses.0.primary', array('type' => 'checkbox'));
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
|
|
|
|
$this->Form->input('Addresses.1.title');
|
|
|
|
$this->Form->input('Addresses.1.first_name');
|
|
|
|
$this->Form->input('Addresses.1.last_name');
|
|
|
|
$this->Form->input('Addresses.1.address');
|
|
|
|
$this->Form->input('Addresses.1.city');
|
|
|
|
$this->Form->input('Addresses.1.phone');
|
2008-08-29 03:11:35 +00:00
|
|
|
$this->Form->input('Addresses.1.primary', array('type' => 'checkbox'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->secure($this->Form->fields);
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2014-04-26 02:05:58 +00:00
|
|
|
$hash = 'a3b9b2ba1cb688838f92818a5970e17dd7943a78%3AAddresses.0.id%7CAddresses.1.id';
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
array(
|
|
|
|
'Addresses.0.id' => '123456',
|
|
|
|
'Addresses.0.title',
|
|
|
|
'Addresses.0.first_name',
|
|
|
|
'Addresses.0.last_name',
|
|
|
|
'Addresses.0.address',
|
|
|
|
'Addresses.0.city',
|
|
|
|
'Addresses.0.phone',
|
|
|
|
'Addresses.0.primary',
|
|
|
|
'Addresses.1.id' => '654321',
|
|
|
|
'Addresses.1.title',
|
|
|
|
'Addresses.1.first_name',
|
|
|
|
'Addresses.1.last_name',
|
|
|
|
'Addresses.1.address',
|
|
|
|
'Addresses.1.city',
|
|
|
|
'Addresses.1.phone',
|
|
|
|
'Addresses.1.primary',
|
|
|
|
),
|
|
|
|
array()
|
|
|
|
)));
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => $hash, 'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
2011-06-14 01:39:49 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-04-05 17:02:17 +00:00
|
|
|
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-09-23 02:30:04 +00:00
|
|
|
/**
|
|
|
|
* Test form security with Model.field.0 style inputs
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testFormSecurityArrayFields() {
|
2011-09-23 02:30:04 +00:00
|
|
|
$key = 'testKey';
|
|
|
|
|
2011-10-02 02:38:20 +00:00
|
|
|
$this->Form->request->params['_Token']['key'] = $key;
|
2011-09-23 02:30:04 +00:00
|
|
|
$this->Form->create('Address');
|
|
|
|
$this->Form->input('Address.primary.1');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('Address.primary', $this->Form->fields[0]);
|
2012-03-17 01:03:02 +00:00
|
|
|
|
|
|
|
$this->Form->input('Address.secondary.1.0');
|
|
|
|
$this->assertEquals('Address.secondary', $this->Form->fields[1]);
|
2011-09-23 02:30:04 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityMultipleInputDisabledFields method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test secure form generation with multiple records and disabled fields.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecurityMultipleInputDisabledFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$key = 'testKey';
|
2011-06-09 01:14:22 +00:00
|
|
|
$this->Form->request->params['_Token'] = array(
|
2010-05-04 03:39:43 +00:00
|
|
|
'key' => $key,
|
2011-06-14 01:39:49 +00:00
|
|
|
'unlockedFields' => array('first_name', 'address')
|
2010-05-04 03:39:43 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create();
|
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.0.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.0.title');
|
|
|
|
$this->Form->input('Addresses.0.first_name');
|
|
|
|
$this->Form->input('Addresses.0.last_name');
|
|
|
|
$this->Form->input('Addresses.0.address');
|
|
|
|
$this->Form->input('Addresses.0.city');
|
|
|
|
$this->Form->input('Addresses.0.phone');
|
|
|
|
$this->Form->hidden('Addresses.1.id', array('value' => '654321'));
|
|
|
|
$this->Form->input('Addresses.1.title');
|
|
|
|
$this->Form->input('Addresses.1.first_name');
|
|
|
|
$this->Form->input('Addresses.1.last_name');
|
|
|
|
$this->Form->input('Addresses.1.address');
|
|
|
|
$this->Form->input('Addresses.1.city');
|
|
|
|
$this->Form->input('Addresses.1.phone');
|
|
|
|
|
|
|
|
$result = $this->Form->secure($this->Form->fields);
|
2014-04-26 02:05:58 +00:00
|
|
|
$hash = '5c9cadf9da008cc444d3960b481391a425a5d979%3AAddresses.0.id%7CAddresses.1.id';
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
array(
|
|
|
|
'Addresses.0.id' => '123456',
|
|
|
|
'Addresses.0.title',
|
|
|
|
'Addresses.0.last_name',
|
|
|
|
'Addresses.0.city',
|
|
|
|
'Addresses.0.phone',
|
|
|
|
'Addresses.1.id' => '654321',
|
|
|
|
'Addresses.1.title',
|
|
|
|
'Addresses.1.last_name',
|
|
|
|
'Addresses.1.city',
|
|
|
|
'Addresses.1.phone'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'first_name',
|
|
|
|
'address'
|
|
|
|
)
|
|
|
|
)));
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden', 'name' =>
|
|
|
|
'data[_Token][fields]',
|
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off'
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][unlocked]',
|
|
|
|
'value' => 'address%7Cfirst_name',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off'
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecurityInputDisabledFields method
|
2008-10-07 16:57:22 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test single record form with disabled fields.
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-06-14 01:39:49 +00:00
|
|
|
public function testFormSecurityInputUnlockedFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$key = 'testKey';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array(
|
2010-05-04 03:39:43 +00:00
|
|
|
'key' => $key,
|
2011-06-14 01:39:49 +00:00
|
|
|
'unlockedFields' => array('first_name', 'address')
|
2010-05-04 03:39:43 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create();
|
2011-06-14 01:39:49 +00:00
|
|
|
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.title');
|
|
|
|
$this->Form->input('Addresses.first_name');
|
|
|
|
$this->Form->input('Addresses.last_name');
|
|
|
|
$this->Form->input('Addresses.address');
|
|
|
|
$this->Form->input('Addresses.city');
|
|
|
|
$this->Form->input('Addresses.phone');
|
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
2008-09-29 16:23:39 +00:00
|
|
|
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
|
2008-09-24 23:02:14 +00:00
|
|
|
'Addresses.city', 'Addresses.phone'
|
2008-09-21 04:06:37 +00:00
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->secure($expected);
|
|
|
|
|
2016-10-16 11:20:11 +00:00
|
|
|
$hash = '40289bd07811587887ff56585a8526ff9da59d7a%3AAddresses.id';
|
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
array(
|
|
|
|
'Addresses.id' => '123456',
|
|
|
|
'Addresses.title',
|
|
|
|
'Addresses.last_name',
|
|
|
|
'Addresses.city',
|
|
|
|
'Addresses.phone'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'first_name',
|
|
|
|
'address'
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => 'address%7Cfirst_name',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => $tokenDebug,
|
|
|
|
'id' => 'preg:/TokenDebug\d+/',
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFormSecurityInputUnlockedFieldsDebugSecurityTrue method
|
|
|
|
*
|
|
|
|
* Test single record form with debugSecurity param.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormSecurityInputUnlockedFieldsDebugSecurityTrue() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'unlockedFields' => array('first_name', 'address')
|
|
|
|
);
|
|
|
|
$this->Form->create();
|
|
|
|
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
|
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.title');
|
|
|
|
$this->Form->input('Addresses.first_name');
|
|
|
|
$this->Form->input('Addresses.last_name');
|
|
|
|
$this->Form->input('Addresses.address');
|
|
|
|
$this->Form->input('Addresses.city');
|
|
|
|
$this->Form->input('Addresses.phone');
|
|
|
|
|
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
|
|
|
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
|
|
|
|
'Addresses.city', 'Addresses.phone'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Form->secure($expected, array('debugSecurity' => true));
|
|
|
|
|
|
|
|
$hash = '40289bd07811587887ff56585a8526ff9da59d7a%3AAddresses.id';
|
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
array(
|
|
|
|
'Addresses.id' => '123456',
|
|
|
|
'Addresses.title',
|
|
|
|
'Addresses.last_name',
|
|
|
|
'Addresses.city',
|
|
|
|
'Addresses.phone'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'first_name',
|
|
|
|
'address'
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => 'address%7Cfirst_name',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFormSecurityInputUnlockedFieldsDebugSecurityDebugFalse method
|
|
|
|
*
|
|
|
|
* Debug is false, debugSecurity is true -> no debug
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormSecurityInputUnlockedFieldsDebugSecurityDebugFalse() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'unlockedFields' => array('first_name', 'address')
|
|
|
|
);
|
|
|
|
$this->Form->create();
|
|
|
|
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
|
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.title');
|
|
|
|
$this->Form->input('Addresses.first_name');
|
|
|
|
$this->Form->input('Addresses.last_name');
|
|
|
|
$this->Form->input('Addresses.address');
|
|
|
|
$this->Form->input('Addresses.city');
|
|
|
|
$this->Form->input('Addresses.phone');
|
|
|
|
|
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
|
|
|
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
|
|
|
|
'Addresses.city', 'Addresses.phone'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
Configure::write('debug', false);
|
|
|
|
$result = $this->Form->secure($expected, array('debugSecurity' => true));
|
|
|
|
|
|
|
|
$hash = '40289bd07811587887ff56585a8526ff9da59d7a%3AAddresses.id';
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][fields]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
|
2017-05-28 01:47:22 +00:00
|
|
|
'value' => 'address%7Cfirst_name',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete'
|
2016-10-16 11:20:11 +00:00
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFormSecurityInputUnlockedFieldsDebugSecurityFalse method
|
|
|
|
*
|
|
|
|
* Test single record form with debugSecurity param.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormSecurityInputUnlockedFieldsDebugSecurityFalse() {
|
|
|
|
$key = 'testKey';
|
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => $key,
|
|
|
|
'unlockedFields' => array('first_name', 'address')
|
|
|
|
);
|
|
|
|
$this->Form->create();
|
|
|
|
$this->assertEquals($this->Form->request['_Token']['unlockedFields'], $this->Form->unlockField());
|
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.title');
|
|
|
|
$this->Form->input('Addresses.first_name');
|
|
|
|
$this->Form->input('Addresses.last_name');
|
|
|
|
$this->Form->input('Addresses.address');
|
|
|
|
$this->Form->input('Addresses.city');
|
|
|
|
$this->Form->input('Addresses.phone');
|
|
|
|
|
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
|
|
|
'Addresses.id' => '123456', 'Addresses.title', 'Addresses.last_name',
|
|
|
|
'Addresses.city', 'Addresses.phone'
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Form->secure($expected, array('debugSecurity' => false));
|
|
|
|
|
2014-04-26 02:05:58 +00:00
|
|
|
$hash = '40289bd07811587887ff56585a8526ff9da59d7a%3AAddresses.id';
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][fields]',
|
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][unlocked]',
|
|
|
|
'value' => 'address%7Cfirst_name',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-28 02:05:30 +00:00
|
|
|
/**
|
|
|
|
* test securing inputs with custom name attributes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecureWithCustomNameAttribute() {
|
2011-02-05 20:24:46 +00:00
|
|
|
$this->Form->request->params['_Token']['key'] = 'testKey';
|
2011-01-28 02:05:30 +00:00
|
|
|
|
|
|
|
$this->Form->text('UserForm.published', array('name' => 'data[User][custom]'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('User.custom', $this->Form->fields[0]);
|
2011-01-28 02:05:30 +00:00
|
|
|
|
|
|
|
$this->Form->text('UserForm.published', array('name' => 'data[User][custom][another][value]'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('User.custom.another.value', $this->Form->fields[1]);
|
2011-01-28 02:05:30 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormSecuredInput method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test generation of entire secure form, assertions made on input() output.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormSecuredInput() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('url' => '/contacts/add'));
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-03-16 01:19:15 +00:00
|
|
|
'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding, 'id' => 'ContactAddForm'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][key]',
|
|
|
|
'value' => 'testKey',
|
|
|
|
'id' => 'preg:/Token\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('UserForm.published', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'UserFormPublished'),
|
|
|
|
'Published',
|
|
|
|
'/label',
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[UserForm][published]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'UserFormPublished'
|
2008-09-24 23:02:14 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('UserForm.other', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'UserFormOther'),
|
|
|
|
'Other',
|
|
|
|
'/label',
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[UserForm][other]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'UserFormOther'
|
2008-09-24 23:02:14 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->hidden('UserForm.stuff');
|
2013-04-12 16:28:40 +00:00
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[UserForm][stuff]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'UserFormStuff'
|
2008-09-24 23:02:14 +00:00
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-08-08 15:08:18 +00:00
|
|
|
$result = $this->Form->hidden('UserForm.hidden', array('value' => '0'));
|
2008-09-24 23:02:14 +00:00
|
|
|
$expected = array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[UserForm][hidden]',
|
|
|
|
'value' => '0', 'id' => 'UserFormHidden'
|
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-08-08 15:08:18 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('UserForm.something', array('type' => 'checkbox'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[UserForm][something]',
|
|
|
|
'value' => '0', 'id' => 'UserFormSomething_'
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
|
'value' => '1', 'id' => 'UserFormSomething'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'label' => array('for' => 'UserFormSomething'),
|
|
|
|
'Something',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
|
|
|
'UserForm.published', 'UserForm.other', 'UserForm.stuff' => '',
|
|
|
|
'UserForm.hidden' => '0', 'UserForm.something'
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2014-04-26 02:05:58 +00:00
|
|
|
$hash = '6014b4e1c4f39eb62389712111dbe6435bec66cb%3AUserForm.hidden%7CUserForm.stuff';
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/contacts/add',
|
|
|
|
$expected,
|
|
|
|
array()
|
|
|
|
)));
|
2008-09-24 23:02:14 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->secure($this->Form->fields);
|
|
|
|
$expected = array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][fields]',
|
|
|
|
'value' => $hash,
|
|
|
|
'id' => 'preg:/TokenFields\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2008-09-24 23:02:14 +00:00
|
|
|
)),
|
2011-06-09 02:46:29 +00:00
|
|
|
array('input' => array(
|
2017-04-05 17:02:17 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[_Token][unlocked]',
|
|
|
|
'value' => '',
|
|
|
|
'id' => 'preg:/TokenUnlocked\d+/',
|
|
|
|
'autocomplete' => 'off',
|
2011-06-09 02:46:29 +00:00
|
|
|
)),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2015-08-23 03:10:44 +00:00
|
|
|
/**
|
|
|
|
* Test that a hidden field followed by a visible field
|
|
|
|
* undoes the hidden field locking.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuredInputDuplicate() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->input('text_val', array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'value' => 'some text',
|
|
|
|
));
|
|
|
|
$expected = array('text_val' => 'some text');
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->input('text_val', array(
|
|
|
|
'type' => 'text',
|
|
|
|
));
|
|
|
|
$expected = array('text_val');
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2013-04-12 16:28:40 +00:00
|
|
|
/**
|
|
|
|
* Test secured inputs with custom names.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuredInputCustomName() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->input('text_input', array(
|
|
|
|
'name' => 'data[Option][General.default_role]',
|
|
|
|
));
|
|
|
|
$expected = array('Option.General.default_role');
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->input('select_box', array(
|
|
|
|
'name' => 'data[Option][General.select_role]',
|
|
|
|
'type' => 'select',
|
|
|
|
'options' => array(1, 2),
|
|
|
|
));
|
|
|
|
$expected = array('Option.General.default_role', 'Option.General.select_role');
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2008-09-29 16:23:39 +00:00
|
|
|
/**
|
|
|
|
* Tests that the correct keys are added to the field hash index
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-05-07 02:13:44 +00:00
|
|
|
public function testSecuredFileInput() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
2008-09-29 16:23:39 +00:00
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Form->file('Attachment.file');
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array(
|
2008-09-29 16:23:39 +00:00
|
|
|
'Attachment.file.name', 'Attachment.file.type', 'Attachment.file.tmp_name',
|
|
|
|
'Attachment.file.error', 'Attachment.file.size'
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
2008-09-29 16:23:39 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-20 03:01:01 +00:00
|
|
|
/**
|
|
|
|
* test that multiple selects keys are added to field hash
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-05-07 02:13:44 +00:00
|
|
|
public function testSecuredMultipleSelect() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
2008-10-29 06:55:42 +00:00
|
|
|
$options = array('1' => 'one', '2' => 'two');
|
2008-10-20 03:01:01 +00:00
|
|
|
|
2008-10-29 06:55:42 +00:00
|
|
|
$this->Form->select('Model.select', $options);
|
2008-10-20 03:01:01 +00:00
|
|
|
$expected = array('Model.select');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
2008-10-20 03:01:01 +00:00
|
|
|
|
|
|
|
$this->Form->fields = array();
|
2010-11-01 01:56:59 +00:00
|
|
|
$this->Form->select('Model.select', $options, array('multiple' => true));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
2008-10-20 03:01:01 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-25 16:32:54 +00:00
|
|
|
/**
|
|
|
|
* testFormSecuredRadio method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-05-07 02:13:44 +00:00
|
|
|
public function testSecuredRadio() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
2008-11-25 16:32:54 +00:00
|
|
|
$options = array('1' => 'option1', '2' => 'option2');
|
|
|
|
|
|
|
|
$this->Form->radio('Test.test', $options);
|
|
|
|
$expected = array('Test.test');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
2015-01-09 04:20:30 +00:00
|
|
|
|
|
|
|
$this->Form->radio('Test.all', $options, array(
|
|
|
|
'disabled' => array('option1', 'option2')
|
|
|
|
));
|
|
|
|
$expected = array('Test.test', 'Test.all' => '');
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->radio('Test.some', $options, array(
|
|
|
|
'disabled' => array('option1')
|
|
|
|
));
|
2015-01-09 20:32:33 +00:00
|
|
|
$expected = array('Test.test', 'Test.all' => '', 'Test.some');
|
2015-01-09 04:20:30 +00:00
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
2008-11-25 16:32:54 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-04-03 16:46:03 +00:00
|
|
|
/**
|
|
|
|
* Test that when disabled is in a list based attribute array it works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-05-07 02:13:44 +00:00
|
|
|
public function testSecuredAndDisabledNotAssoc() {
|
2013-04-03 16:46:03 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
|
|
|
|
$this->Form->select('Model.select', array(1, 2), array('disabled'));
|
|
|
|
$this->Form->checkbox('Model.checkbox', array('disabled'));
|
|
|
|
$this->Form->text('Model.text', array('disabled'));
|
|
|
|
$this->Form->textarea('Model.textarea', array('disabled'));
|
|
|
|
$this->Form->password('Model.password', array('disabled'));
|
|
|
|
$this->Form->radio('Model.radio', array(1, 2), array('disabled'));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'Model.radio' => ''
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2011-12-08 03:30:40 +00:00
|
|
|
/**
|
|
|
|
* test that forms with disabled inputs + secured forms leave off the inputs from the form
|
|
|
|
* hashing.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-05-07 02:13:44 +00:00
|
|
|
public function testSecuredAndDisabled() {
|
2011-12-08 03:30:40 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
|
|
|
|
$this->Form->checkbox('Model.checkbox', array('disabled' => true));
|
|
|
|
$this->Form->text('Model.text', array('disabled' => true));
|
2015-01-09 04:20:30 +00:00
|
|
|
$this->Form->text('Model.text2', array('disabled' => 'disabled'));
|
|
|
|
$this->Form->password('Model.password', array('disabled' => true));
|
2011-12-08 03:30:40 +00:00
|
|
|
$this->Form->textarea('Model.textarea', array('disabled' => true));
|
|
|
|
$this->Form->select('Model.select', array(1, 2), array('disabled' => true));
|
2015-01-09 04:20:30 +00:00
|
|
|
$this->Form->select('Model.select', array(1, 2), array('disabled' => array(1, 2)));
|
2011-12-08 03:30:40 +00:00
|
|
|
$this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
|
|
|
|
$this->Form->year('Model.year', null, null, array('disabled' => true));
|
|
|
|
$this->Form->month('Model.month', array('disabled' => true));
|
|
|
|
$this->Form->day('Model.day', array('disabled' => true));
|
|
|
|
$this->Form->hour('Model.hour', false, array('disabled' => true));
|
|
|
|
$this->Form->minute('Model.minute', array('disabled' => true));
|
|
|
|
$this->Form->meridian('Model.meridian', array('disabled' => true));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'Model.radio' => ''
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2014-05-07 03:00:11 +00:00
|
|
|
/**
|
|
|
|
* Test that only the path + query elements of a form's URL show up in their hash.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuredFormUrlIgnoresHost() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
|
2014-05-07 12:43:25 +00:00
|
|
|
$expected = '0ff0c85cd70584d8fd18fa136846d22c66c21e2d%3A';
|
2014-05-07 03:00:11 +00:00
|
|
|
$this->Form->create('Address', array(
|
|
|
|
'url' => array('controller' => 'articles', 'action' => 'view', 1, '?' => array('page' => 1))
|
|
|
|
));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result);
|
2014-05-07 03:00:11 +00:00
|
|
|
|
|
|
|
$this->Form->create('Address', array('url' => 'http://localhost/articles/view/1?page=1'));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result, 'Full URL should only use path and query.');
|
2014-05-07 03:00:11 +00:00
|
|
|
|
|
|
|
$this->Form->create('Address', array('url' => '/articles/view/1?page=1'));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result, 'URL path + query should work.');
|
2014-05-07 03:00:11 +00:00
|
|
|
|
|
|
|
$this->Form->create('Address', array('url' => '/articles/view/1'));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString($expected, $result, 'URL is different');
|
2014-05-07 03:00:11 +00:00
|
|
|
}
|
|
|
|
|
2014-05-22 18:14:35 +00:00
|
|
|
/**
|
|
|
|
* Ensure named parameters work correctly with hash generation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecuredFormUrlWorksWithNamedParameter() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
|
|
|
|
$expected = 'c890c5f041b1d83d1610dee8f52cd257df7ce618%3A';
|
|
|
|
$this->Form->create('Address', array(
|
|
|
|
'url' => array('controller' => 'articles', 'action' => 'view', 1, 'type' => 'red')
|
|
|
|
));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result);
|
2014-05-22 18:14:35 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 02:40:21 +00:00
|
|
|
/**
|
2014-06-27 03:06:08 +00:00
|
|
|
* Test that URL, HTML and identifier show up in their hashs.
|
2014-05-19 02:40:21 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-06-27 03:06:08 +00:00
|
|
|
public function testSecuredFormUrlHasHtmlAndIdentifier() {
|
2014-05-19 02:40:21 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
|
|
|
|
2014-05-20 01:28:29 +00:00
|
|
|
$expected = 'ece0693fb1b19ca116133db1832ac29baaf41ce5%3A';
|
2014-05-19 02:40:21 +00:00
|
|
|
$this->Form->create('Address', array(
|
2014-05-20 01:28:29 +00:00
|
|
|
'url' => array(
|
|
|
|
'controller' => 'articles',
|
|
|
|
'action' => 'view',
|
|
|
|
'?' => array(
|
|
|
|
'page' => 1,
|
|
|
|
'limit' => 10,
|
|
|
|
'html' => '<>"',
|
|
|
|
),
|
|
|
|
'#' => 'result',
|
|
|
|
),
|
2014-05-19 02:40:21 +00:00
|
|
|
));
|
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result);
|
2014-05-19 02:40:21 +00:00
|
|
|
|
2014-05-20 01:28:29 +00:00
|
|
|
$this->Form->create('Address', array('url' => 'http://localhost/articles/view?page=1&limit=10&html=%3C%3E%22#result'));
|
2014-05-19 02:40:21 +00:00
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result, 'Full URL should only use path and query.');
|
2014-05-19 02:40:21 +00:00
|
|
|
|
2014-05-20 01:28:29 +00:00
|
|
|
$this->Form->create('Address', array('url' => '/articles/view?page=1&limit=10&html=%3C%3E%22#result'));
|
2014-05-19 02:40:21 +00:00
|
|
|
$result = $this->Form->secure();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($expected, $result, 'URL path + query should work.');
|
2014-05-19 02:40:21 +00:00
|
|
|
}
|
|
|
|
|
2010-04-08 22:53:07 +00:00
|
|
|
/**
|
|
|
|
* testDisableSecurityUsingForm method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDisableSecurityUsingForm() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array(
|
2010-05-04 03:39:43 +00:00
|
|
|
'key' => 'testKey',
|
|
|
|
'disabledFields' => array()
|
|
|
|
);
|
2010-04-08 22:53:07 +00:00
|
|
|
$this->Form->create();
|
|
|
|
|
|
|
|
$this->Form->hidden('Addresses.id', array('value' => '123456'));
|
|
|
|
$this->Form->input('Addresses.title');
|
|
|
|
$this->Form->input('Addresses.first_name', array('secure' => false));
|
|
|
|
$this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false));
|
|
|
|
$this->Form->input('Addresses.zip', array(
|
2013-08-07 23:03:21 +00:00
|
|
|
'type' => 'select', 'options' => array(1, 2), 'secure' => false
|
2010-04-08 22:53:07 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Form->fields;
|
|
|
|
$expected = array(
|
|
|
|
'Addresses.id' => '123456', 'Addresses.title',
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-04-08 22:53:07 +00:00
|
|
|
}
|
2011-06-09 02:17:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test disableField
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-06-14 01:39:49 +00:00
|
|
|
public function testUnlockFieldAddsToList() {
|
2011-06-09 02:17:32 +00:00
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => 'testKey',
|
2011-06-14 01:39:49 +00:00
|
|
|
'unlockedFields' => array()
|
2011-06-09 02:17:32 +00:00
|
|
|
);
|
|
|
|
$this->Form->create('Contact');
|
2011-06-14 01:39:49 +00:00
|
|
|
$this->Form->unlockField('Contact.name');
|
2011-06-09 02:17:32 +00:00
|
|
|
$this->Form->text('Contact.name');
|
|
|
|
|
2011-06-14 01:39:49 +00:00
|
|
|
$this->assertEquals(array('Contact.name'), $this->Form->unlockField());
|
2011-06-09 02:17:32 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-14 01:39:49 +00:00
|
|
|
* test unlockField removing from fields array.
|
2011-06-09 02:17:32 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-06-14 01:39:49 +00:00
|
|
|
public function testUnlockFieldRemovingFromFields() {
|
2011-06-09 02:17:32 +00:00
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => 'testKey',
|
2011-06-14 01:39:49 +00:00
|
|
|
'unlockedFields' => array()
|
2011-06-09 02:17:32 +00:00
|
|
|
);
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$this->Form->hidden('Contact.id', array('value' => 1));
|
|
|
|
$this->Form->text('Contact.name');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
|
|
|
|
$this->assertTrue(in_array('Contact.name', $this->Form->fields), 'Field should be secured.');
|
|
|
|
|
2011-06-14 01:39:49 +00:00
|
|
|
$this->Form->unlockField('Contact.name');
|
|
|
|
$this->Form->unlockField('Contact.id');
|
2011-06-09 02:17:32 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2016-05-21 04:33:20 +00:00
|
|
|
/**
|
|
|
|
* test reset unlockFields, when create new form.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testResetUnlockFields() {
|
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => 'testKey',
|
|
|
|
'unlockedFields' => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->Form->unlockField('Contact.id');
|
2016-05-25 21:04:53 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$this->Form->hidden('Contact.id', array('value' => 1));
|
|
|
|
$this->assertEmpty($this->Form->fields, 'Field should be unlocked');
|
2016-05-21 04:33:20 +00:00
|
|
|
$this->Form->end();
|
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$this->Form->hidden('Contact.id', array('value' => 1));
|
|
|
|
$this->assertEquals(1, $this->Form->fields['Contact.id'], 'Hidden input should be secured.');
|
|
|
|
}
|
|
|
|
|
2016-05-21 02:01:49 +00:00
|
|
|
/**
|
|
|
|
* test unlockField removing from fields array. multiple field version.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testUnlockMultipleFieldRemovingFromFields() {
|
|
|
|
$this->Form->request['_Token'] = array(
|
|
|
|
'key' => 'testKey',
|
|
|
|
'unlockedFields' => array()
|
|
|
|
);
|
|
|
|
$this->Form->create('Order');
|
|
|
|
$this->Form->hidden('Order.id', array('value' => 1));
|
|
|
|
$this->Form->checkbox('Ticked.id.');
|
|
|
|
$this->Form->checkbox('Ticked.id.');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $this->Form->fields['Order.id'], 'Hidden input should be secured.');
|
|
|
|
$this->assertTrue(in_array('Ticked.id', $this->Form->fields), 'Field should be secured.');
|
|
|
|
|
|
|
|
$this->Form->unlockField('Order.id');
|
|
|
|
$this->Form->unlockField('Ticked.id');
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2012-02-11 00:39:58 +00:00
|
|
|
/**
|
|
|
|
* testTagIsInvalid method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTagIsInvalid() {
|
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
2013-05-14 01:08:19 +00:00
|
|
|
$Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
|
2012-02-11 00:39:58 +00:00
|
|
|
|
|
|
|
$this->Form->setEntity('Contact.0.email');
|
|
|
|
$result = $this->Form->tagIsInvalid();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Form->setEntity('Contact.1.email');
|
|
|
|
$result = $this->Form->tagIsInvalid();
|
2013-05-14 00:53:37 +00:00
|
|
|
$this->assertFalse($result);
|
2012-02-11 00:39:58 +00:00
|
|
|
|
|
|
|
$this->Form->setEntity('Contact.0.name');
|
|
|
|
$result = $this->Form->tagIsInvalid();
|
2013-05-14 00:53:37 +00:00
|
|
|
$this->assertFalse($result);
|
2012-02-11 00:39:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 01:08:19 +00:00
|
|
|
/**
|
|
|
|
* Test tagIsInvalid with validation errors from a saveMany
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTagIsInvalidSaveMany() {
|
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors[0]['email'] = $expected = array('Please provide an email');
|
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
|
|
|
|
$this->Form->setEntity('0.email');
|
|
|
|
$result = $this->Form->tagIsInvalid();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->Form->setEntity('0.Contact.email');
|
|
|
|
$result = $this->Form->tagIsInvalid();
|
|
|
|
$this->assertEquals($expected, $result);
|
2012-02-11 00:39:58 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2012-09-20 16:24:22 +00:00
|
|
|
* Test validation errors.
|
2008-09-26 00:07:57 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPasswordValidation() {
|
2011-07-14 04:21:23 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
2012-03-16 02:50:05 +00:00
|
|
|
$Contact->validationErrors['password'] = array('Please provide a password');
|
2011-07-14 04:21:23 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.password');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
2008-10-29 06:55:42 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
2008-10-29 06:55:42 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'Please provide a password',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-09-20 16:24:22 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.password', array('errorMessage' => false));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2019-03-15 16:41:29 +00:00
|
|
|
/**
|
|
|
|
* Test validation errors with error options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPasswordValidationWithOptions() {
|
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['password'] = array('Please provide a password');
|
|
|
|
|
2019-03-15 17:50:26 +00:00
|
|
|
$result = $this->Form->input('Contact.password', array(
|
2019-03-15 16:41:29 +00:00
|
|
|
'error' => array(
|
2019-03-15 17:50:26 +00:00
|
|
|
'attributes' => array('class' => 'special-error-class'),
|
|
|
|
)
|
2019-03-15 16:41:29 +00:00
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'special-error-class')),
|
|
|
|
'Please provide a password',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$Contact->validationErrors['password'] = array('Please provide a password<br>otherwise you will not be able to login');
|
2019-03-15 17:50:26 +00:00
|
|
|
$result = $this->Form->input('Contact.password', array(
|
2019-03-15 16:41:29 +00:00
|
|
|
'error' => array(
|
|
|
|
'attributes' => array(
|
|
|
|
'class' => 'special-error-class',
|
|
|
|
'escape' => false,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'special-error-class')),
|
|
|
|
'Please provide a password<br>otherwise you will not be able to login',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2011-09-28 09:02:17 +00:00
|
|
|
/**
|
2012-09-20 16:24:22 +00:00
|
|
|
* Test validation errors, when validation message is an empty string.
|
2011-09-28 09:02:17 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testEmptyErrorValidation() {
|
2011-09-28 15:05:32 +00:00
|
|
|
$this->Form->validationErrors['Contact']['password'] = '';
|
2012-09-20 16:24:22 +00:00
|
|
|
|
2011-09-28 15:05:32 +00:00
|
|
|
$result = $this->Form->input('Contact.password');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
array(),
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-09-20 16:24:22 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.password', array('errorMessage' => false));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2011-09-28 15:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-20 16:24:22 +00:00
|
|
|
* Test validation errors, when calling input() overriding validation message by an empty string.
|
2011-09-28 15:05:32 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testEmptyInputErrorValidation() {
|
2011-09-28 09:02:17 +00:00
|
|
|
$this->Form->validationErrors['Contact']['password'] = 'Please provide a password';
|
2012-09-20 16:24:22 +00:00
|
|
|
|
2011-09-28 09:02:17 +00:00
|
|
|
$result = $this->Form->input('Contact.password', array('error' => ''));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
array(),
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-09-20 16:24:22 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.password', array('error' => '', 'errorMessage' => false));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password error'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
|
|
|
'id' => 'ContactPassword', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2011-09-28 09:02:17 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormValidationAssociated method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test display of form errors in conjunction with model::validates.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormValidationAssociated() {
|
2010-08-05 04:24:38 +00:00
|
|
|
$this->UserForm = ClassRegistry::getObject('UserForm');
|
|
|
|
$this->UserForm->OpenidUrl = ClassRegistry::getObject('OpenidUrl');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-29 06:55:42 +00:00
|
|
|
$data = array(
|
|
|
|
'UserForm' => array('name' => 'user'),
|
|
|
|
'OpenidUrl' => array('url' => 'http://www.cakephp.org')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-18 03:00:04 +00:00
|
|
|
$result = $this->UserForm->OpenidUrl->create($data);
|
|
|
|
$this->assertFalse(empty($result));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($this->UserForm->OpenidUrl->validates());
|
|
|
|
|
2016-01-04 13:22:40 +00:00
|
|
|
$result = $this->Form->create('UserForm', array('type' => 'post', 'url' => array('action' => 'login')));
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-10-29 06:55:42 +00:00
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'action' => '/user_forms/login',
|
|
|
|
'id' => 'UserFormLoginForm',
|
|
|
|
'method' => 'post',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-10-29 06:55:42 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-29 06:55:42 +00:00
|
|
|
$result = $this->Form->error(
|
|
|
|
'OpenidUrl.openid_not_registered', 'Error, not registered', array('wrap' => false)
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Error, not registered', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-29 06:55:42 +00:00
|
|
|
unset($this->UserForm->OpenidUrl, $this->UserForm);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormValidationAssociatedFirstLevel method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test form error display with associated model.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormValidationAssociatedFirstLevel() {
|
2010-08-05 04:24:38 +00:00
|
|
|
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
|
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-10-29 06:55:42 +00:00
|
|
|
$data = array(
|
|
|
|
'ValidateUser' => array('name' => 'mariano'),
|
|
|
|
'ValidateProfile' => array('full_name' => 'Mariano Iglesias')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-18 03:00:04 +00:00
|
|
|
$result = $this->ValidateUser->create($data);
|
|
|
|
$this->assertFalse(empty($result));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($this->ValidateUser->validates());
|
|
|
|
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
|
|
|
|
2016-01-04 13:22:40 +00:00
|
|
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2013-06-09 15:39:48 +00:00
|
|
|
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 04:21:23 +00:00
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateUser.email', 'Invalid email', array('wrap' => false)
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid email', $result);
|
2011-07-14 04:21:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid name', $result);
|
2011-07-14 04:21:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid city', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($this->ValidateUser->ValidateProfile);
|
|
|
|
unset($this->ValidateUser);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormValidationAssociatedSecondLevel method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test form error display with associated model.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormValidationAssociatedSecondLevel() {
|
2010-08-05 04:24:38 +00:00
|
|
|
$this->ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
|
$this->ValidateUser->ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
|
$this->ValidateUser->ValidateProfile->ValidateItem = ClassRegistry::getObject('ValidateItem');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'ValidateUser' => array('name' => 'mariano'),
|
|
|
|
'ValidateProfile' => array('full_name' => 'Mariano Iglesias'),
|
|
|
|
'ValidateItem' => array('name' => 'Item')
|
|
|
|
);
|
|
|
|
|
2010-05-18 03:00:04 +00:00
|
|
|
$result = $this->ValidateUser->create($data);
|
|
|
|
$this->assertFalse(empty($result));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($this->ValidateUser->validates());
|
|
|
|
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
|
|
|
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
|
|
|
|
2016-01-04 13:22:40 +00:00
|
|
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2013-08-07 23:03:21 +00:00
|
|
|
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-07-14 04:21:23 +00:00
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateUser.email', 'Invalid email', array('wrap' => false)
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid email', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 04:21:23 +00:00
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateProfile.full_name', 'Invalid name', array('wrap' => false)
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid name', $result);
|
2011-07-14 04:21:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateProfile.city', 'Invalid city', array('wrap' => false)
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $this->Form->error(
|
|
|
|
'ValidateItem.description', 'Invalid description', array('wrap' => false)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Invalid description', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
unset($this->ValidateUser->ValidateProfile->ValidateItem);
|
|
|
|
unset($this->ValidateUser->ValidateProfile);
|
|
|
|
unset($this->ValidateUser);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormValidationMultiRecord method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test form error display with multiple records.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormValidationMultiRecord() {
|
2011-07-14 04:21:23 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors[2] = array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'name' => array('This field cannot be left blank')
|
2011-07-14 04:21:23 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.2.name');
|
|
|
|
$expected = array(
|
2011-06-25 16:31:08 +00:00
|
|
|
'div' => array('class' => 'input text error'),
|
|
|
|
'label' => array('for' => 'Contact2Name'),
|
|
|
|
'Name',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/label',
|
2008-10-29 06:55:42 +00:00
|
|
|
'input' => array(
|
2011-06-25 16:31:08 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][2][name]', 'id' => 'Contact2Name',
|
2008-10-29 06:55:42 +00:00
|
|
|
'class' => 'form-error', 'maxlength' => 255
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'This field cannot be left blank',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMultipleInputValidation method
|
2008-10-07 16:57:22 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test multiple record form validation error display.
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleInputValidation() {
|
2011-07-14 21:56:55 +00:00
|
|
|
$Address = ClassRegistry::init(array('class' => 'Address', 'table' => false, 'ds' => 'test'));
|
2011-07-14 04:21:23 +00:00
|
|
|
$Address->validationErrors[0] = array(
|
|
|
|
'title' => array('This field cannot be empty'),
|
|
|
|
'first_name' => array('This field cannot be empty')
|
|
|
|
);
|
|
|
|
$Address->validationErrors[1] = array(
|
|
|
|
'last_name' => array('You must have a last name')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create();
|
|
|
|
|
|
|
|
$result = $this->Form->input('Address.0.title');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'preg:/[^<]+/',
|
|
|
|
'/label',
|
2008-10-29 06:55:42 +00:00
|
|
|
'input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'type' => 'text', 'name', 'id', 'class' => 'form-error'
|
2008-10-29 06:55:42 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'This field cannot be empty',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Address.0.first_name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'preg:/[^<]+/',
|
|
|
|
'/label',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'text', 'name', 'id', 'class' => 'form-error'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'This field cannot be empty',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Address.0.last_name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'preg:/[^<]+/',
|
|
|
|
'/label',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'text', 'name', 'id'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Address.1.last_name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'preg:/[^<]+/',
|
|
|
|
'/label',
|
2008-10-29 06:55:42 +00:00
|
|
|
'input' => array(
|
2014-03-22 01:57:06 +00:00
|
|
|
'type' => 'text', 'name', 'id',
|
|
|
|
'class' => 'form-error'
|
2008-10-29 06:55:42 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'You must have a last name',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-10-31 05:45:17 +00:00
|
|
|
* testInput method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test various incarnations of input().
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInput() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('ValidateUser.balance');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'Balance',
|
|
|
|
'/label',
|
2014-03-22 01:57:06 +00:00
|
|
|
'input' => array('name', 'type' => 'number', 'id', 'step'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-09-29 14:40:35 +00:00
|
|
|
$result = $this->Form->input('ValidateUser.cost_decimal');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'Cost Decimal',
|
|
|
|
'/label',
|
2013-09-29 14:44:50 +00:00
|
|
|
'input' => array('name', 'type' => 'number', 'step' => '0.001', 'id'),
|
2013-09-29 14:40:35 +00:00
|
|
|
'/div',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2015-10-02 01:46:21 +00:00
|
|
|
$result = $this->Form->input('ValidateUser.null_decimal');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'Null Decimal',
|
|
|
|
'/label',
|
|
|
|
'input' => array('name', 'type' => 'number', 'step' => 'any', 'id'),
|
|
|
|
'/div',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2014-01-30 20:17:50 +00:00
|
|
|
$result = $this->Form->input('ValidateUser.ratio');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'Ratio',
|
|
|
|
'/label',
|
|
|
|
'input' => array('name', 'type' => 'number', 'step' => '0.000001', 'id'),
|
|
|
|
'/div',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('ValidateUser.population');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class'),
|
|
|
|
'label' => array('for'),
|
|
|
|
'Population',
|
|
|
|
'/label',
|
|
|
|
'input' => array('name', 'type' => 'number', 'step' => '1', 'id'),
|
|
|
|
'/div',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.email', array('id' => 'custom'));
|
|
|
|
$expected = array(
|
2013-01-25 21:47:45 +00:00
|
|
|
'div' => array('class' => 'input email'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'label' => array('for' => 'custom'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2013-01-25 21:47:45 +00:00
|
|
|
'type' => 'email', 'name' => 'data[Contact][email]',
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => 'custom', 'maxlength' => 255
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-02-07 21:30:43 +00:00
|
|
|
$result = $this->Form->input('Contact.email', array('div' => array('class' => false)));
|
|
|
|
$expected = array(
|
|
|
|
'<div',
|
|
|
|
'label' => array('for' => 'ContactEmail'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
2013-01-25 21:47:45 +00:00
|
|
|
'type' => 'email', 'name' => 'data[Contact][email]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactEmail', 'maxlength' => 255
|
|
|
|
)),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-07 21:30:43 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
$result = $this->Form->hidden('Contact.idontexist');
|
2008-12-25 22:13:06 +00:00
|
|
|
$expected = array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][idontexist]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactIdontexist'
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.email', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactEmail'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactEmail'
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.5.email', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'Contact5Email'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][5][email]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'Contact5Email'
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
$result = $this->Form->input('Contact.password');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input password'),
|
|
|
|
'label' => array('for' => 'ContactPassword'),
|
|
|
|
'Password',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'password', 'name' => 'data[Contact][password]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactPassword'
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-22 19:16:34 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.email', array(
|
|
|
|
'type' => 'file', 'class' => 'textbox'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input file'),
|
|
|
|
'label' => array('for' => 'ContactEmail'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'file', 'name' => 'data[Contact][email]', 'class' => 'textbox',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactEmail'
|
2008-12-25 22:13:06 +00:00
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Contact' => array('phone' => 'Hello & World > weird chars'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.phone');
|
|
|
|
$expected = array(
|
2013-01-25 21:47:45 +00:00
|
|
|
'div' => array('class' => 'input tel'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'label' => array('for' => 'ContactPhone'),
|
|
|
|
'Phone',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('input' => array(
|
2013-01-25 21:47:45 +00:00
|
|
|
'type' => 'tel', 'name' => 'data[Contact][phone]',
|
2008-12-25 22:13:06 +00:00
|
|
|
'value' => 'Hello & World > weird chars',
|
|
|
|
'id' => 'ContactPhone', 'maxlength' => 255
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-10-07 16:57:22 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
|
2008-10-06 23:57:27 +00:00
|
|
|
$result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'myId'),
|
|
|
|
'Field',
|
2008-10-06 23:58:35 +00:00
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Model][0][OtherModel][field]',
|
|
|
|
'value' => 'My value', 'id' => 'myId'
|
|
|
|
),
|
2008-10-06 23:57:27 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
unset($this->Form->request->data);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['field'] = array('Badness!');
|
|
|
|
$result = $this->Form->input('Contact.field');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2011-07-14 05:33:29 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'Badness!',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2008-05-30 15:07:32 +00:00
|
|
|
$expected = array(
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2008-05-30 15:07:32 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2011-07-14 05:33:29 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 15:07:32 +00:00
|
|
|
array('span' => array('class' => 'error-message')),
|
|
|
|
'Badness!',
|
|
|
|
'/span'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 15:07:32 +00:00
|
|
|
|
2011-11-08 19:29:33 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
|
|
|
'type' => 'text', 'error' => array('attributes' => array('class' => 'error'))
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
|
|
|
'label' => array('for' => 'ContactField'),
|
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'error')),
|
|
|
|
'Badness!',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2008-05-30 15:07:32 +00:00
|
|
|
$expected = array(
|
|
|
|
'span' => array('class' => 'input text error'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2008-05-30 15:07:32 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2011-07-14 05:33:29 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 15:07:32 +00:00
|
|
|
'Badness!',
|
|
|
|
'/span'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 15:07:32 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2011-07-14 05:33:29 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'A message to you, Rudy',
|
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'Badness!',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->setEntity(null);
|
2011-07-14 05:33:29 +00:00
|
|
|
$this->Form->setEntity('Contact.field');
|
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'after' => 'A message to you, Rudy', 'error' => false
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2011-07-14 05:33:29 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'A message to you, Rudy',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ObjectField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2011-07-14 15:35:41 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'A message to you, Rudy',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$Contact->validationErrors['field'] = array('minLength');
|
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2010-04-20 03:55:57 +00:00
|
|
|
'error' => array(
|
|
|
|
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
|
|
|
'maxLength' => 'login too large'
|
|
|
|
)
|
|
|
|
));
|
2009-10-15 00:10:32 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2009-10-15 00:10:32 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2011-07-14 05:33:29 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
2009-10-15 00:10:32 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'Le login doit contenir au moins 2 caractères',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-04-20 03:55:57 +00:00
|
|
|
|
2011-07-14 05:33:29 +00:00
|
|
|
$Contact->validationErrors['field'] = array('maxLength');
|
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2010-04-20 03:55:57 +00:00
|
|
|
'error' => array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
|
2010-04-20 03:55:57 +00:00
|
|
|
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
|
|
|
'maxLength' => 'login too large',
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
2011-07-14 05:33:29 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2010-04-20 03:55:57 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
2011-07-14 05:33:29 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
2010-04-20 03:55:57 +00:00
|
|
|
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
|
|
|
|
'login too large',
|
|
|
|
'/span',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 00:10:32 +00:00
|
|
|
}
|
2010-06-10 16:48:55 +00:00
|
|
|
|
2012-11-15 02:27:12 +00:00
|
|
|
/**
|
|
|
|
* Test that inputs with 0 can be created.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputZero() {
|
|
|
|
$this->Form->create('User');
|
|
|
|
$result = $this->Form->input('0');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'User0'), '/label',
|
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][0]', 'id' => 'User0'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2010-06-10 16:48:55 +00:00
|
|
|
/**
|
|
|
|
* test input() with checkbox creation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputCheckbox() {
|
2010-06-10 16:48:55 +00:00
|
|
|
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-06-10 16:48:55 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-10 17:46:48 +00:00
|
|
|
|
2010-06-10 23:11:26 +00:00
|
|
|
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][active]', 'value' => '0', 'id' => 'UserActive_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[User][active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-05-07 20:13:27 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('User.disabled', array(
|
|
|
|
'label' => 'Disabled',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'data-foo' => 'disabled'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'data[User][disabled]',
|
|
|
|
'value' => '1',
|
|
|
|
'id' => 'UserDisabled',
|
|
|
|
'data-foo' => 'disabled'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'UserDisabled'),
|
|
|
|
'Disabled',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2010-06-10 16:48:55 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:10:32 +00:00
|
|
|
/**
|
2011-05-10 02:14:06 +00:00
|
|
|
* test form->input() with time types.
|
2009-10-15 00:10:32 +00:00
|
|
|
*
|
2014-04-02 01:02:37 +00:00
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-06-23 19:48:06 +00:00
|
|
|
public function testInputTime() {
|
2009-10-15 00:10:32 +00:00
|
|
|
extract($this->dateRegex);
|
|
|
|
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/option value="23"/', $result[0]);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/option value="24"/', $result[0]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.created', array('type' => 'time', 'timeFormat' => 24));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/option value="23"/', $result[0]);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/option value="24"/', $result[0]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'time', 'timeFormat' => 24, 'interval' => 15
|
|
|
|
));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="50"[^>]*>50</option>#', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('#<option value="15"[^>]*>15</option>#', $result[1]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'time', 'timeFormat' => 12, 'interval' => 15
|
|
|
|
));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="50"[^>]*>50</option>#', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('#<option value="15"[^>]*>15</option>#', $result[1]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('prueba', array(
|
2013-08-07 23:03:21 +00:00
|
|
|
'type' => 'time', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
|
|
|
|
'maxYear' => date('Y') + 1, 'interval' => 15
|
2009-10-15 00:10:32 +00:00
|
|
|
));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="50"[^>]*>50</option>#', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
|
$this->assertMatchesRegularExpression('#<option value="30"[^>]*>30</option>#', $result[1]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
2011-05-10 02:17:51 +00:00
|
|
|
$result = $this->Form->input('Random.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'selected' => '18:15'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="06" selected="selected">6</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="15" selected="selected">15</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-03-14 00:56:04 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('published', array('type' => 'time'));
|
|
|
|
$now = strtotime('now');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="' . date('h', $now) . '" selected="selected">' . date('g', $now) . '</option>', $result);
|
2013-03-14 00:56:04 +00:00
|
|
|
|
|
|
|
$now = strtotime('2013-03-09 00:42:21');
|
|
|
|
$result = $this->Form->input('published', array('type' => 'time', 'selected' => $now));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="42" selected="selected">42</option>', $result);
|
2011-05-10 02:14:06 +00:00
|
|
|
}
|
|
|
|
|
2012-09-29 02:01:53 +00:00
|
|
|
/**
|
|
|
|
* Test interval + selected near the hour roll over.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeSelectedWithInterval() {
|
2012-10-26 00:46:54 +00:00
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2012-10-26 00:46:54 +00:00
|
|
|
|
2012-10-23 16:47:12 +00:00
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '2012-10-23 15:57:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2012-10-23 16:47:12 +00:00
|
|
|
|
2012-09-29 02:01:53 +00:00
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '15:57'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="16" selected="selected">16</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2012-09-29 02:01:53 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '23:57'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">0</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2012-09-29 02:01:53 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.created', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'datetime',
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '2012-09-30 23:56'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="2012" selected="selected">2012</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="10" selected="selected">October</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="01" selected="selected">1</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">0</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2012-09-29 02:01:53 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 13:58:50 +00:00
|
|
|
/**
|
|
|
|
* Test interval + value near the hour roll over.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeValueWithInterval() {
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => array('hour' => '3', 'min' => '57', 'meridian' => 'pm')
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '2012-10-23 15:57:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '15:57'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="16" selected="selected">16</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'time',
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '23:57'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">0</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.created', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'type' => 'datetime',
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '2012-09-30 23:56'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="2012" selected="selected">2012</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="10" selected="selected">October</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="01" selected="selected">1</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">0</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 22:36:27 +00:00
|
|
|
/**
|
|
|
|
* Test time with selected values around 12:xx:xx
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeSelectedWithIntervalTwelve() {
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '00:00:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="am" selected="selected">am</option>', $result);
|
2013-12-19 22:36:27 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '12:00:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-12-19 22:36:27 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'selected' => '12:15:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="15" selected="selected">15</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-12-19 22:36:27 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 13:58:50 +00:00
|
|
|
/**
|
|
|
|
* Test time with selected values around 12:xx:xx
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeValueWithIntervalTwelve() {
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '00:00:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="am" selected="selected">am</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '12:00:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="00" selected="selected">00</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 15,
|
|
|
|
'value' => '12:15:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="15" selected="selected">15</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2015-07-21 13:58:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 01:37:38 +00:00
|
|
|
/**
|
|
|
|
* Test interval & timeFormat = 12
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputTimeWithIntervalAnd12HourFormat() {
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => 12,
|
|
|
|
'interval' => 5,
|
|
|
|
'selected' => array('hour' => '4', 'min' => '30', 'meridian' => 'pm')
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-03-19 01:37:38 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => '12',
|
|
|
|
'interval' => 5,
|
|
|
|
'selected' => '2013-04-19 16:30:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="04" selected="selected">4</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-04-20 15:51:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => '12',
|
|
|
|
'interval' => 10,
|
|
|
|
'selected' => '2013-05-19 00:33:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="12" selected="selected">12</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="am" selected="selected">am</option>', $result);
|
2013-04-20 18:39:47 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => '12',
|
|
|
|
'interval' => 10,
|
|
|
|
'selected' => '2013-05-19 13:33:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="01" selected="selected">1</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="pm" selected="selected">pm</option>', $result);
|
2013-04-20 18:39:47 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.start_time', array(
|
|
|
|
'type' => 'time',
|
|
|
|
'timeFormat' => '12',
|
|
|
|
'interval' => 10,
|
|
|
|
'selected' => '2013-05-19 01:33:00'
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="01" selected="selected">1</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
$this->assertStringContainsString('<option value="am" selected="selected">am</option>', $result);
|
2013-03-19 01:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:14:06 +00:00
|
|
|
/**
|
|
|
|
* test form->input() with datetime, date and time types
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testInputDatetime() {
|
2011-05-10 02:14:06 +00:00
|
|
|
extract($this->dateRegex);
|
2009-10-15 00:10:32 +00:00
|
|
|
$result = $this->Form->input('prueba', array(
|
2011-12-01 07:21:31 +00:00
|
|
|
'type' => 'datetime', 'timeFormat' => 24, 'dateFormat' => 'DMY', 'minYear' => 2008,
|
|
|
|
'maxYear' => date('Y') + 1, 'interval' => 15
|
2009-10-15 00:10:32 +00:00
|
|
|
));
|
|
|
|
$result = explode(':', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="12"[^>]*>12</option>#', $result[1]);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('#<option value="50"[^>]*>50</option>#', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('#<option value="15"[^>]*>15</option>#', $result[1]);
|
|
|
|
$this->assertMatchesRegularExpression('#<option value="30"[^>]*>30</option>#', $result[1]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
//related to ticket #5013
|
|
|
|
$result = $this->Form->input('Contact.date', array(
|
|
|
|
'type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/class="customClass"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/onChange="function\(\)\{\}"/', $result);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.date', array(
|
|
|
|
'type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/id="customIdDay"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/id="customIdMonth"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/onChange="function\(\)\{\}"/', $result);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/id="customIDDay"/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/id="customIDHour"/', $result);
|
2009-10-15 00:10:32 +00:00
|
|
|
$result = explode('</select><select', $result);
|
|
|
|
$result = explode(':', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/option value="23"/', $result[0]);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/option value="24"/', $result[0]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'datetime', 'timeFormat' => 12
|
|
|
|
));
|
|
|
|
$result = explode('</select><select', $result);
|
|
|
|
$result = explode(':', $result[1]);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/option value="12"/', $result[0]);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/option value="13"/', $result[0]);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Contact' => array('created' => null));
|
2009-10-15 00:10:32 +00:00
|
|
|
$result = $this->Form->input('Contact.created', array('empty' => 'Date Unknown'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input date'),
|
|
|
|
'label' => array('for' => 'ContactCreatedMonth'),
|
|
|
|
'Created',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[Contact][created][month]', 'id' => 'ContactCreatedMonth')),
|
|
|
|
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
|
$monthsRegex,
|
|
|
|
'/select', '-',
|
|
|
|
array('select' => array('name' => 'data[Contact][created][day]', 'id' => 'ContactCreatedDay')),
|
|
|
|
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select', '-',
|
|
|
|
array('select' => array('name' => 'data[Contact][created][year]', 'id' => 'ContactCreatedYear')),
|
|
|
|
array('option' => array('value' => '')), 'Date Unknown', '/option',
|
|
|
|
$yearsRegex,
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 01:17:00 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Contact' => array('created' => null));
|
2009-10-15 01:17:00 +00:00
|
|
|
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'dateFormat' => 'NONE'));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/for\="ContactCreatedHour"/', $result);
|
2010-01-13 22:43:39 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Contact' => array('created' => null));
|
2009-10-15 01:17:00 +00:00
|
|
|
$result = $this->Form->input('Contact.created', array('type' => 'datetime', 'timeFormat' => 'NONE'));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/for\="ContactCreatedMonth"/', $result);
|
2010-03-05 03:46:43 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.created', array(
|
|
|
|
'type' => 'date',
|
|
|
|
'id' => array('day' => 'created-day', 'month' => 'created-month', 'year' => 'created-year'),
|
|
|
|
'timeFormat' => 'NONE'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/for\="created-month"/', $result);
|
2009-10-15 00:10:32 +00:00
|
|
|
}
|
2010-06-10 16:48:55 +00:00
|
|
|
|
2009-10-15 00:10:32 +00:00
|
|
|
/**
|
|
|
|
* Test generating checkboxes in a loop.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputCheckboxesInLoop() {
|
2009-10-15 00:10:32 +00:00
|
|
|
for ($i = 1; $i < 5; $i++) {
|
|
|
|
$result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => "data[Contact][{$i}][email]", 'value' => '0', 'id' => "Contact{$i}Email_"),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][{$i}][email]", 'value' => $i, 'id' => "Contact{$i}Email")),
|
|
|
|
'label' => array('for' => "Contact{$i}Email"),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 00:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 16:48:55 +00:00
|
|
|
|
2012-07-23 14:39:46 +00:00
|
|
|
/**
|
|
|
|
* Test generating checkboxes with disabled elements.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputCheckboxWithDisabledElements() {
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three');
|
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => 'disabled', 'options' => $options));
|
2012-08-04 19:57:04 +00:00
|
|
|
|
2012-07-23 14:39:46 +00:00
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => "ContactMultiple")),
|
|
|
|
'Multiple',
|
|
|
|
'/label',
|
2014-10-25 19:05:37 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple", 'disabled' => 'disabled')),
|
2012-07-23 14:39:46 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'disabled' => 'disabled', 'id' => "ContactMultiple1")),
|
|
|
|
array('label' => array('for' => "ContactMultiple1")),
|
|
|
|
'One',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
|
|
|
|
array('label' => array('for' => "ContactMultiple2")),
|
|
|
|
'Two',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
|
|
|
|
array('label' => array('for' => "ContactMultiple3")),
|
|
|
|
'Three',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-08-04 19:57:04 +00:00
|
|
|
|
2012-07-23 14:39:46 +00:00
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => true, 'options' => $options));
|
|
|
|
$this->assertTags($result, $expected);
|
2012-08-04 19:57:04 +00:00
|
|
|
|
2012-07-23 14:39:46 +00:00
|
|
|
$disabled = array('2', 3);
|
2012-08-04 19:57:04 +00:00
|
|
|
|
2012-07-23 14:39:46 +00:00
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => "ContactMultiple")),
|
|
|
|
'Multiple',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 1, 'id' => "ContactMultiple1")),
|
|
|
|
array('label' => array('for' => "ContactMultiple1")),
|
|
|
|
'One',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 2, 'disabled' => 'disabled', 'id' => "ContactMultiple2")),
|
|
|
|
array('label' => array('for' => "ContactMultiple2")),
|
|
|
|
'Two',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 3, 'disabled' => 'disabled', 'id' => "ContactMultiple3")),
|
|
|
|
array('label' => array('for' => "ContactMultiple3")),
|
|
|
|
'Three',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
|
|
|
|
$this->assertTags($result, $expected);
|
2013-01-30 12:54:09 +00:00
|
|
|
|
|
|
|
// make sure 50 does only disable 50, and not 50f5c0cf
|
|
|
|
$options = array('50' => 'Fifty', '50f5c0cf' => 'Stringy');
|
|
|
|
$disabled = array(50);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => "ContactMultiple")),
|
|
|
|
'Multiple',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => "data[Contact][multiple]", 'value' => '', 'id' => "ContactMultiple")),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => 50, 'disabled' => 'disabled', 'id' => "ContactMultiple50")),
|
|
|
|
array('label' => array('for' => "ContactMultiple50")),
|
|
|
|
'Fifty',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => "data[Contact][multiple][]", 'value' => '50f5c0cf', 'id' => "ContactMultiple50f5c0cf")),
|
|
|
|
array('label' => array('for' => "ContactMultiple50f5c0cf")),
|
|
|
|
'Stringy',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'checkbox', 'disabled' => $disabled, 'options' => $options));
|
|
|
|
$this->assertTags($result, $expected);
|
2012-07-23 14:39:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-29 01:32:49 +00:00
|
|
|
/**
|
|
|
|
* test input name with leading integer, ensure attributes are generated correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputWithLeadingInteger() {
|
2010-06-29 01:32:49 +00:00
|
|
|
$result = $this->Form->text('0.Node.title');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('name' => 'data[0][Node][title]', 'id' => '0NodeTitle', 'type' => 'text')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-06-29 01:32:49 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 00:10:32 +00:00
|
|
|
/**
|
|
|
|
* test form->input() with select type inputs.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputSelectType() {
|
2009-10-15 00:10:32 +00:00
|
|
|
$result = $this->Form->input('email', array(
|
|
|
|
'options' => array('è' => 'Firést', 'é' => 'Secoènd'), 'empty' => true)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'email'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[email]', 'id' => 'email')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'è')),
|
|
|
|
'Firést',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'é')),
|
|
|
|
'Secoènd',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('email', array(
|
|
|
|
'options' => array('First', 'Second'), 'empty' => true)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'email'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[email]', 'id' => 'email')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '0')),
|
|
|
|
'First',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'Second',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 00:10:32 +00:00
|
|
|
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('user_id' => 'value'));
|
2010-08-28 04:01:41 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Model.user_id', array('empty' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'ModelUserId'),
|
|
|
|
'User',
|
|
|
|
'/label',
|
|
|
|
'select' => array('name' => 'data[Model][user_id]', 'id' => 'ModelUserId'),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2011-07-14 15:35:41 +00:00
|
|
|
$this->Form->request->data = array('Thing' => array('user_id' => null));
|
|
|
|
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
|
2008-11-29 00:28:31 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
2011-07-14 15:35:41 +00:00
|
|
|
'label' => array('for' => 'ThingUserId'),
|
2008-11-29 00:28:31 +00:00
|
|
|
'User',
|
|
|
|
'/label',
|
2011-07-14 15:35:41 +00:00
|
|
|
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
|
2008-11-29 00:28:31 +00:00
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'Some Empty',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-11-29 00:28:31 +00:00
|
|
|
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2011-07-14 15:35:41 +00:00
|
|
|
$this->Form->request->data = array('Thing' => array('user_id' => 'value'));
|
|
|
|
$result = $this->Form->input('Thing.user_id', array('empty' => 'Some Empty'));
|
2008-11-29 00:28:31 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
2011-07-14 15:35:41 +00:00
|
|
|
'label' => array('for' => 'ThingUserId'),
|
2008-11-29 00:28:31 +00:00
|
|
|
'User',
|
|
|
|
'/label',
|
2011-07-14 15:35:41 +00:00
|
|
|
'select' => array('name' => 'data[Thing][user_id]', 'id' => 'ThingUserId'),
|
2008-11-29 00:28:31 +00:00
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'Some Empty',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-11-29 00:28:31 +00:00
|
|
|
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('User' => array('User' => array('value')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('User.User', array('empty' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'UserUser'),
|
|
|
|
'User',
|
|
|
|
'/label',
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => '', 'id' => 'UserUser_'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'select' => array('name' => 'data[User][User][]', 'id' => 'UserUser', 'multiple' => 'multiple'),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-18 20:55:39 +00:00
|
|
|
|
|
|
|
$this->Form->data = array();
|
|
|
|
$result = $this->Form->input('Publisher.id', array(
|
|
|
|
'label' => 'Publisher',
|
|
|
|
'type' => 'select',
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'options' => array('Value 1' => 'Label 1', 'Value 2' => 'Label 2')
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'PublisherId')),
|
|
|
|
'Publisher',
|
|
|
|
'/label',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Publisher][id]', 'value' => '', 'id' => 'PublisherId'),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 1', 'id' => 'PublisherIdValue1')),
|
|
|
|
array('label' => array('for' => 'PublisherIdValue1')),
|
|
|
|
'Label 1',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Publisher][id][]', 'value' => 'Value 2', 'id' => 'PublisherIdValue2')),
|
|
|
|
array('label' => array('for' => 'PublisherIdValue2')),
|
|
|
|
'Label 2',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-04 04:20:14 +00:00
|
|
|
/**
|
|
|
|
* test that input() and a non standard primary key makes a hidden input by default.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputWithNonStandardPrimaryKeyMakesHidden() {
|
2010-06-04 04:20:14 +00:00
|
|
|
$this->Form->create('User');
|
|
|
|
$this->Form->fieldset = array(
|
|
|
|
'User' => array(
|
|
|
|
'fields' => array(
|
|
|
|
'model_id' => array('type' => 'integer')
|
|
|
|
),
|
|
|
|
'validates' => array(),
|
|
|
|
'key' => 'model_id'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Form->input('model_id');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[User][model_id]', 'id' => 'UserModelId'),
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-06-04 04:20:14 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 05:45:17 +00:00
|
|
|
/**
|
|
|
|
* test that overriding the magic select type widget is possible
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputOverridingMagicSelectType() {
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2009-10-31 05:45:17 +00:00
|
|
|
$result = $this->Form->input('Model.user_id', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ModelUserId'), 'User', '/label',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('name' => 'data[Model][user_id]', 'type' => 'text', 'id' => 'ModelUserId'),
|
2009-10-31 05:45:17 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-20 17:49:24 +00:00
|
|
|
|
|
|
|
//Check that magic types still work for plural/singular vars
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad');
|
2010-02-20 17:49:24 +00:00
|
|
|
$result = $this->Form->input('Model.type');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'ModelType'), 'Type', '/label',
|
|
|
|
'select' => array('name' => 'data[Model][type]', 'id' => 'ModelType'),
|
|
|
|
array('option' => array('value' => 'value')), 'good', '/option',
|
|
|
|
array('option' => array('value' => 'other')), 'bad', '/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 05:45:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 04:26:20 +00:00
|
|
|
/**
|
|
|
|
* Test that inferred types do not override developer input
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputMagicTypeDoesNotOverride() {
|
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
|
|
|
$result = $this->Form->input('Model.user', array('type' => 'checkbox'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[Model][user]',
|
|
|
|
'id' => 'ModelUser_',
|
|
|
|
'value' => 0,
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'name' => 'data[Model][user]',
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'id' => 'ModelUser',
|
|
|
|
'value' => 1
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'ModelUser'), 'User', '/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:07:43 +00:00
|
|
|
/**
|
|
|
|
* Test that magic input() selects are created for type=number
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputMagicSelectForTypeNumber() {
|
|
|
|
$this->View->viewVars['balances'] = array(0 => 'nothing', 1 => 'some', 100 => 'a lot');
|
|
|
|
$this->Form->request->data = array('ValidateUser' => array('balance' => 1));
|
|
|
|
$result = $this->Form->input('ValidateUser.balance');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input select'),
|
|
|
|
'label' => array('for' => 'ValidateUserBalance'),
|
|
|
|
'Balance',
|
|
|
|
'/label',
|
|
|
|
'select' => array('name' => 'data[ValidateUser][balance]', 'id' => 'ValidateUserBalance'),
|
|
|
|
array('option' => array('value' => '0')),
|
|
|
|
'nothing',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
|
'some',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '100')),
|
|
|
|
'a lot',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2010-01-13 04:27:17 +00:00
|
|
|
/**
|
|
|
|
* Test that magic input() selects can easily be converted into radio types without error.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputMagicSelectChangeToRadio() {
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
2010-01-13 04:27:17 +00:00
|
|
|
$result = $this->Form->input('Model.user_id', array('type' => 'radio'));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/input type="radio"/', $result);
|
2010-01-13 04:27:17 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 04:46:51 +00:00
|
|
|
/**
|
|
|
|
* fields with the same name as the model should work.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputWithMatchingFieldAndModelName() {
|
2010-09-26 04:46:51 +00:00
|
|
|
$this->Form->create('User');
|
|
|
|
$this->Form->fieldset = array(
|
|
|
|
'User' => array(
|
|
|
|
'fields' => array(
|
|
|
|
'User' => array('type' => 'text')
|
|
|
|
),
|
|
|
|
'validates' => array(),
|
|
|
|
'key' => 'id'
|
|
|
|
)
|
|
|
|
);
|
2010-10-14 03:09:55 +00:00
|
|
|
$this->Form->request->data['User']['User'] = 'ABC, Inc.';
|
2010-09-26 04:46:51 +00:00
|
|
|
$result = $this->Form->input('User', array('type' => 'text'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'UserUser'), 'User', '/label',
|
|
|
|
'input' => array('name' => 'data[User][User]', 'type' => 'text', 'id' => 'UserUser', 'value' => 'ABC, Inc.'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-09-26 04:46:51 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFormInputs method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test correct results from form::inputs().
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormInputs() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs('The Legend');
|
|
|
|
$expected = array(
|
|
|
|
'<fieldset',
|
|
|
|
'<legend',
|
|
|
|
'The Legend',
|
|
|
|
'/legend',
|
|
|
|
'*/fieldset',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array('class' => 'classy-stuff'),
|
|
|
|
'<legend',
|
|
|
|
'Field of Dreams',
|
|
|
|
'/legend',
|
|
|
|
'*/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-12 18:41:02 +00:00
|
|
|
$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('Contact');
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['prefix'] = 'admin';
|
2010-05-18 03:31:47 +00:00
|
|
|
$this->Form->request['action'] = 'admin_edit';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->inputs();
|
|
|
|
$expected = array(
|
|
|
|
'<fieldset',
|
|
|
|
'<legend',
|
|
|
|
'Edit Contact',
|
|
|
|
'/legend',
|
|
|
|
'*/fieldset',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(false);
|
|
|
|
$expected = array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
|
|
|
|
$expected = array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-12 18:41:02 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(null, null, array('fieldset' => false));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
|
|
|
|
$expected = array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-12 18:41:02 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs('Hello');
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Hello',
|
|
|
|
'/legend',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(array('legend' => 'Hello'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Hello',
|
|
|
|
'/legend',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'id' => 'ContactId'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input email')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
2013-01-25 21:47:45 +00:00
|
|
|
array('div' => array('class' => 'input tel')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input password')),
|
|
|
|
'*/div',
|
2016-05-02 15:13:22 +00:00
|
|
|
array('div' => array('class' => 'input time')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input date')),
|
|
|
|
'*/div',
|
|
|
|
array('div' => array('class' => 'input datetime')),
|
|
|
|
'*/div',
|
2011-08-11 01:40:53 +00:00
|
|
|
array('div' => array('class' => 'input number')),
|
|
|
|
'*/div',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
'*/div',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-11-12 18:41:02 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
|
|
|
|
$this->assertTags($result, $expected);
|
2012-12-19 21:02:24 +00:00
|
|
|
$this->Form->end();
|
|
|
|
|
|
|
|
$this->Form->create(false);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
array('div' => array('class' => 'input text')),
|
|
|
|
'label' => array('for' => 'foo'),
|
|
|
|
'Foo',
|
|
|
|
'/label',
|
|
|
|
'input' => array('type' => 'text', 'name' => 'data[foo]', 'id' => 'foo'),
|
|
|
|
'*/div',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$result = $this->Form->inputs(
|
|
|
|
array('foo' => array('type' => 'text')),
|
|
|
|
array(),
|
|
|
|
array('legend' => false)
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-01-30 03:00:36 +00:00
|
|
|
/**
|
|
|
|
* Tests inputs() works with plugin models
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputsPluginModel() {
|
|
|
|
$this->loadFixtures('Post');
|
|
|
|
App::build(array(
|
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
|
));
|
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$this->Form->request['models'] = array(
|
|
|
|
'TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost')
|
|
|
|
);
|
|
|
|
$this->Form->create('TestPlugin.TestPluginPost');
|
|
|
|
$result = $this->Form->inputs();
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('data[TestPluginPost][id]', $result);
|
|
|
|
$this->assertStringContainsString('data[TestPluginPost][author_id]', $result);
|
|
|
|
$this->assertStringContainsString('data[TestPluginPost][title]', $result);
|
2013-01-30 03:00:36 +00:00
|
|
|
$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
|
|
|
|
$this->assertFalse(ClassRegistry::isKeySet('TestPlugin'));
|
|
|
|
$this->assertEquals('TestPluginPost', $this->Form->model());
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSelectAsCheckbox method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test multi-select widget with checkbox formatting.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectAsCheckbox() {
|
2010-08-05 18:14:36 +00:00
|
|
|
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array('multiple' => 'checkbox', 'value' => array(0, 1)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField0', 'class' => 'selected')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField1', 'class' => 'selected')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
2010-08-05 23:31:51 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-10 17:46:48 +00:00
|
|
|
|
2010-11-01 01:56:59 +00:00
|
|
|
$result = $this->Form->select('Model.multi_field', array('1/2' => 'half'), array('multiple' => 'checkbox'));
|
2010-10-10 17:46:48 +00:00
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
2014-02-03 17:51:57 +00:00
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1/2', 'id' => 'ModelMultiField12')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField12')),
|
2010-10-10 17:46:48 +00:00
|
|
|
'half',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLabel method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test label generation.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLabel() {
|
2008-09-18 03:09:19 +00:00
|
|
|
$this->Form->text('Person.name');
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->label();
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
|
|
|
|
|
|
|
|
$this->Form->text('Person.name');
|
|
|
|
$result = $this->Form->label();
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.first_name');
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'First Name', '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.first_name', 'Your first name');
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), 'Your first name', '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class'));
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class'), 'Your first name', '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.first_name', 'Your first name', array('class' => 'my-class', 'id' => 'LabelID'));
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName', 'class' => 'my-class', 'id' => 'LabelID'), 'Your first name', '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.first_name', '');
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'PersonFirstName'), '/label'));
|
|
|
|
|
|
|
|
$result = $this->Form->label('Person.2.name', '');
|
|
|
|
$this->assertTags($result, array('label' => array('for' => 'Person2Name'), '/label'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testTextbox method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test textbox element generation
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTextbox() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->text('Model.field');
|
2010-02-07 21:30:43 +00:00
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->text('Model.field', array('type' => 'password'));
|
2010-02-07 21:30:43 +00:00
|
|
|
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'id' => 'ModelField')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->text('Model.field', array('id' => 'theID'));
|
2010-02-07 21:30:43 +00:00
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'theID')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['text'] = 'test <strong>HTML</strong> values';
|
2008-09-18 03:09:19 +00:00
|
|
|
$result = $this->Form->text('Model.text');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText')));
|
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['text'] = array(true);
|
|
|
|
$this->Form->request->data['Contact']['text'] = 'test';
|
|
|
|
$result = $this->Form->text('Contact.text', array('id' => 'theID'));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Contact][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
2008-10-07 16:57:22 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['0']['OtherModel']['field'] = 'My value';
|
2008-10-06 23:57:27 +00:00
|
|
|
$result = $this->Form->text('Model.0.OtherModel.field', array('id' => 'myId'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDefaultValue method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test default value setting
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDefaultValue() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = 'test';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->text('Model.field', array('default' => 'default value'));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'test', 'id' => 'ModelField')));
|
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
unset($this->Form->request->data['Model']['field']);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->text('Model.field', array('default' => 'default value'));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => 'default value', 'id' => 'ModelField')));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-09 15:03:23 +00:00
|
|
|
/**
|
|
|
|
* testCheckboxDefaultValue method
|
|
|
|
*
|
|
|
|
* Test default value setting on checkbox() method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckboxDefaultValue() {
|
2010-06-09 15:03:23 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = false;
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
|
|
|
|
|
|
|
|
unset($this->Form->request->data['Model']['field']);
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('default' => true, 'hiddenField' => false));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
|
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = true;
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked')));
|
|
|
|
|
|
|
|
unset($this->Form->request->data['Model']['field']);
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('default' => false, 'hiddenField' => false));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField')));
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-09-10 13:56:20 +00:00
|
|
|
* testError method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test field error generation
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testError() {
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['field'] = array(1);
|
|
|
|
$result = $this->Form->error('Contact.field');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
|
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Error in field Field', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
|
|
|
$result = $this->Form->error('Contact.field', null, array('wrap' => false));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('This field contains invalid input', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact->validationErrors['field'] = array("This field contains invalid input");
|
|
|
|
$result = $this->Form->error('Contact.field', null, array('wrap' => 'span'));
|
2008-05-30 15:07:32 +00:00
|
|
|
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span'));
|
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', 'There is an error fool!', array('wrap' => 'span'));
|
2008-05-30 15:07:32 +00:00
|
|
|
$this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span'));
|
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('<strong>Badness!</strong>', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => true));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('<strong>Badness!</strong>', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('<strong>Badness!</strong>', $result);
|
2009-09-10 13:56:20 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact->validationErrors['field'] = array("email");
|
|
|
|
$result = $this->Form->error('Contact.field', array('attributes' => array('class' => 'field-error'), 'email' => 'No good!'));
|
2009-09-10 13:56:20 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'field-error'),
|
|
|
|
'No good!',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2015-05-17 20:27:16 +00:00
|
|
|
$Contact->validationErrors['field'] = array('notBlank', 'email', 'Something else');
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', array(
|
2015-05-17 20:27:16 +00:00
|
|
|
'notBlank' => 'Cannot be empty',
|
2010-12-26 06:40:02 +00:00
|
|
|
'email' => 'No good!'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'error-message'),
|
|
|
|
'ul' => array(),
|
|
|
|
'<li', 'Cannot be empty', '/li',
|
|
|
|
'<li', 'No good!', '/li',
|
|
|
|
'<li', 'Something else', '/li',
|
|
|
|
'/ul',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2013-01-11 14:06:54 +00:00
|
|
|
// Testing error messages list options
|
2015-05-17 20:27:16 +00:00
|
|
|
$Contact->validationErrors['field'] = array('notBlank', 'email');
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', null, array('listOptions' => 'ol'));
|
2010-12-26 06:40:02 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'error-message'),
|
|
|
|
'ol' => array(),
|
2015-05-17 20:27:16 +00:00
|
|
|
'<li', 'notBlank', '/li',
|
2010-12-26 06:40:02 +00:00
|
|
|
'<li', 'email', '/li',
|
|
|
|
'/ol',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', null, array('listOptions' => array('tag' => 'ol')));
|
2010-12-26 06:40:02 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'error-message'),
|
|
|
|
'ol' => array(),
|
2015-05-17 20:27:16 +00:00
|
|
|
'<li', 'notBlank', '/li',
|
2010-12-26 06:40:02 +00:00
|
|
|
'<li', 'email', '/li',
|
|
|
|
'/ol',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->error('Contact.field', null, array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'listOptions' => array(
|
|
|
|
'class' => 'ul-class',
|
|
|
|
'itemOptions' => array(
|
|
|
|
'class' => 'li-class'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'error-message'),
|
|
|
|
'ul' => array('class' => 'ul-class'),
|
2015-05-17 20:27:16 +00:00
|
|
|
array('li' => array('class' => 'li-class')), 'notBlank', '/li',
|
2010-12-26 06:40:02 +00:00
|
|
|
array('li' => array('class' => 'li-class')), 'email', '/li',
|
|
|
|
'/ul',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-31 02:25:49 +00:00
|
|
|
/**
|
|
|
|
* test error options when using form->input();
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputErrorEscape() {
|
2009-10-31 02:25:49 +00:00
|
|
|
$this->Form->create('ValidateProfile');
|
2011-07-14 18:23:10 +00:00
|
|
|
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
|
$ValidateProfile->validationErrors['city'] = array('required<br>');
|
2013-05-17 08:36:17 +00:00
|
|
|
$result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => true))));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/required<br>/', $result);
|
2009-10-31 02:25:49 +00:00
|
|
|
|
2013-05-17 08:36:17 +00:00
|
|
|
$result = $this->Form->input('city', array('error' => array('attributes' => array('escape' => false))));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/required<br>/', $result);
|
2009-10-31 02:25:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPassword method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test password element generation
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPassword() {
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$result = $this->Form->password('Contact.field');
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][field]', 'id' => 'ContactField')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact->validationErrors['passwd'] = 1;
|
|
|
|
$this->Form->request->data['Contact']['passwd'] = 'test';
|
|
|
|
$result = $this->Form->password('Contact.passwd', array('id' => 'theID'));
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Contact][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testRadio method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test radio element set generation
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRadio() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('option A'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
'label' => array('for' => 'ModelField0'),
|
|
|
|
'option A',
|
|
|
|
'/label'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-10-10 17:46:48 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('1/2' => 'half'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
2014-02-03 17:51:57 +00:00
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1/2', 'id' => 'ModelField12')),
|
|
|
|
'label' => array('for' => 'ModelField12'),
|
2010-10-10 17:46:48 +00:00
|
|
|
'half',
|
|
|
|
'/label'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-10 17:46:48 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '<br/>'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'br' => array(),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2016-05-22 20:39:49 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('fieldset' => 'classy-stuff'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array('class' => 'classy-stuff'),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2016-05-20 00:28:47 +00:00
|
|
|
|
2014-03-19 02:11:57 +00:00
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Employee.gender',
|
|
|
|
array('male' => 'Male', 'female' => 'Female'),
|
|
|
|
array('form' => 'my-form')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Gender',
|
|
|
|
'/legend',
|
2014-03-19 02:11:57 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_', 'form' => 'my-form'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale', 'form' => 'my-form')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'EmployeeGenderMale')),
|
|
|
|
'Male',
|
|
|
|
'/label',
|
2014-03-19 02:11:57 +00:00
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale', 'form' => 'my-form')),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'EmployeeGenderFemale')),
|
|
|
|
'Female',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio('Officer.gender', array('male' => 'Male', 'female' => 'Female'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Gender',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Officer][gender]', 'value' => '', 'id' => 'OfficerGender_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'male', 'id' => 'OfficerGenderMale')),
|
|
|
|
array('label' => array('for' => 'OfficerGenderMale')),
|
|
|
|
'Male',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Officer][gender]', 'value' => 'female', 'id' => 'OfficerGenderFemale')),
|
|
|
|
array('label' => array('for' => 'OfficerGenderFemale')),
|
|
|
|
'Female',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-12-17 01:49:58 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio('Contact.1.imrequired', array('option A'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][1][imrequired]', 'value' => '', 'id' => 'Contact1Imrequired_'),
|
2012-12-19 20:12:49 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'name' => 'data[Contact][1][imrequired]',
|
|
|
|
'value' => '0',
|
|
|
|
'id' => 'Contact1Imrequired0',
|
|
|
|
'required' => 'required'
|
|
|
|
)),
|
2008-12-17 01:49:58 +00:00
|
|
|
'label' => array('for' => 'Contact1Imrequired0'),
|
|
|
|
'option A',
|
|
|
|
'/label'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-12-17 01:49:58 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.1.field', array('option A'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
|
'label' => array('for' => 'Model1Field0'),
|
|
|
|
'option A',
|
|
|
|
'/label'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-04-16 18:12:01 +00:00
|
|
|
|
2009-04-15 17:18:01 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('option A', 'option B'), array('name' => 'data[Model][custom]'));
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][custom]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][custom]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-12-04 01:14:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][field]',
|
2013-12-24 14:20:32 +00:00
|
|
|
'id' => 'ModelField_', 'value' => '',
|
2013-12-04 01:14:08 +00:00
|
|
|
),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'id' => 'ModelFieldAB', 'value' => 'a>b')),
|
|
|
|
array('label' => array('for' => 'ModelFieldAB')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'id' => 'ModelFieldAB1', 'value' => 'a<b')),
|
|
|
|
array('label' => array('for' => 'ModelFieldAB1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'id' => 'ModelFieldAB2', 'value' => 'a"b')),
|
|
|
|
array('label' => array('for' => 'ModelFieldAB2')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2015-05-25 13:10:50 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.multibyte',
|
|
|
|
array('男性' => '男性')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multibyte]',
|
|
|
|
'id' => 'ModelMultibyte_', 'value' => '',
|
|
|
|
),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][multibyte]',
|
|
|
|
'id' => 'ModelMultibyte男性', 'value' => '男性')
|
|
|
|
),
|
|
|
|
array('label' => array('for' => 'ModelMultibyte男性')),
|
|
|
|
'男性',
|
|
|
|
'/label',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-02-07 14:36:00 +00:00
|
|
|
}
|
2011-12-18 16:25:42 +00:00
|
|
|
|
2014-02-27 21:04:16 +00:00
|
|
|
/**
|
|
|
|
* testRadioDifferentModel
|
|
|
|
* Refs #2911
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioDifferentModel() {
|
|
|
|
$this->Form->create('User');
|
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('v1' => 'option A', 'v2' => 'option B'),
|
|
|
|
array('label' => true, 'legend' => false, 'value' => false)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => 'v1', 'id' => 'ModelFieldV1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelFieldV1')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => 'v2', 'id' => 'ModelFieldV2'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelFieldV2')),
|
|
|
|
'option B',
|
|
|
|
'/label'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2013-02-07 14:36:00 +00:00
|
|
|
/**
|
|
|
|
* Test radio inputs with between as string or array. Also ensure
|
|
|
|
* that an array with less between elements works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioBetween() {
|
2011-12-18 16:25:42 +00:00
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('option A', 'option B'),
|
|
|
|
array('between' => 'I am between')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'I am between',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '', 'id' => 'ModelField_'
|
|
|
|
),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '0', 'id' => 'ModelField0'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '1', 'id' => 'ModelField1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-09-20 22:06:26 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('option A', 'option B', 'option C'),
|
|
|
|
array('separator' => '--separator--', 'between' => array('between A', 'between B', 'between C'))
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '', 'id' => 'ModelField_'
|
|
|
|
),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '0', 'id' => 'ModelField0'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'between A',
|
|
|
|
'--separator--',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '1', 'id' => 'ModelField1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'between B',
|
|
|
|
'--separator--',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Model][field]',
|
|
|
|
'value' => '2', 'id' => 'ModelField2'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'option C',
|
|
|
|
'/label',
|
|
|
|
'between C',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-02-07 14:36:00 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'options' => array('1' => 'first', '2' => 'second'),
|
|
|
|
'type' => 'radio',
|
|
|
|
'before' => '--before--',
|
|
|
|
'after' => '--after--',
|
|
|
|
'separator' => '--separator--',
|
|
|
|
'between' => array('--between first--', '--between second--')
|
|
|
|
));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'--before--',
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'--between first--',
|
|
|
|
'--separator--',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
|
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'--between second--',
|
|
|
|
'/fieldset',
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'options' => array('1' => 'first', '2' => 'second'),
|
|
|
|
'type' => 'radio',
|
|
|
|
'before' => '--before--',
|
|
|
|
'after' => '--after--',
|
|
|
|
'separator' => '--separator--',
|
|
|
|
'between' => array('--between first--')
|
|
|
|
));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'--before--',
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'--between first--',
|
|
|
|
'--separator--',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
|
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-19 14:14:29 +00:00
|
|
|
/**
|
|
|
|
* Test that radios with a 0 value are selected under the correct conditions.
|
2013-01-08 02:12:53 +00:00
|
|
|
* Also ensure that values that are booleanish are handled correctly.
|
2012-09-19 14:14:29 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-01-08 02:12:53 +00:00
|
|
|
public function testRadioOptionWithBooleanishValues() {
|
2012-09-19 14:14:29 +00:00
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'Yes',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'checked' => 'checked')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'No',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0'));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 0));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2013-01-08 02:12:53 +00:00
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => false));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2012-09-19 14:14:29 +00:00
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'Yes',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'No',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => ''));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'));
|
|
|
|
$this->assertTags($result, $expected);
|
2013-01-08 02:12:53 +00:00
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'checked' => 'checked', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'Yes',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'No',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => 1));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1'));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => true));
|
|
|
|
$this->assertTags($result, $expected);
|
2012-09-19 14:14:29 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 23:35:37 +00:00
|
|
|
/**
|
|
|
|
* test disabled radio options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRadioDisabled() {
|
2011-03-13 23:35:37 +00:00
|
|
|
$result = $this->Form->radio(
|
2011-05-16 22:49:00 +00:00
|
|
|
'Model.field',
|
2011-03-13 23:35:37 +00:00
|
|
|
array('option A', 'option B'),
|
2013-02-07 14:36:00 +00:00
|
|
|
array('disabled' => array(0), 'value' => '0')
|
2011-03-13 23:35:37 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-11-17 15:39:37 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('option A', 'option B'),
|
2012-09-19 14:14:29 +00:00
|
|
|
array('disabled' => true, 'value' => '0')
|
2011-11-17 15:39:37 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
2011-11-24 08:51:05 +00:00
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->radio(
|
|
|
|
'Model.field',
|
|
|
|
array('option A', 'option B'),
|
2012-09-19 14:14:29 +00:00
|
|
|
array('disabled' => 'disabled', 'value' => '0')
|
2011-11-24 08:51:05 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField0', 'disabled' => 'disabled', 'checked' => 'checked')),
|
|
|
|
array('label' => array('for' => 'ModelField0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'disabled' => 'disabled')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'option B',
|
2011-03-13 23:35:37 +00:00
|
|
|
'/label',
|
|
|
|
'/fieldset'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-09-20 22:06:26 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
2013-02-07 14:36:00 +00:00
|
|
|
'options' => array(1 => 'first', 2 => 'second', '2x' => '2x', '3' => 'third', '3x' => '3x'),
|
2012-09-20 22:06:26 +00:00
|
|
|
'type' => 'radio',
|
2013-02-07 14:36:00 +00:00
|
|
|
'disabled' => array(2, '3x'),
|
2012-09-20 22:06:26 +00:00
|
|
|
));
|
2012-09-20 22:09:42 +00:00
|
|
|
|
2012-09-20 22:06:26 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
2013-02-07 14:36:00 +00:00
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '2', 'id' => 'ModelField2')),
|
2012-09-20 22:06:26 +00:00
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
2013-02-07 14:36:00 +00:00
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2x', 'id' => 'ModelField2x')),
|
|
|
|
array('label' => array('for' => 'ModelField2x')),
|
|
|
|
'2x',
|
2012-09-21 00:57:10 +00:00
|
|
|
'/label',
|
2013-02-07 14:36:00 +00:00
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '3', 'id' => 'ModelField3')),
|
|
|
|
array('label' => array('for' => 'ModelField3')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'disabled' => 'disabled', 'value' => '3x', 'id' => 'ModelField3x')),
|
|
|
|
array('label' => array('for' => 'ModelField3x')),
|
|
|
|
'3x',
|
2012-09-21 00:57:10 +00:00
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'/div'
|
|
|
|
);
|
2013-02-07 14:36:00 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-09-25 12:01:35 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array(
|
|
|
|
1 => 'A',
|
|
|
|
2 => 'B',
|
|
|
|
3 => 'C'
|
|
|
|
),
|
|
|
|
'disabled' => array(1)
|
|
|
|
));
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField1', 'disabled' => 'disabled', 'value' => '1')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField2', 'value' => '2')),
|
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'B',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField3', 'value' => '3')),
|
|
|
|
array('label' => array('for' => 'ModelField3')),
|
|
|
|
'C',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2011-03-13 23:35:37 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 03:23:33 +00:00
|
|
|
/**
|
|
|
|
* test disabling the hidden input for radio buttons
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRadioHiddenInputDisabling() {
|
2009-10-31 03:23:33 +00:00
|
|
|
$result = $this->Form->input('Model.1.field', array(
|
2009-10-31 20:28:43 +00:00
|
|
|
'type' => 'radio',
|
2009-10-31 03:23:33 +00:00
|
|
|
'options' => array('option A'),
|
|
|
|
'hiddenField' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
|
|
|
|
'label' => array('for' => 'Model1Field0'),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 03:23:33 +00:00
|
|
|
|
|
|
|
$result = $this->Form->radio('Model.1.field', array('option A'), array('hiddenField' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0'),
|
|
|
|
'label' => array('for' => 'Model1Field0'),
|
|
|
|
'option A',
|
|
|
|
'/label'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 02:02:07 +00:00
|
|
|
/**
|
|
|
|
* test setting a hiddenField value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioHiddenFieldValue() {
|
|
|
|
$result = $this->Form->input('Model.1.field', array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array('option A'),
|
|
|
|
'hiddenField' => 'N'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][1][field]', 'value' => 'N', 'id' => 'Model1Field_')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
|
'label' => array('for' => 'Model1Field0'),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2012-03-29 12:03:23 +00:00
|
|
|
/**
|
|
|
|
* test adding an empty option for radio buttons
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioAddEmptyOption() {
|
|
|
|
$result = $this->Form->input('Model.1.field', array(
|
2012-04-07 01:46:34 +00:00
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array('option A'),
|
|
|
|
'empty' => true,
|
|
|
|
'hiddenField' => false
|
|
|
|
));
|
2012-03-29 12:03:23 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
|
|
|
|
array('label' => array('for' => 'Model1Field')),
|
|
|
|
__('empty'),
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
|
array('label' => array('for' => 'Model1Field0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Model.1.field', array(
|
2012-04-07 01:46:34 +00:00
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array('option A'),
|
|
|
|
'empty' => 'CustomEmptyLabel',
|
|
|
|
'hiddenField' => false
|
|
|
|
));
|
2012-03-29 12:03:23 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Field',
|
|
|
|
'/legend',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
|
|
|
|
array('label' => array('for' => 'Model1Field')),
|
|
|
|
'CustomEmptyLabel',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
|
|
|
|
array('label' => array('for' => 'Model1Field0')),
|
|
|
|
'option A',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-04-21 00:52:10 +00:00
|
|
|
|
2012-03-29 12:03:23 +00:00
|
|
|
$result = $this->Form->input('Model.1.field', array(
|
2012-04-07 01:46:34 +00:00
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array('option A'),
|
|
|
|
'empty' => false,
|
|
|
|
'hiddenField' => false
|
|
|
|
));
|
2012-03-29 12:03:23 +00:00
|
|
|
$this->assertTextNotContains('"Model1Field"', $result);
|
|
|
|
}
|
|
|
|
|
2015-06-16 11:23:51 +00:00
|
|
|
/**
|
|
|
|
* Test that radio() accepts a deep array for options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioOptionsArray() {
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'legend' => false,
|
|
|
|
'div' => false,
|
|
|
|
'options' => array(
|
|
|
|
'1' => array('name' => 'Option A', 'title' => 'A Title'),
|
|
|
|
'2' => array('name' => 'Option B', 'data-foo' => 'bar'))
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField1', 'value' => '1', 'title' => 'A Title')),
|
|
|
|
array('label' => array('for' => 'ModelField1')),
|
|
|
|
'Option A',
|
|
|
|
'/label',
|
|
|
|
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'id' => 'ModelField2', 'value' => '2', 'data-foo' => 'bar')),
|
|
|
|
array('label' => array('for' => 'ModelField2')),
|
|
|
|
'Option B',
|
|
|
|
'/label'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2013-09-05 14:30:52 +00:00
|
|
|
/**
|
|
|
|
* Test that radio() accepts an array for label
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioLabelArray() {
|
|
|
|
$result = $this->Form->input('Model.field', array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'legend' => false,
|
|
|
|
'label' => array(
|
|
|
|
'class' => 'checkbox float-left',
|
|
|
|
),
|
|
|
|
'options' => array('1' => 'Option A', '2' => 'Option B.')
|
|
|
|
));
|
|
|
|
$this->assertTextContains(
|
|
|
|
'<label for="ModelField1" class="checkbox float-left">Option A</label>',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-17 02:38:07 +00:00
|
|
|
/**
|
|
|
|
* Test that label id's match the input element id's when radio is called after create().
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRadioWithCreate() {
|
|
|
|
$this->Form->create('Model');
|
|
|
|
$result = $this->Form->radio('recipient',
|
|
|
|
array('1' => '1', '2' => '2', '3' => '3'),
|
|
|
|
array('legend' => false, 'value' => '1')
|
|
|
|
);
|
|
|
|
$this->assertTextNotContains(
|
|
|
|
'<label for="ModelModelRecipient1">1</label>',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
$this->assertTextContains(
|
|
|
|
'<label for="ModelRecipient1">1</label>',
|
|
|
|
$result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-12-04 00:30:57 +00:00
|
|
|
/**
|
|
|
|
* testDomIdSuffix method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDomIdSuffix() {
|
|
|
|
$result = $this->Form->domIdSuffix('1 string with 1$-dollar signs');
|
2014-02-03 17:51:57 +00:00
|
|
|
$this->assertEquals('1StringWith1DollarSigns', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
|
|
|
$result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>');
|
2014-02-03 17:51:57 +00:00
|
|
|
$this->assertEquals('AbcXFooYBar', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
2014-02-03 17:51:57 +00:00
|
|
|
$result = $this->Form->domIdSuffix('1 string with 1$-dollar signs', 'html5');
|
|
|
|
$this->assertEquals('1StringWith1$-dollarSigns', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
2014-02-03 17:51:57 +00:00
|
|
|
$result = $this->Form->domIdSuffix('<abc x="foo" y=\'bar\'>', 'html5');
|
|
|
|
$this->assertEquals('AbcX=FooY=Bar', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testDomIdSuffixCollisionResolvement()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDomIdSuffixCollisionResolvement() {
|
|
|
|
$result = $this->Form->domIdSuffix('a>b');
|
|
|
|
$this->assertEquals('AB', $result);
|
|
|
|
|
|
|
|
$result = $this->Form->domIdSuffix('a<b');
|
|
|
|
$this->assertEquals('AB1', $result);
|
|
|
|
|
|
|
|
$result = $this->Form->domIdSuffix('a\'b');
|
|
|
|
$this->assertEquals('AB2', $result);
|
|
|
|
|
2014-02-03 17:51:57 +00:00
|
|
|
$result = $this->Form->domIdSuffix('1 string with 1$-dollar');
|
|
|
|
$this->assertEquals('1StringWith1Dollar', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
2014-02-03 17:51:57 +00:00
|
|
|
$result = $this->Form->domIdSuffix('1 string with 1$-dollar');
|
|
|
|
$this->assertEquals('1StringWith1Dollar1', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
2014-02-03 17:51:57 +00:00
|
|
|
$result = $this->Form->domIdSuffix('1 string with 1$-dollar');
|
|
|
|
$this->assertEquals('1StringWith1Dollar2', $result);
|
2013-12-04 00:30:57 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSelect method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test select element generation.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelect() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->select('Model.field', array());
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('field' => 'value'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value', 'selected' => 'selected')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->select('Model.field', array('value' => 'good', 'other' => 'bad'));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'value')),
|
|
|
|
'good',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'other')),
|
|
|
|
'bad',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field', array('first' => 'first "html" <chars>', 'second' => 'value'),
|
2010-08-05 18:14:36 +00:00
|
|
|
array('empty' => false)
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 'first')),
|
|
|
|
'first "html" <chars>',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'second')),
|
|
|
|
'value',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
|
|
|
array('first' => 'first "html" <chars>', 'second' => 'value'),
|
2010-08-05 18:14:36 +00:00
|
|
|
array('escape' => false, 'empty' => false)
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 'first')),
|
|
|
|
'first "html" <chars>',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'second')),
|
|
|
|
'value',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-19 02:05:17 +00:00
|
|
|
|
2011-10-24 02:27:07 +00:00
|
|
|
$options = array(
|
|
|
|
array('value' => 'first', 'name' => 'First'),
|
|
|
|
array('value' => 'first', 'name' => 'Another First'),
|
|
|
|
);
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
|
|
|
$options,
|
|
|
|
array('escape' => false, 'empty' => false)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 'first')),
|
|
|
|
'First',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'first')),
|
|
|
|
'Another First',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('contact_id' => 228));
|
2009-10-19 02:05:17 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.contact_id',
|
|
|
|
array('228' => '228 value', '228-1' => '228-1 value', '228-2' => '228-2 value'),
|
2010-08-05 18:14:36 +00:00
|
|
|
array('escape' => false, 'empty' => 'pick something')
|
2009-10-19 02:05:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][contact_id]', 'id' => 'ModelContactId'),
|
|
|
|
array('option' => array('value' => '')), 'pick something', '/option',
|
|
|
|
array('option' => array('value' => '228', 'selected' => 'selected')), '228 value', '/option',
|
|
|
|
array('option' => array('value' => '228-1')), '228-1 value', '/option',
|
|
|
|
array('option' => array('value' => '228-2')), '228-2 value', '/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-12-09 01:15:54 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = 0;
|
|
|
|
$result = $this->Form->select('Model.field', array('0' => 'No', '1' => 'Yes'));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '')), '/option',
|
|
|
|
array('option' => array('value' => '0', 'selected' => 'selected')), 'No', '/option',
|
|
|
|
array('option' => array('value' => '1')), 'Yes', '/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-01-24 02:19:37 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = 50;
|
|
|
|
$result = $this->Form->select('Model.field', array('50f5c0cf' => 'Stringy', '50' => 'fifty'));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '')), '/option',
|
|
|
|
array('option' => array('value' => '50f5c0cf')), 'Stringy', '/option',
|
|
|
|
array('option' => array('value' => '50', 'selected' => 'selected')), 'fifty', '/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-04-15 18:32:04 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select('Contact.required_one', array('option A'));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][required_one]',
|
|
|
|
'id' => 'ContactRequiredOne',
|
|
|
|
'required' => 'required'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '')), '/option',
|
|
|
|
array('option' => array('value' => '0')), 'option A', '/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->select('Contact.required_one', array('option A'), array('disabled' => true));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][required_one]',
|
|
|
|
'id' => 'ContactRequiredOne',
|
|
|
|
'disabled' => 'disabled'
|
|
|
|
),
|
2013-06-09 13:27:09 +00:00
|
|
|
array('option' => array('value' => '')), '/option',
|
|
|
|
array('option' => array('value' => '0')), 'option A', '/option',
|
2013-04-15 18:32:04 +00:00
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2016-03-16 02:59:03 +00:00
|
|
|
/**
|
|
|
|
* testSelect boolean method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectBoolean() {
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
|
|
|
array(0 => 'No', 1 => 'Yes'),
|
|
|
|
array('value' => false, 'empty' => false)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
|
'No',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'Yes',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
|
|
|
array(0 => 'No', 1 => 'Yes', 2 => 'Yes again'),
|
2016-03-17 01:17:42 +00:00
|
|
|
array('value' => array(false, 2), 'empty' => false)
|
2016-03-16 02:59:03 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
|
'No',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'Yes',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2', 'selected' => 'selected')),
|
|
|
|
'Yes again',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2017-02-27 15:16:53 +00:00
|
|
|
/**
|
|
|
|
* test that select() with numeric label of optiongroup.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectOptionGroupWithNumericLabel() {
|
|
|
|
$options = array(
|
|
|
|
1 => array(
|
|
|
|
1 => '1Foo',
|
|
|
|
2 => '2Bar',
|
|
|
|
3 => '3Baz',
|
|
|
|
4 => '1',
|
|
|
|
5 => '2',
|
|
|
|
6 => '3',
|
|
|
|
7 => 1,
|
|
|
|
8 => 2,
|
|
|
|
9 => 3,
|
|
|
|
),
|
|
|
|
2 => array(
|
|
|
|
11 => '1Foo',
|
|
|
|
12 => '2Bar',
|
|
|
|
13 => '3Baz',
|
|
|
|
14 => '1',
|
|
|
|
15 => '2',
|
|
|
|
16 => '3',
|
|
|
|
17 => 1,
|
|
|
|
18 => 2,
|
|
|
|
19 => 3,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$result = $this->Form->select('Model.field', $options, array('empty' => false));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('optgroup' => array('label' => '1')),
|
|
|
|
array('option' => array('value' => '1')), '1Foo', '/option',
|
|
|
|
array('option' => array('value' => '2')), '2Bar', '/option',
|
|
|
|
array('option' => array('value' => '3')), '3Baz', '/option',
|
|
|
|
array('option' => array('value' => '6')), '3', '/option',
|
|
|
|
array('option' => array('value' => '9')), '3', '/option',
|
|
|
|
'/optgroup',
|
|
|
|
array('optgroup' => array('label' => '2')),
|
|
|
|
array('option' => array('value' => '11')), '1Foo', '/option',
|
|
|
|
array('option' => array('value' => '12')), '2Bar', '/option',
|
|
|
|
array('option' => array('value' => '13')), '3Baz', '/option',
|
|
|
|
array('option' => array('value' => '14')), '1', '/option',
|
|
|
|
array('option' => array('value' => '16')), '3', '/option',
|
|
|
|
array('option' => array('value' => '17')), '1', '/option',
|
|
|
|
array('option' => array('value' => '19')), '3', '/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2010-10-14 01:59:53 +00:00
|
|
|
/**
|
|
|
|
* test that select() with optiongroups listens to the escape param.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectOptionGroupEscaping() {
|
2010-10-14 01:59:53 +00:00
|
|
|
$options = array(
|
|
|
|
'>< Key' => array(
|
|
|
|
1 => 'One',
|
|
|
|
2 => 'Two'
|
|
|
|
)
|
|
|
|
);
|
2010-11-01 01:56:59 +00:00
|
|
|
$result = $this->Form->select('Model.field', $options, array('empty' => false));
|
2010-10-14 01:59:53 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
'optgroup' => array('label' => '>< Key'),
|
|
|
|
array('option' => array('value' => '1')), 'One', '/option',
|
|
|
|
array('option' => array('value' => '2')), 'Two', '/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-18 20:55:39 +00:00
|
|
|
|
2010-10-14 01:59:53 +00:00
|
|
|
$options = array(
|
|
|
|
'>< Key' => array(
|
|
|
|
1 => 'One',
|
|
|
|
2 => 'Two'
|
|
|
|
)
|
|
|
|
);
|
2010-11-01 01:56:59 +00:00
|
|
|
$result = $this->Form->select('Model.field', $options, array('empty' => false, 'escape' => false));
|
2010-10-14 01:59:53 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
'optgroup' => array('label' => '>< Key'),
|
|
|
|
array('option' => array('value' => '1')), 'One', '/option',
|
|
|
|
array('option' => array('value' => '2')), 'Two', '/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-14 01:59:53 +00:00
|
|
|
}
|
|
|
|
|
2008-10-03 21:55:41 +00:00
|
|
|
/**
|
|
|
|
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectWithNullAttributes() {
|
2010-08-05 18:14:36 +00:00
|
|
|
$result = $this->Form->select('Model.field', array('first', 'second'), array('empty' => false));
|
2008-10-03 21:55:41 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => '0')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-10-03 21:55:41 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-04 15:57:45 +00:00
|
|
|
/**
|
|
|
|
* testNestedSelect method
|
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test select element generation with optgroups
|
|
|
|
*
|
2008-06-04 15:57:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNestedSelect() {
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
|
|
|
array(1 => 'One', 2 => 'Two', 'Three' => array(
|
|
|
|
3 => 'Three', 4 => 'Four', 5 => 'Five'
|
2010-08-05 18:14:36 +00:00
|
|
|
)), array('empty' => false)
|
2008-09-24 23:02:14 +00:00
|
|
|
);
|
2008-06-04 15:57:45 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]',
|
|
|
|
'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 1)),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 2)),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('optgroup' => array('label' => 'Three')),
|
|
|
|
array('option' => array('value' => 4)),
|
|
|
|
'Four',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 5)),
|
|
|
|
'Five',
|
|
|
|
'/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-04 15:57:45 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.field',
|
2010-08-05 18:14:36 +00:00
|
|
|
array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')),
|
2009-10-17 05:29:16 +00:00
|
|
|
array('showParents' => true, 'empty' => false)
|
2008-09-24 23:02:14 +00:00
|
|
|
);
|
2008-06-04 17:07:40 +00:00
|
|
|
|
2008-06-04 15:57:45 +00:00
|
|
|
$expected = array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 1)),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 2)),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('optgroup' => array('label' => 'Three')),
|
|
|
|
array('option' => array('value' => 3)),
|
|
|
|
'Three',
|
2008-06-04 15:57:45 +00:00
|
|
|
'/option',
|
2008-09-24 23:02:14 +00:00
|
|
|
array('option' => array('value' => 4)),
|
|
|
|
'Four',
|
2008-06-04 15:57:45 +00:00
|
|
|
'/option',
|
2008-09-24 23:02:14 +00:00
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-04 15:57:45 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSelectMultiple method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test generation of multiple select elements
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectMultiple() {
|
2008-12-23 08:13:00 +00:00
|
|
|
$options = array('first', 'second', 'third');
|
|
|
|
$result = $this->Form->select(
|
2010-08-05 18:14:36 +00:00
|
|
|
'Model.multi_field', $options, array('multiple' => true)
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-23 08:13:00 +00:00
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][multi_field][]',
|
|
|
|
'id' => 'ModelMultiField', 'multiple' => 'multiple'
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('option' => array('value' => '0')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'third',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
$result = $this->Form->select(
|
2014-03-19 02:11:57 +00:00
|
|
|
'Model.multi_field', $options, array('form' => 'my-form', 'multiple' => 'multiple')
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-23 08:13:00 +00:00
|
|
|
'input' => array(
|
2014-03-19 02:11:57 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_',
|
|
|
|
'form' => 'my-form',
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][multi_field][]',
|
2014-03-19 02:11:57 +00:00
|
|
|
'id' => 'ModelMultiField',
|
|
|
|
'multiple' => 'multiple',
|
|
|
|
'form' => 'my-form',
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('option' => array('value' => '0')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'third',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
$result = $this->Form->select(
|
2010-08-05 18:14:36 +00:00
|
|
|
'Model.multi_field', $options, array('multiple' => true, 'value' => array(0, 1))
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-23 08:13:00 +00:00
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField',
|
|
|
|
'multiple' => 'multiple'
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'third',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-04-13 04:32:15 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select(
|
2011-05-04 05:40:23 +00:00
|
|
|
'Model.multi_field', $options, array('multiple' => false, 'value' => array(0, 1))
|
2011-04-13 04:32:15 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][multi_field]', 'id' => 'ModelMultiField'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '0', 'selected' => 'selected')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
2008-05-30 11:40:08 +00:00
|
|
|
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'third',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-02-07 14:36:00 +00:00
|
|
|
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$selected = array('2', '3x');
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field', $options, array('multiple' => true, 'value' => $selected)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField_'
|
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][multi_field][]', 'multiple' => 'multiple', 'id' => 'ModelMultiField'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2', 'selected' => 'selected')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x', 'selected' => 'selected')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-04-15 18:32:04 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select('Contact.required_one', array(
|
|
|
|
'1' => 'option A',
|
|
|
|
'2' => 'option B'
|
|
|
|
), array('multiple' => true));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][required_one]', 'value' => '', 'id' => 'ContactRequiredOne_'
|
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][required_one][]',
|
|
|
|
'id' => 'ContactRequiredOne',
|
|
|
|
'required' => 'required',
|
|
|
|
'multiple' => 'multiple'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')), 'option A', '/option',
|
|
|
|
array('option' => array('value' => '2')), 'option B', '/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-12-04 00:51:39 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
|
|
|
array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
|
|
|
|
array('multiple' => true)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '',
|
|
|
|
'id' => 'ModelMultiField_'
|
|
|
|
),
|
|
|
|
array('select' => array('name' => 'data[Model][multi_field][]',
|
|
|
|
'multiple' => 'multiple', 'id' => 'ModelMultiField'
|
|
|
|
)),
|
|
|
|
array('option' => array('value' => 'a>b')),
|
|
|
|
'first',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'a<b')),
|
|
|
|
'second',
|
|
|
|
'/option',
|
|
|
|
array('option' => array(
|
|
|
|
'value' => 'a"b'
|
|
|
|
)),
|
|
|
|
'third',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-02-07 14:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test generating multiple select with disabled elements.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectMultipleWithDisabledElements() {
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
2014-05-23 17:26:11 +00:00
|
|
|
$disabled = array(1);
|
2013-02-07 14:36:00 +00:00
|
|
|
$result = $this->Form->select('Contact.multiple', $options, array('multiple' => 'multiple', 'disabled' => $disabled));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
|
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
|
),
|
2014-05-23 17:26:11 +00:00
|
|
|
array('option' => array('value' => '1', 'disabled' => 'disabled')),
|
2013-02-07 14:36:00 +00:00
|
|
|
'One',
|
|
|
|
'/option',
|
2014-05-23 17:26:11 +00:00
|
|
|
array('option' => array('value' => '2')),
|
2013-02-07 14:36:00 +00:00
|
|
|
'Two',
|
|
|
|
'/option',
|
2014-05-23 17:26:11 +00:00
|
|
|
array('option' => array('value' => '3')),
|
2013-02-07 14:36:00 +00:00
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$disabled = array('2', '3x');
|
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ContactMultiple')),
|
|
|
|
'Multiple',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_'
|
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][multiple][]', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x', 'disabled' => 'disabled')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-06-01 09:46:23 +00:00
|
|
|
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$disabled = true;
|
|
|
|
$result = $this->Form->input('Contact.multiple', array('multiple' => 'multiple', 'disabled' => $disabled, 'options' => $options));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ContactMultiple')),
|
|
|
|
'Multiple',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
2014-10-25 19:05:37 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][multiple]', 'value' => '', 'id' => 'ContactMultiple_', 'disabled' => 'disabled'
|
2013-06-01 09:46:23 +00:00
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Contact][multiple][]', 'disabled' => 'disabled', 'multiple' => 'multiple', 'id' => 'ContactMultiple'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test generating select with disabled elements.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectWithDisabledElements() {
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$disabled = array(2, 3);
|
|
|
|
$result = $this->Form->select('Model.field', $options, array('disabled' => $disabled));
|
|
|
|
$expected = array(
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][field]', 'id' => 'ModelField'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3', 'disabled' => 'disabled')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$disabled = array('2', '3x');
|
|
|
|
$result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ModelField')),
|
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][field]', 'id' => 'ModelField'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2', 'disabled' => 'disabled')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x', 'disabled' => 'disabled')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$options = array(1 => 'One', 2 => 'Two', '3' => 'Three', '3x' => 'Stringy');
|
|
|
|
$disabled = true;
|
|
|
|
$result = $this->Form->input('Model.field', array('disabled' => $disabled, 'options' => $options));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ModelField')),
|
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[Model][field]', 'id' => 'ModelField', 'disabled' => 'disabled'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1')),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3')),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3x')),
|
|
|
|
'Stringy',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-04 18:56:44 +00:00
|
|
|
/**
|
|
|
|
* test generation of habtm select boxes.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHabtmSelectBox() {
|
2010-07-15 03:09:35 +00:00
|
|
|
$this->View->viewVars['contactTags'] = array(
|
2009-11-04 18:56:44 +00:00
|
|
|
1 => 'blue',
|
|
|
|
2 => 'red',
|
|
|
|
3 => 'green'
|
|
|
|
);
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array(
|
2009-11-04 18:56:44 +00:00
|
|
|
'Contact' => array(),
|
|
|
|
'ContactTag' => array(
|
|
|
|
array(
|
2013-01-30 12:54:09 +00:00
|
|
|
'id' => '1',
|
2009-11-04 18:56:44 +00:00
|
|
|
'name' => 'blue'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 3,
|
|
|
|
'name' => 'green'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
|
2009-11-04 18:56:44 +00:00
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
|
|
|
|
'multiple' => 'multiple'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
|
'blue',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2')),
|
|
|
|
'red',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '3', 'selected' => 'selected')),
|
|
|
|
'green',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-01-30 12:54:09 +00:00
|
|
|
|
|
|
|
// make sure only 50 is selected, and not 50f5c0cf
|
|
|
|
$this->View->viewVars['contactTags'] = array(
|
|
|
|
'1' => 'blue',
|
|
|
|
'50f5c0cf' => 'red',
|
|
|
|
'50' => 'green'
|
|
|
|
);
|
|
|
|
$this->Form->request->data = array(
|
|
|
|
'Contact' => array(),
|
|
|
|
'ContactTag' => array(
|
|
|
|
array(
|
|
|
|
'id' => 1,
|
|
|
|
'name' => 'blue'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 50,
|
|
|
|
'name' => 'green'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('ContactTag', array('div' => false, 'label' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '', 'id' => 'ContactTagContactTag_'
|
|
|
|
),
|
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[ContactTag][ContactTag][]', 'id' => 'ContactTagContactTag',
|
|
|
|
'multiple' => 'multiple'
|
|
|
|
),
|
|
|
|
array('option' => array('value' => '1', 'selected' => 'selected')),
|
|
|
|
'blue',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '50f5c0cf')),
|
|
|
|
'red',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '50', 'selected' => 'selected')),
|
|
|
|
'green',
|
|
|
|
'/option',
|
|
|
|
'/select'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2009-11-04 18:56:44 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-26 00:07:57 +00:00
|
|
|
* test generation of multi select elements in checkbox format
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectMultipleCheckboxes() {
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
2010-08-05 18:14:36 +00:00
|
|
|
array('first', 'second', 'third'),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('multiple' => 'checkbox')
|
|
|
|
);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-09-24 23:02:14 +00:00
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
2008-09-24 23:02:14 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '0', 'id' => 'ModelMultiField0'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '1', 'id' => 'ModelMultiField1'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '2', 'id' => 'ModelMultiField2'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-24 23:02:14 +00:00
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
2010-08-05 18:14:36 +00:00
|
|
|
array('a' => 'first', 'b' => 'second', 'c' => 'third'),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('multiple' => 'checkbox')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-23 08:13:00 +00:00
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'a', 'id' => 'ModelMultiFieldA'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldA')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'b', 'id' => 'ModelMultiFieldB'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldB')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-09-24 23:02:14 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'c', 'id' => 'ModelMultiFieldC'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldC')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
$result = $this->Form->select(
|
2010-08-05 18:14:36 +00:00
|
|
|
'Model.multi_field', array('1' => 'first'), array('multiple' => 'checkbox')
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-23 08:13:00 +00:00
|
|
|
'input' => array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
2008-12-23 08:13:00 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
2008-12-23 08:13:00 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '1', 'id' => 'ModelMultiField1'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-03-13 04:17:11 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('tags' => array(1)));
|
2010-03-13 04:17:11 +00:00
|
|
|
$result = $this->Form->select(
|
2010-08-05 18:14:36 +00:00
|
|
|
'Model.tags', array('1' => 'first', 'Array' => 'Array'), array('multiple' => 'checkbox')
|
2010-03-13 04:17:11 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
|
'value' => '1', 'id' => 'ModelTags1', 'checked' => 'checked'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelTags1', 'class' => 'selected')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
2010-04-20 04:02:58 +00:00
|
|
|
|
2010-03-13 04:17:11 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
|
'value' => 'Array', 'id' => 'ModelTagsArray'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelTagsArray')),
|
|
|
|
'Array',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-12-04 00:30:57 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
|
|
|
array('a+' => 'first', 'a++' => 'second', 'a+++' => 'third'),
|
|
|
|
array('multiple' => 'checkbox')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
2014-02-03 17:51:57 +00:00
|
|
|
'value' => 'a+', 'id' => 'ModelMultiFieldA2'
|
2013-12-04 00:30:57 +00:00
|
|
|
)),
|
2014-02-03 17:51:57 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldA2')),
|
2013-12-04 00:30:57 +00:00
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
2014-02-03 17:51:57 +00:00
|
|
|
'value' => 'a++', 'id' => 'ModelMultiFieldA1'
|
2013-12-04 00:30:57 +00:00
|
|
|
)),
|
2014-02-03 17:51:57 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldA1')),
|
2013-12-04 00:30:57 +00:00
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
2014-02-03 17:51:57 +00:00
|
|
|
'value' => 'a+++', 'id' => 'ModelMultiFieldA'
|
2013-12-04 00:30:57 +00:00
|
|
|
)),
|
2014-02-03 17:51:57 +00:00
|
|
|
array('label' => array('for' => 'ModelMultiFieldA')),
|
2013-12-04 00:30:57 +00:00
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2014-02-03 17:51:57 +00:00
|
|
|
|
2013-12-04 00:30:57 +00:00
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
|
|
|
array('a>b' => 'first', 'a<b' => 'second', 'a"b' => 'third'),
|
|
|
|
array('multiple' => 'checkbox')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'a>b', 'id' => 'ModelMultiFieldAB2'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldAB2')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'a<b', 'id' => 'ModelMultiFieldAB1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldAB1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => 'a"b', 'id' => 'ModelMultiFieldAB'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldAB')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-10-16 17:32:04 +00:00
|
|
|
/**
|
|
|
|
* test multiple checkboxes with div styles.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectMultipleCheckboxDiv() {
|
2010-10-16 17:32:04 +00:00
|
|
|
$result = $this->Form->select(
|
2011-01-18 20:55:39 +00:00
|
|
|
'Model.tags',
|
2010-10-16 17:32:04 +00:00
|
|
|
array('first', 'second'),
|
|
|
|
array('multiple' => 'checkbox', 'class' => 'my-class')
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][tags]', 'value' => '', 'id' => 'ModelTags'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'my-class')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
|
'value' => '0', 'id' => 'ModelTags0'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelTags0')), 'first', '/label',
|
|
|
|
'/div',
|
|
|
|
|
|
|
|
array('div' => array('class' => 'my-class')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][tags][]',
|
|
|
|
'value' => '1', 'id' => 'ModelTags1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ModelTags1')), 'second', '/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-16 17:32:04 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.tags', array(
|
|
|
|
'options' => array('first', 'second'),
|
2011-01-18 20:55:39 +00:00
|
|
|
'multiple' => 'checkbox',
|
2010-10-16 17:32:04 +00:00
|
|
|
'class' => 'my-class',
|
|
|
|
'div' => false,
|
|
|
|
'label' => false
|
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-11 14:50:55 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['tags'] = 'Select atleast one option';
|
|
|
|
$result = $this->Form->input('Contact.tags', array(
|
2011-03-11 14:50:55 +00:00
|
|
|
'options' => array('one'),
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'label' => false,
|
|
|
|
'div' => false
|
|
|
|
));
|
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
|
2011-03-11 14:50:55 +00:00
|
|
|
array('div' => array('class' => 'checkbox form-error')),
|
2011-07-14 18:23:10 +00:00
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
|
|
|
array('label' => array('for' => 'ContactTags0')),
|
2011-03-11 14:50:55 +00:00
|
|
|
'one',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-11 14:50:55 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->input('Contact.tags', array(
|
2011-03-11 14:50:55 +00:00
|
|
|
'options' => array('one'),
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'class' => 'mycheckbox',
|
|
|
|
'label' => false,
|
|
|
|
'div' => false
|
|
|
|
));
|
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][tags]', 'value' => '', 'id' => 'ContactTags'),
|
2011-03-11 14:50:55 +00:00
|
|
|
array('div' => array('class' => 'mycheckbox form-error')),
|
2011-07-14 18:23:10 +00:00
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][tags][]', 'value' => '0', 'id' => 'ContactTags0')),
|
|
|
|
array('label' => array('for' => 'ContactTags0')),
|
2011-03-11 14:50:55 +00:00
|
|
|
'one',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-10-16 17:32:04 +00:00
|
|
|
}
|
|
|
|
|
2008-12-23 08:13:00 +00:00
|
|
|
/**
|
|
|
|
* Checks the security hash array generated for multiple-input checkbox elements
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectMultipleCheckboxSecurity() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['_Token'] = array('key' => 'testKey');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
2008-12-23 08:13:00 +00:00
|
|
|
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field', array('1' => 'first', '2' => 'second', '3' => 'third'),
|
2010-11-01 01:56:59 +00:00
|
|
|
array('multiple' => 'checkbox')
|
2008-12-23 08:13:00 +00:00
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Model.multi_field'), $this->Form->fields);
|
2008-12-23 08:13:00 +00:00
|
|
|
|
|
|
|
$result = $this->Form->secure($this->Form->fields);
|
2010-11-21 05:09:45 +00:00
|
|
|
$key = 'f7d573650a295b94e0938d32b323fde775e5f32b%3A';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/"' . $key . '"/', $result);
|
2008-12-23 08:13:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-09-18 18:41:51 +00:00
|
|
|
/**
|
|
|
|
* Multiple select elements should always be secured as they always participate
|
|
|
|
* in the POST data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectMultipleSecureWithNoOptions() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testkey');
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Form->select(
|
2012-09-18 18:41:51 +00:00
|
|
|
'Model.select',
|
|
|
|
array(),
|
|
|
|
array('multiple' => true)
|
|
|
|
);
|
|
|
|
$this->assertEquals(array('Model.select'), $this->Form->fields);
|
|
|
|
}
|
2012-08-27 02:53:48 +00:00
|
|
|
/**
|
|
|
|
* When a select box has no options it should not be added to the fields list
|
|
|
|
* as it always fail post validation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectNoSecureWithNoOptions() {
|
|
|
|
$this->Form->request['_Token'] = array('key' => 'testkey');
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->select(
|
|
|
|
'Model.select',
|
|
|
|
array()
|
|
|
|
);
|
|
|
|
$this->assertEquals(array(), $this->Form->fields);
|
|
|
|
|
|
|
|
$this->Form->select(
|
|
|
|
'Model.select',
|
|
|
|
array(),
|
|
|
|
array('empty' => true)
|
|
|
|
);
|
|
|
|
$this->assertEquals(array('Model.select'), $this->Form->fields);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testInputMultipleCheckboxes method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test input() resulting in multi select elements being generated.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputMultipleCheckboxes() {
|
2010-09-05 05:28:13 +00:00
|
|
|
$result = $this->Form->input('Model.multi_field', array(
|
2010-10-10 17:46:48 +00:00
|
|
|
'options' => array('first', 'second', 'third'),
|
2010-09-05 05:28:13 +00:00
|
|
|
'multiple' => 'checkbox'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField')),
|
|
|
|
'Multi Field',
|
|
|
|
'/label',
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-09-05 05:28:13 +00:00
|
|
|
$result = $this->Form->input('Model.multi_field', array(
|
|
|
|
'options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'),
|
|
|
|
'multiple' => 'checkbox'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField')),
|
|
|
|
'Multi Field',
|
|
|
|
'/label',
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'a', 'id' => 'ModelMultiFieldA')),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldA')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'b', 'id' => 'ModelMultiFieldB')),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldB')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => 'c', 'id' => 'ModelMultiFieldC')),
|
|
|
|
array('label' => array('for' => 'ModelMultiFieldC')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-09-05 05:28:13 +00:00
|
|
|
$result = $this->Form->input('Model.multi_field', array(
|
|
|
|
'options' => array('1' => 'first'),
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'label' => false,
|
|
|
|
'div' => false
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-09-05 05:28:13 +00:00
|
|
|
$result = $this->Form->input('Model.multi_field', array(
|
|
|
|
'options' => array('2' => 'second'),
|
|
|
|
'multiple' => 'checkbox',
|
2010-10-10 17:46:48 +00:00
|
|
|
'label' => false,
|
2010-09-05 05:28:13 +00:00
|
|
|
'div' => false
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'ModelMultiField'),
|
2008-05-30 11:40:08 +00:00
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '2', 'id' => 'ModelMultiField2')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField2')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2011-03-21 13:48:53 +00:00
|
|
|
/**
|
|
|
|
* testSelectHiddenFieldOmission method
|
|
|
|
*
|
|
|
|
* test that select() with 'hiddenField' => false omits the hidden field
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectHiddenFieldOmission() {
|
2011-03-21 13:48:53 +00:00
|
|
|
$result = $this->Form->select('Model.multi_field',
|
|
|
|
array('first', 'second'),
|
2011-05-04 05:40:23 +00:00
|
|
|
array('multiple' => 'checkbox', 'hiddenField' => false, 'value' => null)
|
2011-03-21 13:48:53 +00:00
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-21 13:48:53 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.multi_field', array(
|
|
|
|
'options' => array('first', 'second'),
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'hiddenField' => false
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
array('div' => array('class' => 'input select')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField')),
|
|
|
|
'Multi Field',
|
|
|
|
'/label',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '0', 'id' => 'ModelMultiField0')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField0')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][multi_field][]', 'value' => '1', 'id' => 'ModelMultiField1')),
|
|
|
|
array('label' => array('for' => 'ModelMultiField1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-21 13:48:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-05 05:28:13 +00:00
|
|
|
/**
|
|
|
|
* test that select() with multiple = checkbox works with overriding name attribute.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSelectCheckboxMultipleOverrideName() {
|
2010-09-05 05:28:13 +00:00
|
|
|
$result = $this->Form->input('category', array(
|
|
|
|
'type' => 'select',
|
|
|
|
'multiple' => 'checkbox',
|
|
|
|
'name' => 'data[fish]',
|
|
|
|
'options' => array('1', '2'),
|
|
|
|
'div' => false,
|
|
|
|
'label' => false,
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[fish]', 'value' => '', 'id' => 'category'),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '0', 'id' => 'Category0')),
|
|
|
|
array('label' => array('for' => 'Category0')), '1', '/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[fish][]', 'value' => '1', 'id' => 'Category1')),
|
|
|
|
array('label' => array('for' => 'Category1')), '2', '/label',
|
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-06-07 02:32:55 +00:00
|
|
|
/**
|
|
|
|
* Test that 'id' overrides all the checkbox id's as well.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSelectCheckboxMultipleId() {
|
|
|
|
$result = $this->Form->select(
|
|
|
|
'Model.multi_field',
|
|
|
|
array('first', 'second', 'third'),
|
|
|
|
array('multiple' => 'checkbox', 'id' => 'CustomId')
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '', 'id' => 'CustomId'
|
|
|
|
),
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '0', 'id' => 'CustomId0'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'CustomId0')),
|
|
|
|
'first',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '1', 'id' => 'CustomId1'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'CustomId1')),
|
|
|
|
'second',
|
|
|
|
'/label',
|
|
|
|
'/div',
|
|
|
|
array('div' => array('class' => 'checkbox')),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[Model][multi_field][]',
|
|
|
|
'value' => '2', 'id' => 'CustomId2'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'CustomId2')),
|
|
|
|
'third',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testCheckbox method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test generation of checkboxes
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckbox() {
|
2011-03-16 01:39:37 +00:00
|
|
|
$result = $this->Form->checkbox('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-16 01:39:37 +00:00
|
|
|
|
2014-03-19 02:11:57 +00:00
|
|
|
$result = $this->Form->checkbox('Model.field', array(
|
|
|
|
'id' => 'theID',
|
|
|
|
'value' => 'myvalue',
|
|
|
|
'form' => 'my-form',
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2014-03-19 02:11:57 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_', 'form' => 'my-form'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID', 'form' => 'my-form'))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['field'] = 1;
|
|
|
|
$this->Form->request->data['Contact']['field'] = 'myvalue';
|
|
|
|
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID', 'value' => 'myvalue'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
|
2014-03-22 01:57:06 +00:00
|
|
|
array('input' => array('type', 'name', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error'))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
2014-03-22 01:57:06 +00:00
|
|
|
array('input' => array('type', 'name', 'value' => 'myvalue', 'id' => 'ContactField', 'checked' => 'checked', 'class' => 'form-error'))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$this->Form->request->data['Contact']['field'] = '';
|
|
|
|
$result = $this->Form->checkbox('Contact.field', array('id' => 'theID'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'theID_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error'))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact->validationErrors = array();
|
|
|
|
$result = $this->Form->checkbox('Contact.field', array('value' => 'myvalue'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][field]', 'value' => '0', 'id' => 'ContactField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][field]', 'value' => 'myvalue', 'id' => 'ContactField'))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = 1;
|
2009-10-31 04:58:21 +00:00
|
|
|
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID', 'checked' => 'checked'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = 0;
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = $this->Form->checkbox('Contact.published', array('id' => 'theID'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Contact][published]', 'value' => '0', 'id' => 'theID_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][published]', 'value' => '1', 'id' => 'theID'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->checkbox('Model.CustomField.1.value');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][CustomField][1][value]', 'value' => '0', 'id' => 'ModelCustomField1Value_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][CustomField][1][value]', 'value' => '1', 'id' => 'ModelCustomField1Value'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->checkbox('CustomField.1.value');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[CustomField][1][value]', 'value' => '0', 'id' => 'CustomField1Value_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-16 01:39:37 +00:00
|
|
|
}
|
2008-09-18 03:09:19 +00:00
|
|
|
|
2011-03-16 01:39:37 +00:00
|
|
|
/**
|
|
|
|
* test checkbox() with a custom name attribute
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckboxCustomNameAttribute() {
|
2008-08-09 22:08:17 +00:00
|
|
|
$result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'myField', 'value' => '1', 'id' => 'TestTest'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-15 02:48:23 +00:00
|
|
|
/**
|
|
|
|
* test the checked option for checkboxes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckboxCheckedOption() {
|
2011-01-15 02:48:23 +00:00
|
|
|
$result = $this->Form->checkbox('Model.field', array('checked' => 'checked'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 02:48:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('checked' => 1));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 02:48:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('checked' => true));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField', 'checked' => 'checked'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 02:48:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->checkbox('Model.field', array('checked' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 02:48:23 +00:00
|
|
|
|
2011-01-19 01:04:30 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = 1;
|
2011-01-15 02:48:23 +00:00
|
|
|
$result = $this->Form->checkbox('Model.field', array('checked' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 02:48:23 +00:00
|
|
|
}
|
|
|
|
|
2009-03-25 16:58:29 +00:00
|
|
|
/**
|
2011-03-16 01:39:37 +00:00
|
|
|
* Test that disabled attribute works on both the checkbox and hidden input.
|
2009-03-25 16:58:29 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCheckboxDisabling() {
|
2009-03-25 16:58:29 +00:00
|
|
|
$result = $this->Form->checkbox('Account.show_name', array('disabled' => 'disabled'));
|
|
|
|
$expected = array(
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_', 'disabled' => 'disabled')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName', 'disabled' => 'disabled'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-14 03:26:53 +00:00
|
|
|
$result = $this->Form->checkbox('Account.show_name', array('disabled' => false));
|
|
|
|
$expected = array(
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[Account][show_name]', 'value' => '0', 'id' => 'AccountShowName_')),
|
|
|
|
array('input' => array('type' => 'checkbox', 'name' => 'data[Account][show_name]', 'value' => '1', 'id' => 'AccountShowName'))
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-05-14 03:26:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-31 03:23:33 +00:00
|
|
|
/**
|
2011-12-19 07:34:19 +00:00
|
|
|
* Test that the hidden input for checkboxes can be omitted or set to a
|
|
|
|
* specific value.
|
2009-10-31 03:23:33 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-19 07:34:19 +00:00
|
|
|
public function testCheckboxHiddenField() {
|
2009-10-31 03:23:33 +00:00
|
|
|
$result = $this->Form->input('UserForm.something', array(
|
2011-12-19 07:34:19 +00:00
|
|
|
'type' => 'checkbox',
|
|
|
|
'hiddenField' => false
|
|
|
|
));
|
2009-10-31 03:23:33 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
|
'value' => '1', 'id' => 'UserFormSomething'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'UserFormSomething'),
|
|
|
|
'Something',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-12-19 07:34:19 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('UserForm.something', array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'value' => 'Y',
|
|
|
|
'hiddenField' => 'N',
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[UserForm][something]',
|
|
|
|
'value' => 'N', 'id' => 'UserFormSomething_'
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[UserForm][something]',
|
|
|
|
'value' => 'Y', 'id' => 'UserFormSomething'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'UserFormSomething'),
|
|
|
|
'Something',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 02:12:06 +00:00
|
|
|
/**
|
|
|
|
* Test that a checkbox can have 0 for the value and 1 for the hidden input.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCheckboxZeroValue() {
|
|
|
|
$result = $this->Form->input('User.get_spam', array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'value' => '0',
|
|
|
|
'hiddenField' => '1',
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[User][get_spam]',
|
|
|
|
'value' => '1', 'id' => 'UserGetSpam_'
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox', 'name' => 'data[User][get_spam]',
|
|
|
|
'value' => '0', 'id' => 'UserGetSpam'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'UserGetSpam'),
|
|
|
|
'Get Spam',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDateTime method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* Test generation of date/time select elements
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDateTime() {
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$now = strtotime('now');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
|
|
|
|
date('g', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
|
$minutesRegex,
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
|
2008-05-30 11:40:08 +00:00
|
|
|
date('i', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
|
|
|
|
date('a', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
2010-08-05 23:31:51 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
2012-04-25 00:09:39 +00:00
|
|
|
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'value' => ''));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'00',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '05')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'05',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '10')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
|
2012-04-22 01:31:24 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['data'] = null;
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = date('Y') . '-01-01 00:00:00';
|
2010-08-05 23:30:49 +00:00
|
|
|
$now = strtotime($this->Form->data['Model']['field']);
|
|
|
|
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('empty' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => date('h', $now), 'selected' => 'selected')),
|
|
|
|
date('g', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
$minutesRegex,
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => date('i', $now), 'selected' => 'selected')),
|
2008-05-30 11:40:08 +00:00
|
|
|
date('i', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Model][field][meridian]', 'id' => 'ModelFieldMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => date('a', $now), 'selected' => 'selected')),
|
|
|
|
date('a', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-11-08 02:58:37 +00:00
|
|
|
|
2011-07-28 00:20:24 +00:00
|
|
|
$selected = strtotime('2008-10-26 12:33:00');
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Model.field', 'DMY', '12', array('value' => $selected));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="10"[^<>]+selected="selected"[^>]*>October<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="12"[^<>]+selected="selected"[^>]*>12<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="pm"[^<>]+selected="selected"[^>]*>pm<\/option>/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('published');
|
|
|
|
$now = strtotime('now');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input date'),
|
|
|
|
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
|
'Published',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('published2', array('type' => 'date'));
|
|
|
|
$now = strtotime('now');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input date'),
|
|
|
|
'label' => array('for' => 'ContactPublished2Month'),
|
|
|
|
'Published2',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[Contact][published2][month]', 'id' => 'ContactPublished2Month')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published2][day]', 'id' => 'ContactPublished2Day')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published2][year]', 'id' => 'ContactPublished2Year')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
$result = $this->Form->input('published', array('monthNames' => false));
|
|
|
|
$now = strtotime('now');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input date'),
|
|
|
|
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
|
'Published',
|
|
|
|
'/label',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth')),
|
|
|
|
'preg:/(?:<option value="([\d])+">[\d]+<\/option>[\r\n]*)*/',
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('m', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-09-04 02:47:17 +00:00
|
|
|
$result = $this->Form->input('published', array(
|
|
|
|
'timeFormat' => 24,
|
|
|
|
'interval' => 5,
|
|
|
|
'selected' => strtotime('2009-09-03 13:37:00'),
|
|
|
|
'type' => 'datetime'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
|
2013-03-14 00:29:45 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 13:42:08 +00:00
|
|
|
/**
|
|
|
|
* Test dateTime with rounding
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDateTimeRounding() {
|
|
|
|
$this->Form->request->data['Contact'] = array(
|
|
|
|
'date' => array(
|
|
|
|
'day' => '13',
|
|
|
|
'month' => '12',
|
|
|
|
'year' => '2010',
|
|
|
|
'hour' => '04',
|
|
|
|
'min' => '19',
|
|
|
|
'meridian' => 'AM'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15));
|
|
|
|
$this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
|
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 15, 'round' => 'up'));
|
|
|
|
$this->assertTextContains('<option value="30" selected="selected">30</option>', $result);
|
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('interval' => 5, 'round' => 'down'));
|
|
|
|
$this->assertTextContains('<option value="15" selected="selected">15</option>', $result);
|
2013-03-14 00:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that empty values don't trigger errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDateTimeNoErrorsOnEmptyData() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact'] = array(
|
2009-12-19 16:55:35 +00:00
|
|
|
'date' => array(
|
|
|
|
'day' => '',
|
|
|
|
'month' => '',
|
|
|
|
'year' => '',
|
|
|
|
'hour' => '',
|
|
|
|
'min' => '',
|
|
|
|
'meridian' => ''
|
|
|
|
)
|
|
|
|
);
|
2010-08-05 23:30:49 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('empty' => false));
|
2013-03-14 00:29:45 +00:00
|
|
|
$this->assertNotEmpty($result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-08-10 03:49:18 +00:00
|
|
|
/**
|
|
|
|
* test that datetime() and default values work.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDatetimeWithDefault() {
|
2010-11-01 01:56:59 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => '2009-06-01 11:15:30'));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
|
2010-08-10 03:49:18 +00:00
|
|
|
|
2010-11-01 01:56:59 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array(
|
2010-08-10 03:49:18 +00:00
|
|
|
'default' => '2009-06-01 11:15:30'
|
|
|
|
));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option[^<>]+value="06"[^<>]+selected="selected"[^>]*>June<\/option>/', $result);
|
2010-08-10 03:49:18 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 11:43:00 +00:00
|
|
|
/**
|
|
|
|
* test that bogus non-date time data doesn't cause errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDateTimeWithBogusData() {
|
2011-02-05 20:24:46 +00:00
|
|
|
$result = $this->Form->dateTime('Contact.updated', 'DMY', '12', array('value' => 'CURRENT_TIMESTAMP'));
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/selected="selected">\d/', $result);
|
2011-02-05 11:43:00 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 15:23:45 +00:00
|
|
|
/**
|
|
|
|
* testDateTime all zeros
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDateTimeAllZeros() {
|
|
|
|
$result = $this->Form->dateTime('Contact.date',
|
|
|
|
'DMY',
|
|
|
|
false,
|
|
|
|
array(
|
|
|
|
'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
|
|
|
|
'value' => '0000-00-00'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option value="">-<\/option>/', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option value="0" selected="selected">0<\/option>/', $result);
|
2014-01-15 15:23:45 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 20:17:21 +00:00
|
|
|
/**
|
|
|
|
* testDateTimeEmptyAsArray
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDateTimeEmptyAsArray() {
|
|
|
|
$result = $this->Form->dateTime('Contact.date',
|
|
|
|
'DMY',
|
|
|
|
'12',
|
|
|
|
array(
|
|
|
|
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR',
|
|
|
|
'hour' => 'HOUR', 'minute' => 'MINUTE', 'meridian' => false
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option value="">DAY<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">MONTH<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">YEAR<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">HOUR<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">MINUTE<\/option>/', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<option value=""><\/option>/', $result);
|
2012-07-27 20:17:21 +00:00
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.date',
|
|
|
|
'DMY',
|
|
|
|
'12',
|
|
|
|
array(
|
|
|
|
'empty' => array('day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option value="">DAY<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">MONTH<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<option value="">YEAR<\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<select[^<>]+id="ContactDateHour">\s<option value=""><\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<select[^<>]+id="ContactDateMin">\s<option value=""><\/option>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<select[^<>]+id="ContactDateMeridian">\s<option value=""><\/option>/', $result);
|
2012-07-27 20:17:21 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 00:07:57 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testFormDateTimeMulti method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test multiple datetime element generation
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormDateTimeMulti() {
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.1.updated');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][day]', 'id' => 'Contact1UpdatedDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][month]', 'id' => 'Contact1UpdatedMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][year]', 'id' => 'Contact1UpdatedYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][hour]', 'id' => 'Contact1UpdatedHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][min]', 'id' => 'Contact1UpdatedMin')),
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][1][updated][meridian]', 'id' => 'Contact1UpdatedMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->dateTime('Contact.2.updated');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][day]', 'id' => 'Contact2UpdatedDay')),
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][month]', 'id' => 'Contact2UpdatedMonth')),
|
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][year]', 'id' => 'Contact2UpdatedYear')),
|
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][hour]', 'id' => 'Contact2UpdatedHour')),
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
':',
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][min]', 'id' => 'Contact2UpdatedMin')),
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
' ',
|
|
|
|
array('select' => array('name' => 'data[Contact][2][updated][meridian]', 'id' => 'Contact2UpdatedMeridian')),
|
|
|
|
$meridianRegex,
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-12-20 03:09:46 +00:00
|
|
|
/**
|
|
|
|
* When changing the date format, the label should always focus the first select box when
|
|
|
|
* clicked.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testDateTimeLabelIdMatchesFirstInput() {
|
2011-12-20 03:09:46 +00:00
|
|
|
$result = $this->Form->input('Model.date', array('type' => 'date'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('label for="ModelDateMonth"', $result);
|
2011-12-20 03:09:46 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'DMY'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('label for="ModelDateDay"', $result);
|
2011-12-20 03:09:46 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Model.date', array('type' => 'date', 'dateFormat' => 'YMD'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('label for="ModelDateYear"', $result);
|
2011-12-20 03:09:46 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMonth method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMonth() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->month('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
date('F', strtotime('2008-01-01 00:00:00')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
date('F', strtotime('2008-02-01 00:00:00')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-04 15:57:45 +00:00
|
|
|
|
2010-08-05 22:00:15 +00:00
|
|
|
$result = $this->Form->month('Model.field', array('empty' => true));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
2008-05-30 15:07:32 +00:00
|
|
|
date('F', strtotime('2008-01-01 00:00:00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
2008-05-30 15:07:32 +00:00
|
|
|
date('F', strtotime('2008-02-01 00:00:00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-11-02 15:51:16 +00:00
|
|
|
|
2010-08-05 22:00:15 +00:00
|
|
|
$result = $this->Form->month('Model.field', array('monthNames' => false));
|
2009-11-02 15:51:16 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'01',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'02',
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-11-02 15:51:16 +00:00
|
|
|
|
|
|
|
$monthNames = array(
|
|
|
|
'01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
|
|
|
|
'07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
|
2010-08-05 22:00:15 +00:00
|
|
|
$result = $this->Form->month('Model.field', array('monthNames' => $monthNames));
|
2009-11-02 15:51:16 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'Jan',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'Feb',
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-03-05 21:11:23 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Project']['release'] = '2050-02-10';
|
|
|
|
$result = $this->Form->month('Project.release');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Project][release][month]', 'id' => 'ProjectReleaseMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'January',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02', 'selected' => 'selected')),
|
|
|
|
'February',
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2014-02-19 23:50:30 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = '12a';
|
|
|
|
$result = $this->Form->month('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
date('F', strtotime('2008-01-01 00:00:00')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
date('F', strtotime('2008-02-01 00:00:00')),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDay method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDay() {
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 21:47:14 +00:00
|
|
|
$result = $this->Form->day('Model.field', array('value' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->day('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '';
|
2010-08-05 21:47:14 +00:00
|
|
|
$result = $this->Form->day('Model.field', array('value' => '10'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 23:12:32';
|
2010-08-05 21:47:14 +00:00
|
|
|
$result = $this->Form->day('Model.field', array('value' => true));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2013-03-05 21:11:23 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Project']['release'] = '2050-10-10';
|
|
|
|
$result = $this->Form->day('Project.release');
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Project][release][day]', 'id' => 'ProjectReleaseDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2014-02-19 23:50:30 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = '12e';
|
|
|
|
$result = $this->Form->day('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$daysRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testMinute method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMinute() {
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->minute('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'00',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '01')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'01',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '02')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'02',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->minute('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'00',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '01')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'01',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '02')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'02',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
array('option' => array('value' => '12', 'selected' => 'selected')),
|
|
|
|
'12',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '';
|
2010-08-05 22:07:08 +00:00
|
|
|
$result = $this->Form->minute('Model.field', array('interval' => 5));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'00',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '05')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'05',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '10')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 00:10:32';
|
2010-08-05 22:07:08 +00:00
|
|
|
$result = $this->Form->minute('Model.field', array('interval' => 5));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '00')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'00',
|
|
|
|
'/option',
|
2009-11-01 04:01:12 +00:00
|
|
|
array('option' => array('value' => '05')),
|
2008-05-30 11:40:08 +00:00
|
|
|
'05',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '10', 'selected' => 'selected')),
|
|
|
|
'10',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2014-02-19 23:50:30 +00:00
|
|
|
|
|
|
|
$result = $this->Form->minute('Model.field', array('value' => '#invalid#'));
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '00')),
|
|
|
|
'00',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'01',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'02',
|
|
|
|
'/option',
|
|
|
|
$minutesRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testHour method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHour() {
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->hour('Model.field', false);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$hoursRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->hour('Model.field', false);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$hoursRegex,
|
|
|
|
array('option' => array('value' => '12', 'selected' => 'selected')),
|
|
|
|
'12',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '';
|
2010-08-05 22:04:00 +00:00
|
|
|
$result = $this->Form->hour('Model.field', true, array('value' => '23'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="23" selected="selected">23</option>', $result);
|
2012-10-23 16:47:12 +00:00
|
|
|
|
|
|
|
$result = $this->Form->hour('Model.field', false, array('value' => '23'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<option value="11" selected="selected">11</option>', $result);
|
2012-10-23 16:47:12 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['field'] = '2006-10-10 00:12:32';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->hour('Model.field', true);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '00', 'selected' => 'selected')),
|
|
|
|
'0',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$hoursRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-12-30 16:20:38 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
unset($this->Form->request->data['Model']['field']);
|
2010-08-05 22:04:00 +00:00
|
|
|
$result = $this->Form->hour('Model.field', true, array('value' => 'now'));
|
2008-12-30 16:20:38 +00:00
|
|
|
$thisHour = date('H');
|
2009-01-13 18:42:08 +00:00
|
|
|
$optValue = date('G');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
|
2013-03-05 21:11:23 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
|
|
|
|
$result = $this->Form->hour('Model.field', true);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '00')),
|
|
|
|
'0',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01', 'selected' => 'selected')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$hoursRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2014-02-19 23:50:30 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['field'] = '18a';
|
|
|
|
$result = $this->Form->hour('Model.field', false);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '01')),
|
|
|
|
'1',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '02')),
|
|
|
|
'2',
|
|
|
|
'/option',
|
|
|
|
$hoursRegex,
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testYear method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testYear() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->year('Model.field', 2006, 2007);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Model.field', 2006, 2007, array('orderYear' => 'asc'));
|
2010-01-27 20:18:53 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Model][field][year]', 'id' => 'ModelFieldYear')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-01-27 20:18:53 +00:00
|
|
|
|
2019-12-05 10:52:16 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('value' => 2007));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2007, array('empty' => false, 'value' => 2007));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false, 'value' => 2007));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2008')),
|
|
|
|
'2008',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007', 'selected' => 'selected')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['published'] = '2006-10-10';
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('Contact.published', 2006, 2008, array('empty' => false));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2008')),
|
|
|
|
'2008',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006', 'selected' => 'selected')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-11-30 18:43:26 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array();
|
2009-11-30 18:43:26 +00:00
|
|
|
$this->Form->create('Contact');
|
2010-08-05 21:56:29 +00:00
|
|
|
$result = $this->Form->year('published', 2006, 2008, array('empty' => false));
|
2009-11-30 18:43:26 +00:00
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '2008')),
|
|
|
|
'2008',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2007')),
|
|
|
|
'2007',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2006')),
|
|
|
|
'2006',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-12-12 03:03:39 +00:00
|
|
|
|
|
|
|
$result = $this->Form->year('published', array(), array(), array('empty' => false));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('data[Contact][published][year]', $result);
|
2014-02-19 23:50:30 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Contact']['published'] = '2014ee';
|
|
|
|
$result = $this->Form->year('Contact.published', 2010, 2011);
|
|
|
|
$expected = array(
|
|
|
|
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
|
|
|
|
array('option' => array('value' => '')),
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2011')),
|
|
|
|
'2011',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => '2010')),
|
|
|
|
'2010',
|
|
|
|
'/option',
|
|
|
|
'/select',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-03-01 12:37:52 +00:00
|
|
|
/**
|
|
|
|
* testYearAutoExpandRange method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testYearAutoExpandRange() {
|
|
|
|
$this->Form->request->data['User']['birthday'] = '1930-10-10';
|
|
|
|
$result = $this->Form->year('User.birthday');
|
|
|
|
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
|
|
|
|
|
$result = $matches[1];
|
|
|
|
$expected = range(date('Y') + 20, 1930);
|
2013-09-25 20:07:52 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-03-01 12:37:52 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Project']['release'] = '2050-10-10';
|
|
|
|
$result = $this->Form->year('Project.release');
|
|
|
|
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
|
|
|
|
|
$result = $matches[1];
|
|
|
|
$expected = range(2050, date('Y') - 20);
|
2013-09-25 20:07:52 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-03-05 21:11:23 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Project']['release'] = '1881-10-10';
|
|
|
|
$result = $this->Form->year('Project.release', 1890, 1900);
|
|
|
|
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
|
|
|
|
|
|
|
$result = $matches[1];
|
|
|
|
$expected = range(1900, 1881);
|
2013-09-25 20:07:52 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-03-01 12:37:52 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 09:54:29 +00:00
|
|
|
/**
|
|
|
|
* testInputDate method
|
|
|
|
*
|
2013-06-25 10:11:10 +00:00
|
|
|
* Test various inputs with type date and different dateFormat values.
|
|
|
|
* Failing to provide a dateFormat key should not error.
|
|
|
|
* It should simply not pre-select any value then.
|
2013-06-25 09:54:29 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputDate() {
|
2013-06-25 10:11:10 +00:00
|
|
|
$this->Form->request->data = array(
|
|
|
|
'User' => array(
|
|
|
|
'month_year' => array('month' => date('m')),
|
|
|
|
'just_year' => array('month' => date('m')),
|
|
|
|
'just_month' => array('year' => date('Y')),
|
|
|
|
'just_day' => array('month' => date('m')),
|
|
|
|
)
|
|
|
|
);
|
2013-06-25 09:54:29 +00:00
|
|
|
$this->Form->create('User');
|
|
|
|
$result = $this->Form->input('month_year',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
|
|
|
'div' => false,
|
|
|
|
'type' => 'date',
|
|
|
|
'dateFormat' => 'MY',
|
|
|
|
'minYear' => 2006,
|
|
|
|
'maxYear' => 2008
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('value="' . date('m') . '" selected="selected"', $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('value="2008" selected="selected"', $result);
|
2013-06-25 09:54:29 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('just_year',
|
|
|
|
array(
|
|
|
|
'type' => 'date',
|
|
|
|
'label' => false,
|
|
|
|
'dateFormat' => 'Y',
|
|
|
|
'minYear' => date('Y'),
|
|
|
|
'maxYear' => date('Y', strtotime('+20 years'))
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('value="' . date('Y') . '" selected="selected"', $result);
|
2013-06-25 09:54:29 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('just_month',
|
|
|
|
array(
|
|
|
|
'type' => 'date',
|
|
|
|
'label' => false,
|
|
|
|
'dateFormat' => 'M',
|
|
|
|
'empty' => false,
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('value="' . date('m') . '" selected="selected"', $result);
|
2013-06-25 09:54:29 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('just_day',
|
|
|
|
array(
|
|
|
|
'type' => 'date',
|
|
|
|
'label' => false,
|
|
|
|
'dateFormat' => 'D',
|
|
|
|
'empty' => false,
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('value="' . date('d') . '" selected="selected"', $result);
|
2013-06-25 09:54:29 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 16:38:19 +00:00
|
|
|
/**
|
|
|
|
* testInputDate method
|
|
|
|
*
|
|
|
|
* Test various inputs with type date and different option attributes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputDateOptions() {
|
|
|
|
$this->Form->create('User');
|
|
|
|
|
|
|
|
$result = $this->Form->input('date',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
|
|
|
'type' => 'day',
|
|
|
|
'class' => 'form-control'
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class="form-control"', $result);
|
2015-04-20 16:38:19 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('date',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
|
|
|
'type' => 'month',
|
|
|
|
'class' => 'form-control'
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class="form-control"', $result);
|
2015-04-20 16:38:19 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('date',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
|
|
|
'type' => 'year',
|
|
|
|
'class' => 'form-control'
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class="form-control"', $result);
|
2015-04-20 16:38:19 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('date',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
2015-04-20 16:39:54 +00:00
|
|
|
'type' => 'hour',
|
2015-04-20 16:38:19 +00:00
|
|
|
'class' => 'form-control'
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class="form-control"', $result);
|
2015-04-20 16:38:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 19:10:18 +00:00
|
|
|
/**
|
|
|
|
* testInputDateMaxYear method
|
2013-06-19 19:06:51 +00:00
|
|
|
*
|
|
|
|
* Let's say we want to only allow users born from 2006 to 2008 to register
|
|
|
|
* This being the first singup page, we still don't have any data
|
2013-06-13 19:10:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputDateMaxYear() {
|
2013-06-19 19:06:51 +00:00
|
|
|
$this->Form->request->data = array();
|
|
|
|
$this->Form->create('User');
|
|
|
|
$result = $this->Form->input('birthday',
|
|
|
|
array(
|
|
|
|
'label' => false,
|
|
|
|
'div' => false,
|
|
|
|
'type' => 'date',
|
|
|
|
'dateFormat' => 'DMY',
|
|
|
|
'minYear' => 2006,
|
|
|
|
'maxYear' => 2008
|
|
|
|
)
|
|
|
|
);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('value="2008" selected="selected"', $result);
|
2013-06-13 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
2016-05-02 15:13:22 +00:00
|
|
|
/**
|
|
|
|
* testInputTimeWithMicrosecondsAsText method
|
|
|
|
*
|
|
|
|
* since times and datetimes can now have a Length, specifying the microsecond
|
|
|
|
* precision, a text-type input shouldn't have set a maxLength attribute.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputTimeWithMicrosecondsAsText() {
|
|
|
|
$this->Form->request->data = array();
|
|
|
|
$this->Form->create('Contact');
|
2016-05-03 01:58:20 +00:00
|
|
|
$result = $this->Form->input('lap_time', array(
|
|
|
|
'type' => 'text',
|
|
|
|
));
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('maxlength=', $result);
|
2016-05-03 01:58:20 +00:00
|
|
|
$result = $this->Form->input('last_seen', array(
|
|
|
|
'type' => 'text',
|
|
|
|
));
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('maxlength=', $result);
|
2016-05-02 15:13:22 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testTextArea method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTextArea() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('field' => 'some test data'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->textarea('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
'some test data',
|
|
|
|
'/textarea',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-09-18 03:09:19 +00:00
|
|
|
$result = $this->Form->textarea('Model.tmp');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'),
|
|
|
|
'/textarea',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->textarea('Model.field');
|
|
|
|
$expected = array(
|
|
|
|
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
htmlentities('some <strong>test</strong> data with <a href="#">HTML</a> chars'),
|
|
|
|
'/textarea',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-01-21 01:15:29 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
|
2009-01-21 01:15:29 +00:00
|
|
|
$result = $this->Form->textarea('Model.field', array('escape' => false));
|
|
|
|
$expected = array(
|
|
|
|
'textarea' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
'some <strong>test</strong> data with <a href="#">HTML</a> chars',
|
|
|
|
'/textarea',
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-04-16 18:12:01 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model']['0']['OtherModel']['field'] = null;
|
2009-04-16 18:12:01 +00:00
|
|
|
$result = $this->Form->textarea('Model.0.OtherModel.field');
|
|
|
|
$expected = array(
|
|
|
|
'textarea' => array('name' => 'data[Model][0][OtherModel][field]', 'id' => 'Model0OtherModelField'),
|
|
|
|
'/textarea'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2014-09-13 02:03:33 +00:00
|
|
|
/**
|
2014-09-13 11:39:11 +00:00
|
|
|
* Test textareas maxlength reading from schema.
|
2014-09-13 02:03:33 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTextAreaMaxLength() {
|
|
|
|
$result = $this->Form->input('UserForm.other', array('type' => 'textarea'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input textarea'),
|
|
|
|
'label' => array('for' => 'UserFormOther'),
|
|
|
|
'Other',
|
|
|
|
'/label',
|
|
|
|
'textarea' => array('name' => 'data[UserForm][other]', 'cols' => '30', 'rows' => '6', 'id' => 'UserFormOther'),
|
|
|
|
'/textarea',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('UserForm.stuff', array('type' => 'textarea'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input textarea'),
|
|
|
|
'label' => array('for' => 'UserFormStuff'),
|
|
|
|
'Stuff',
|
|
|
|
'/label',
|
|
|
|
'textarea' => array('name' => 'data[UserForm][stuff]', 'maxlength' => 10, 'cols' => '30', 'rows' => '6', 'id' => 'UserFormStuff'),
|
|
|
|
'/textarea',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-08-01 05:39:53 +00:00
|
|
|
/**
|
|
|
|
* testTextAreaWithStupidCharacters method
|
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test text area with non-ascii characters
|
|
|
|
*
|
2008-08-01 05:39:53 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTextAreaWithStupidCharacters() {
|
2011-07-23 00:45:33 +00:00
|
|
|
$this->loadFixtures('Post');
|
2008-08-01 05:39:53 +00:00
|
|
|
$result = $this->Form->input('Post.content', array(
|
|
|
|
'label' => 'Current Text', 'value' => "GREAT®", 'rows' => '15', 'cols' => '75'
|
|
|
|
));
|
|
|
|
$expected = array(
|
2012-09-28 12:50:32 +00:00
|
|
|
'div' => array('class' => 'input textarea'),
|
2008-08-01 05:39:53 +00:00
|
|
|
'label' => array('for' => 'PostContent'),
|
|
|
|
'Current Text',
|
|
|
|
'/label',
|
|
|
|
'textarea' => array('name' => 'data[Post][content]', 'id' => 'PostContent', 'rows' => '15', 'cols' => '75'),
|
|
|
|
'GREAT®',
|
|
|
|
'/textarea',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-08-01 05:39:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testHiddenField method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHiddenField() {
|
2011-07-14 18:23:10 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['field'] = 1;
|
|
|
|
$this->Form->request->data['Contact']['field'] = 'test';
|
|
|
|
$result = $this->Form->hidden('Contact.field', array('id' => 'theID'));
|
2011-04-21 01:37:47 +00:00
|
|
|
$this->assertTags($result, array(
|
2011-07-14 18:23:10 +00:00
|
|
|
'input' => array('type' => 'hidden', 'class' => 'form-error', 'name' => 'data[Contact][field]', 'id' => 'theID', 'value' => 'test'))
|
2011-04-21 01:37:47 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testFileUploadField method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFileUploadField() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->file('Model.upload');
|
2010-02-07 21:30:43 +00:00
|
|
|
$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Model.upload', array('type' => 'file'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input file'),
|
|
|
|
'label' => array('for' => 'ModelUpload'),
|
|
|
|
'Upload',
|
|
|
|
'/label',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-12-09 18:31:01 +00:00
|
|
|
|
|
|
|
$this->Form->request->data['Model']['upload'] = 'no data should be set in value';
|
|
|
|
$result = $this->Form->file('Model.upload');
|
|
|
|
$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
|
2009-03-28 02:46:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-28 02:46:23 +00:00
|
|
|
/**
|
|
|
|
* test File upload input on a model not used in create();
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFileUploadOnOtherModel() {
|
2009-03-28 02:46:23 +00:00
|
|
|
$this->Form->create('ValidateUser', array('type' => 'file'));
|
|
|
|
$result = $this->Form->file('ValidateProfile.city');
|
|
|
|
$expected = array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'file', 'name' => 'data[ValidateProfile][city]', 'id' => 'ValidateProfileCity')
|
2009-03-28 02:46:23 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testButton method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testButton() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->button('Hi');
|
2009-10-20 03:57:23 +00:00
|
|
|
$this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-20 03:57:23 +00:00
|
|
|
$result = $this->Form->button('Clear Form >', array('type' => 'reset'));
|
|
|
|
$this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-21 16:33:03 +00:00
|
|
|
$result = $this->Form->button('Clear Form >', array('type' => 'reset', 'id' => 'clearForm'));
|
|
|
|
$this->assertTags($result, array('button' => array('type' => 'reset', 'id' => 'clearForm'), 'Clear Form >', '/button'));
|
|
|
|
|
2009-10-20 03:57:23 +00:00
|
|
|
$result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
|
|
|
|
$this->assertTags($result, array('button' => array('type' => 'reset'), '<Clear Form>', '/button'));
|
2009-05-30 19:12:15 +00:00
|
|
|
|
2012-02-14 02:00:57 +00:00
|
|
|
$result = $this->Form->button('No type', array('type' => false));
|
|
|
|
$this->assertTags($result, array('button' => array(), 'No type', '/button'));
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2009-05-30 19:12:15 +00:00
|
|
|
$result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false));
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/\&039/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-06-15 02:37:02 +00:00
|
|
|
/**
|
|
|
|
* Test that button() makes unlocked fields by default.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testButtonUnlockedByDefault() {
|
|
|
|
$this->Form->request->params['_Token']['key'] = 'secured';
|
|
|
|
$this->Form->button('Save', array('name' => 'save'));
|
|
|
|
$this->Form->button('Clear');
|
|
|
|
|
|
|
|
$result = $this->Form->unlockField();
|
|
|
|
$this->assertEquals(array('save'), $result);
|
|
|
|
}
|
|
|
|
|
2010-10-18 19:53:27 +00:00
|
|
|
/**
|
|
|
|
* testPostButton method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostButton() {
|
|
|
|
$result = $this->Form->postButton('Hi', '/controller/action');
|
|
|
|
$this->assertTags($result, array(
|
2012-04-18 00:46:19 +00:00
|
|
|
'form' => array('method' => 'post', 'action' => '/controller/action', 'accept-charset' => 'utf-8'),
|
2010-10-18 19:53:27 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div',
|
|
|
|
'button' => array('type' => 'submit'),
|
|
|
|
'Hi',
|
|
|
|
'/button',
|
|
|
|
'/form'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Form->postButton('Send', '/', array('data' => array('extra' => 'value')));
|
2011-02-05 10:52:18 +00:00
|
|
|
$this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false);
|
2010-10-18 19:53:27 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 02:17:31 +00:00
|
|
|
/**
|
|
|
|
* Test using postButton with N dimensional data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostButtonNestedData() {
|
|
|
|
$data = array(
|
|
|
|
'one' => array(
|
|
|
|
'two' => array(
|
|
|
|
3, 4, 5
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Form->postButton('Send', '/', array('data' => $data));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][0]" value="3"', $result);
|
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][1]" value="4"', $result);
|
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][2]" value="5"', $result);
|
2014-02-25 02:17:31 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 02:00:02 +00:00
|
|
|
/**
|
|
|
|
* Test that postButton adds _Token fields.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecurePostButton() {
|
|
|
|
$this->Form->request->params['_Token'] = array('key' => 'testkey');
|
|
|
|
|
|
|
|
$result = $this->Form->postButton('Delete', '/posts/delete/1');
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/posts/delete/1',
|
|
|
|
array(),
|
|
|
|
array()
|
|
|
|
)));
|
|
|
|
|
2011-08-11 02:00:02 +00:00
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1', 'accept-charset' => 'utf-8',
|
|
|
|
),
|
|
|
|
array('div' => array('style' => 'display:none;')),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/', 'autocomplete')),
|
2011-08-11 02:00:02 +00:00
|
|
|
'/div',
|
|
|
|
'button' => array('type' => 'submit'),
|
|
|
|
'Delete',
|
|
|
|
'/button',
|
|
|
|
array('div' => array('style' => 'display:none;')),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/', 'autocomplete')),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/', 'autocomplete')),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2011-08-11 02:00:02 +00:00
|
|
|
'/div',
|
|
|
|
'/form',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-10-18 23:51:17 +00:00
|
|
|
/**
|
|
|
|
* testPostLink method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLink() {
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
|
|
|
$this->assertTags($result, array(
|
2010-10-31 00:39:31 +00:00
|
|
|
'form' => array(
|
2011-07-19 00:33:45 +00:00
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
2010-10-31 00:39:31 +00:00
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
2010-10-18 23:51:17 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
2012-09-02 17:50:08 +00:00
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
2012-09-04 00:09:13 +00:00
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('method' => 'delete'));
|
2012-09-02 17:50:08 +00:00
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE'),
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
2010-10-18 23:51:17 +00:00
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
|
|
|
|
$this->assertTags($result, array(
|
2010-10-31 00:39:31 +00:00
|
|
|
'form' => array(
|
2011-07-19 00:33:45 +00:00
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
2010-10-31 00:39:31 +00:00
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
2010-10-18 23:51:17 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
2013-08-05 14:20:53 +00:00
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
2010-10-18 23:51:17 +00:00
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
2013-08-13 08:11:22 +00:00
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/if \(confirm\("'Confirm' this \\\\"deletion\\\\"\?"\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
2010-10-18 23:51:17 +00:00
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete', array('data' => array('id' => 1)));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[id]" value="1"/>', $result);
|
2012-12-12 10:23:41 +00:00
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('target' => '_blank'));
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'target' => '_blank', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
2013-08-21 17:09:47 +00:00
|
|
|
|
|
|
|
$result = $this->Form->postLink(
|
|
|
|
'',
|
|
|
|
array('controller' => 'items', 'action' => 'delete', 10),
|
|
|
|
array('class' => 'btn btn-danger', 'escape' => false),
|
|
|
|
'Confirm thing'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/items/delete/10',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
2013-08-25 01:51:42 +00:00
|
|
|
'a' => array('class' => 'btn btn-danger', 'href' => '#', 'onclick' => 'preg:/if \(confirm\(\"\;Confirm thing\"\;\)\) \{ document\.post_\w+\.submit\(\); \} event\.returnValue = false; return false;/'),
|
2013-08-21 17:09:47 +00:00
|
|
|
'/a'
|
|
|
|
));
|
2011-08-11 01:53:33 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 15:23:52 +00:00
|
|
|
/**
|
|
|
|
* Test that security hashes for postLink include the url.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLinkSecurityHash() {
|
|
|
|
$hash = Security::hash(
|
|
|
|
'/posts/delete/1' .
|
|
|
|
serialize(array()) .
|
|
|
|
'' .
|
|
|
|
Configure::read('Security.salt')
|
|
|
|
);
|
|
|
|
$hash .= '%3A';
|
|
|
|
$this->Form->request->params['_Token']['key'] = 'test';
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/posts/delete/1',
|
|
|
|
array(),
|
|
|
|
array()
|
|
|
|
)));
|
2014-04-29 15:23:52 +00:00
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name', 'id', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'test', 'id', 'autocomplete')),
|
2014-04-29 15:23:52 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => $hash, 'id', 'autocomplete')),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id', 'autocomplete')),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2014-04-29 15:23:52 +00:00
|
|
|
'/div',
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2016-04-02 03:08:31 +00:00
|
|
|
/**
|
|
|
|
* Test that postLink doesn't modify the fields in the containing form.
|
|
|
|
*
|
|
|
|
* postLink() calls inside open forms should not modify the field list
|
|
|
|
* for the form.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLinkSecurityHashInline() {
|
|
|
|
$hash = Security::hash(
|
2016-09-14 02:21:01 +00:00
|
|
|
'/basedir/posts/delete/1' .
|
2016-04-02 03:08:31 +00:00
|
|
|
serialize(array()) .
|
|
|
|
'' .
|
|
|
|
Configure::read('Security.salt')
|
|
|
|
);
|
|
|
|
$hash .= '%3A';
|
2016-09-14 02:21:01 +00:00
|
|
|
$this->Form->request->base = '/basedir';
|
|
|
|
$this->Form->request->webroot = '/basedir/';
|
2016-04-02 03:08:31 +00:00
|
|
|
$this->Form->request->params['_Token']['key'] = 'test';
|
|
|
|
|
2016-04-03 01:45:02 +00:00
|
|
|
$this->Form->create('Post', array('url' => array('action' => 'add')));
|
2016-04-02 03:08:31 +00:00
|
|
|
$this->Form->input('title');
|
2016-04-03 01:45:02 +00:00
|
|
|
$this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
|
2016-04-02 03:08:31 +00:00
|
|
|
$result = $this->View->fetch('postLink');
|
|
|
|
|
|
|
|
$this->assertEquals(array('Post.title'), $this->Form->fields);
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString($hash, $result, 'Should contain the correct hash.');
|
2023-01-07 11:25:24 +00:00
|
|
|
|
|
|
|
$property = new ReflectionProperty($this->Form, '_lastAction');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertSame(
|
2016-09-14 02:21:01 +00:00
|
|
|
'/basedir/posts/add',
|
2023-01-07 11:25:24 +00:00
|
|
|
$property->getValue($this->Form),
|
|
|
|
'lastAction was should be restored.'
|
|
|
|
);
|
2016-04-02 03:08:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 02:17:31 +00:00
|
|
|
/**
|
|
|
|
* Test using postLink with N dimensional data.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLinkNestedData() {
|
|
|
|
$data = array(
|
|
|
|
'one' => array(
|
|
|
|
'two' => array(
|
|
|
|
3, 4, 5
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = $this->Form->postLink('Send', '/', array('data' => $data));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][0]" value="3"', $result);
|
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][1]" value="4"', $result);
|
|
|
|
$this->assertStringContainsString('<input type="hidden" name="data[one][two][2]" value="5"', $result);
|
2014-02-25 02:17:31 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 02:56:17 +00:00
|
|
|
/**
|
|
|
|
* test creating postLinks after a GET form.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLinkAfterGetForm() {
|
|
|
|
$this->Form->request->params['_Token']['key'] = 'testkey';
|
|
|
|
$this->Form->create('User', array('type' => 'get'));
|
|
|
|
$this->Form->end();
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/posts/delete/1',
|
|
|
|
array(),
|
|
|
|
array()
|
|
|
|
)));
|
2013-11-12 02:56:17 +00:00
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/', 'autocomplete' => 'off')),
|
2013-11-12 02:56:17 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/', 'autocomplete')),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/', 'autocomplete')),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2013-11-12 02:56:17 +00:00
|
|
|
'/div',
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2011-08-11 01:53:33 +00:00
|
|
|
/**
|
|
|
|
* Test that postLink adds _Token fields.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSecurePostLink() {
|
|
|
|
$this->Form->request->params['_Token'] = array('key' => 'testkey');
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1');
|
2016-10-16 11:20:11 +00:00
|
|
|
$tokenDebug = urlencode(json_encode(array(
|
|
|
|
'/posts/delete/1',
|
|
|
|
array(),
|
|
|
|
array()
|
|
|
|
)));
|
2011-08-11 01:53:33 +00:00
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][key]', 'value' => 'testkey', 'id' => 'preg:/Token\d+/', 'autocomplete' => 'off')),
|
2011-08-11 01:53:33 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2017-04-05 17:02:17 +00:00
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][fields]', 'value' => 'preg:/[\w\d%]+/', 'id' => 'preg:/TokenFields\d+/', 'autocomplete')),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => 'data[_Token][unlocked]', 'value' => '', 'id' => 'preg:/TokenUnlocked\d+/', 'autocomplete')),
|
2016-10-16 11:20:11 +00:00
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[_Token][debug]',
|
|
|
|
'value' => $tokenDebug, 'id' => 'preg:/TokenDebug\d+/',
|
|
|
|
)),
|
2011-08-11 01:53:33 +00:00
|
|
|
'/div',
|
|
|
|
'/form',
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2010-10-18 23:51:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-03 17:29:10 +00:00
|
|
|
/**
|
|
|
|
* Test that postLink adds form tags to view block
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPostLinkFormBuffer() {
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('inline' => false));
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->View->fetch('postLink');
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/2',
|
|
|
|
array('inline' => false, 'method' => 'DELETE')
|
|
|
|
);
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->View->fetch('postLink');
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form',
|
|
|
|
array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/2',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
),
|
|
|
|
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'DELETE')),
|
|
|
|
'/form'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'foobar'));
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
|
|
|
|
'Delete',
|
|
|
|
'/a'
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->View->fetch('foobar');
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'form' => array(
|
|
|
|
'method' => 'post', 'action' => '/posts/delete/1',
|
|
|
|
'name' => 'preg:/post_\w+/', 'id' => 'preg:/post_\w+/', 'style' => 'display:none;'
|
|
|
|
),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/form'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSubmitButton method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSubmitButton() {
|
2011-03-03 01:27:02 +00:00
|
|
|
$result = $this->Form->submit('');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-03 01:27:02 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->submit('Test Submit');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 15:44:39 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test Submit', array('div' => array('tag' => 'span')));
|
|
|
|
$expected = array(
|
|
|
|
'span' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
|
'/span'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test Submit', array('class' => 'save', 'div' => false));
|
|
|
|
$expected = array('input' => array('type' => 'submit', 'value' => 'Test Submit', 'class' => 'save'));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test Submit', array('div' => array('id' => 'SaveButton')));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit', 'id' => 'SaveButton'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test Submit'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Next >');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Next >'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Next >', array('escape' => false));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Next >'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-20 03:44:50 +00:00
|
|
|
$result = $this->Form->submit('Reset!', array('type' => 'reset'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'reset', 'value' => 'Reset!'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$before = '--before--';
|
|
|
|
$after = '--after--';
|
|
|
|
$result = $this->Form->submit('Test', array('before' => $before));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'--before--',
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test', array('after' => $after));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'--before--',
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Test'),
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2016-08-20 10:51:13 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Test', array('confirm' => 'Confirm?'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'submit', 'value' => 'Test',
|
2016-08-21 15:09:43 +00:00
|
|
|
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ return true; \} event\.returnValue = false; return false;/'
|
2016-08-20 10:51:13 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2009-10-20 03:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test image submit types.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSubmitImage() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->submit('http://example.com/cake.power.gif');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'http://example.com/cake.power.gif'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('/relative/cake.power.gif');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'relative/cake.power.gif'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('cake.power.gif');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('Not.an.image');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$after = '--after--';
|
|
|
|
$before = '--before--';
|
|
|
|
$result = $this->Form->submit('cake.power.gif', array('after' => $after));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('cake.power.gif', array('before' => $before));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'--before--',
|
|
|
|
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 19:50:49 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'--before--',
|
|
|
|
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 20:28:43 +00:00
|
|
|
|
2009-10-31 19:50:49 +00:00
|
|
|
$result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'--before--',
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
|
|
|
|
'--after--',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2016-08-20 10:51:13 +00:00
|
|
|
|
|
|
|
$result = $this->Form->submit('cake.power.gif', array('confirm' => 'Confirm?'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'image', 'src' => 'img/cake.power.gif',
|
2016-08-21 15:09:43 +00:00
|
|
|
'onclick' => 'preg:/if \(confirm\("Confirm\?"\)\) \{ return true; \} event\.returnValue = false; return false;/'
|
2016-08-20 10:51:13 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-06-15 02:37:02 +00:00
|
|
|
/**
|
|
|
|
* Submit buttons should be unlocked by default as there could be multiples, and only one will
|
|
|
|
* be submitted at a time.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSubmitUnlockedByDefault() {
|
|
|
|
$this->Form->request->params['_Token']['key'] = 'secured';
|
|
|
|
$this->Form->submit('Go go');
|
|
|
|
$this->Form->submit('Save', array('name' => 'save'));
|
|
|
|
|
|
|
|
$result = $this->Form->unlockField();
|
|
|
|
$this->assertEquals(array('save'), $result, 'Only submits with name attributes should be unlocked.');
|
|
|
|
}
|
|
|
|
|
2011-10-20 01:47:55 +00:00
|
|
|
/**
|
|
|
|
* Test submit image with timestamps.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testSubmitImageTimestamp() {
|
2011-10-20 01:47:55 +00:00
|
|
|
Configure::write('Asset.timestamp', 'force');
|
|
|
|
|
|
|
|
$result = $this->Form->submit('cake.power.gif');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'image', 'src' => 'preg:/img\/cake\.power\.gif\?\d*/'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2009-10-31 04:08:49 +00:00
|
|
|
* test the create() method
|
2008-06-04 15:57:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreate() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact');
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'preg:/display\s*\:\s*none;\s*/'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('type' => 'GET'));
|
2008-12-25 22:13:06 +00:00
|
|
|
$expected = array('form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('type' => 'get'));
|
2008-12-25 22:13:06 +00:00
|
|
|
$expected = array('form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('type' => 'put'));
|
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-10-31 04:08:49 +00:00
|
|
|
$result = $this->Form->create('Contact', array('type' => 'file'));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
2009-10-31 04:08:49 +00:00
|
|
|
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-10-31 04:08:49 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-10-31 04:08:49 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 04:08:49 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['id'] = 1;
|
2011-03-02 01:31:02 +00:00
|
|
|
$this->Form->request->here = '/contacts/edit/1';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['action'] = 'edit';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact');
|
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-10-30 05:02:54 +00:00
|
|
|
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['Contact']['id'] = 1;
|
2011-03-02 01:31:02 +00:00
|
|
|
$this->Form->request->here = '/contacts/edit/1';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['action'] = 'edit';
|
2009-10-31 04:08:49 +00:00
|
|
|
$result = $this->Form->create('Contact', array('type' => 'file'));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'id' => 'ContactEditForm', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
|
'accept-charset' => $encoding, 'enctype' => 'multipart/form-data'
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-10-31 04:08:49 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-10-31 04:08:49 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 04:08:49 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['ContactNonStandardPk']['pk'] = 1;
|
2011-03-02 01:31:02 +00:00
|
|
|
$result = $this->Form->create('ContactNonStandardPk', array('url' => array('action' => 'edit')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
|
|
|
'id' => 'ContactNonStandardPkEditForm', 'method' => 'post',
|
2013-06-09 15:39:48 +00:00
|
|
|
'action' => '/contact_non_standard_pks/edit/1', 'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array('id' => 'TestId'));
|
|
|
|
$expected = array(
|
2009-10-30 05:02:54 +00:00
|
|
|
'form' => array(
|
|
|
|
'id' => 'TestId', 'method' => 'post', 'action' => '/contacts/edit/1',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'PUT'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['action'] = 'add';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
|
|
|
$expected = array(
|
2009-10-30 05:02:54 +00:00
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'action' => '/users/login',
|
|
|
|
'id' => 'UserLoginForm',
|
|
|
|
'method' => 'post',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2016-01-04 14:08:31 +00:00
|
|
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->create('User', array('url' => '/users/login'));
|
|
|
|
$expected = array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'form' => array(
|
|
|
|
'action' => '/users/login',
|
|
|
|
'id' => 'UserAddForm',
|
|
|
|
'method' => 'post',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request['controller'] = 'pages';
|
2016-01-04 14:08:31 +00:00
|
|
|
$result = $this->Form->create('User', array('url' => array('action' => 'signup')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-11-13 14:45:25 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array();
|
|
|
|
$this->Form->request['controller'] = 'contacts';
|
2011-07-14 21:56:55 +00:00
|
|
|
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
2009-11-13 14:45:25 +00:00
|
|
|
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactIndexForm', 'method' => 'post', 'action' => '/contacts/index/param',
|
2009-11-13 14:53:31 +00:00
|
|
|
'accept-charset' => 'utf-8'
|
2009-11-13 14:45:25 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-11-13 14:45:25 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-11-13 14:45:25 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-09-08 00:57:28 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 14:53:48 +00:00
|
|
|
/**
|
2016-01-07 09:48:20 +00:00
|
|
|
* Test create() with no URL (no "action" attribute for <form> tag)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreateNoUrl() {
|
|
|
|
$result = $this->Form->create(false, array('url' => false));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'id' => 'addForm',
|
|
|
|
'method' => 'post',
|
|
|
|
'accept-charset' => strtolower(Configure::read('App.encoding'))
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2016-05-02 02:21:23 +00:00
|
|
|
/**
|
|
|
|
* Test that the action key still uses the model as the implicit controller
|
|
|
|
* when the url option is undefined. While the action parameter is deprecated
|
|
|
|
* we need it to continue working for the duration of 2.x
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-05-02 08:42:42 +00:00
|
|
|
public function testCreateUrlImpliedController() {
|
2016-05-02 02:21:23 +00:00
|
|
|
$restore = error_reporting(E_ALL ^ E_USER_DEPRECATED);
|
|
|
|
$this->Form->request['controller'] = 'posts';
|
|
|
|
$result = $this->Form->create('Comment', array(
|
|
|
|
'action' => 'addComment',
|
|
|
|
'id' => 'addCommentForm',
|
|
|
|
'type' => 'POST'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'action' => '/comments/addComment',
|
|
|
|
'id' => 'addCommentForm',
|
|
|
|
'method' => 'post',
|
|
|
|
'accept-charset' => strtolower(Configure::read('App.encoding'))
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
error_reporting($restore);
|
|
|
|
}
|
|
|
|
|
2016-01-07 10:09:48 +00:00
|
|
|
/**
|
2011-09-08 00:57:28 +00:00
|
|
|
* Test the onsubmit option for create()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreateOnSubmit() {
|
2011-09-07 22:38:46 +00:00
|
|
|
$this->Form->request->data = array();
|
|
|
|
$this->Form->request['controller'] = 'contacts';
|
|
|
|
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
|
|
|
$result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactIndexForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
|
2011-09-07 22:38:46 +00:00
|
|
|
'accept-charset' => 'utf-8'
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$this->Form->request->data = array();
|
|
|
|
$this->Form->request['controller'] = 'contacts';
|
|
|
|
$this->Form->request['models'] = array('Contact' => array('plugin' => null, 'className' => 'Contact'));
|
2011-09-08 00:57:28 +00:00
|
|
|
$result = $this->Form->create(array(
|
|
|
|
'url' => array('action' => 'index', 'param'),
|
|
|
|
'default' => false,
|
|
|
|
'onsubmit' => 'someFunction();'
|
|
|
|
));
|
2011-09-07 22:38:46 +00:00
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactIndexForm', 'method' => 'post',
|
2011-09-08 00:57:28 +00:00
|
|
|
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
|
|
|
|
'action' => '/contacts/index/param',
|
2011-09-07 22:38:46 +00:00
|
|
|
'accept-charset' => 'utf-8'
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2011-03-03 02:47:11 +00:00
|
|
|
}
|
2011-03-02 01:31:02 +00:00
|
|
|
|
2011-03-03 02:47:11 +00:00
|
|
|
/**
|
|
|
|
* test create() with automatic url generation
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateAutoUrl() {
|
2011-03-03 02:47:11 +00:00
|
|
|
Router::setRequestInfo(array(array(), array('base' => '/base_url')));
|
|
|
|
$this->Form->request->here = '/base_url/contacts/add/Contact:1';
|
|
|
|
$this->Form->request->base = '/base_url';
|
|
|
|
$result = $this->Form->create('Contact');
|
2011-03-02 01:31:02 +00:00
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2011-03-03 02:47:11 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/base_url/contacts/add/Contact:1',
|
2011-03-02 01:31:02 +00:00
|
|
|
'accept-charset' => 'utf-8'
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-02 01:31:02 +00:00
|
|
|
|
|
|
|
$this->Form->request['action'] = 'delete';
|
2011-03-03 02:47:11 +00:00
|
|
|
$this->Form->request->here = '/base_url/contacts/delete/10/User:42';
|
|
|
|
$this->Form->request->base = '/base_url';
|
|
|
|
$result = $this->Form->create('Contact');
|
2011-03-02 01:31:02 +00:00
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2011-03-03 02:47:11 +00:00
|
|
|
'id' => 'ContactDeleteForm', 'method' => 'post', 'action' => '/base_url/contacts/delete/10/User:42',
|
2011-03-02 01:31:02 +00:00
|
|
|
'accept-charset' => 'utf-8'
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-02-03 02:52:41 +00:00
|
|
|
/**
|
|
|
|
* test create() with a custom route
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateCustomRoute() {
|
2011-02-03 02:52:41 +00:00
|
|
|
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
|
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
|
|
2016-01-04 13:22:40 +00:00
|
|
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
2011-02-03 02:52:41 +00:00
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-02-03 02:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 04:44:38 +00:00
|
|
|
/**
|
|
|
|
* test that inputDefaults are stored and used.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateWithInputDefaults() {
|
2009-10-15 04:44:38 +00:00
|
|
|
$this->Form->create('User', array(
|
2012-03-16 02:50:05 +00:00
|
|
|
'inputDefaults' => array(
|
|
|
|
'div' => false,
|
|
|
|
'label' => false,
|
2012-03-28 20:22:58 +00:00
|
|
|
'error' => array('attributes' => array('wrap' => 'small', 'class' => 'error')),
|
|
|
|
'format' => array('before', 'label', 'between', 'input', 'after', 'error')
|
2012-03-16 02:50:05 +00:00
|
|
|
)
|
|
|
|
));
|
2009-10-15 04:44:38 +00:00
|
|
|
$result = $this->Form->input('username');
|
|
|
|
$expected = array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
|
2009-10-15 04:44:38 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 04:44:38 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('username', array('div' => true, 'label' => 'username'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'UserUsername'), 'username', '/label',
|
2010-02-07 21:30:43 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
2009-10-15 04:44:38 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2012-03-28 20:22:58 +00:00
|
|
|
$result = $this->Form->input('username', array('label' => 'Username', 'format' => array('input', 'label')));
|
2012-02-29 10:03:55 +00:00
|
|
|
$expected = array(
|
2012-03-28 20:22:58 +00:00
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
|
|
|
'label' => array('for' => 'UserUsername'), 'Username', '/label',
|
2012-02-29 10:03:55 +00:00
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-04-05 15:46:47 +00:00
|
|
|
|
|
|
|
$this->Form->create('User', array(
|
|
|
|
'inputDefaults' => array(
|
|
|
|
'div' => false,
|
|
|
|
'label' => array('class' => 'nice', 'for' => 'changed'),
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = $this->Form->input('username', array('div' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'changed', 'class' => 'nice'), 'Username', '/label',
|
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2009-10-15 04:44:38 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 03:23:33 +00:00
|
|
|
/**
|
|
|
|
* test automatic accept-charset overriding
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateWithAcceptCharset() {
|
2009-10-31 03:23:33 +00:00
|
|
|
$result = $this->Form->create('UserForm', array(
|
2016-01-04 13:22:40 +00:00
|
|
|
'type' => 'post', 'url' => array('action' => 'login'), 'encoding' => 'iso-8859-1'
|
2009-10-31 03:23:33 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
|
2009-10-31 03:23:33 +00:00
|
|
|
'accept-charset' => 'iso-8859-1'
|
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-10-31 03:23:33 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-10-31 03:23:33 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-31 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 02:29:50 +00:00
|
|
|
/**
|
2013-10-08 03:17:58 +00:00
|
|
|
* Test base form URL when url param is passed with multiple parameters (&)
|
2009-04-15 02:29:50 +00:00
|
|
|
*
|
2014-04-02 01:02:37 +00:00
|
|
|
* @return void
|
2009-04-15 02:29:50 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateQuerystringrequest() {
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2009-04-15 02:29:50 +00:00
|
|
|
$result = $this->Form->create('Contact', array(
|
|
|
|
'type' => 'post',
|
|
|
|
'escape' => false,
|
|
|
|
'url' => array(
|
|
|
|
'controller' => 'controller',
|
|
|
|
'action' => 'action',
|
2011-06-23 21:05:50 +00:00
|
|
|
'?' => array('param1' => 'value1', 'param2' => 'value2')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactActionForm',
|
2011-06-23 21:05:50 +00:00
|
|
|
'method' => 'post',
|
|
|
|
'action' => '/controller/action?param1=value1&param2=value2',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->create('Contact', array(
|
|
|
|
'type' => 'post',
|
|
|
|
'url' => array(
|
|
|
|
'controller' => 'controller',
|
|
|
|
'action' => 'action',
|
2009-04-15 02:29:50 +00:00
|
|
|
'?' => array('param1' => 'value1', 'param2' => 'value2')
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactActionForm',
|
2009-04-16 18:12:01 +00:00
|
|
|
'method' => 'post',
|
2009-12-09 03:58:08 +00:00
|
|
|
'action' => '/controller/action?param1=value1&param2=value2',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2009-04-15 02:29:50 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-04-15 02:29:50 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-04-15 02:29:50 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-04-15 02:29:50 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-05 01:08:40 +00:00
|
|
|
/**
|
|
|
|
* test that create() doesn't cause errors by multiple id's being in the primary key
|
|
|
|
* as could happen with multiple select or checkboxes.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreateWithMultipleIdInData() {
|
2010-11-05 01:08:40 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
|
|
2010-11-17 02:48:13 +00:00
|
|
|
$this->Form->request->data['Contact']['id'] = array(1, 2);
|
2010-11-05 01:08:40 +00:00
|
|
|
$result = $this->Form->create('Contact');
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'id' => 'ContactAddForm',
|
|
|
|
'method' => 'post',
|
|
|
|
'action' => '/contacts/add',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-11-05 01:08:40 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 01:36:05 +00:00
|
|
|
/**
|
|
|
|
* test that create() doesn't add in extra passed params.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCreatePassedArgs() {
|
2010-10-14 01:36:05 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2010-10-14 03:09:55 +00:00
|
|
|
$this->Form->request->data['Contact']['id'] = 1;
|
2010-10-14 01:36:05 +00:00
|
|
|
$result = $this->Form->create('Contact', array(
|
|
|
|
'type' => 'post',
|
|
|
|
'escape' => false,
|
|
|
|
'url' => array(
|
|
|
|
'action' => 'edit',
|
2015-03-20 01:15:20 +00:00
|
|
|
'0',
|
2010-10-14 01:36:05 +00:00
|
|
|
'myparam'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
2016-01-04 14:08:31 +00:00
|
|
|
'id' => 'ContactEditForm',
|
2010-10-14 01:36:05 +00:00
|
|
|
'method' => 'post',
|
2015-03-20 01:15:20 +00:00
|
|
|
'action' => '/contacts/edit/0/myparam',
|
2010-10-14 01:36:05 +00:00
|
|
|
'accept-charset' => $encoding
|
2009-04-15 02:29:50 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2009-04-15 02:29:50 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2009-04-15 02:29:50 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-04-15 02:29:50 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2014-04-25 20:58:17 +00:00
|
|
|
/**
|
|
|
|
* test that create() works without raising errors with a Mock Model
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCreateNoErrorsWithMockModel() {
|
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
|
$ContactMock = $this->getMockBuilder('Contact')
|
2015-03-20 01:15:20 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2014-04-25 20:58:17 +00:00
|
|
|
ClassRegistry::removeObject('Contact');
|
|
|
|
ClassRegistry::addObject('Contact', $ContactMock);
|
|
|
|
$result = $this->Form->create('Contact', array('type' => 'GET'));
|
|
|
|
$expected = array('form' => array(
|
|
|
|
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
));
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2009-10-31 03:23:33 +00:00
|
|
|
* test creating a get form, and get form inputs.
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetFormCreate() {
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact', array('type' => 'get'));
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'get', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->text('Contact.name');
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'name' => 'name', 'type' => 'text', 'id' => 'ContactName',
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->password('password');
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'name' => 'password', 'type' => 'password', 'id' => 'ContactPassword'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->text('user_form');
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'name' => 'user_form', 'type' => 'text', 'id' => 'ContactUserForm'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-15 19:39:24 +00:00
|
|
|
/**
|
|
|
|
* test get form, and inputs when the model param is false
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetFormWithFalseModel() {
|
2011-01-15 19:39:24 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2011-03-02 01:31:02 +00:00
|
|
|
$this->Form->request['controller'] = 'contact_test';
|
|
|
|
$result = $this->Form->create(false, array('type' => 'get', 'url' => array('controller' => 'contact_test')));
|
2011-01-15 19:39:24 +00:00
|
|
|
|
|
|
|
$expected = array('form' => array(
|
|
|
|
'id' => 'addForm', 'method' => 'get', 'action' => '/contact_test/add',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
));
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-18 20:55:39 +00:00
|
|
|
|
2011-01-15 19:39:24 +00:00
|
|
|
$result = $this->Form->text('reason');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'text', 'name' => 'reason', 'id' => 'reason')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-01-15 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
2010-04-02 19:43:20 +00:00
|
|
|
/**
|
|
|
|
* test that datetime() works with GET style forms.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDateTimeWithGetForms() {
|
2010-04-02 19:43:20 +00:00
|
|
|
extract($this->dateRegex);
|
|
|
|
$this->Form->create('Contact', array('type' => 'get'));
|
|
|
|
$result = $this->Form->datetime('created');
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/name="created\[year\]"/', $result, 'year name attribute is wrong.');
|
|
|
|
$this->assertMatchesRegularExpression('/name="created\[month\]"/', $result, 'month name attribute is wrong.');
|
|
|
|
$this->assertMatchesRegularExpression('/name="created\[day\]"/', $result, 'day name attribute is wrong.');
|
|
|
|
$this->assertMatchesRegularExpression('/name="created\[hour\]"/', $result, 'hour name attribute is wrong.');
|
|
|
|
$this->assertMatchesRegularExpression('/name="created\[min\]"/', $result, 'min name attribute is wrong.');
|
|
|
|
$this->assertMatchesRegularExpression('/name="created\[meridian\]"/', $result, 'meridian name attribute is wrong.');
|
2010-04-02 19:43:20 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testEditFormWithData method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-09-26 00:07:57 +00:00
|
|
|
* test auto populating form elements from submitted data.
|
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testEditFormWithData() {
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array('Person' => array(
|
2009-10-31 03:23:33 +00:00
|
|
|
'id' => 1,
|
|
|
|
'first_name' => 'Nate',
|
|
|
|
'last_name' => 'Abele',
|
|
|
|
'email' => 'nate@example.com'
|
2008-05-30 11:40:08 +00:00
|
|
|
));
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->addParams(array(
|
2010-12-26 06:40:02 +00:00
|
|
|
'models' => array('Person'),
|
2010-05-14 04:21:22 +00:00
|
|
|
'controller' => 'people',
|
|
|
|
'action' => 'add'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
|
|
|
|
|
|
|
|
$this->Form->create();
|
2010-08-05 18:14:36 +00:00
|
|
|
$result = $this->Form->select('People.People', $options, array('multiple' => true));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
2010-01-13 22:43:39 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => 'data[People][People]', 'value' => '', 'id' => 'PeoplePeople_'),
|
2008-12-25 22:13:06 +00:00
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[People][People][]', 'multiple' => 'multiple', 'id' => 'PeoplePeople'
|
|
|
|
),
|
2009-10-31 03:23:33 +00:00
|
|
|
array('option' => array('value' => 1)), 'Nate', '/option',
|
|
|
|
array('option' => array('value' => 2)), 'Garrett', '/option',
|
|
|
|
array('option' => array('value' => 3)), 'Larry', '/option',
|
2008-05-30 11:40:08 +00:00
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2011-10-29 01:35:43 +00:00
|
|
|
* Test that required fields are created for various types of validation.
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testFormInputRequiredDetection() {
|
2011-10-29 01:35:43 +00:00
|
|
|
$this->Form->create('Contact');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.non_existing');
|
|
|
|
$expected = array(
|
2012-03-11 01:57:18 +00:00
|
|
|
'div' => array('class' => 'input text'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'label' => array('for' => 'ContactNonExisting'),
|
|
|
|
'Non Existing',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][non_existing]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactNonExisting'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-06-23 00:07:33 +00:00
|
|
|
$result = $this->Form->input('Contact.imrequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequired'),
|
|
|
|
'Imrequired',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequired',
|
|
|
|
'required' => 'required'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-06-23 00:07:33 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-23 00:07:33 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imalsorequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImalsorequired'),
|
|
|
|
'Imalsorequired',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImalsorequired',
|
|
|
|
'required' => 'required'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-06-23 00:07:33 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-23 00:07:33 +00:00
|
|
|
|
2010-02-23 14:25:01 +00:00
|
|
|
$result = $this->Form->input('Contact.imrequiredtoo');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredtoo'),
|
|
|
|
'Imrequiredtoo',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequiredtoo',
|
|
|
|
'required' => 'required'
|
2010-02-23 14:25:01 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-23 14:25:01 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.required_one');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactRequiredOne'),
|
|
|
|
'Required One',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][required_one]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactRequiredOne',
|
|
|
|
'required' => 'required'
|
2010-02-23 14:25:01 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-23 14:25:01 +00:00
|
|
|
|
2011-10-29 01:35:43 +00:00
|
|
|
$result = $this->Form->input('Contact.string_required');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactStringRequired'),
|
|
|
|
'String Required',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][string_required]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactStringRequired',
|
|
|
|
'required' => 'required'
|
2011-10-29 01:35:43 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.imnotrequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactImnotrequired'),
|
|
|
|
'Imnotrequired',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactImnotrequired'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-06-22 19:16:34 +00:00
|
|
|
$result = $this->Form->input('Contact.imalsonotrequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactImalsonotrequired'),
|
|
|
|
'Imalsonotrequired',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactImalsonotrequired'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-06-22 19:16:34 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-22 19:16:34 +00:00
|
|
|
|
2012-10-31 23:34:37 +00:00
|
|
|
$result = $this->Form->input('Contact.imalsonotrequired2');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactImalsonotrequired2'),
|
|
|
|
'Imalsonotrequired2',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired2]',
|
|
|
|
'id' => 'ContactImalsonotrequired2'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2010-04-30 21:12:59 +00:00
|
|
|
$result = $this->Form->input('Contact.imnotrequiredeither');
|
2010-04-30 19:49:52 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
2010-04-30 21:12:59 +00:00
|
|
|
'label' => array('for' => 'ContactImnotrequiredeither'),
|
|
|
|
'Imnotrequiredeither',
|
2010-04-30 19:49:52 +00:00
|
|
|
'/label',
|
|
|
|
'input' => array(
|
2010-04-30 21:12:59 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
|
|
|
|
'id' => 'ContactImnotrequiredeither'
|
2010-04-30 19:49:52 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2012-10-26 07:28:24 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.iamrequiredalways');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactIamrequiredalways'),
|
|
|
|
'Iamrequiredalways',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][iamrequiredalways]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactIamrequiredalways',
|
|
|
|
'required' => 'required'
|
2012-10-26 07:28:24 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-01-23 15:08:24 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox required'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[Contact][boolean_field]',
|
|
|
|
'id' => 'ContactBooleanField_',
|
|
|
|
'value' => '0'
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'data[Contact][boolean_field]',
|
|
|
|
'value' => '1',
|
|
|
|
'id' => 'ContactBooleanField'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'ContactBooleanField'),
|
2013-01-31 15:21:01 +00:00
|
|
|
'Boolean Field',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.boolean_field', array('type' => 'checkbox', 'required' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input checkbox required'),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'data[Contact][boolean_field]',
|
|
|
|
'id' => 'ContactBooleanField_',
|
|
|
|
'value' => '0'
|
|
|
|
)),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'data[Contact][boolean_field]',
|
|
|
|
'value' => '1',
|
|
|
|
'id' => 'ContactBooleanField',
|
|
|
|
'required' => 'required'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'ContactBooleanField'),
|
2013-01-23 15:08:24 +00:00
|
|
|
'Boolean Field',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2013-10-04 15:05:38 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.iamrequiredalways', array('type' => 'file'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input file required'),
|
|
|
|
'label' => array('for' => 'ContactIamrequiredalways'),
|
|
|
|
'Iamrequiredalways',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'file',
|
|
|
|
'name' => 'data[Contact][iamrequiredalways]',
|
|
|
|
'id' => 'ContactIamrequiredalways',
|
|
|
|
'required' => 'required'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2011-10-29 01:35:43 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 01:11:49 +00:00
|
|
|
/**
|
|
|
|
* Test that required fields are created when only using ModelValidator::add().
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormInputRequiredDetectionModelValidator() {
|
2015-05-17 20:27:16 +00:00
|
|
|
ClassRegistry::getObject('ContactTag')->validator()->add('iwillberequired', 'required', array('rule' => 'notBlank'));
|
2013-07-30 01:26:49 +00:00
|
|
|
|
2013-07-30 01:11:49 +00:00
|
|
|
$this->Form->create('ContactTag');
|
|
|
|
$result = $this->Form->input('ContactTag.iwillberequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactTagIwillberequired'),
|
|
|
|
'Iwillberequired',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'name' => 'data[ContactTag][iwillberequired]',
|
|
|
|
'type' => 'text',
|
|
|
|
'id' => 'ContactTagIwillberequired',
|
|
|
|
'required' => 'required'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
2011-10-29 01:35:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testFormMagicInput method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormMagicInput() {
|
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
|
|
|
$result = $this->Form->create('Contact');
|
|
|
|
$expected = array(
|
|
|
|
'form' => array(
|
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
|
|
|
'accept-charset' => $encoding
|
|
|
|
),
|
|
|
|
'div' => array('style' => 'display:none;'),
|
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactName'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
|
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('non_existing_field_in_contact_model');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactNonExistingFieldInContactModel'),
|
|
|
|
'Non Existing Field In Contact Model',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][non_existing_field_in_contact_model]',
|
|
|
|
'id' => 'ContactNonExistingFieldInContactModel'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Address.street');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'AddressStreet'),
|
|
|
|
'Street',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Address][street]',
|
|
|
|
'id' => 'AddressStreet'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Address.non_existing_field_in_model');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'AddressNonExistingFieldInModel'),
|
|
|
|
'Non Existing Field In Model',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Address][non_existing_field_in_model]',
|
|
|
|
'id' => 'AddressNonExistingFieldInModel'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('name', array('div' => false));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactName'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
|
|
|
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2008-11-29 00:28:31 +00:00
|
|
|
extract($this->dateRegex);
|
2008-05-30 11:40:08 +00:00
|
|
|
$now = strtotime('now');
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.published', array('div' => false));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactPublishedMonth'),
|
|
|
|
'Published',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][published][month]', 'id' => 'ContactPublishedMonth'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][published][day]', 'id' => 'ContactPublishedDay'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.updated', array('div' => false));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactUpdatedMonth'),
|
|
|
|
'Updated',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][updated][month]', 'id' => 'ContactUpdatedMonth'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$monthsRegex,
|
|
|
|
array('option' => array('value' => date('m', $now), 'selected' => 'selected')),
|
|
|
|
date('F', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][updated][day]', 'id' => 'ContactUpdatedDay'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$daysRegex,
|
|
|
|
array('option' => array('value' => date('d', $now), 'selected' => 'selected')),
|
|
|
|
date('j', $now),
|
|
|
|
'/option',
|
|
|
|
'*/select',
|
|
|
|
'-',
|
2008-12-25 22:13:06 +00:00
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[Contact][updated][year]', 'id' => 'ContactUpdatedYear'
|
|
|
|
)),
|
2008-05-30 11:40:08 +00:00
|
|
|
$yearsRegex,
|
|
|
|
array('option' => array('value' => date('Y', $now), 'selected' => 'selected')),
|
|
|
|
date('Y', $now),
|
|
|
|
'*/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-04-22 21:07:15 +00:00
|
|
|
|
2010-08-05 17:23:56 +00:00
|
|
|
$result = $this->Form->input('UserForm.stuff');
|
2010-04-22 21:07:15 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
2010-08-05 17:23:56 +00:00
|
|
|
'label' => array('for' => 'UserFormStuff'),
|
2010-04-22 21:07:15 +00:00
|
|
|
'Stuff',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
2010-08-05 17:23:56 +00:00
|
|
|
'type' => 'text', 'name' => 'data[UserForm][stuff]',
|
|
|
|
'id' => 'UserFormStuff', 'maxlength' => 10
|
2010-04-22 21:07:15 +00:00
|
|
|
),
|
|
|
|
'/div'
|
2010-08-05 23:31:51 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testForMagicInputNonExistingNorValidated method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testForMagicInputNonExistingNorValidated() {
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact');
|
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
|
'Non Existing Nor Validated',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactNonExistingNorValidated'
|
2008-12-25 22:13:06 +00:00
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.non_existing_nor_validated', array(
|
|
|
|
'div' => false, 'value' => 'my value'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
|
'Non Existing Nor Validated',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
|
|
|
'value' => 'my value', 'id' => 'ContactNonExistingNorValidated'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'Contact' => array('non_existing_nor_validated' => 'CakePHP magic'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->input('Contact.non_existing_nor_validated', array('div' => false));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactNonExistingNorValidated'),
|
|
|
|
'Non Existing Nor Validated',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][non_existing_nor_validated]',
|
|
|
|
'value' => 'CakePHP magic', 'id' => 'ContactNonExistingNorValidated'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testFormMagicInputLabel method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormMagicInputLabel() {
|
2009-10-30 05:02:54 +00:00
|
|
|
$encoding = strtolower(Configure::read('App.encoding'));
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->create('Contact');
|
|
|
|
$expected = array(
|
2008-12-25 22:13:06 +00:00
|
|
|
'form' => array(
|
2009-12-09 03:58:08 +00:00
|
|
|
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/add',
|
2009-10-30 05:02:54 +00:00
|
|
|
'accept-charset' => $encoding
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2009-12-09 03:58:08 +00:00
|
|
|
'div' => array('style' => 'display:none;'),
|
2008-05-30 11:40:08 +00:00
|
|
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
2009-12-09 03:58:08 +00:00
|
|
|
'/div'
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
|
|
|
'name' => 'data[Contact][name]', 'type' => 'text',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactName', 'maxlength' => '255')
|
2008-12-25 22:13:06 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactName'),
|
|
|
|
'My label',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ContactName', 'maxlength' => '255'
|
2008-12-25 22:13:06 +00:00
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.name', array(
|
|
|
|
'div' => false, 'label' => array('class' => 'mandatory')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.name', array(
|
|
|
|
'div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactName', 'class' => 'mandatory'),
|
|
|
|
'My label',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => 'ContactName', 'maxlength' => '255'
|
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.name', array(
|
|
|
|
'div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'my_id'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][name]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'my_id', 'maxlength' => '255'
|
2008-12-25 22:13:06 +00:00
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('1.id');
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'Contact1Id'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input("1.name");
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'Contact1Name'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][1][name]',
|
2008-12-25 22:13:06 +00:00
|
|
|
'id' => 'Contact1Name', 'maxlength' => '255'
|
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('Contact.1.id');
|
|
|
|
$this->assertTags($result, array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][1][id]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'Contact1Id'
|
2008-12-25 22:13:06 +00:00
|
|
|
)
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input("Model.1.name");
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'Model1Name'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Model][1][name]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'Model1Name'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testFormEnd method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormEnd() {
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('</form>', $this->Form->end());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2014-02-17 16:03:49 +00:00
|
|
|
$result = $this->Form->end('', array('form' => 'form-name'));
|
2013-12-30 15:28:10 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
2014-02-17 16:03:49 +00:00
|
|
|
'input' => array('type' => 'submit', 'value' => ''),
|
2013-12-30 15:28:10 +00:00
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2011-03-03 01:27:02 +00:00
|
|
|
$result = $this->Form->end('');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-11 14:50:55 +00:00
|
|
|
|
2011-03-03 01:27:02 +00:00
|
|
|
$result = $this->Form->end(array('label' => ''));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => ''),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-03-03 01:27:02 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Form->end('save');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'save'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->end(array('label' => 'save'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'save'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->end(array('name' => 'Whatever'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'submit'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'Submit', 'name' => 'Whatever'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Form->end(array('label' => 'save', 'name' => 'Whatever', 'div' => 'good'));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'good'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->end(array(
|
|
|
|
'label' => 'save', 'name' => 'Whatever', 'div' => array('class' => 'good')
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'good'),
|
|
|
|
'input' => array('type' => 'submit', 'value' => 'save', 'name' => 'Whatever'),
|
|
|
|
'/div',
|
|
|
|
'/form'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMultipleFormWithIdFields method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleFormWithIdFields() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('UserForm');
|
|
|
|
|
|
|
|
$result = $this->Form->input('id');
|
2008-12-25 22:13:06 +00:00
|
|
|
$this->assertTags($result, array('input' => array(
|
2010-02-07 21:30:43 +00:00
|
|
|
'type' => 'hidden', 'name' => 'data[UserForm][id]', 'id' => 'UserFormId'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('ValidateItem.id');
|
|
|
|
$this->assertTags($result, array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[ValidateItem][id]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ValidateItemId'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2008-12-25 22:13:06 +00:00
|
|
|
$result = $this->Form->input('ValidateUser.id');
|
|
|
|
$this->assertTags($result, array('input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[ValidateUser][id]',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'ValidateUserId'
|
2008-12-25 22:13:06 +00:00
|
|
|
)));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testDbLessModel method
|
2008-06-14 21:40:01 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDbLessModel() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Form->create('TestMail');
|
|
|
|
|
|
|
|
$result = $this->Form->input('name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'TestMailName'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'name' => 'data[TestMail][name]', 'type' => 'text',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'TestMailName'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
ClassRegistry::init('TestMail');
|
|
|
|
$this->Form->create('TestMail');
|
|
|
|
$result = $this->Form->input('name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'TestMailName'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
2008-12-25 22:13:06 +00:00
|
|
|
'input' => array(
|
|
|
|
'name' => 'data[TestMail][name]', 'type' => 'text',
|
2010-02-07 21:30:43 +00:00
|
|
|
'id' => 'TestMailName'
|
2008-12-25 22:13:06 +00:00
|
|
|
),
|
2008-05-30 11:40:08 +00:00
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* testBrokenness method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBrokenness() {
|
2008-06-20 20:17:23 +00:00
|
|
|
/*
|
2008-09-29 16:23:39 +00:00
|
|
|
* #4 This test has two parents and four children. By default (as of r7117) both
|
2008-12-25 22:13:06 +00:00
|
|
|
* parents are show but the first parent is missing a child. This is the inconsistency
|
|
|
|
* in the default behaviour - one parent has all children, the other does not - dependent
|
|
|
|
* on the data values.
|
2008-09-29 16:23:39 +00:00
|
|
|
*/
|
2008-06-20 20:17:23 +00:00
|
|
|
$result = $this->Form->select('Model.field', array(
|
|
|
|
'Fred' => array(
|
|
|
|
'freds_son_1' => 'Fred',
|
|
|
|
'freds_son_2' => 'Freddie'
|
|
|
|
),
|
|
|
|
'Bert' => array(
|
|
|
|
'berts_son_1' => 'Albert',
|
|
|
|
'berts_son_2' => 'Bertie')
|
|
|
|
),
|
2009-10-17 05:29:16 +00:00
|
|
|
array('showParents' => true, 'empty' => false)
|
2008-06-20 20:17:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('optgroup' => array('label' => 'Fred')),
|
|
|
|
array('option' => array('value' => 'freds_son_1')),
|
|
|
|
'Fred',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'freds_son_2')),
|
|
|
|
'Freddie',
|
|
|
|
'/option',
|
|
|
|
'/optgroup',
|
|
|
|
array('optgroup' => array('label' => 'Bert')),
|
|
|
|
array('option' => array('value' => 'berts_son_1')),
|
|
|
|
'Albert',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 'berts_son_2')),
|
|
|
|
'Bertie',
|
|
|
|
'/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-20 20:17:23 +00:00
|
|
|
|
|
|
|
/*
|
2008-12-25 22:13:06 +00:00
|
|
|
* #2 This is structurally identical to the test above (#1) - only the parent name has
|
|
|
|
* changed, so we should expect the same select list data, just with a different name
|
2012-12-22 22:48:15 +00:00
|
|
|
* for the parent. As of #7117, this test fails because option 3 => 'Three' disappears.
|
2008-12-25 22:13:06 +00:00
|
|
|
* This is where data corruption can occur, because when a select value is missing from
|
|
|
|
* a list a form will substitute the first value in the list - without the user knowing.
|
|
|
|
* If the optgroup name 'Parent' (above) is updated to 'Three' (below), this should not
|
|
|
|
* affect the availability of 3 => 'Three' as a valid option.
|
2008-06-20 20:17:23 +00:00
|
|
|
*/
|
2008-12-25 22:13:06 +00:00
|
|
|
$options = array(1 => 'One', 2 => 'Two', 'Three' => array(
|
|
|
|
3 => 'Three', 4 => 'Four', 5 => 'Five'
|
|
|
|
));
|
|
|
|
$result = $this->Form->select(
|
2010-08-05 18:14:36 +00:00
|
|
|
'Model.field', $options, array('showParents' => true, 'empty' => false)
|
2008-06-20 20:17:23 +00:00
|
|
|
);
|
2008-07-30 13:40:59 +00:00
|
|
|
|
2008-06-20 20:17:23 +00:00
|
|
|
$expected = array(
|
|
|
|
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
|
|
|
array('option' => array('value' => 1)),
|
|
|
|
'One',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 2)),
|
|
|
|
'Two',
|
|
|
|
'/option',
|
|
|
|
array('optgroup' => array('label' => 'Three')),
|
|
|
|
array('option' => array('value' => 3)),
|
|
|
|
'Three',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 4)),
|
|
|
|
'Four',
|
|
|
|
'/option',
|
|
|
|
array('option' => array('value' => 5)),
|
|
|
|
'Five',
|
|
|
|
'/option',
|
|
|
|
'/optgroup',
|
|
|
|
'/select'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2008-06-20 20:17:23 +00:00
|
|
|
}
|
2009-10-22 03:45:42 +00:00
|
|
|
|
2009-10-22 04:24:54 +00:00
|
|
|
/**
|
|
|
|
* Test the generation of fields for a multi record form.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultiRecordForm() {
|
2009-10-21 21:09:16 +00:00
|
|
|
$this->Form->create('ValidateProfile');
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['name'] = 'Value';
|
2009-10-21 21:09:16 +00:00
|
|
|
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.name');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input textarea'),
|
|
|
|
'label' => array('for' => 'ValidateProfile1ValidateItem2Name'),
|
|
|
|
'Name',
|
|
|
|
'/label',
|
|
|
|
'textarea' => array(
|
|
|
|
'id' => 'ValidateProfile1ValidateItem2Name',
|
|
|
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][name]',
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255,
|
2009-10-21 21:09:16 +00:00
|
|
|
'cols' => 30,
|
|
|
|
'rows' => 6
|
|
|
|
),
|
|
|
|
'Value',
|
|
|
|
'/textarea',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2013-05-17 08:36:17 +00:00
|
|
|
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.created', array('empty' => true));
|
2009-10-21 21:09:16 +00:00
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input date'),
|
|
|
|
'label' => array('for' => 'ValidateProfile1ValidateItem2CreatedMonth'),
|
|
|
|
'Created',
|
|
|
|
'/label',
|
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][month]',
|
|
|
|
'id' => 'ValidateProfile1ValidateItem2CreatedMonth'
|
|
|
|
)
|
|
|
|
),
|
2009-10-22 03:45:42 +00:00
|
|
|
array('option' => array('value' => '')), '/option',
|
2009-10-21 21:09:16 +00:00
|
|
|
$this->dateRegex['monthsRegex'],
|
|
|
|
'/select', '-',
|
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][day]',
|
|
|
|
'id' => 'ValidateProfile1ValidateItem2CreatedDay'
|
|
|
|
)
|
|
|
|
),
|
2009-10-22 03:45:42 +00:00
|
|
|
array('option' => array('value' => '')), '/option',
|
2009-10-21 21:09:16 +00:00
|
|
|
$this->dateRegex['daysRegex'],
|
|
|
|
'/select', '-',
|
|
|
|
array('select' => array(
|
|
|
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][created][year]',
|
|
|
|
'id' => 'ValidateProfile1ValidateItem2CreatedYear'
|
|
|
|
)
|
|
|
|
),
|
2009-10-22 03:45:42 +00:00
|
|
|
array('option' => array('value' => '')), '/option',
|
2009-10-21 21:09:16 +00:00
|
|
|
$this->dateRegex['yearsRegex'],
|
|
|
|
'/select',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2011-07-14 18:26:31 +00:00
|
|
|
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
|
$ValidateProfile->validationErrors[1]['ValidateItem'][2]['profile_id'] = 'Error';
|
2010-05-14 04:21:22 +00:00
|
|
|
$this->Form->request->data['ValidateProfile'][1]['ValidateItem'][2]['profile_id'] = '1';
|
2009-10-21 21:09:16 +00:00
|
|
|
$result = $this->Form->input('ValidateProfile.1.ValidateItem.2.profile_id');
|
|
|
|
$expected = array(
|
2010-01-13 04:27:17 +00:00
|
|
|
'div' => array('class' => 'input select error'),
|
2009-10-21 21:09:16 +00:00
|
|
|
'label' => array('for' => 'ValidateProfile1ValidateItem2ProfileId'),
|
|
|
|
'Profile',
|
|
|
|
'/label',
|
2010-01-13 04:27:17 +00:00
|
|
|
'select' => array(
|
|
|
|
'name' => 'data[ValidateProfile][1][ValidateItem][2][profile_id]',
|
2009-10-21 21:09:16 +00:00
|
|
|
'id' => 'ValidateProfile1ValidateItem2ProfileId',
|
|
|
|
'class' => 'form-error'
|
|
|
|
),
|
2010-01-13 04:27:17 +00:00
|
|
|
'/select',
|
2009-10-21 21:09:16 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
|
|
|
'Error',
|
|
|
|
'/div',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2009-10-21 21:09:16 +00:00
|
|
|
}
|
2009-10-22 04:24:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test the correct display of multi-record form validation errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultiRecordFormValidationErrors() {
|
2009-10-21 21:09:16 +00:00
|
|
|
$this->Form->create('ValidateProfile');
|
2011-07-14 18:26:31 +00:00
|
|
|
$ValidateProfile = ClassRegistry::getObject('ValidateProfile');
|
|
|
|
$ValidateProfile->validationErrors[2]['ValidateItem'][1]['name'] = array('Error in field name');
|
2009-10-21 21:09:16 +00:00
|
|
|
$result = $this->Form->error('ValidateProfile.2.ValidateItem.1.name');
|
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2011-07-14 18:26:31 +00:00
|
|
|
$ValidateProfile->validationErrors[2]['city'] = array('Error in field city');
|
2009-10-21 21:09:16 +00:00
|
|
|
$result = $this->Form->error('ValidateProfile.2.city');
|
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
2009-10-22 04:24:54 +00:00
|
|
|
|
2009-10-21 21:09:16 +00:00
|
|
|
$result = $this->Form->error('2.city');
|
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
2009-10-21 13:08:20 +00:00
|
|
|
}
|
2009-10-30 05:02:54 +00:00
|
|
|
|
2013-05-14 01:08:19 +00:00
|
|
|
/**
|
|
|
|
* test the correct display of multi-record form validation errors.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSaveManyRecordFormValidationErrors() {
|
|
|
|
$this->Form->create('ValidateUser');
|
|
|
|
$ValidateUser = ClassRegistry::getObject('ValidateUser');
|
|
|
|
$ValidateUser->validationErrors[0]['ValidateItem']['name'] = array('Error in field name');
|
|
|
|
|
|
|
|
$result = $this->Form->error('0.ValidateUser.ValidateItem.name');
|
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field name', '/div'));
|
|
|
|
|
|
|
|
$ValidateUser->validationErrors[0]['city'] = array('Error in field city');
|
|
|
|
$result = $this->Form->error('ValidateUser.0.city');
|
|
|
|
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field city', '/div'));
|
|
|
|
}
|
|
|
|
|
2010-02-28 03:48:21 +00:00
|
|
|
/**
|
|
|
|
* tests the ability to change the order of the form input placeholder "input", "label", "before", "between", "after", "error"
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInputTemplate() {
|
2010-02-28 03:48:21 +00:00
|
|
|
$result = $this->Form->input('Contact.email', array(
|
|
|
|
'type' => 'text', 'format' => array('input')
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'input' => array(
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
2010-02-28 03:48:21 +00:00
|
|
|
'id' => 'ContactEmail'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-28 03:48:21 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.email', array(
|
|
|
|
'type' => 'text', 'format' => array('input', 'label'),
|
|
|
|
'label' => '<em>Email (required)</em>'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
array('input' => array(
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
2010-02-28 03:48:21 +00:00
|
|
|
'id' => 'ContactEmail'
|
|
|
|
)),
|
|
|
|
'label' => array('for' => 'ContactEmail'),
|
|
|
|
'em' => array(),
|
|
|
|
'Email (required)',
|
|
|
|
'/em',
|
|
|
|
'/label',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-02-28 03:48:21 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.email', array(
|
|
|
|
'type' => 'text', 'format' => array('input', 'between', 'label', 'after'),
|
|
|
|
'between' => '<div>Something in the middle</div>',
|
|
|
|
'after' => '<span>Some text at the end</span>'
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
array('input' => array(
|
2014-09-13 02:03:33 +00:00
|
|
|
'maxlength' => 255, 'type' => 'text', 'name' => 'data[Contact][email]',
|
2010-02-28 03:48:21 +00:00
|
|
|
'id' => 'ContactEmail'
|
|
|
|
)),
|
|
|
|
array('div' => array()),
|
|
|
|
'Something in the middle',
|
|
|
|
'/div',
|
|
|
|
'label' => array('for' => 'ContactEmail'),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
'span' => array(),
|
|
|
|
'Some text at the end',
|
|
|
|
'/span',
|
|
|
|
'/div'
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-12-18 16:25:42 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.method', array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'options' => array('email' => 'Email', 'pigeon' => 'Pigeon'),
|
|
|
|
'between' => 'I am between',
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input radio'),
|
|
|
|
'fieldset' => array(),
|
|
|
|
'legend' => array(),
|
|
|
|
'Method',
|
|
|
|
'/legend',
|
|
|
|
'I am between',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'hidden', 'name' => 'data[Contact][method]',
|
|
|
|
'value' => '', 'id' => 'ContactMethod_'
|
|
|
|
),
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Contact][method]',
|
|
|
|
'value' => 'email', 'id' => 'ContactMethodEmail'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ContactMethodEmail')),
|
|
|
|
'Email',
|
|
|
|
'/label',
|
|
|
|
array('input' => array(
|
|
|
|
'type' => 'radio', 'name' => 'data[Contact][method]',
|
|
|
|
'value' => 'pigeon', 'id' => 'ContactMethodPigeon'
|
|
|
|
)),
|
|
|
|
array('label' => array('for' => 'ContactMethodPigeon')),
|
|
|
|
'Pigeon',
|
|
|
|
'/label',
|
|
|
|
'/fieldset',
|
|
|
|
'/div',
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2010-02-28 03:48:21 +00:00
|
|
|
}
|
2010-08-17 04:06:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that some html5 inputs + FormHelper::__call() work
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHtml5Inputs() {
|
2010-08-17 04:06:23 +00:00
|
|
|
$result = $this->Form->email('User.email');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'email', 'name' => 'data[User][email]', 'id' => 'UserEmail')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-08-17 04:06:23 +00:00
|
|
|
|
|
|
|
$result = $this->Form->search('User.query');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-08-17 04:13:22 +00:00
|
|
|
|
2010-08-17 04:06:23 +00:00
|
|
|
$result = $this->Form->search('User.query', array('value' => 'test'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'search', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2010-12-26 06:40:02 +00:00
|
|
|
|
2010-08-17 04:13:22 +00:00
|
|
|
$result = $this->Form->search('User.query', array('type' => 'text', 'value' => 'test'));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'text', 'name' => 'data[User][query]', 'id' => 'UserQuery', 'value' => 'test')
|
|
|
|
);
|
2011-05-17 04:36:22 +00:00
|
|
|
$this->assertTags($result, $expected);
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2011-08-09 17:47:25 +00:00
|
|
|
$result = $this->Form->input('User.website', array('type' => 'url', 'value' => 'http://domain.tld', 'div' => false, 'label' => false));
|
|
|
|
$expected = array(
|
|
|
|
'input' => array('type' => 'url', 'name' => 'data[User][website]', 'id' => 'UserWebsite', 'value' => 'http://domain.tld')
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2010-08-17 04:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHtml5InputException() {
|
2022-12-31 04:13:42 +00:00
|
|
|
$this->expectException(CakeException::class);
|
2010-08-17 04:06:23 +00:00
|
|
|
$this->Form->email();
|
|
|
|
}
|
2011-06-09 02:17:32 +00:00
|
|
|
|
2011-07-14 21:56:55 +00:00
|
|
|
/**
|
|
|
|
* Tests that a model can be loaded from the model names passed in the request object
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIntrospectModelFromRequest() {
|
|
|
|
$this->loadFixtures('Post');
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2011-07-14 21:56:55 +00:00
|
|
|
));
|
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$this->Form->request['models'] = array('TestPluginPost' => array('plugin' => 'TestPlugin', 'className' => 'TestPluginPost'));
|
|
|
|
|
|
|
|
$this->assertFalse(ClassRegistry::isKeySet('TestPluginPost'));
|
|
|
|
$this->Form->create('TestPluginPost');
|
|
|
|
$this->assertTrue(ClassRegistry::isKeySet('TestPluginPost'));
|
2011-07-14 21:58:53 +00:00
|
|
|
$this->assertInstanceOf('TestPluginPost', ClassRegistry::getObject('TestPluginPost'));
|
2011-07-14 21:56:55 +00:00
|
|
|
|
|
|
|
CakePlugin::unload();
|
|
|
|
App::build();
|
|
|
|
}
|
2011-07-15 22:54:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that it is possible to set the validation errors directly in the helper for a field
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCustomValidationErrors() {
|
|
|
|
$this->Form->validationErrors['Thing']['field'] = 'Badness!';
|
|
|
|
$result = $this->Form->error('Thing.field', null, array('wrap' => false));
|
|
|
|
$this->assertEquals('Badness!', $result);
|
|
|
|
}
|
2012-02-07 13:06:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the 'on' key validates as expected on create
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequiredOnCreate() {
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequiredonupdate');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredonupdate'),
|
|
|
|
'Imrequiredonupdate',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
|
|
|
|
'id' => 'ContactImrequiredonupdate'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequiredoncreate');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredoncreate'),
|
|
|
|
'Imrequiredoncreate',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequiredoncreate',
|
|
|
|
'required' => 'required'
|
2012-02-07 13:06:36 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequiredonboth');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredonboth'),
|
|
|
|
'Imrequiredonboth',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequiredonboth',
|
|
|
|
'required' => 'required'
|
2012-02-07 13:06:36 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2012-12-19 20:12:49 +00:00
|
|
|
$this->Form->inputDefaults(array('required' => false));
|
2012-02-07 13:06:36 +00:00
|
|
|
$result = $this->Form->input('Contact.imrequired');
|
|
|
|
$expected = array(
|
2013-04-26 13:41:35 +00:00
|
|
|
'div' => array('class' => 'input text'),
|
2012-02-07 13:06:36 +00:00
|
|
|
'label' => array('for' => 'ContactImrequired'),
|
|
|
|
'Imrequired',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
|
'id' => 'ContactImrequired'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
2012-12-19 20:12:49 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequired', array('required' => false));
|
|
|
|
$this->assertTags($result, $expected);
|
2013-04-26 13:41:35 +00:00
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequired', array('required' => true));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequired'),
|
|
|
|
'Imrequired',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'required' => 'required', 'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
|
|
|
'id' => 'ContactImrequired'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequired', array('required' => null));
|
|
|
|
$this->assertTags($result, $expected);
|
2012-02-07 13:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the 'on' key validates as expected on update
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequiredOnUpdate() {
|
|
|
|
$this->Form->request->data['Contact']['id'] = 1;
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequiredonupdate');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredonupdate'),
|
|
|
|
'Imrequiredonupdate',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredonupdate]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequiredonupdate',
|
|
|
|
'required' => 'required'
|
2012-02-07 13:06:36 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
$result = $this->Form->input('Contact.imrequiredoncreate');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredoncreate'),
|
|
|
|
'Imrequiredoncreate',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredoncreate]',
|
|
|
|
'id' => 'ContactImrequiredoncreate'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequiredonboth');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequiredonboth'),
|
|
|
|
'Imrequiredonboth',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequiredonboth]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequiredonboth',
|
|
|
|
'required' => 'required'
|
2012-02-07 13:06:36 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->input('Contact.imrequired');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text required'),
|
|
|
|
'label' => array('for' => 'ContactImrequired'),
|
|
|
|
'Imrequired',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
2012-12-19 20:12:49 +00:00
|
|
|
'id' => 'ContactImrequired',
|
|
|
|
'required' => 'required'
|
2012-02-07 13:06:36 +00:00
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
2012-05-20 19:42:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test inputDefaults setter and getter
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputDefaults() {
|
|
|
|
$this->Form->create('Contact');
|
|
|
|
|
|
|
|
$this->Form->inputDefaults(array(
|
|
|
|
'label' => false,
|
|
|
|
'div' => array(
|
|
|
|
'style' => 'color: #000;'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$result = $this->Form->input('Contact.field1');
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text', 'style' => 'color: #000;'),
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
|
'id' => 'ContactField1'
|
|
|
|
),
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$this->Form->inputDefaults(array(
|
|
|
|
'div' => false,
|
|
|
|
'label' => 'Label',
|
|
|
|
));
|
|
|
|
$result = $this->Form->input('Contact.field1');
|
|
|
|
$expected = array(
|
|
|
|
'label' => array('for' => 'ContactField1'),
|
|
|
|
'Label',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
|
'id' => 'ContactField1'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$this->Form->inputDefaults(array(
|
|
|
|
'label' => false,
|
|
|
|
), true);
|
|
|
|
$result = $this->Form->input('Contact.field1');
|
|
|
|
$expected = array(
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][field1]',
|
|
|
|
'id' => 'ContactField1'
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Form->inputDefaults();
|
|
|
|
$expected = array(
|
|
|
|
'div' => false,
|
|
|
|
'label' => false,
|
|
|
|
);
|
2013-09-25 18:58:29 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-20 19:42:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-20 13:07:36 +00:00
|
|
|
/**
|
|
|
|
* Tests `_lastAction`.
|
|
|
|
*
|
|
|
|
* With named, numeric value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLastActionWithNamedNumeric() {
|
|
|
|
$here = '/users/index/page:1';
|
|
|
|
|
|
|
|
$this->Form->request->here = $here;
|
|
|
|
$this->Form->create('User');
|
|
|
|
|
2023-01-07 11:25:24 +00:00
|
|
|
$property = new ReflectionProperty($this->Form, '_lastAction');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertSame($here, $property->getValue($this->Form), "_lastAction shouldn't be empty.");
|
2016-09-20 13:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests `_lastAction`.
|
|
|
|
*
|
|
|
|
* With named, string value
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLastActionWithNamedString() {
|
|
|
|
$here = '/users/index/foo:bar';
|
|
|
|
|
|
|
|
$this->Form->request->here = $here;
|
|
|
|
$this->Form->create('User');
|
|
|
|
|
2023-01-07 11:25:24 +00:00
|
|
|
$property = new ReflectionProperty($this->Form, '_lastAction');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
|
|
|
|
$this->assertSame($here, $property->getValue($this->Form), "_lastAction shouldn't be empty.");
|
2016-09-20 13:07:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 12:15:00 +00:00
|
|
|
/**
|
|
|
|
* Tests the 'errorClass' option when error is returned.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInputErrorClass() {
|
2017-03-08 12:43:40 +00:00
|
|
|
$Contact = ClassRegistry::getObject('Contact');
|
|
|
|
$Contact->validationErrors['field'] = array('Badness!');
|
|
|
|
|
2017-03-08 12:15:00 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
|
|
|
'type' => 'text',
|
2017-03-08 12:43:40 +00:00
|
|
|
'div' => array('errorClass' => 'has-error')
|
2017-03-08 12:15:00 +00:00
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text has-error'),
|
|
|
|
'label' => array('for' => 'ContactField'),
|
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
|
|
|
),
|
2017-03-08 12:43:40 +00:00
|
|
|
array('div' => array('class' => 'error-message')),
|
2017-03-08 12:15:00 +00:00
|
|
|
'Badness!',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2017-03-08 12:43:40 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2017-03-08 12:15:00 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'error' => array('attributes' => array('class' => 'error'))
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text error'),
|
2017-03-08 12:43:40 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2017-03-08 12:15:00 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
2017-03-08 12:43:40 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2017-03-08 12:15:00 +00:00
|
|
|
),
|
|
|
|
array('div' => array('class' => 'error')),
|
|
|
|
'Badness!',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
|
2017-03-08 13:16:08 +00:00
|
|
|
$result = $this->Form->input('Contact.field', array(
|
2017-03-08 12:15:00 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'div' => array('errorClass' => 'has-error'),
|
|
|
|
'error' => array('attributes' => array('class' => 'form-control-feedback'))
|
|
|
|
));
|
|
|
|
$expected = array(
|
|
|
|
'div' => array('class' => 'input text has-error'),
|
2017-03-08 12:43:40 +00:00
|
|
|
'label' => array('for' => 'ContactField'),
|
2017-03-08 12:15:00 +00:00
|
|
|
'Field',
|
|
|
|
'/label',
|
|
|
|
'input' => array(
|
2017-03-08 12:43:40 +00:00
|
|
|
'type' => 'text', 'name' => 'data[Contact][field]',
|
|
|
|
'id' => 'ContactField', 'class' => 'form-error'
|
2017-03-08 12:15:00 +00:00
|
|
|
),
|
|
|
|
array('div' => array('class' => 'form-control-feedback')),
|
|
|
|
'Badness!',
|
|
|
|
'/div'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|