2007-02-06 17:18:23 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
2008-01-01 22:18:17 +00:00
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
* Copyright 2006 - 2008 , Cake Software Foundation , Inc .
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
2007-02-06 17:18:23 +00:00
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2008-01-01 22:18:17 +00:00
* @ 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
2007-02-06 17:18:23 +00:00
*/
2007-06-23 07:44:39 +00:00
if ( ! defined ( 'CAKEPHP_UNIT_TEST_EXECUTION' )) {
define ( 'CAKEPHP_UNIT_TEST_EXECUTION' , 1 );
}
2007-03-16 23:35:25 +00:00
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
uses ( 'view' . DS . 'helpers' . DS . 'app_helper' ,
2007-09-16 18:32:02 +00:00
'class_registry' , 'controller' . DS . 'controller' , 'model' . DS . 'model' ,
'view' . DS . 'helper' , 'view' . DS . 'helpers' . DS . 'html' , 'view' . DS . 'view' ,
Closes #2119 Only define clone() in PHP4 when it hasn't been already defined.
Closes #2213, Support multiple plugin paths.
Closes #2234, filepaths to behavior classes should be cached in class.paths.php also
Closes #2345, ability to group components into subfolders
Closes #2645, Improvement to basic.php for class loading.
Fixes #3526, Cache::write, when using just the config name, it fails.
Fixes #3559, loading plugin model as assoc don't work.
Closes #3567 Controller Folders (Note this does not need routing to work, but controller names can not conflict with others in the same application so naming must still be unique)
Fixes #3579, email.php component: Parse error with php 4.
Adding new class and file importer.
Updated most of the core to use the importer.
Added ClassRegsitry::init() that will create and instance of an object and store it in the registry.
Deprecated most of the load functions in basics.php
Plugin model loading now forces using the dot notation, to use models within a plugin, all the model associations must be in the PluginName.Model syntax, if this is not used, the plugin will look for the models in the main app/models directory first, if not found then it will search the plugin directories recursively until it finds a model.
var $belongsTo = array('SomeModel'); will look for some_model.php in the app/models
var $belongsTo = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $belongsTo = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
The controllers of the plugin will still look for the default models inside the plugin if var $uses is not set:
var $uses = array('SomeModel'); will look for some_model.php in the app/models
var $uses = array('MyPlugin.SomeModel'); will look for some_model.php in my_plugin/models
var $uses = array('MyPlugin.MyPlugin', 'SomeModel'); will used my_plugin/models/my_plugin.php and app/models/some_model.php
All of the above will work between plugins and main app
These changes also allow placing model and controllers is sub directories
Removed old class.paths.php file generation
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6001 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-16 09:35:19 +00:00
'view' . DS . 'helpers' . DS . 'form' );
2007-07-08 01:17:57 +00:00
2007-06-23 07:44:39 +00:00
class ContactTestController extends Controller {
var $name = 'ContactTest' ;
var $uses = null ;
}
2007-10-27 20:32:19 +00:00
class Contact extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $primaryKey = 'id' ;
var $useTable = false ;
var $name = 'Contact' ;
2008-01-21 00:39:44 +00:00
var $validate = array ( 'non_existing' => array (), 'idontexist' => array (), 'imnotrequired' => array ( 'required' => false , 'rule' => 'alphaNumeric' ));
2007-06-23 07:44:39 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +00:00
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
2007-11-04 18:07:59 +00:00
'email' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'phone' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'password' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
2007-10-28 04:18:18 +00:00
'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 )
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-03-16 23:35:25 +00:00
}
2008-02-18 21:58:32 +00:00
var $hasAndBelongsToMany = array ( 'ContactTag' => array ());
2007-06-23 07:44:39 +00:00
}
2008-04-17 20:31:49 +00:00
Class ContactNonStandardPk extends Contact {
var $primaryKey = 'pk' ;
var $name = 'ContactNonStandardPk' ;
function schema () {
$this -> _schema = parent :: schema ();
$this -> _schema [ 'pk' ] = $this -> _schema [ 'id' ];
unset ( $this -> _schema [ 'id' ]);
return $this -> _schema ;
}
}
2008-02-18 21:58:32 +00:00
class ContactTag extends Model {
2007-04-25 00:24:19 +00:00
2008-02-18 21:58:32 +00:00
var $useTable = false ;
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 ;
}
}
2007-10-27 20:32:19 +00:00
class UserForm extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $useTable = false ;
var $primaryKey = 'id' ;
var $name = 'UserForm' ;
var $hasMany = array ( 'OpenidUrl' => array ( 'className' => 'OpenidUrl' , 'foreignKey' => 'user_form_id' ));
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +00:00
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'published' => array ( 'type' => 'date' , 'null' => true , 'default' => null , 'length' => null ),
2007-11-04 18:07:59 +00:00
'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 ),
2007-10-28 04:18:18 +00:00
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-04-06 17:33:49 +00:00
}
2007-10-28 04:18:18 +00:00
2007-06-23 07:44:39 +00:00
}
2007-04-25 00:24:19 +00:00
2007-10-27 20:32:19 +00:00
class OpenidUrl extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $useTable = false ;
var $primaryKey = 'id' ;
var $name = 'OpenidUrl' ;
var $belongsTo = array ( 'UserForm' => array ( 'className' => 'UserForm' , 'foreignKey' => 'user_form_id' ));
2007-11-04 18:07:59 +00:00
var $validate = array ( 'openid_not_registered' => array ());
2007-04-25 00:24:19 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +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' ),
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-04-06 17:33:49 +00:00
}
2007-04-29 03:10:44 +00:00
2007-06-23 07:44:39 +00:00
function beforeValidate () {
$this -> invalidate ( 'openid_not_registered' );
return true ;
}
}
2007-04-29 03:10:44 +00:00
2007-10-27 20:32:19 +00:00
class ValidateUser extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $primaryKey = 'id' ;
var $useTable = false ;
var $name = 'ValidateUser' ;
var $hasOne = array ( 'ValidateProfile' => array ( 'className' => 'ValidateProfile' , 'foreignKey' => 'user_id' ));
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +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' ),
2008-05-23 05:14:57 +00:00
'balance' => array ( 'type' => 'float' , 'null' => false , 'length' => '5,2' ),
2007-10-28 04:18:18 +00:00
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-04-26 11:52:56 +00:00
}
2007-04-29 03:10:44 +00:00
2007-06-23 07:44:39 +00:00
function beforeValidate () {
$this -> invalidate ( 'email' );
return false ;
}
}
2007-04-29 03:10:44 +00:00
2007-10-27 20:32:19 +00:00
class ValidateProfile extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $primaryKey = 'id' ;
var $useTable = false ;
var $name = 'ValidateProfile' ;
var $hasOne = array ( 'ValidateItem' => array ( 'className' => 'ValidateItem' , 'foreignKey' => 'profile_id' ));
var $belongsTo = array ( 'ValidateUser' => array ( 'className' => 'ValidateUser' , 'foreignKey' => 'user_id' ));
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +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 )
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-04-26 11:52:56 +00:00
}
2007-04-29 03:10:44 +00:00
2007-06-23 07:44:39 +00:00
function beforeValidate () {
$this -> invalidate ( 'full_name' );
$this -> invalidate ( 'city' );
return false ;
}
}
2007-04-29 03:10:44 +00:00
2007-10-27 20:32:19 +00:00
class ValidateItem extends CakeTestModel {
2007-06-23 07:44:39 +00:00
var $primaryKey = 'id' ;
var $useTable = false ;
var $name = 'ValidateItem' ;
var $belongsTo = array ( 'ValidateProfile' => array ( 'className' => 'ValidateProfile' , 'foreignKey' => 'profile_id' ));
2007-10-28 04:18:18 +00:00
function schema () {
2007-11-04 18:07:59 +00:00
$this -> _schema = array (
2007-10-28 04:18:18 +00:00
'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 )
);
2007-11-04 18:07:59 +00:00
return $this -> _schema ;
2007-04-26 11:52:56 +00:00
}
2007-03-16 23:35:25 +00:00
2007-06-23 07:44:39 +00:00
function beforeValidate () {
$this -> invalidate ( 'description' );
return false ;
}
}
2008-02-28 00:23:28 +00:00
class TestMail extends CakeTestModel {
var $primaryKey = 'id' ;
var $useTable = false ;
var $name = 'TestMail' ;
}
2007-02-06 17:18:23 +00:00
/**
* Short description for class .
*
2007-04-06 17:33:49 +00:00
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . view . helpers
2007-02-06 17:18:23 +00:00
*/
2007-04-26 11:52:56 +00:00
class FormHelperTest extends CakeTestCase {
2007-10-27 20:32:19 +00:00
var $fixtures = array ( null );
2007-06-23 08:40:52 +00:00
function setUp () {
2007-10-27 20:32:19 +00:00
parent :: setUp ();
2007-06-23 08:40:52 +00:00
Router :: reload ();
2007-09-16 18:32:02 +00:00
2008-03-09 07:36:34 +00:00
$this -> Form =& new FormHelper ();
$this -> Form -> Html =& new HtmlHelper ();
$this -> Controller =& new ContactTestController ();
$this -> View =& new View ( $this -> Controller );
2007-09-16 18:32:02 +00:00
ClassRegistry :: addObject ( 'view' , $view );
ClassRegistry :: addObject ( 'Contact' , new Contact ());
2008-04-17 20:31:49 +00:00
ClassRegistry :: addObject ( 'ContactNonStandardPk' , new ContactNonStandardPk ());
2007-09-16 18:32:02 +00:00
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 ());
2007-06-23 08:40:52 +00:00
}
2007-10-04 18:15:48 +00:00
function testFormCreateWithSecurity () {
$this -> Form -> params [ '_Token' ] = array ( 'key' => 'testKey' );
$result = $this -> Form -> create ( 'Contact' , array ( 'url' => '/contacts/add' ));
2008-04-22 19:53:00 +00:00
$expected = array (
'form' => array ( 'method' => 'post' , 'action' => '/contacts/add' ),
'fieldset' => array ( 'style' => 'display:none;' ),
array ( 'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' )),
array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][key]' , 'value' => 'testKey' , 'id' )),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-22 19:53:00 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-04 18:15:48 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'url' => '/contacts/add' , 'id' => 'MyForm' ));
2008-04-22 19:53:00 +00:00
$expected [ 'form' ][ 'id' ] = 'MyForm' ;
$this -> assertTags ( $result , $expected );
2007-10-04 18:15:48 +00:00
}
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
function testFormSecurityFields () {
$key = 'testKey' ;
2007-11-04 18:07:59 +00:00
$fields = array (
'Model' => array ( 'password' , 'username' , 'valid' ),
'_Model' => array ( 'valid' => '0' ),
'__Token' => array ( 'key' => $key )
);
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$this -> Form -> params [ '_Token' ][ 'key' ] = $key ;
$result = $this -> Form -> secure ( $fields );
2008-04-03 06:48:56 +00:00
$fields = $this -> __sortFields ( $fields );
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $expected , 'id' => 'preg:/TokenFields\d+/' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
}
function testFormSecurityMultipleFields () {
$key = 'testKey' ;
$fields = array (
'Model' => array (
0 => array ( 'username' , 'password' , 'valid' ),
1 => array ( 'username' , 'password' , 'valid' )),
'_Model' => array (
0 => array ( 'hidden' => 'value' , 'valid' => '0' ),
1 => array ( 'hidden' => 'value' , 'valid' => '0' )),
'__Token' => array ( 'key' => $key ));
$this -> Form -> params [ '_Token' ][ 'key' ] = $key ;
$result = $this -> Form -> secure ( $fields );
$fields = $this -> __sortFields ( $fields );
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $expected , 'id' => 'preg:/TokenFields\d+/' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
}
function testFormSecurityMultipleInputFields () {
$key = 'testKey' ;
$this -> Form -> params [ '_Token' ][ 'key' ] = $key ;
$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' );
$fields = array (
'Addresses' => array (
0 => array ( 'title' , 'first_name' , 'last_name' , 'address' , 'city' , 'phone' ),
1 => array ( 'title' , 'first_name' , 'last_name' , 'address' , 'city' , 'phone' )),
'_Addresses' => array (
0 => array ( 'id' => '123456' ),
1 => array ( 'id' => '654321' )),
'__Token' => array ( 'key' => $key ));
$fields = $this -> __sortFields ( $fields );
$result = $this -> Form -> secure ( $this -> Form -> fields );
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $expected , 'id' => 'preg:/TokenFields\d+/' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
}
function testFormSecurityMultipleInputDisabledFields () {
$key = 'testKey' ;
$this -> Form -> params [ '_Token' ][ 'key' ] = $key ;
$this -> Form -> params [ '_Token' ][ 'disabledFields' ] = array ( 'first_name' , 'address' );
$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' );
$fields = array (
'Addresses' => array (
0 => array ( 'title' , 'last_name' , 'city' , 'phone' ),
1 => array ( 'title' , 'last_name' , 'city' , 'phone' )),
'_Addresses' => array (
0 => array ( 'id' => '123456' ),
1 => array ( 'id' => '654321' )),
'__Token' => array ( 'key' => $key ));
$fields = $this -> __sortFields ( $fields );
$result = $this -> Form -> secure ( $this -> Form -> fields );
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $expected , 'id' => 'preg:/TokenFields\d+/' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
}
function testFormSecurityInputDisabledFields () {
$key = 'testKey' ;
$this -> Form -> params [ '_Token' ][ 'key' ] = $key ;
$this -> Form -> params [ '_Token' ][ 'disabledFields' ] = array ( 'first_name' , 'address' );
$this -> Form -> create ();
$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' );
$fields = array (
'Addresses' => array ( 'title' , 'last_name' , 'city' , 'phone' ),
'_Addresses' => array ( 'id' => '123456' ),
'__Token' => array ( 'key' => $key ));
$fields = $this -> __sortFields ( $fields );
$result = $this -> Form -> secure ( $this -> Form -> fields );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $expected , 'id' => 'preg:/TokenFields\d+/' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
}
function testFormSecuredInput () {
2007-11-04 18:07:59 +00:00
$fields = array (
2007-11-06 00:27:20 +00:00
'UserForm' => array ( '0' => 'published' , '1' => 'other' , '2' => 'something' ),
'_UserForm' => array ( 'stuff' => '' , 'something' => '0' ),
2007-11-04 18:07:59 +00:00
'__Token' => array ( 'key' => 'testKey'
));
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$fields = $this -> __sortFields ( $fields );
$fieldsKey = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
$fields [ '__Token' ][ 'fields' ] = $fieldsKey ;
$this -> Form -> params [ '_Token' ][ 'key' ] = 'testKey' ;
$result = $this -> Form -> create ( 'Contact' , array ( 'url' => '/contacts/add' ));
2008-04-26 15:09:41 +00:00
$expected = array (
'form' => array ( 'method' => 'post' , 'action' => '/contacts/add' ),
'fieldset' => array ( 'style' => 'display:none;' ),
array ( 'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' )),
array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][key]' , 'value' => 'testKey' , 'id' => 'preg:/Token\d+/' )),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.published' , array ( 'type' => 'text' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'UserFormPublished' ),
'Published' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[UserForm][published]' , 'value' => '' , 'id' => 'UserFormPublished' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.other' , array ( 'type' => 'text' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'UserFormOther' ),
'Other' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[UserForm][other]' , 'value' => '' , 'id' => 'UserFormOther' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
2008-04-26 15:09:41 +00:00
$result = $this -> Form -> hidden ( 'UserForm.stuff' );
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[_UserForm][stuff]' , 'value' => '' , 'id' => 'UserFormStuff' )
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.something' , array ( 'type' => 'checkbox' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input checkbox' ),
2008-04-26 15:09:41 +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' )),
'label' => array ( 'for' => 'UserFormSomething' ),
'Something' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$result = $this -> Form -> secure ( $this -> Form -> fields );
2008-04-26 15:09:41 +00:00
$expected = array (
'fieldset' => array ( 'style' => 'display:none;' ),
array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[__Token][fields]' , 'value' => $fieldsKey , 'id' => 'preg:/TokenFields\d+/' )),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$result = $this -> Form -> fields ;
$result = $this -> __sortFields ( $result );
2007-11-06 00:27:20 +00:00
$this -> assertEqual ( $result , $fields );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
}
2008-03-10 03:54:15 +00:00
function testPasswordValidation () {
$this -> Form -> validationErrors [ 'Contact' ][ 'password' ] = 'Please provide a password' ;
$result = $this -> Form -> input ( 'Contact.password' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input password error' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ContactPassword' ),
'Password' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'input' => array ( 'type' => 'password' , 'name' => 'data[Contact][password]' , 'value' => '' , 'id' => 'ContactPassword' , 'class' => 'form-error' ),
array ( 'div' => array ( 'class' => 'error-message' )),
'Please provide a password' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-03-10 03:54:15 +00:00
}
2007-10-04 18:16:44 +00:00
function testFormValidationAssociated () {
2007-09-16 18:32:02 +00:00
$this -> UserForm =& ClassRegistry :: getObject ( 'UserForm' );
$this -> UserForm -> OpenidUrl =& ClassRegistry :: getObject ( 'OpenidUrl' );
2007-04-25 00:24:19 +00:00
2007-07-07 23:30:40 +00:00
$data = array ( 'UserForm' => array ( 'name' => 'user' ), 'OpenidUrl' => array ( 'url' => 'http://www.cakephp.org' ));
2007-04-25 00:24:19 +00:00
2007-11-04 18:07:59 +00:00
$this -> assertTrue ( $this -> UserForm -> OpenidUrl -> create ( $data ));
$this -> assertFalse ( $this -> UserForm -> OpenidUrl -> validates ());
2007-04-25 00:24:19 +00:00
2007-04-06 17:33:49 +00:00
$result = $this -> Form -> create ( 'UserForm' , array ( 'type' => 'post' , 'action' => 'login' ));
2008-04-26 15:09:41 +00:00
$expected = array (
'form' => array ( 'method' => 'post' , 'action' => '/user_forms/login/' , 'id' => 'UserFormLoginForm' ),
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-25 00:24:19 +00:00
2007-06-23 07:44:39 +00:00
$expected = array ( 'OpenidUrl' => array ( 'openid_not_registered' => 1 ));
2007-04-06 17:33:49 +00:00
$this -> assertEqual ( $this -> Form -> validationErrors , $expected );
2007-04-25 00:24:19 +00:00
2007-04-06 17:33:49 +00:00
$result = $this -> Form -> error ( 'OpenidUrl.openid_not_registered' , 'Error, not registered' , array ( 'wrap' => false ));
$this -> assertEqual ( $result , 'Error, not registered' );
2007-04-25 00:24:19 +00:00
2007-04-06 17:33:49 +00:00
unset ( $this -> UserForm -> OpenidUrl );
unset ( $this -> UserForm );
}
2007-04-29 03:10:44 +00:00
2007-10-04 18:16:44 +00:00
function testFormValidationAssociatedFirstLevel () {
2007-09-16 18:32:02 +00:00
$this -> ValidateUser =& ClassRegistry :: getObject ( 'ValidateUser' );
$this -> ValidateUser -> ValidateProfile =& ClassRegistry :: getObject ( 'ValidateProfile' );
2007-04-29 03:10:44 +00:00
2007-09-16 18:32:02 +00:00
$data = array ( 'ValidateUser' => array ( 'name' => 'mariano' ), 'ValidateProfile' => array ( 'full_name' => 'Mariano Iglesias' ));
2007-04-26 11:52:56 +00:00
2007-09-16 18:32:02 +00:00
$this -> assertTrue ( $this -> ValidateUser -> create ( $data ));
$this -> assertFalse ( $this -> ValidateUser -> validates ());
$this -> assertFalse ( $this -> ValidateUser -> ValidateProfile -> validates ());
2007-04-29 03:10:44 +00:00
2007-04-26 12:02:51 +00:00
$result = $this -> Form -> create ( 'ValidateUser' , array ( 'type' => 'post' , 'action' => 'add' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-08 11:32:31 +00:00
'form' => array ( 'method' => 'post' , 'action' => '/validate_users/add/' , 'id' ),
2008-04-26 15:09:41 +00:00
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2007-09-16 18:32:02 +00:00
$expected = array (
'ValidateUser' => array ( 'email' => 1 ),
'ValidateProfile' => array ( 'full_name' => 1 , 'city' => 1 )
);
2007-04-26 11:52:56 +00:00
$this -> assertEqual ( $this -> Form -> validationErrors , $expected );
2007-04-26 12:02:51 +00:00
unset ( $this -> ValidateUser -> ValidateProfile );
unset ( $this -> ValidateUser );
2007-04-26 11:52:56 +00:00
}
2007-04-29 03:10:44 +00:00
2007-10-04 18:16:44 +00:00
function testFormValidationAssociatedSecondLevel () {
2007-09-16 18:32:02 +00:00
$this -> ValidateUser =& ClassRegistry :: getObject ( 'ValidateUser' );
$this -> ValidateUser -> ValidateProfile =& ClassRegistry :: getObject ( 'ValidateProfile' );
$this -> ValidateUser -> ValidateProfile -> ValidateItem =& ClassRegistry :: getObject ( 'ValidateItem' );
2007-04-29 03:10:44 +00:00
2007-09-16 18:32:02 +00:00
$data = array (
'ValidateUser' => array ( 'name' => 'mariano' ),
'ValidateProfile' => array ( 'full_name' => 'Mariano Iglesias' ),
'ValidateItem' => array ( 'name' => 'Item' )
);
2007-04-26 11:52:56 +00:00
2007-09-16 18:32:02 +00:00
$this -> assertTrue ( $this -> ValidateUser -> create ( $data ));
$this -> assertFalse ( $this -> ValidateUser -> validates ());
$this -> assertFalse ( $this -> ValidateUser -> ValidateProfile -> validates ());
$this -> assertFalse ( $this -> ValidateUser -> ValidateProfile -> ValidateItem -> validates ());
2007-04-29 03:10:44 +00:00
2007-04-26 12:02:51 +00:00
$result = $this -> Form -> create ( 'ValidateUser' , array ( 'type' => 'post' , 'action' => 'add' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-08 11:32:31 +00:00
'form' => array ( 'method' => 'post' , 'action' => '/validate_users/add/' , 'id' ),
2008-04-26 15:09:41 +00:00
'fieldset' => array ( 'style' => 'display:none;' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
2008-05-08 13:14:47 +00:00
'/fieldset'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2007-09-16 18:32:02 +00:00
$expected = array (
'ValidateUser' => array ( 'email' => 1 ),
'ValidateProfile' => array ( 'full_name' => 1 , 'city' => 1 ),
'ValidateItem' => array ( 'description' => 1 )
);
2007-04-26 11:52:56 +00:00
$this -> assertEqual ( $this -> Form -> validationErrors , $expected );
2007-04-29 03:10:44 +00:00
2007-04-26 12:02:51 +00:00
unset ( $this -> ValidateUser -> ValidateProfile -> ValidateItem );
unset ( $this -> ValidateUser -> ValidateProfile );
unset ( $this -> ValidateUser );
2007-04-26 11:52:56 +00:00
}
2007-02-06 17:18:23 +00:00
2008-03-09 18:28:38 +00:00
function testFormValidationMultiRecord () {
$this -> Form -> validationErrors [ 'Contact' ] = array ( 2 => array ( 'name' => 'This field cannot be left blank' ));
$result = $this -> Form -> input ( 'Contact.2.name' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-23 05:14:57 +00:00
'input' => array ( 'type' => 'text' , 'name' , 'value' => '' , 'id' , 'class' => 'form-error' , 'maxlength' => 255 ),
2008-04-26 15:09:41 +00:00
array ( 'div' => array ( 'class' => 'error-message' )),
'This field cannot be left blank' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-03-09 18:28:38 +00:00
$this -> Form -> validationErrors [ 'UserForm' ] = array ( 'OpenidUrl' => array ( 'url' => 'You must provide a URL' ));
$this -> Form -> create ( 'UserForm' );
$result = $this -> Form -> input ( 'OpenidUrl.url' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-08 11:32:31 +00:00
'input' => array ( 'type' => 'text' , 'name' , 'value' => '' , 'id' , 'class' => 'form-error' ),
2008-04-26 15:09:41 +00:00
array ( 'div' => array ( 'class' => 'error-message' )),
'You must provide a URL' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
2008-03-09 18:28:38 +00:00
}
2008-04-26 15:09:41 +00:00
function testMultipleInputValidation () {
$this -> Form -> create ();
$this -> Form -> validationErrors [ 'Address' ][ 0 ][ 'title' ] = 'This field cannot be empty' ;
$this -> Form -> validationErrors [ 'Address' ][ 0 ][ 'first_name' ] = 'This field cannot be empty' ;
$this -> Form -> validationErrors [ 'Address' ][ 1 ][ 'last_name' ] = 'You must have a last name' ;
$result = $this -> Form -> input ( 'Address.0.title' );
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-08 11:32:31 +00:00
'input' => array ( 'type' => 'text' , 'name' , 'value' => '' , 'id' , 'class' => 'form-error' ),
2008-04-26 15:09:41 +00:00
array ( 'div' => array ( 'class' => 'error-message' )),
'This field cannot be empty' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
$result = $this -> Form -> input ( 'Address.0.first_name' );
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-08 11:32:31 +00:00
'input' => array ( 'type' => 'text' , 'name' , 'value' => '' , 'id' , 'class' => 'form-error' ),
2008-04-26 15:09:41 +00:00
array ( 'div' => array ( 'class' => 'error-message' )),
'This field cannot be empty' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
$result = $this -> Form -> input ( 'Address.0.last_name' );
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-08 11:32:31 +00:00
'input' => array ( 'type' => 'text' , 'name' , 'value' => '' , 'id' , 'class' => 'form-error' ),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
$result = $this -> Form -> input ( 'Address.1.last_name' );
$expected = array (
2008-05-08 11:32:31 +00:00
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'preg:/[^<]+/' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-08 11:32:31 +00:00
'input' => array ( 'type' => 'text' , 'name' => 'preg:/[^<]+/' , 'value' => '' , 'id' => 'preg:/[^<]+/' , 'class' => 'form-error' ),
2008-04-26 15:09:41 +00:00
array ( 'div' => array ( 'class' => 'error-message' )),
'You must have a last name' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-23 14:14:58 +00:00
}
2007-10-04 18:16:44 +00:00
function testFormInput () {
2008-05-23 05:14:57 +00:00
$result = $this -> Form -> input ( 'ValidateUser.balance' );
$expected = array (
'div' => array ( 'class' ),
'label' => array ( 'for' ),
'Balance' ,
'/label' ,
'input' => array ( 'name' , 'type' => 'text' , 'maxlength' => 8 , 'value' => '' , 'id' ),
'/div' ,
);
$this -> assertTags ( $result , $expected );
2007-11-09 01:36:34 +00:00
$result = $this -> Form -> input ( 'Contact.email' , array ( 'id' => 'custom' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'custom' ),
'Email' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-23 05:14:57 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][email]' , 'value' => '' , 'id' => 'custom' , 'maxlength' => 255 )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-09 01:36:34 +00:00
2007-11-06 00:27:20 +00:00
$result = $this -> Form -> hidden ( 'Contact/idontexist' );
2008-04-26 15:09:41 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][idontexist]' , 'value' => '' , 'id' => 'ContactIdontexist' ),
);
$this -> assertTags ( $result , $expected );
2007-11-06 00:27:20 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact.email' , array ( 'type' => 'text' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ContactEmail' ),
'Email' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][email]' , 'value' => '' , 'id' => 'ContactEmail' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-02-06 17:18:23 +00:00
2008-02-03 06:54:05 +00:00
$result = $this -> Form -> input ( 'Contact.5.email' , array ( 'type' => 'text' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'Contact5Email' ),
'Email' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][5][email]' , 'value' => '' , 'id' => 'Contact5Email' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2008-02-18 21:58:32 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact/password' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input password' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ContactPassword' ),
'Password' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'password' , 'name' => 'data[Contact][password]' , 'value' => '' , 'id' => 'ContactPassword' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-01 04:55:56 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'email' , array ( 'options' => array ( 'First' , 'Second' ), 'empty' => true ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input select' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'email' ),
'Email' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'select' => array ( 'name' => 'data[email]' , 'id' => 'email' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => '0' )),
'First' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => '1' )),
'Second' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-25 00:24:19 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact.email' , array ( 'type' => 'file' , 'class' => 'textbox' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input file' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ContactEmail' ),
'Email' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
array ( 'input' => array ( 'type' => 'file' , 'name' => 'data[Contact][email]' , 'class' => 'textbox' , 'value' => '' , 'id' => 'ContactEmail' )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact.created' , array ( 'type' => 'time' , 'timeFormat' => 24 ));
2007-08-11 14:47:53 +00:00
$result = explode ( ':' , $result );
$this -> assertPattern ( '/option value="23"/' , $result [ 0 ]);
$this -> assertNoPattern ( '/option value="24"/' , $result [ 0 ]);
$result = $this -> Form -> input ( 'Model.field' , array ( 'type' => 'time' , 'timeFormat' => 12 ));
$result = explode ( ':' , $result );
$this -> assertPattern ( '/option value="12"/' , $result [ 0 ]);
$this -> assertNoPattern ( '/option value="13"/' , $result [ 0 ]);
2007-11-09 01:36:34 +00:00
$result = $this -> Form -> input ( 'Model.field' , array ( 'type' => 'datetime' , 'timeFormat' => 24 , 'id' => 'customID' ));
$this -> assertPattern ( '/id="customIDDay"/' , $result );
$this -> assertPattern ( '/id="customIDHour"/' , $result );
2007-08-11 14:47:53 +00:00
$result = explode ( '</select><select' , $result );
$result = explode ( ':' , $result [ 1 ]);
$this -> 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 ( '</select><select' , $result );
$result = explode ( ':' , $result [ 1 ]);
$this -> assertPattern ( '/option value="12"/' , $result [ 0 ]);
$this -> assertNoPattern ( '/option value="13"/' , $result [ 0 ]);
2007-11-04 18:07:59 +00:00
$this -> Form -> data = array ( 'Contact' => array ( 'phone' => 'Hello & World > weird chars' ));
$result = $this -> Form -> input ( 'Contact.phone' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ContactPhone' ),
'Phone' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-23 05:14:57 +00:00
array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][phone]' , 'value' => 'Hello & World > weird chars' , 'id' => 'ContactPhone' , 'maxlength' => 255 )),
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-28 07:48:31 +00:00
unset ( $this -> Form -> data );
2007-07-07 23:30:40 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 'Badness!' ;
$result = $this -> Form -> input ( 'Model.field' );
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text error' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ModelField' ),
'Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' , 'class' => 'form-error' ),
array ( 'div' => array ( 'class' => 'error-message' )),
'Badness!' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-07-07 23:30:40 +00:00
$result = $this -> Form -> input ( 'Model.field' , array ( 'after' => 'A message to you, Rudy' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text error' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ModelField' ),
'Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'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!' ,
2008-05-08 13:14:47 +00:00
'/div' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-04 18:07:59 +00:00
$this -> Form -> setEntity ( null );
$this -> Form -> setEntity ( 'Model.field' );
2007-07-07 23:30:40 +00:00
$result = $this -> Form -> input ( 'Model.field' , array ( 'after' => 'A message to you, Rudy' , 'error' => false ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ModelField' ),
'Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' , 'class' => 'form-error' ),
'A message to you, Rudy' ,
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-07-07 23:30:40 +00:00
unset ( $this -> Form -> validationErrors [ 'Model' ][ 'field' ]);
$result = $this -> Form -> input ( 'Model.field' , array ( 'after' => 'A message to you, Rudy' ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ModelField' ),
'Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' ),
'A message to you, Rudy' ,
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-15 07:47:13 +00:00
$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 ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input select' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'ModelUserId' ),
'User' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'select' => array ( 'name' => 'data[Model][user_id]' , 'id' => 'ModelUserId' ),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => 'value' , 'selected' => 'selected' )),
'good' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => 'other' )),
'bad' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-15 07:47:13 +00:00
$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 ));
2008-04-26 15:09:41 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input select' ),
2008-04-26 15:09:41 +00:00
'label' => array ( 'for' => 'UserUser' ),
'User' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 15:09:41 +00:00
'input' => array ( 'type' => 'hidden' , 'name' => 'data[User][User]' , 'value' => '' ),
'select' => array ( 'name' => 'data[User][User][]' , 'id' => 'UserUser' , 'multiple' => 'multiple' ),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => 'value' , 'selected' => 'selected' )),
'good' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 15:09:41 +00:00
array ( 'option' => array ( 'value' => 'other' )),
'bad' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
'/div'
2008-04-26 15:09:41 +00:00
);
$this -> assertTags ( $result , $expected );
2007-02-26 18:58:18 +00:00
}
2007-10-14 23:41:05 +00:00
function testFormInputs () {
$this -> Form -> create ( 'Contact' );
$result = $this -> Form -> inputs ( 'The Legend' );
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-08 13:14:47 +00:00
'<fieldset' ,
'<legend' ,
2008-04-26 18:44:01 +00:00
'The Legend' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
'*/fieldset' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2008-05-21 03:57:35 +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'
);
$this -> assertTags ( $result , $expected );
2007-10-14 23:41:05 +00:00
2007-11-09 00:17:44 +00:00
$View = ClassRegistry :: getObject ( 'view' );
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-10-14 23:41:05 +00:00
$this -> Form -> params [ 'prefix' ] = 'admin' ;
$this -> Form -> action = 'admin_edit' ;
$result = $this -> Form -> inputs ();
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-08 13:14:47 +00:00
'<fieldset' ,
'<legend' ,
2008-04-26 18:44:01 +00:00
'Edit Contact' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
'*/fieldset' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-14 23:41:05 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-12-30 18:25:00 +00:00
$result = $this -> Form -> inputs ( false );
2008-04-26 18:44:01 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-16 04:41:00 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-10-16 04:41:00 +00:00
$result = $this -> Form -> inputs ( array ( 'fieldset' => false , 'legend' => false ));
2008-04-26 18:44:01 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-30 18:25:00 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-12-30 18:25:00 +00:00
$result = $this -> Form -> inputs ( array ( 'fieldset' => true , 'legend' => false ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-16 04:41:00 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-10-16 04:41:00 +00:00
$result = $this -> Form -> inputs ( array ( 'fieldset' => false , 'legend' => 'Hello' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-30 18:25:00 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-12-30 18:25:00 +00:00
$result = $this -> Form -> inputs ( 'Hello' );
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Hello' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-16 04:41:00 +00:00
2008-02-18 21:58:32 +00:00
$this -> Form -> create ( 'Contact' );
2007-10-16 04:41:00 +00:00
$result = $this -> Form -> inputs ( array ( 'legend' => 'Hello' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Hello' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][id]' , 'value' => '' , 'id' => 'ContactId' ),
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input text' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input password' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input date' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input datetime' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-08 13:14:47 +00:00
'*/div' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-14 23:41:05 +00:00
}
2007-11-17 04:27:24 +00:00
function testSelectAsCheckbox () {
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), array ( 0 , 1 ), array ( 'multiple' => 'checkbox' ));
2008-04-26 18:44:01 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-08 11:57:58 +00:00
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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-08 11:57:58 +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' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-17 04:27:24 +00:00
}
2007-10-04 18:16:44 +00:00
function testLabel () {
2007-03-16 23:35:25 +00:00
$this -> Form -> text ( 'Person/name' );
$result = $this -> Form -> label ();
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonName' ), 'Name' , '/label' ));
2007-03-16 23:35:25 +00:00
2007-03-22 18:47:38 +00:00
$this -> Form -> text ( 'Person.name' );
$result = $this -> Form -> label ();
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonName' ), 'Name' , '/label' ));
2007-03-22 18:47:38 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' );
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonFirstName' ), 'First Name' , '/label' ));
2007-03-16 23:35:25 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' , 'Your first name' );
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonFirstName' ), 'Your first name' , '/label' ));
2007-03-16 23:35:25 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' , 'Your first name' , array ( 'class' => 'my-class' ));
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonFirstName' , 'class' => 'my-class' ), 'Your first name' , '/label' ));
2007-03-16 23:35:25 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' , 'Your first name' , array ( 'class' => 'my-class' , 'id' => 'LabelID' ));
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonFirstName' , 'class' => 'my-class' , 'id' => 'LabelID' ), 'Your first name' , '/label' ));
2007-04-29 03:10:44 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' , '' );
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'PersonFirstName' ), '/label' ));
2008-02-03 06:54:05 +00:00
$result = $this -> Form -> label ( 'Person.2.name' , '' );
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'label' => array ( 'for' => 'Person2Name' ), '/label' ));
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testTextbox () {
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' );
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' )));
2007-02-26 18:58:18 +00:00
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' , array ( 'type' => 'password' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'password' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' )));
2007-02-26 18:58:18 +00:00
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' , array ( 'id' => 'theID' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'theID' )));
2007-03-16 23:35:25 +00:00
2007-10-17 17:08:34 +00:00
$this -> Form -> data [ 'Model' ][ 'text' ] = 'test <strong>HTML</strong> values' ;
$result = $this -> Form -> text ( 'Model/text' );
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][text]' , 'value' => 'test <strong>HTML</strong> values' , 'id' => 'ModelText' )));
2007-10-17 17:08:34 +00:00
2007-03-16 23:35:25 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'text' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'text' ] = 'test' ;
$result = $this -> Form -> text ( 'Model/text' , array ( 'id' => 'theID' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][text]' , 'value' => 'test' , 'id' => 'theID' , 'class' => 'form-error' )));
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testDefaultValue () {
2007-03-23 17:32:02 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = 'test' ;
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' , array ( 'default' => 'default value' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => 'test' , 'id' => 'ModelField' )));
2007-03-23 17:32:02 +00:00
unset ( $this -> Form -> data [ 'Model' ][ 'field' ]);
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' , array ( 'default' => 'default value' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'text' , 'name' => 'data[Model][field]' , 'value' => 'default value' , 'id' => 'ModelField' )));
2007-03-23 17:32:02 +00:00
}
2007-10-04 18:16:44 +00:00
function testFieldError () {
2007-03-23 16:06:48 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$result = $this -> Form -> error ( 'Model.field' );
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , array ( 'div' => array ( 'class' => 'error-message' ), 'Error in field Field' , '/div' ));
2007-03-23 16:06:48 +00:00
$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' );
$result = $this -> Form -> error ( 'Model.field' , " <strong>Badness!</strong> " , array ( 'wrap' => false ));
$this -> assertEqual ( $result , '<strong>Badness!</strong>' );
$result = $this -> Form -> error ( 'Model.field' , " <strong>Badness!</strong> " , array ( 'wrap' => false , 'escape' => true ));
$this -> assertEqual ( $result , '<strong>Badness!</strong>' );
$result = $this -> Form -> error ( 'Model.field' , " <strong>Badness!</strong> " , array ( 'wrap' => false , 'escape' => false ));
$this -> assertEqual ( $result , '<strong>Badness!</strong>' );
}
2007-10-04 18:16:44 +00:00
function testPassword () {
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> password ( 'Model.field' );
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'password' , 'name' => 'data[Model][field]' , 'value' => '' , 'id' => 'ModelField' )));
2007-03-16 23:35:25 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'passwd' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'passwd' ] = 'test' ;
$result = $this -> Form -> password ( 'Model/passwd' , array ( 'id' => 'theID' ));
2008-04-26 18:44:01 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'password' , 'name' => 'data[Model][passwd]' , 'value' => 'test' , 'id' => 'theID' , 'class' => 'form-error' )));
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testRadio () {
2007-10-15 07:47:13 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( 'option A' ));
2008-04-26 18:44:01 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-15 07:47:13 +00:00
2007-08-17 08:50:16 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( 'option A' , 'option B' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '1' , 'id' => 'ModelField1' )),
array ( 'label' => array ( 'for' => 'ModelField1' )),
'option B' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-14 23:41:05 +00:00
2007-10-11 16:45:23 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( 'option A' , 'option B' ), array ( 'separator' => '<br/>' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
'br' => array (),
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '1' , 'id' => 'ModelField1' )),
array ( 'label' => array ( 'for' => 'ModelField1' )),
'option B' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( '1' => 'Yes' , '0' => 'No' ), array ( 'value' => '1' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '1' , 'id' => 'ModelField1' , 'checked' => 'checked' )),
array ( 'label' => array ( 'for' => 'ModelField1' )),
'Yes' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'ModelField0' )),
array ( 'label' => array ( 'for' => 'ModelField0' )),
'No' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-09-07 01:22:03 +00:00
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( '1' => 'Yes' , '0' => 'No' ), array ( 'value' => '0' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '1' , 'id' => 'ModelField1' )),
array ( 'label' => array ( 'for' => 'ModelField1' )),
'Yes' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'ModelField0' , 'checked' => 'checked' )),
array ( 'label' => array ( 'for' => 'ModelField0' )),
'No' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
2008-04-03 02:29:17 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( '1' => 'Yes' , '0' => 'No' ), array ( 'value' => null ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'ModelField0' )),
array ( 'label' => array ( 'for' => 'ModelField0' )),
'No' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
2008-04-03 02:29:17 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( '1' => 'Yes' , '0' => 'No' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Field' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'ModelField0' )),
array ( 'label' => array ( 'for' => 'ModelField0' )),
'No' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2008-04-03 06:48:56 +00:00
2007-10-15 07:47:13 +00:00
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => 'Legend title' , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input radio' ),
2008-04-26 18:44:01 +00:00
'fieldset' => array (),
'legend' => array (),
'Legend title' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Newsletter][subscribe]' , 'value' => '1' , 'id' => 'NewsletterSubscribe1' )),
array ( 'label' => array ( 'for' => 'NewsletterSubscribe1' )),
'Subscribe' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset' ,
'/div'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-15 07:47:13 +00:00
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input radio' ),
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Newsletter][subscribe]' , 'value' => '1' , 'id' => 'NewsletterSubscribe1' )),
array ( 'label' => array ( 'for' => 'NewsletterSubscribe1' )),
'Subscribe' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-15 07:47:13 +00:00
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => 'Legend title' , 'label' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input radio' ),
2008-04-26 18:44:01 +00:00
'fieldset' => array (),
'legend' => array (),
'Legend title' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/fieldset' ,
'/div'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-06 15:55:44 +00:00
2007-10-15 07:47:13 +00:00
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => false , 'label' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
2008-04-26 18:44:01 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input radio' ),
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/div'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-06 15:55:44 +00:00
$result = $this -> Form -> radio ( 'Employee.gender' , array ( 'male' => 'Male' , 'female' => 'Female' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Gender' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Employee][gender]' , 'value' => 'female' , 'id' => 'EmployeeGenderFemale' )),
array ( 'label' => array ( 'for' => 'EmployeeGenderFemale' )),
'Female' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-06 15:55:44 +00:00
$result = $this -> Form -> radio ( 'Officer.gender' , array ( 'male' => 'Male' , 'female' => 'Female' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'fieldset' => array (),
'legend' => array (),
'Gender' ,
2008-05-08 13:14:47 +00:00
'/legend' ,
2008-04-26 18:44:01 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-04-26 18:44:01 +00:00
array ( 'input' => array ( 'type' => 'radio' , 'name' => 'data[Officer][gender]' , 'value' => 'female' , 'id' => 'OfficerGenderFemale' )),
array ( 'label' => array ( 'for' => 'OfficerGenderFemale' )),
'Female' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/fieldset' ,
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-08-17 08:50:16 +00:00
}
2007-10-04 18:16:44 +00:00
function testSelect () {
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> select ( 'Model.field' , array ());
2008-04-26 18:44:01 +00:00
$expected = array (
'select' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$this -> Form -> data = array ( 'Model' => array ( 'field' => 'value' ));
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> select ( 'Model.field' , array ( 'value' => 'good' , 'other' => 'bad' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'select' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'value' , 'selected' => 'selected' )),
'good' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'other' )),
'bad' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-05 00:34:56 +00:00
$this -> Form -> data = array ();
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> select ( 'Model.field' , array ( 'value' => 'good' , 'other' => 'bad' ));
2008-04-26 18:44:01 +00:00
$expected = array (
'select' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'value' )),
'good' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'other' )),
'bad' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> select ( 'Model.field' , array ( 'first' => 'first "html" <chars>' , 'second' => 'value' ), null , array (), false );
2008-04-26 18:44:01 +00:00
$expected = array (
'select' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
array ( 'option' => array ( 'value' => 'first' )),
'first "html" <chars>' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'second' )),
'value' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> select ( 'Model.field' , array ( 'first' => 'first "html" <chars>' , 'second' => 'value' ), null , array ( 'escape' => false ), false );
2008-04-26 18:44:01 +00:00
$expected = array (
'select' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
array ( 'option' => array ( 'value' => 'first' )),
'first "html" <chars>' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-04-26 18:44:01 +00:00
array ( 'option' => array ( 'value' => 'second' )),
'value' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-04-26 18:44:01 +00:00
);
$this -> assertTags ( $result , $expected );
2007-08-13 20:20:01 +00:00
}
2007-10-04 18:16:44 +00:00
function testSelectMultiple () {
2007-08-13 20:20:01 +00:00
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), null , array ( 'multiple' => true ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '1' )),
'second' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-08-13 20:20:01 +00:00
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), null , array ( 'multiple' => 'multiple' ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '1' )),
'second' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-08-13 20:20:01 +00:00
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), array ( 0 , 1 ), array ( 'multiple' => true ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '1' , 'selected' => 'selected' )),
'second' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
}
2007-05-25 03:16:47 +00:00
2007-11-15 20:07:46 +00:00
function testSelectMultipleCheckboxes () {
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), null , array ( 'multiple' => 'checkbox' ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +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' )),
'second' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +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' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-15 20:07:46 +00:00
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'a' => 'first' , 'b' => 'second' , 'c' => 'third' ), null , array ( 'multiple' => 'checkbox' ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +00:00
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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +00:00
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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-15 20:07:46 +00:00
$result = $this -> Form -> select ( 'Model.multi_field' , array ( '1' => 'first' ), null , array ( 'multiple' => 'checkbox' ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-15 20:07:46 +00:00
}
2007-11-16 05:27:16 +00:00
function testInputMultipleCheckboxes () {
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( 'first' , 'second' , 'third' ), 'multiple' => 'checkbox' ));
2008-05-01 22:09:16 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-01 22:09:16 +00:00
array ( 'label' => array ( 'for' => 'ModelMultiField' )),
'Multi Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +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' )),
'second' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +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' )),
'third' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-16 05:27:16 +00:00
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( 'a' => 'first' , 'b' => 'second' , 'c' => 'third' ), 'multiple' => 'checkbox' ));
2008-05-01 22:09:16 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
array ( 'div' => array ( 'class' => 'input select' )),
2008-05-01 22:09:16 +00:00
array ( 'label' => array ( 'for' => 'ModelMultiField' )),
'Multi Field' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
'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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +00:00
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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
2008-05-01 22:09:16 +00:00
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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-16 05:27:16 +00:00
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( '1' => 'first' ), 'multiple' => 'checkbox' , 'label' => false , 'div' => false ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-16 05:27:16 +00:00
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( '2' => 'second' ), 'multiple' => 'checkbox' , 'label' => false , 'div' => false ));
2008-05-01 22:09:16 +00:00
$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' ,
2008-05-08 13:14:47 +00:00
'/label' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-11-16 05:27:16 +00:00
}
2007-10-04 18:16:44 +00:00
function testCheckbox () {
2007-07-26 14:23:38 +00:00
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'id' => 'theID' , 'value' => 'myvalue' ));
2008-05-01 22:09:16 +00:00
$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 );
2007-07-26 14:23:38 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'field' ] = 'myvalue' ;
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'id' => 'theID' , 'value' => 'myvalue' ));
2008-05-01 22:09:16 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'theID_' ),
2008-05-08 11:32:31 +00:00
array ( 'input' => array ( 'preg:/[^<]+/' , 'value' => 'myvalue' , 'id' => 'theID' , 'checked' => 'checked' , 'class' => 'form-error' ))
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-07-26 14:23:38 +00:00
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'value' => 'myvalue' ));
2008-05-01 22:09:16 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[Model][field]' , 'value' => '0' , 'id' => 'ModelField_' ),
2008-05-08 11:32:31 +00:00
array ( 'input' => array ( 'preg:/[^<]+/' , 'value' => 'myvalue' , 'id' => 'ModelField' , 'checked' => 'checked' , 'class' => 'form-error' ))
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-07-26 14:23:38 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'id' => 'theID' ));
2008-05-01 22:09:16 +00:00
$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 );
2007-10-28 04:18:18 +00:00
2007-07-26 14:23:38 +00:00
unset ( $this -> Form -> validationErrors [ 'Model' ][ 'field' ]);
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'value' => 'myvalue' ));
2008-05-01 22:09:16 +00:00
$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 );
2007-07-26 14:23:38 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> checkbox ( 'Contact.name' , array ( 'value' => 'myvalue' ));
2008-05-01 22:09:16 +00:00
$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 );
2007-07-26 14:23:38 +00:00
$result = $this -> Form -> checkbox ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$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 );
2007-10-28 04:18:18 +00:00
2007-10-24 02:51:15 +00:00
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'checked' => false ));
2008-05-01 22:09:16 +00:00
$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 );
2007-10-28 04:18:18 +00:00
2007-07-26 14:23:38 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$this -> Form -> data [ 'Contact' ][ 'published' ] = 1 ;
$result = $this -> Form -> checkbox ( 'Contact.published' , array ( 'id' => 'theID' ));
2008-05-01 22:09:16 +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' ))
);
$this -> assertTags ( $result , $expected );
2007-07-26 14:23:38 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$this -> Form -> data [ 'Contact' ][ 'published' ] = 0 ;
$result = $this -> Form -> checkbox ( 'Contact.published' , array ( 'id' => 'theID' ));
2008-05-01 22:09:16 +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' ))
);
$this -> assertTags ( $result , $expected );
2008-04-18 00:58:47 +00:00
$result = $this -> Form -> checkbox ( 'Model.CustomField.1.value' );
2008-05-01 22:09:16 +00:00
$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 );
2008-04-18 00:58:47 +00:00
$result = $this -> Form -> checkbox ( 'CustomField.1.value' );
2008-05-01 22:09:16 +00:00
$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 );
2007-07-26 14:23:38 +00:00
}
2007-12-21 19:09:46 +00:00
function testDateTime () {
2008-05-08 11:32:31 +00:00
Configure :: write ( 'FormHelperTest.regex' , 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]*)*/' ,
));
extract ( Configure :: read ( 'FormHelperTest.regex' ));
2008-05-10 03:20:06 +00:00
2007-12-21 19:09:46 +00:00
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' , null , array (), false );
2008-05-01 22:09:16 +00:00
$now = strtotime ( 'now' );
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'd' , $now ), 'selected' => 'selected' )),
date ( 'j' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'm' , $now ), 'selected' => 'selected' )),
date ( 'F' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'Y' , $now ), 'selected' => 'selected' )),
date ( 'Y' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'h' , $now ), 'selected' => 'selected' )),
date ( 'g' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => intval ( date ( 'i' , $now )), 'selected' => 'selected' )),
date ( 'i' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'a' , $now ), 'selected' => 'selected' )),
date ( 'a' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
2008-05-08 13:14:47 +00:00
$this -> assertTags ( $result , $expected );
2007-12-21 19:09:46 +00:00
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-21 19:09:46 +00:00
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' , false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
2007-12-21 19:09:46 +00:00
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' , '' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
2007-12-21 19:09:46 +00:00
2007-12-25 06:45:48 +00:00
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' , '' , array ( 'interval' => 5 ));
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '5' )),
'05' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
2008-04-04 12:48:13 +00:00
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' , '' , array ( 'minuteInterval' => 5 ));
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '5' )),
'05' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
2007-12-25 06:45:48 +00:00
2007-12-21 19:09:46 +00:00
$this -> Form -> data [ 'Contact' ][ 'data' ] = null ;
$result = $this -> Form -> dateTime ( 'Contact.date' , 'DMY' , '12' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][date][day]' , 'id' => 'ContactDateDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][month]' , 'id' => 'ContactDateMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][year]' , 'id' => 'ContactDateYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][hour]' , 'id' => 'ContactDateHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][date][min]' , 'id' => 'ContactDateMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][date][meridian]' , 'id' => 'ContactDateMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
$this -> assertNoPattern ( '/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/' , $result );
2008-02-18 21:58:32 +00:00
2008-05-01 22:09:16 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = date ( 'Y' ) . '-01-01 00:00:00' ;
$now = strtotime ( $this -> Form -> data [ 'Model' ][ 'field' ]);
2008-01-21 12:53:37 +00:00
$result = $this -> Form -> dateTime ( 'Model.field' , 'DMY' , '12' , null , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][day]' , 'id' => 'ModelFieldDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'd' , $now ), 'selected' => 'selected' )),
date ( 'j' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Model][field][month]' , 'id' => 'ModelFieldMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'm' , $now ), 'selected' => 'selected' )),
date ( 'F' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Model][field][year]' , 'id' => 'ModelFieldYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'Y' , $now ), 'selected' => 'selected' )),
date ( 'Y' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Model][field][hour]' , 'id' => 'ModelFieldHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'h' , $now ), 'selected' => 'selected' )),
date ( 'g' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Model][field][min]' , 'id' => 'ModelFieldMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => intval ( date ( 'i' , $now )), 'selected' => 'selected' )),
date ( 'i' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Model][field][meridian]' , 'id' => 'ModelFieldMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'a' , $now ), 'selected' => 'selected' )),
date ( 'a' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-02-11 02:20:43 +00:00
$this -> Form -> create ( 'Contact' );
$result = $this -> Form -> input ( 'published' );
2008-05-01 22:09:16 +00:00
$now = strtotime ( 'now' );
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input date' ),
2008-05-01 22:09:16 +00:00
'label' => array ( 'for' => 'ContactPublishedMonth' ),
'Published' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][published][month]' , 'id' => 'ContactPublishedMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'm' , $now ), 'selected' => 'selected' )),
date ( 'F' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][published][day]' , 'id' => 'ContactPublishedDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'd' , $now ), 'selected' => 'selected' )),
date ( 'j' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'Y' , $now ), 'selected' => 'selected' )),
date ( 'Y' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-02-11 02:20:43 +00:00
$result = $this -> Form -> input ( 'published2' , array ( 'type' => 'date' ));
2008-05-01 22:09:16 +00:00
$now = strtotime ( 'now' );
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input date' ),
2008-05-01 22:09:16 +00:00
'label' => array ( 'for' => 'ContactPublished2Month' ),
'Published2' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][published2][month]' , 'id' => 'ContactPublished2Month' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'm' , $now ), 'selected' => 'selected' )),
date ( 'F' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][published2][day]' , 'id' => 'ContactPublished2Day' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'd' , $now ), 'selected' => 'selected' )),
date ( 'j' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][published2][year]' , 'id' => 'ContactPublished2Year' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => date ( 'Y' , $now ), 'selected' => 'selected' )),
date ( 'Y' , $now ),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-02-18 21:58:32 +00:00
$result = $this -> Form -> input ( 'ContactTag' );
2008-05-01 22:09:16 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input select' ),
2008-05-01 22:09:16 +00:00
'label' => array ( 'for' => 'ContactTagContactTag' ),
'Contact Tag' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[ContactTag][ContactTag]' , 'value' => '' )),
array ( 'select' => array ( 'name' => 'data[ContactTag][ContactTag][]' , 'multiple' => 'multiple' , 'id' => 'ContactTagContactTag' )),
2008-05-08 13:14:47 +00:00
'/select' ,
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-05-24 04:00:26 +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'
);
$this -> assertTags ( $result , $expected );
2007-12-21 19:09:46 +00:00
2008-05-24 04:00:26 +00:00
}
2008-03-09 07:36:34 +00:00
function testFormDateTimeMulti () {
2008-05-08 11:32:31 +00:00
extract ( Configure :: read ( 'FormHelperTest.regex' ));
2008-03-09 07:36:34 +00:00
$result = $this -> Form -> dateTime ( 'Contact.1.updated' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][day]' , 'id' => 'Contact1UpdatedDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][month]' , 'id' => 'Contact1UpdatedMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][year]' , 'id' => 'Contact1UpdatedYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][hour]' , 'id' => 'Contact1UpdatedHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][min]' , 'id' => 'Contact1UpdatedMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][1][updated][meridian]' , 'id' => 'Contact1UpdatedMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-03-09 07:36:34 +00:00
$result = $this -> Form -> dateTime ( 'Contact.2.updated' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][day]' , 'id' => 'Contact2UpdatedDay' )),
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][month]' , 'id' => 'Contact2UpdatedMonth' )),
2008-05-08 11:32:31 +00:00
$monthsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][year]' , 'id' => 'Contact2UpdatedYear' )),
2008-05-08 11:32:31 +00:00
$yearsRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][hour]' , 'id' => 'Contact2UpdatedHour' )),
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
':' ,
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][min]' , 'id' => 'Contact2UpdatedMin' )),
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-08 11:32:31 +00:00
' ' ,
2008-05-01 22:09:16 +00:00
array ( 'select' => array ( 'name' => 'data[Contact][2][updated][meridian]' , 'id' => 'Contact2UpdatedMeridian' )),
2008-05-08 11:32:31 +00:00
$meridianRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-03-09 07:36:34 +00:00
}
2008-02-18 21:58:32 +00:00
2007-10-04 18:16:44 +00:00
function testMonth () {
2007-05-24 23:14:14 +00:00
$result = $this -> Form -> month ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][month]' , 'id' => 'ModelFieldMonth' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
date ( 'F' , strtotime ( '2008-01-01 00:00:00' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
date ( 'F' , strtotime ( '2008-02-01 00:00:00' )),
2008-05-08 13:14:47 +00:00
'/option' ,
'*/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2008-05-24 04:00:26 +00:00
$result = $this -> Form -> month ( 'Model.field' , null , array (), true , false );
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][month]' , 'id' => 'ModelFieldMonth' )),
array ( 'option' => array ( 'value' => '' )),
'/option' ,
array ( 'option' => array ( 'value' => '01' )),
date ( 'm' , strtotime ( '2008-01-01 00:00:00' )),
'/option' ,
array ( 'option' => array ( 'value' => '02' )),
date ( 'm' , strtotime ( '2008-02-01 00:00:00' )),
'/option' ,
'*/select' ,
);
$this -> assertTags ( $result , $expected );
2007-05-24 23:14:14 +00:00
}
2007-05-25 03:16:47 +00:00
2007-10-04 18:16:44 +00:00
function testDay () {
2008-05-08 11:32:31 +00:00
extract ( Configure :: read ( 'FormHelperTest.regex' ));
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> day ( 'Model.field' , false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][day]' , 'id' => 'ModelFieldDay' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-05-30 01:21:58 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 23:12:32' ;
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> day ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][day]' , 'id' => 'ModelFieldDay' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' , 'selected' => 'selected' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> day ( 'Model.field' , '10' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][day]' , 'id' => 'ModelFieldDay' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' , 'selected' => 'selected' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-05-30 01:21:58 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 23:12:32' ;
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> day ( 'Model.field' , true );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][day]' , 'id' => 'ModelFieldDay' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' , 'selected' => 'selected' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$daysRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-01 04:55:56 +00:00
}
2007-12-25 06:45:48 +00:00
function testMinute () {
2008-05-08 11:32:31 +00:00
extract ( Configure :: read ( 'FormHelperTest.regex' ));
2007-12-25 06:45:48 +00:00
$result = $this -> Form -> minute ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][min]' , 'id' => 'ModelFieldMin' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '1' )),
'01' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2' )),
'02' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-25 06:45:48 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 00:12:32' ;
$result = $this -> Form -> minute ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][min]' , 'id' => 'ModelFieldMin' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '1' )),
'01' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2' )),
'02' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '12' , 'selected' => 'selected' )),
'12' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-25 06:45:48 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> minute ( 'Model.field' , null , array ( 'interval' => 5 ));
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][min]' , 'id' => 'ModelFieldMin' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '5' )),
'05' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-25 06:45:48 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 00:10:32' ;
$result = $this -> Form -> minute ( 'Model.field' , null , array ( 'interval' => 5 ));
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][min]' , 'id' => 'ModelFieldMin' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '0' )),
'00' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '5' )),
'05' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '10' , 'selected' => 'selected' )),
'10' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$minutesRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-12-25 06:45:48 +00:00
}
2007-10-04 18:16:44 +00:00
function testHour () {
2008-05-08 11:32:31 +00:00
extract ( Configure :: read ( 'FormHelperTest.regex' ));
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> hour ( 'Model.field' , false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][hour]' , 'id' => 'ModelFieldHour' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-25 00:24:19 +00:00
2007-05-30 01:21:58 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 00:12:32' ;
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> hour ( 'Model.field' , false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][hour]' , 'id' => 'ModelFieldHour' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '12' , 'selected' => 'selected' )),
'12' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
2008-05-08 11:32:31 +00:00
$result = $this -> Form -> hour ( 'Model.field' , true , '23' );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][hour]' , 'id' => 'ModelFieldHour' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '00' )),
'0' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$hoursRegex ,
array ( 'option' => array ( 'value' => '23' , 'selected' => 'selected' )),
2008-05-01 22:09:16 +00:00
'23' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-05-30 01:21:58 +00:00
$this -> Form -> data [ 'Model' ][ 'field' ] = '2006-10-10 00:12:32' ;
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> hour ( 'Model.field' , true );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][hour]' , 'id' => 'ModelFieldHour' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '00' , 'selected' => 'selected' )),
'0' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '01' )),
'1' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '02' )),
'2' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-08 11:32:31 +00:00
$hoursRegex ,
2008-05-08 13:14:47 +00:00
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-01 15:07:27 +00:00
}
2007-04-25 00:24:19 +00:00
2007-10-04 18:16:44 +00:00
function testYear () {
2007-04-01 14:31:23 +00:00
$result = $this -> Form -> year ( 'Model.field' , 2006 , 2007 );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Model][field][year]' , 'id' => 'ModelFieldYear' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , null , array ( 'class' => 'year' ));
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' , 'class' => 'year' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '2006-10-10' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , null , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' , 'selected' => 'selected' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '2006-10-10' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , false , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' , 'selected' => 'selected' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , 2007 );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '' )),
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' , 'selected' => 'selected' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '2006-10-10' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , 2007 , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '2007' , 'selected' => 'selected' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2008 , 2007 , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '2008' )),
'2008' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' , 'selected' => 'selected' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '2006-10-10' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2008 , null , array (), false );
2008-05-01 22:09:16 +00:00
$expected = array (
array ( 'select' => array ( 'name' => 'data[Contact][published][year]' , 'id' => 'ContactPublishedYear' )),
array ( 'option' => array ( 'value' => '2008' )),
'2008' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2007' )),
'2007' ,
2008-05-08 13:14:47 +00:00
'/option' ,
2008-05-01 22:09:16 +00:00
array ( 'option' => array ( 'value' => '2006' , 'selected' => 'selected' )),
'2006' ,
2008-05-08 13:14:47 +00:00
'/option' ,
'/select' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-04-01 14:31:23 +00:00
}
2007-04-25 00:24:19 +00:00
2007-10-04 18:16:44 +00:00
function testTextArea () {
2007-03-16 23:35:25 +00:00
$this -> Form -> data = array ( 'Model' => array ( 'field' => 'some test data' ));
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> textarea ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
'textarea' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
'some test data' ,
2008-05-08 13:14:47 +00:00
'/textarea' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> textarea ( 'Model/tmp' );
2008-05-01 22:09:16 +00:00
$expected = array (
'textarea' => array ( 'name' => 'data[Model][tmp]' , 'id' => 'ModelTmp' ),
2008-05-08 13:14:47 +00:00
'/textarea' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-10-17 17:08:34 +00:00
$this -> Form -> data = array ( 'Model' => array ( 'field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars' ));
$result = $this -> Form -> textarea ( 'Model.field' );
2008-05-01 22:09:16 +00:00
$expected = array (
'textarea' => array ( 'name' => 'data[Model][field]' , 'id' => 'ModelField' ),
htmlentities ( 'some <strong>test</strong> data with <a href="#">HTML</a> chars' ),
2008-05-08 13:14:47 +00:00
'/textarea' ,
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testHiddenField () {
2007-03-16 23:35:25 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'field' ] = 'test' ;
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> hidden ( 'Model.field' , array ( 'id' => 'theID' ));
2008-05-01 22:09:16 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[Model][field]' , 'id' => 'theID' , 'value' => 'test' )));
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testFileUploadField () {
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> file ( 'Model.upload' );
2008-05-01 22:09:16 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'file' , 'name' => 'data[Model][upload]' , 'id' => 'ModelUpload' , 'value' => '' )));
2007-12-21 19:09:46 +00:00
2007-12-15 23:46:56 +00:00
$this -> Form -> data [ 'Model.upload' ] = array ( " name " => " " , " type " => " " , " tmp_name " => " " , " error " => 4 , " size " => 0 );
$result = $this -> Form -> input ( 'Model.upload' , array ( 'type' => 'file' ));
2008-05-01 22:09:16 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input file' ),
2008-05-01 22:09:16 +00:00
'label' => array ( 'for' => 'ModelUpload' ),
'Upload' ,
2008-05-08 13:14:47 +00:00
'/label' ,
2008-05-01 22:09:16 +00:00
'input' => array ( 'type' => 'file' , 'name' => 'data[Model][upload]' , 'id' => 'ModelUpload' , 'value' => '' ),
2008-05-08 13:14:47 +00:00
'/div'
2008-05-01 22:09:16 +00:00
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
}
2007-12-22 01:27:50 +00:00
function testButton () {
$result = $this -> Form -> button ( 'Hi' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'button' , 'value' => 'Hi' )));
2007-12-22 01:27:50 +00:00
$result = $this -> Form -> button ( 'Clear Form' , array ( 'type' => 'clear' ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'clear' , 'value' => 'Clear Form' )));
2007-12-22 01:27:50 +00:00
$result = $this -> Form -> button ( 'Reset Form' , array ( 'type' => 'reset' ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'reset' , 'value' => 'Reset Form' )));
2007-12-22 01:27:50 +00:00
$result = $this -> Form -> button ( 'Options' , array ( 'type' => 'reset' , 'name' => 'Post.options' ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'reset' , 'name' => 'data[Post][options]' , 'id' => 'PostOptions' , 'value' => 'Options' )));
2007-12-22 01:27:50 +00:00
$result = $this -> Form -> button ( 'Options' , array ( 'type' => 'reset' , 'name' => 'Post.options' , 'id' => 'Opt' ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'reset' , 'name' => 'data[Post][options]' , 'id' => 'Opt' , 'value' => 'Options' )));
2007-12-22 01:27:50 +00:00
}
2007-10-04 18:16:44 +00:00
function testSubmitButton () {
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> submit ( 'Test Submit' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Test Submit' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-04-25 00:24:19 +00:00
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> submit ( 'Test Submit' , array ( 'class' => 'save' , 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array ( 'input' => array ( 'type' => 'submit' , 'value' => 'Test Submit' , 'class' => 'save' ));
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> submit ( 'Test Submit' , array ( 'div' => array ( 'id' => 'SaveButton' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' , 'id' => 'SaveButton' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Test Submit' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2007-04-28 07:42:54 +00:00
$result = $this -> Form -> submit ( 'Next >' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Next >' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> submit ( 'Next >' , array ( 'escape' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Next >' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-12-15 18:46:02 +00:00
$result = $this -> Form -> submit ( 'http://example.com/cake.power.gif' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'image' , 'src' => 'http://example.com/cake.power.gif' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-12-15 18:46:02 +00:00
$result = $this -> Form -> submit ( '/relative/cake.power.gif' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'image' , 'src' => 'relative/cake.power.gif' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-12-15 18:46:02 +00:00
$result = $this -> Form -> submit ( 'cake.power.gif' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'image' , 'src' => 'img/cake.power.gif' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-12-21 19:09:46 +00:00
2007-12-15 18:46:02 +00:00
$result = $this -> Form -> submit ( 'Not.an.image' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Not.an.image' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
}
2007-10-04 18:16:44 +00:00
function testFormCreate () {
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> create ( 'Contact' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'post' , 'action' => '/contacts/add/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'GET' ));
2008-05-10 03:20:06 +00:00
$expected = array ( 'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'get' , 'action' => '/contacts/add/' ));
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'get' ));
2008-05-10 03:20:06 +00:00
$expected = array ( 'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'get' , 'action' => '/contacts/add/' ));
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'put' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'post' , 'action' => '/contacts/add/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'PUT' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
$this -> Form -> data [ 'Contact' ][ 'id' ] = 1 ;
$result = $this -> Form -> create ( 'Contact' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactEditForm' , 'method' => 'post' , 'action' => '/contacts/edit/1' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'PUT' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-04-29 03:10:44 +00:00
2008-04-17 20:31:49 +00:00
$this -> Form -> data [ 'ContactNonStandardPk' ][ 'pk' ] = 1 ;
$result = $this -> Form -> create ( 'ContactNonStandardPk' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactNonStandardPkEditForm' , 'method' => 'post' , 'action' => '/contact_non_standard_pks/edit/1' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'PUT' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2008-04-17 20:31:49 +00:00
2007-04-28 09:20:35 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'id' => 'TestId' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'TestId' , 'method' => 'post' , 'action' => '/contacts/edit/1' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'PUT' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-08-15 14:18:39 +00:00
$result = $this -> Form -> create ( 'User' , array ( 'url' => array ( 'action' => 'login' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'UserAddForm' , 'method' => 'post' , 'action' => '/users/login/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-08-15 14:18:39 +00:00
$result = $this -> Form -> create ( 'User' , array ( 'action' => 'login' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'UserLoginForm' , 'method' => 'post' , 'action' => '/users/login/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-10-07 14:13:03 +00:00
$result = $this -> Form -> create ( 'User' , array ( 'url' => '/users/login' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'method' => 'post' , 'action' => '/users/login' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-10-23 02:36:07 +00:00
$this -> Form -> params [ 'controller' ] = 'pages' ;
$this -> Form -> params [ 'models' ] = array ( 'User' , 'Post' );
$result = $this -> Form -> create ( 'User' , array ( 'action' => 'signup' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'UserSignupForm' , 'method' => 'post' , 'action' => '/users/signup/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-03-16 23:35:25 +00:00
}
2007-05-21 05:15:26 +00:00
2007-10-09 20:44:28 +00:00
function testGetFormCreate () {
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'get' ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'get' , 'action' => '/contacts/add/' )));
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> text ( 'Contact.name' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'name' => 'name' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactName' )));
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> password ( 'password' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'name' => 'password' , 'type' => 'password' , 'value' => '' , 'id' => 'ContactPassword' )));
2007-10-09 20:44:28 +00:00
$this -> assertNoPattern ( '/<input[^<>]+[^id|name|type|value]=[^<>]*>$/' , $result );
2007-11-17 04:27:24 +00:00
$result = $this -> Form -> text ( 'user_form' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'name' => 'user_form' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactUserForm' )));
2007-10-09 20:44:28 +00:00
}
2007-10-14 22:55:37 +00:00
function testEditFormWithData () {
$this -> Form -> data = array ( 'Person' => array (
'id' => 1 ,
'first_name' => 'Nate' ,
'last_name' => 'Abele' ,
2008-05-10 03:20:06 +00:00
'email' => 'nate@example.com'
2007-10-14 22:55:37 +00:00
));
2008-03-09 07:36:34 +00:00
$this -> Form -> params = array ( 'models' => array ( 'Person' ), 'controller' => 'people' );
2007-10-14 22:55:37 +00:00
$options = array ( 1 => 'Nate' , 2 => 'Garrett' , 3 => 'Larry' );
$this -> Form -> create ();
$result = $this -> Form -> select ( 'People.People' , $options , null , array ( 'multiple' => true ));
2008-05-10 03:20:06 +00:00
$expected = array (
'input' => array ( 'type' => 'hidden' , 'name' => 'data[People][People]' , 'value' => '' ),
'select' => array ( 'name' => 'data[People][People][]' , 'multiple' => 'multiple' , 'id' => 'PeoplePeople' ),
array ( 'option' => array ( 'value' => 1 )),
'Nate' ,
'/option' ,
array ( 'option' => array ( 'value' => 2 )),
'Garrett' ,
'/option' ,
array ( 'option' => array ( 'value' => 3 )),
'Larry' ,
'/option' ,
'/select'
);
$this -> assertTags ( $result , $expected );
2007-10-14 22:55:37 +00:00
}
2008-05-19 12:17:37 +00:00
2007-10-04 18:16:44 +00:00
function testFormMagicInput () {
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> create ( 'Contact' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'post' , 'action' => '/contacts/add/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'name' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'ContactName' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2008-05-19 12:17:37 +00:00
$result = $this -> Form -> input ( 'non_existing_field_in_contact_model' );
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-19 12:17:37 +00:00
'label' => array ( 'for' => 'ContactNonExistingFieldInContactModel' ),
'Non Existing Field In Contact Model' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][non_existing_field_in_contact_model]' , 'value' => '' , 'id' => 'ContactNonExistingFieldInContactModel' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-07-07 23:30:40 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'Address.street' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'AddressStreet' ),
'Street' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Address][street]' , 'value' => '' , 'id' => 'AddressStreet' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2008-05-19 12:17:37 +00:00
$result = $this -> Form -> input ( 'Address.non_existing_field_in_model' );
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-19 12:17:37 +00:00
'label' => array ( 'for' => 'AddressNonExistingFieldInModel' ),
'Non Existing Field In Model' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Address][non_existing_field_in_model]' , 'value' => '' , 'id' => 'AddressNonExistingFieldInModel' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'name' , array ( 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactName' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' )
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.non_existing' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text required' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'ContactNonExisting' ),
'Non Existing' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][non_existing]' , 'value' => '' , 'id' => 'ContactNonExisting' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2008-01-21 00:39:44 +00:00
$result = $this -> Form -> input ( 'Contact.imnotrequired' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'ContactImnotrequired' ),
'Imnotrequired' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][imnotrequired]' , 'value' => '' , 'id' => 'ContactImnotrequired' ),
'/div'
);
$this -> assertTags ( $result , $expected );
extract ( Configure :: read ( 'FormHelperTest.regex' ));
$now = strtotime ( 'now' );
2008-01-21 00:39:44 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.published' , array ( 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'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 ),
'*/select'
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.updated' , array ( 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactUpdatedMonth' ),
'Updated' ,
'/label' ,
array ( 'select' => array ( 'name' => 'data[Contact][updated][month]' , 'id' => 'ContactUpdatedMonth' )),
$monthsRegex ,
array ( 'option' => array ( 'value' => date ( 'm' , $now ), 'selected' => 'selected' )),
date ( 'F' , $now ),
'/option' ,
'*/select' ,
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][updated][day]' , 'id' => 'ContactUpdatedDay' )),
$daysRegex ,
array ( 'option' => array ( 'value' => date ( 'd' , $now ), 'selected' => 'selected' )),
date ( 'j' , $now ),
'/option' ,
'*/select' ,
'-' ,
array ( 'select' => array ( 'name' => 'data[Contact][updated][year]' , 'id' => 'ContactUpdatedYear' )),
$yearsRegex ,
array ( 'option' => array ( 'value' => date ( 'Y' , $now ), 'selected' => 'selected' )),
date ( 'Y' , $now ),
'*/select'
);
$this -> assertTags ( $result , $expected );
2007-05-13 12:07:23 +00:00
}
2007-05-21 05:15:26 +00:00
2007-11-07 23:01:58 +00:00
function testForMagicInputNonExistingNorValidated () {
$result = $this -> Form -> create ( 'Contact' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'post' , 'action' => '/contacts/add/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-11-07 23:01:58 +00:00
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactNonExistingNorValidated' ),
'Non Existing Nor Validated' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][non_existing_nor_validated]' , 'value' => '' , 'id' => 'ContactNonExistingNorValidated' )
);
$this -> assertTags ( $result , $expected );
2007-11-07 23:01:58 +00:00
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false , 'value' => 'my value' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactNonExistingNorValidated' ),
'Non Existing Nor Validated' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][non_existing_nor_validated]' , 'value' => 'my value' , 'id' => 'ContactNonExistingNorValidated' )
);
$this -> assertTags ( $result , $expected );
2007-11-07 23:01:58 +00:00
$this -> Form -> data = array ( 'Contact' => array ( 'non_existing_nor_validated' => 'CakePHP magic' ));
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactNonExistingNorValidated' ),
'Non Existing Nor Validated' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][non_existing_nor_validated]' , 'value' => 'CakePHP magic' , 'id' => 'ContactNonExistingNorValidated' )
);
$this -> assertTags ( $result , $expected );
2007-11-07 23:01:58 +00:00
}
2007-10-04 18:16:44 +00:00
function testFormMagicInputLabel () {
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> create ( 'Contact' );
2008-05-10 03:20:06 +00:00
$expected = array (
'form' => array ( 'id' => 'ContactAddForm' , 'method' => 'post' , 'action' => '/contacts/add/' ),
'fieldset' => array ( 'style' => 'preg:/display\s*\:\s*none;\s*/' ),
'input' => array ( 'type' => 'hidden' , 'name' => '_method' , 'value' => 'POST' ),
'/fieldset'
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.name' , array ( 'div' => false , 'label' => false ));
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'name' => 'data[Contact][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' )));
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.name' , array ( 'div' => false , 'label' => 'My label' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactName' ),
'My label' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' )
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.name' , array ( 'div' => false , 'label' => array ( 'class' => 'mandatory' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactName' , 'class' => 'mandatory' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' )
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.name' , array ( 'div' => false , 'label' => array ( 'class' => 'mandatory' , 'text' => 'My label' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'ContactName' , 'class' => 'mandatory' ),
'My label' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'ContactName' , 'maxlength' => '255' )
);
$this -> assertTags ( $result , $expected );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.name' , array ( 'div' => false , 'id' => 'my_id' , 'label' => array ( 'for' => 'my_id' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'label' => array ( 'for' => 'my_id' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'my_id' , 'maxlength' => '255' )
);
$this -> assertTags ( $result , $expected );
2008-01-10 18:50:31 +00:00
$result = $this -> Form -> input ( '1.id' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[Contact][1][id]' , 'value' => '' , 'id' => 'Contact1Id' )));
2008-01-10 18:50:31 +00:00
$result = $this -> Form -> input ( " 1.name " );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'Contact1Name' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Contact][1][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'Contact1Name' , 'maxlength' => '255' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2008-01-10 18:50:31 +00:00
$result = $this -> Form -> input ( " Model.1.id " );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[Model][1][id]' , 'value' => '' , 'id' => 'Model1Id' )));
2008-01-10 18:50:31 +00:00
$result = $this -> Form -> input ( " Model.1.name " );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'Model1Name' ),
'Name' ,
'/label' ,
'input' => array ( 'type' => 'text' , 'name' => 'data[Model][1][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'Model1Name' , 'maxlength' => '255' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2007-05-13 12:07:23 +00:00
}
2007-03-16 23:35:25 +00:00
2007-10-04 18:16:44 +00:00
function testFormEnd () {
2007-03-16 23:35:25 +00:00
$this -> assertEqual ( $this -> Form -> end (), '</form>' );
2007-05-25 03:16:47 +00:00
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> end ( 'save' );
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'save' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-05-25 03:16:47 +00:00
2007-11-29 07:33:51 +00:00
$result = $this -> Form -> end ( array ( 'label' => 'save' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'save' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-11-29 07:33:51 +00:00
$result = $this -> Form -> end ( array ( 'label' => 'save' , 'name' => 'Whatever' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'save' , 'name' => 'Whatever' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-11-29 07:33:51 +00:00
$result = $this -> Form -> end ( array ( 'name' => 'Whatever' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'submit' ),
'input' => array ( 'type' => 'submit' , 'value' => 'Submit' , 'name' => 'Whatever' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-11-29 07:33:51 +00:00
$result = $this -> Form -> end ( array ( 'label' => 'save' , 'name' => 'Whatever' , 'div' => 'good' ));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'good' ),
'input' => array ( 'type' => 'submit' , 'value' => 'save' , 'name' => 'Whatever' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-11-29 07:33:51 +00:00
$result = $this -> Form -> end ( array ( 'label' => 'save' , 'name' => 'Whatever' , 'div' => array ( 'class' => 'good' )));
2008-05-10 03:20:06 +00:00
$expected = array (
'div' => array ( 'class' => 'good' ),
'input' => array ( 'type' => 'submit' , 'value' => 'save' , 'name' => 'Whatever' ),
'/div' ,
'/form'
);
$this -> assertTags ( $result , $expected );
2007-02-06 17:18:23 +00:00
}
2007-05-25 03:16:47 +00:00
2007-12-06 07:43:19 +00:00
function testMultipleFormWithIdFields () {
$this -> Form -> create ( 'UserForm' );
$result = $this -> Form -> input ( 'id' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[UserForm][id]' , 'value' => '' , 'id' => 'UserFormId' )));
2007-12-06 07:43:19 +00:00
$result = $this -> Form -> input ( 'My.id' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[My][id]' , 'value' => '' , 'id' => 'MyId' )));
2007-12-06 07:43:19 +00:00
$result = $this -> Form -> input ( 'MyOther.id' );
2008-05-10 03:20:06 +00:00
$this -> assertTags ( $result , array ( 'input' => array ( 'type' => 'hidden' , 'name' => 'data[MyOther][id]' , 'value' => '' , 'id' => 'MyOtherId' )));
2007-12-06 07:43:19 +00:00
}
2008-03-10 00:25:59 +00:00
2008-02-28 00:23:28 +00:00
function testDbLessModel () {
$this -> Form -> create ( 'TestMail' );
$result = $this -> Form -> input ( 'name' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'TestMailName' ),
'Name' ,
'/label' ,
'input' => array ( 'name' => 'data[TestMail][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'TestMailName' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2008-02-28 00:23:28 +00:00
ClassRegistry :: init ( 'TestMail' );
$this -> Form -> create ( 'TestMail' );
$result = $this -> Form -> input ( 'name' );
2008-05-10 03:20:06 +00:00
$expected = array (
2008-05-19 21:01:02 +00:00
'div' => array ( 'class' => 'input text' ),
2008-05-10 03:20:06 +00:00
'label' => array ( 'for' => 'TestMailName' ),
'Name' ,
'/label' ,
'input' => array ( 'name' => 'data[TestMail][name]' , 'type' => 'text' , 'value' => '' , 'id' => 'TestMailName' ),
'/div'
);
$this -> assertTags ( $result , $expected );
2008-02-28 00:23:28 +00:00
}
2007-12-06 07:43:19 +00:00
2007-02-06 17:18:23 +00:00
function tearDown () {
2007-09-16 18:32:02 +00:00
ClassRegistry :: removeObject ( 'view' );
ClassRegistry :: removeObject ( 'Contact' );
2008-04-17 20:33:54 +00:00
ClassRegistry :: removeObject ( 'ContactNonStandardPk' );
2008-02-18 21:58:32 +00:00
ClassRegistry :: removeObject ( 'ContactTag' );
2007-09-16 18:32:02 +00:00
ClassRegistry :: removeObject ( 'OpenidUrl' );
ClassRegistry :: removeObject ( 'UserForm' );
ClassRegistry :: removeObject ( 'ValidateItem' );
ClassRegistry :: removeObject ( 'ValidateUser' );
ClassRegistry :: removeObject ( 'ValidateProfile' );
2008-03-09 07:36:34 +00:00
unset ( $this -> Form -> Html , $this -> Form , $this -> Controller , $this -> View );
2007-02-06 17:18:23 +00:00
}
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
function __sortFields ( $fields ) {
foreach ( $fields as $key => $value ) {
2007-10-28 04:18:18 +00:00
if ( $key { 0 } !== '_' ) {
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
sort ( $fields [ $key ]);
}
}
ksort ( $fields );
return $fields ;
}
2007-02-06 17:18:23 +00:00
}
2007-09-16 18:32:02 +00:00
2007-10-28 04:18:18 +00:00
?>