* Copyright 2006-2008, Cake Software Foundation, Inc. * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package cake.tests * @subpackage cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { define('CAKEPHP_UNIT_TEST_EXECUTION', 1); } App::import('Core', array('ClassRegistry', 'Controller', 'View', 'Model', 'Security')); App::import('Helper', 'Html'); App::import('Helper', 'Form'); /** * ContactTestController class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactTestController extends Controller { /** * name property * * @var string 'ContactTest' * @access public */ var $name = 'ContactTest'; /** * uses property * * @var mixed null * @access public */ var $uses = null; } /** * Contact class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class Contact extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'Contact' * @access public */ var $name = 'Contact'; /** * Default schema * * @var array * @access public */ var $_schema = array( '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'), 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * validate property * * @var array * @access public */ var $validate = array( 'non_existing' => array(), 'idontexist' => array(), 'imrequired' => array('rule' => array('between', 5, 30), 'required' => true), 'imalsorequired' => array('rule' => 'alphaNumeric', 'required' => true), 'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric'), 'imalsonotrequired' => array('alpha' => array('rule' => 'alphaNumeric','required' => false), 'between' => array('rule' => array('between', 5, 30)))); /** * schema method * * @access public * @return void */ function setSchema($schema) { $this->_schema = $schema; } /** * hasAndBelongsToMany property * * @var array * @access public */ var $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact')); } class ContactTagsContact extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'Contact' * @access public */ var $name = 'ContactTagsContact'; /** * Default schema * * @var array * @access public */ var $_schema = array( 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'contact_tag_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8') ); /** * schema method * * @access public * @return void */ function setSchema($schema) { $this->_schema = $schema; } } Class ContactNonStandardPk extends Contact { /** * primaryKey property * * @var string 'pk' * @access public */ var $primaryKey = 'pk'; /** * name property * * @var string 'ContactNonStandardPk' * @access public */ var $name = 'ContactNonStandardPk'; /** * schema method * * @access public * @return void */ function schema() { $this->_schema = parent::schema(); $this->_schema['pk'] = $this->_schema['id']; unset($this->_schema['id']); return $this->_schema; } } /** * ContactTag class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactTag extends Model { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( '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) ); return $this->_schema; } } /** * UserForm class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class UserForm extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * name property * * @var string 'UserForm' * @access public */ var $name = 'UserForm'; /** * hasMany property * * @var array * @access public */ var $hasMany = array('OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id')); /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( '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), 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255), 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); return $this->_schema; } } /** * OpenidUrl class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class OpenidUrl extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * name property * * @var string 'OpenidUrl' * @access public */ var $name = 'OpenidUrl'; /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('UserForm' => array('className' => 'UserForm', 'foreignKey' => 'user_form_id')); /** * validate property * * @var array * @access public */ var $validate = array('openid_not_registered' => array()); /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( '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'), ); return $this->_schema; } /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('openid_not_registered'); return true; } } /** * ValidateUser class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateUser extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'ValidateUser' * @access public */ var $name = 'ValidateUser'; /** * hasOne property * * @var array * @access public */ var $hasOne = array('ValidateProfile' => array('className' => 'ValidateProfile', 'foreignKey' => 'user_id')); /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( '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'), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); return $this->_schema; } /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('email'); return false; } } /** * ValidateProfile class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateProfile extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'ValidateProfile' * @access public */ var $name = 'ValidateProfile'; /** * hasOne property * * @var array * @access public */ var $hasOne = array('ValidateItem' => array('className' => 'ValidateItem', 'foreignKey' => 'profile_id')); /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('ValidateUser' => array('className' => 'ValidateUser', 'foreignKey' => 'user_id')); /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( '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) ); return $this->_schema; } /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('full_name'); $this->invalidate('city'); return false; } } /** * ValidateItem class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateItem extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'ValidateItem' * @access public */ var $name = 'ValidateItem'; /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('ValidateProfile' => array('className' => 'ValidateProfile', 'foreignKey' => 'profile_id')); /** * schema method * * @access public * @return void */ function schema() { $this->_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'name' => array('type' => 'string', '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) ); return $this->_schema; } /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('description'); return false; } } /** * TestMail class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class TestMail extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'TestMail' * @access public */ var $name = 'TestMail'; } /** * Short description for class. * * @package cake.tests * @subpackage cake.tests.cases.libs.view.helpers */ class FormHelperTest extends CakeTestCase { /** * fixtures property * * @var array * @access public */ var $fixtures = array(null); /** * setUp method * * @access public * @return void */ function setUp() { parent::setUp(); Router::reload(); $this->Form =& new FormHelper(); $this->Form->Html =& new HtmlHelper(); $this->Controller =& new ContactTestController(); $this->View =& new View($this->Controller); ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk()); ClassRegistry::addObject('OpenidUrl', new OpenidUrl()); ClassRegistry::addObject('UserForm', new UserForm()); ClassRegistry::addObject('ValidateItem', new ValidateItem()); ClassRegistry::addObject('ValidateUser', new ValidateUser()); ClassRegistry::addObject('ValidateProfile', new ValidateProfile()); $this->oldSalt = Configure::read('Security.salt'); $this->dateRegex = array( 'daysRegex' => 'preg:/(?:#', $result[1]); $this->assertNoPattern('##', $result[1]); $this->assertPattern('##', $result[1]); $result = $this->Form->input('Model.field', array('type' => 'time', 'timeFormat' => 12, 'interval' => 15)); $result = explode(':', $result); $this->assertNoPattern('##', $result[1]); $this->assertNoPattern('##', $result[1]); $this->assertPattern('##', $result[1]); //related to ticket #5013 $result = $this->Form->input('Contact.date', array('type' => 'date', 'class' => 'customClass', 'onChange' => 'function(){}')); $this->assertPattern('/class="customClass"/', $result); $this->assertPattern('/onChange="function\(\)\{\}"/', $result); $result = $this->Form->input('Contact.date', array('type' => 'date', 'id' => 'customId', 'onChange' => 'function(){}')); $this->assertPattern('/id="customIdDay"/', $result); $this->assertPattern('/id="customIdMonth"/', $result); $this->assertPattern('/onChange="function\(\)\{\}"/', $result); $result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 24, 'id' => 'customID')); $this->assertPattern('/id="customIDDay"/', $result); $this->assertPattern('/id="customIDHour"/', $result); $result = explode('assertPattern('/option value="23"/', $result[0]); $this->assertNoPattern('/option value="24"/', $result[0]); $result = $this->Form->input('Model.field', array('type' => 'datetime', 'timeFormat' => 12)); $result = explode('assertPattern('/option value="12"/', $result[0]); $this->assertNoPattern('/option value="13"/', $result[0]); $this->Form->data = array('Contact' => array('phone' => 'Hello & World > weird chars' )); $result = $this->Form->input('Contact.phone'); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ContactPhone'), 'Phone', '/label', array('input' => array('type' => 'text', 'name' => 'data[Contact][phone]', 'value' => 'Hello & World > weird chars', 'id' => 'ContactPhone', 'maxlength' => 255)), '/div' ); $this->assertTags($result, $expected); $this->Form->data['Model']['0']['OtherModel']['field'] = 'My value'; $result = $this->Form->input('Model.0.OtherModel.field', array('id' => 'myId')); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'myId'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][0][OtherModel][field]', 'value' => 'My value', 'id' => 'myId'), '/div' ); $this->assertTags($result, $expected); unset($this->Form->data); $this->Form->validationErrors['Model']['field'] = 'Badness!'; $result = $this->Form->input('Model.field'); $expected = array( 'div' => array('class' => 'input text error'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'Badness!', '/div', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.field', array('div' => false, 'error' => array('wrap' => 'span'))); $expected = array( 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), array('span' => array('class' => 'error-message')), 'Badness!', '/span' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.field', array('div' => array('tag' => 'span'), 'error' => array('wrap' => false))); $expected = array( 'span' => array('class' => 'input text error'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), 'Badness!', '/span' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy')); $expected = array( 'div' => array('class' => 'input text error'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), 'A message to you, Rudy', array('div' => array('class' => 'error-message')), 'Badness!', '/div', '/div' ); $this->assertTags($result, $expected); $this->Form->setEntity(null); $this->Form->setEntity('Model.field'); $result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy', 'error' => false)); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), 'A message to you, Rudy', '/div' ); $this->assertTags($result, $expected); unset($this->Form->validationErrors['Model']['field']); $result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy')); $expected = array( 'div' => array('class' => 'input text'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'), 'A message to you, Rudy', '/div' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => 'value')); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $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' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => null)); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('empty' => 'Some Empty')); $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' => '')), 'Some Empty', '/option', array('option' => array('value' => 'value')), 'good', '/option', array('option' => array('value' => 'other')), 'bad', '/option', '/select', '/div' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => 'value')); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('empty' => 'Some Empty')); $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' => '')), 'Some Empty', '/option', array('option' => array('value' => 'value', 'selected' => 'selected')), 'good', '/option', array('option' => array('value' => 'other')), 'bad', '/option', '/select', '/div' ); $this->assertTags($result, $expected); extract($this->dateRegex); $this->Form->data = array('Contact' => array('created' => null)); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $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' ); $this->assertTags($result, $expected); $this->Form->data = array('User' => array('User' => array('value'))); $view =& ClassRegistry::getObject('view'); $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('User.User', array('empty' => true)); $expected = array( 'div' => array('class' => 'input select'), 'label' => array('for' => 'UserUser'), 'User', '/label', 'input' => array('type' => 'hidden', 'name' => 'data[User][User]', 'value' => ''), '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' ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 'minLength'; $result = $this->Form->input('Model.field', array('error' => array('minLength' => __('Le login doit contenir au moins 2 caractères', true)))); $expected = array( 'div' => array('class' => 'input text error'), 'label' => array('for' => 'ModelField'), 'Field', '/label', 'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField', 'class' => 'form-error'), array('div' => array('class' => 'error-message')), 'Le login doit contenir au moins 2 caractères', '/div', '/div' ); $this->assertTags($result, $expected); 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' ); $this->assertTags($result, $expected); } } /** * testFormInputs method * * test correct results from form::inputs(). * * @access public * @return void */ function testFormInputs() { $this->Form->create('Contact'); $result = $this->Form->inputs('The Legend'); $expected = array( 'assertTags($result, $expected); $result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff')); $expected = array( 'fieldset' => array('class' => 'classy-stuff'), 'assertTags($result, $expected); $View = ClassRegistry::getObject('view'); $this->Form->create('Contact'); $this->Form->params['prefix'] = 'admin'; $this->Form->action = 'admin_edit'; $result = $this->Form->inputs(); $expected = array( 'assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(false); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('fieldset' => true, 'legend' => false)); $expected = array( 'fieldset' => array(), 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', '/fieldset' ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs('Hello'); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Hello', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', '/fieldset' ); $this->assertTags($result, $expected); $this->Form->create('Contact'); $result = $this->Form->inputs(array('legend' => 'Hello')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Hello', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Contact][id]', 'value' => '', 'id' => 'ContactId'), array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input text')), '*/div', array('div' => array('class' => 'input password')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input date')), '*/div', array('div' => array('class' => 'input datetime')), '*/div', array('div' => array('class' => 'input select')), '*/div', '/fieldset' ); $this->assertTags($result, $expected); } /** * testSelectAsCheckbox method * * test multi-select widget with checkbox formatting. * * @access public * @return void */ function testSelectAsCheckbox() { $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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', ); $this->assertTags($result, $expected); } /** * testLabel method * * test label generation. * * @access public * @return void */ function testLabel() { $this->Form->text('Person.name'); $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')); } /** * testTextbox method * * test textbox element generation * * @access public * @return void */ function testTextbox() { $result = $this->Form->text('Model.field'); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $result = $this->Form->text('Model.field', array('type' => 'password')); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $result = $this->Form->text('Model.field', array('id' => 'theID')); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'theID'))); $this->Form->data['Model']['text'] = 'test HTML values'; $result = $this->Form->text('Model.text'); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test <strong>HTML</strong> values', 'id' => 'ModelText'))); $this->Form->validationErrors['Model']['text'] = 1; $this->Form->data['Model']['text'] = 'test'; $result = $this->Form->text('Model.text', array('id' => 'theID')); $this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error'))); $this->Form->data['Model']['0']['OtherModel']['field'] = 'My value'; $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') ); $this->assertTags($result, $expected); } /** * testDefaultValue method * * Test default value setting * * @access public * @return void */ function testDefaultValue() { $this->Form->data['Model']['field'] = 'test'; $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'))); unset($this->Form->data['Model']['field']); $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'))); } /** * testFieldError method * * Test field error generation * * @access public * @return void */ function testFieldError() { $this->Form->validationErrors['Model']['field'] = 1; $result = $this->Form->error('Model.field'); $this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div')); $result = $this->Form->error('Model.field', null, array('wrap' => false)); $this->assertEqual($result, 'Error in field Field'); $this->Form->validationErrors['Model']['field'] = "This field contains invalid input"; $result = $this->Form->error('Model.field', null, array('wrap' => false)); $this->assertEqual($result, 'This field contains invalid input'); $this->Form->validationErrors['Model']['field'] = "This field contains invalid input"; $result = $this->Form->error('Model.field', null, array('wrap' => 'span')); $this->assertTags($result, array('span' => array('class' => 'error-message'), 'This field contains invalid input', '/span')); $result = $this->Form->error('Model.field', 'There is an error fool!', array('wrap' => 'span')); $this->assertTags($result, array('span' => array('class' => 'error-message'), 'There is an error fool!', '/span')); $result = $this->Form->error('Model.field', "Badness!", array('wrap' => false)); $this->assertEqual($result, '<strong>Badness!</strong>'); $result = $this->Form->error('Model.field', "Badness!", array('wrap' => false, 'escape' => true)); $this->assertEqual($result, '<strong>Badness!</strong>'); $result = $this->Form->error('Model.field', "Badness!", array('wrap' => false, 'escape' => false)); $this->assertEqual($result, 'Badness!'); } /** * testPassword method * * Test password element generation * * @access public * @return void */ function testPassword() { $result = $this->Form->password('Model.field'); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'ModelField'))); $this->Form->validationErrors['Model']['passwd'] = 1; $this->Form->data['Model']['passwd'] = 'test'; $result = $this->Form->password('Model.passwd', array('id' => 'theID')); $this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error'))); } /** * testRadio method * * Test radio element set generation * * @access public * @return void */ function testRadio() { $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' ); $this->assertTags($result, $expected); $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' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('option A', 'option B'), array('separator' => '
')); $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' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '1')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Field', '/legend', array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1', 'checked' => 'checked')), 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' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => '0')); $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' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No'), array('value' => null)); $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' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Model.field', array('1' => 'Yes', '0' => 'No')); $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' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'fieldset' => array(), 'legend' => array(), 'Legend title', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), array('label' => array('for' => 'NewsletterSubscribe0')), 'Unsubscribe', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), array('label' => array('for' => 'NewsletterSubscribe1')), 'Subscribe', '/label', '/fieldset', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), array('label' => array('for' => 'NewsletterSubscribe0')), 'Unsubscribe', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), array('label' => array('for' => 'NewsletterSubscribe1')), 'Subscribe', '/label', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => 'Legend title', 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'fieldset' => array(), 'legend' => array(), 'Legend title', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), 'Subscribe', '/fieldset', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), 'input' => array('type' => 'hidden', 'name' => 'data[Newsletter][subscribe]', 'value' => '', 'id' => 'NewsletterSubscribe_'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1')), 'Subscribe', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'value' => '1', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe'))); $expected = array( 'div' => array('class' => 'input radio'), array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '0', 'id' => 'NewsletterSubscribe0')), 'Unsubscribe', array('input' => array('type' => 'radio', 'name' => 'data[Newsletter][subscribe]', 'value' => '1', 'id' => 'NewsletterSubscribe1', 'checked' => 'checked')), 'Subscribe', '/div' ); $this->assertTags($result, $expected); $result = $this->Form->radio('Employee.gender', array('male' => 'Male', 'female' => 'Female')); $expected = array( 'fieldset' => array(), 'legend' => array(), 'Gender', '/legend', 'input' => array('type' => 'hidden', 'name' => 'data[Employee][gender]', 'value' => '', 'id' => 'EmployeeGender_'), array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'male', 'id' => 'EmployeeGenderMale')), array('label' => array('for' => 'EmployeeGenderMale')), 'Male', '/label', array('input' => array('type' => 'radio', 'name' => 'data[Employee][gender]', 'value' => 'female', 'id' => 'EmployeeGenderFemale')), array('label' => array('for' => 'EmployeeGenderFemale')), 'Female', '/label', '/fieldset', ); $this->assertTags($result, $expected); $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', ); $this->assertTags($result, $expected); } /** * testSelect method * * Test select element generation. * * @access public * @return void */ function testSelect() { $result = $this->Form->select('Model.field', array()); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => '')), '/option', '/select' ); $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('field' => 'value')); $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' ); $this->assertTags($result, $expected); $this->Form->data = array(); $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' ); $this->assertTags($result, $expected); $result = $this->Form->select('Model.field', array('first' => 'first "html" ', 'second' => 'value'), null, array(), false); $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' ); $this->assertTags($result, $expected); $result = $this->Form->select('Model.field', array('first' => 'first "html" ', 'second' => 'value'), null, array('escape' => false), false); $expected = array( 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), array('option' => array('value' => 'first')), 'first "html" ', '/option', array('option' => array('value' => 'second')), 'value', '/option', '/select' ); $this->assertTags($result, $expected); } /** * Tests that FormHelper::select() allows null to be passed in the $attributes parameter * * @access public * @return void */ function testSelectWithNullAttributes() { $result = $this->Form->select('Model.field', array('first', 'second'), null, null, false); $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' ); $this->assertTags($result, $expected); } /** * testNestedSelect method * * test select element generation with optgroups * * @access public * @return void */ function testNestedSelect() { $result = $this->Form->select( 'Model.field', array(1 => 'One', 2 => 'Two', 'Three' => array( 3 => 'Three', 4 => 'Four', 5 => 'Five' )), null, array(), false ); $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' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.field', array(1 => 'One', 2 => 'Two', 'Three' => array(3 => 'Three', 4 => 'Four')), null, array('showParents' => true), false ); $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', '/optgroup', '/select' ); $this->assertTags($result, $expected); } /** * testSelectMultiple method * * test generation of multiple select elements * * @access public * @return void */ function testSelectMultiple() { $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => true)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 'select' => array('name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple'), array('option' => array('value' => '0')), 'first', '/option', array('option' => array('value' => '1')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => 'multiple')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 'select' => array('name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple'), array('option' => array('value' => '0')), 'first', '/option', array('option' => array('value' => '1')), 'second', '/option', array('option' => array('value' => '2')), 'third', '/option', '/select' ); $this->assertTags($result, $expected); $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => true)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 'select' => array('name' => 'data[Model][multi_field][]', 'id' => 'ModelMultiField', 'multiple' => 'multiple'), 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' ); $this->assertTags($result, $expected); } /** * testSelectMultipleCheckboxes method * * test generation of multi select elements in checkbox format * * @access public * @return void */ function testSelectMultipleCheckboxes() { $result = $this->Form->select( 'Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array( 'type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => '' ), 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' ); $this->assertTags($result, $expected); $result = $this->Form->select( 'Model.multi_field', array('a' => 'first', 'b' => 'second', 'c' => 'third'), null, array('multiple' => 'checkbox') ); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); $result = $this->Form->select('Model.multi_field', array('1' => 'first'), null, array('multiple' => 'checkbox')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); } /** * testInputMultipleCheckboxes method * * test input() resulting in multi select elements being generated. * * @access public * @return void */ function testInputMultipleCheckboxes() { $result = $this->Form->input('Model.multi_field', array('options' => array('first', 'second', 'third'), 'multiple' => 'checkbox')); $expected = array( array('div' => array('class' => 'input select')), array('label' => array('for' => 'ModelMultiField')), 'Multi Field', '/label', 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array('options' => array('a' => 'first', 'b' => 'second', 'c' => 'third'), 'multiple' => 'checkbox')); $expected = array( array('div' => array('class' => 'input select')), array('label' => array('for' => 'ModelMultiField')), 'Multi Field', '/label', 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array('options' => array('1' => 'first'), 'multiple' => 'checkbox', 'label' => false, 'div' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); $result = $this->Form->input('Model.multi_field', array('options' => array('2' => 'second'), 'multiple' => 'checkbox', 'label' => false, 'div' => false)); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][multi_field]', 'value' => ''), 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' ); $this->assertTags($result, $expected); } /** * testCheckbox method * * Test generation of checkboxes * * @access public * @return void */ function testCheckbox() { $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'theID')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Model']['field'] = 'myvalue'; $result = $this->Form->checkbox('Model.field', array('id' => 'theID', 'value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'theID', 'checked' => 'checked', 'class' => 'form-error')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Model.field', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('preg:/[^<]+/', 'value' => 'myvalue', 'id' => 'ModelField', 'checked' => 'checked', 'class' => 'form-error')) ); $this->assertTags($result, $expected); $this->Form->data['Model']['field'] = ''; $result = $this->Form->checkbox('Model.field', array('id' => 'theID')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'theID_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'theID', 'class' => 'form-error')) ); $this->assertTags($result, $expected); unset($this->Form->validationErrors['Model']['field']); $result = $this->Form->checkbox('Model.field', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'value' => '0', 'id' => 'ModelField_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Model][field]', 'value' => 'myvalue', 'id' => 'ModelField')) ); $this->assertTags($result, $expected); $result = $this->Form->checkbox('Contact.name', array('value' => 'myvalue')); $expected = array( 'input' => array('type' => 'hidden', 'name' => 'data[Contact][name]', 'value' => '0', 'id' => 'ContactName_'), array('input' => array('type' => 'checkbox', 'name' => 'data[Contact][name]', 'value' => 'myvalue', 'id' => 'ContactName')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 1; $result = $this->Form->checkbox('Contact.published', array('id'=>'theID')); $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')) ); $this->assertTags($result, $expected); $this->Form->validationErrors['Model']['field'] = 1; $this->Form->data['Contact']['published'] = 0; $result = $this->Form->checkbox('Contact.published', array('id'=>'theID')); $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')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); $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')) ); $this->assertTags($result, $expected); } /** * testDateTime method * * Test generation of date/time select elements * * @access public * @return void */ function testDateTime() { extract($this->dateRegex); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', null, array(), false); $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, array('option' => array('value' => intval(date('i', $now)), 'selected' => 'selected')), 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' ); $this->assertTags($result, $expected); $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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', false); $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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', '', array('interval' => 5)); $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', array('option' => array('value' => '0')), '00', '/option', array('option' => array('value' => '5')), '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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', '', array('minuteInterval' => 5)); $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', array('option' => array('value' => '0')), '00', '/option', array('option' => array('value' => '5')), '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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->Form->data['Contact']['data'] = null; $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' ); $this->assertTags($result, $expected); $this->assertNoPattern('/]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->Form->data['Model']['field'] = date('Y') . '-01-01 00:00:00'; $now = strtotime($this->Form->data['Model']['field']); $result = $this->Form->dateTime('Model.field', 'DMY', '12', null, array(), false); $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, array('option' => array('value' => intval(date('i', $now)), 'selected' => 'selected')), 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' ); $this->assertTags($result, $expected); $selected = strtotime('2008-10-26 10:33:00'); $result = $this->Form->dateTime('Model.field', 'DMY', '12', $selected); $this->assertPattern('/]+value="2008"[^<>]+selected="selected"[^>]*>2008<\/option>/', $result); $this->assertPattern('/]+value="10"[^<>]+selected="selected"[^>]*>10<\/option>/', $result); $this->assertPattern('/]+value="26"[^<>]+selected="selected"[^>]*>26<\/option>/', $result); $this->assertPattern('/]+value="10"[^<>]+selected="selected"[^>]*>10<\/option>/', $result); $this->assertPattern('/]+value="33"[^<>]+selected="selected"[^>]*>33<\/option>/', $result); $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' ); $this->assertTags($result, $expected); $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' ); $this->assertTags($result, $expected); $result = $this->Form->input('ContactTag'); $expected = array( 'div' => array('class' => 'input select'), 'label' => array('for' => 'ContactTagContactTag'), 'Contact Tag', '/label', array('input' => array('type' => 'hidden', 'name' => 'data[ContactTag][ContactTag]', 'value' => '')), array('select' => array('name' => 'data[ContactTag][ContactTag][]', 'multiple' => 'multiple', 'id' => 'ContactTagContactTag')), '/select', '/div' ); $this->assertTags($result, $expected); $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:/(?: