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
*
* CakePHP Test Suite < https :// trac . cakephp . org / wiki / Developement / TestSuite >
* Copyright ( c ) 2006 , Larry E . Masters Shorewood , IL . 60431
* Author ( s ) : Larry E . Masters aka PhpNut < phpnut @ gmail . com >
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
* @ author Larry E . Masters aka PhpNut < phpnut @ gmail . com >
* @ copyright Copyright ( c ) 2006 , Larry E . Masters Shorewood , IL . 60431
* @ link http :// www . phpnut . com / projects /
* @ package test_suite
* @ subpackage test_suite . cases . app
* @ since CakePHP Test Suite v 1.0 . 0.0
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
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' ;
2007-11-06 00:27:20 +00:00
var $validate = array ( 'non_existing' => array (), 'idontexist' => array ());
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
}
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 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' ),
'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 ;
}
}
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
ClassRegistry :: addObject ( 'view' , $view );
ClassRegistry :: addObject ( 'Contact' , new Contact ());
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-04-26 11:52:56 +00:00
function startTest ( $method ) {
2007-10-27 20:32:19 +00:00
parent :: startTest ( $method );
2007-04-28 07:48:31 +00:00
$this -> Form =& new FormHelper ();
$this -> Form -> Html =& new HtmlHelper ();
2007-06-23 07:44:39 +00:00
$this -> Controller =& new ContactTestController ();
2007-04-28 07:48:31 +00:00
$this -> View =& new View ( $this -> Controller );
2007-02-06 17:18:23 +00:00
}
2007-04-29 03:10:44 +00:00
2007-04-28 07:48:31 +00:00
function endTest ( $method ) {
2007-10-27 20:32:19 +00:00
parent :: endTest ( $method );
2007-04-30 09:52:37 +00:00
if ( isset ( $this -> Form )) {
2007-11-04 18:07:59 +00:00
unset ( $this -> Form -> Html , $this -> Form );
2007-04-30 09:52:37 +00:00
}
2007-11-04 18:07:59 +00:00
unset ( $this -> Controller , $this -> View );
2007-04-28 07:48:31 +00:00
}
2007-04-25 00:24:19 +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' ));
2007-10-04 19:43:32 +00:00
$this -> assertPattern ( '/^<form[^<>]*>.+$/' , $result );
2007-10-04 18:15:48 +00:00
$this -> assertPattern ( '/^<form[^<>]+method="post"[^<>]*>.+$/' , $result );
$this -> assertPattern ( '/^<form[^<>]+action="[^"]+"[^<>]*>.+$/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^id|method|action]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="hidden"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[__Token\]\[key\]"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="testKey"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="\w+"[^<>]*\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|value|id]=[^<>]*>/' , $result );
$result = $this -> Form -> create ( 'Contact' , array ( 'url' => '/contacts/add' , 'id' => 'MyForm' ));
$this -> assertPattern ( '/^<form[^<>]+id="MyForm"[^<>]*>.+$/' , $result );
$this -> assertPattern ( '/^<form[^<>]+method="post"[^<>]*>.+$/' , $result );
$this -> assertPattern ( '/^<form[^<>]+action="[^"]+"[^<>]*>.+$/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^id|method|action]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="hidden"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[__Token\]\[key\]"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="testKey"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="\w+"[^<>]*\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|value|id]=[^<>]*>/' , $result );
}
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 );
$expected = urlencode ( Security :: hash ( serialize ( $fields ) . Configure :: read ( 'Security.salt' )));
$this -> assertPattern ( '/' . $expected . '/' , $result );
$this -> assertPattern ( '/input type="hidden" name="data\[__Token\]\[fields\]" value="' . $expected . '"/' , $result );
}
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' ));
$expected = '/^<form method="post" action="\/contacts\/add"(.+)<input type="hidden" name="data\[__Token\]\[key\]" value="testKey"(.+)<\/p>$/' ;
$this -> assertPattern ( $expected , $result );
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.published' , array ( 'type' => 'text' ));
$expected = '<div class="input"><label for="UserFormPublished">Published</label><input name="data[UserForm][published]" type="text" value="" id="UserFormPublished" /></div>' ;
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 -> assertEqual ( $result , $expected );
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.other' , array ( 'type' => 'text' ));
$expected = '<div class="input"><label for="UserFormOther">Other</label><input name="data[UserForm][other]" type="text" value="" id="UserFormOther" /></div>' ;
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 -> assertEqual ( $result , $expected );
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> hidden ( 'UserForm.stuff' , array ( 'type' => 'text' ));
$expected = '<input type="hidden" name="data[_UserForm][stuff]" type="text" value="" id="UserFormStuff" />' ;
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 -> assertEqual ( $result , $expected );
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'UserForm.something' , array ( 'type' => 'checkbox' ));
$expected = '<div class="input"><input type="hidden" name="data[_UserForm][something]" value="0" id="UserFormSomething_" /><input type="checkbox" name="data[UserForm][something]" value="1" id="UserFormSomething" /><label for="UserFormSomething">Something</label></div>' ;
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 -> assertEqual ( $result , $expected );
$result = $this -> Form -> secure ( $this -> Form -> fields );
$expected = '/<p style="display: none;"><input type="hidden" name="data\[__Token\]\[fields\]" value="' . $fieldsKey . '" id="(.+)" \/><\/p>$/' ;
2007-11-06 00:27:20 +00:00
$this -> assertPattern ( $expected , $result );
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
}
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' ));
2007-10-28 05:28:45 +00:00
$this -> assertPattern ( '/^<form\s+[^<>]+><input\s+[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<form[^<>]+id="UserFormLoginForm"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<form[^<>]+method="post"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<form[^<>]+action="\/user_forms\/login\/"[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<form[^<>]+[^id|method|action]=[^<>\/]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="hidden"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="_method"[^<>]*\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="POST"[^<>]*\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|value]=[^<>\/]*\/>/' , $result );
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' ));
2007-10-28 05:28:45 +00:00
$this -> assertPattern ( '/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/' , $result );
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' ));
2007-10-28 05:28:45 +00:00
$this -> assertPattern ( '/^<form\s+id="[^"]+"\s+method="post"\s+action="\/validate_users\/add\/"[^>]*><input\s+[^<>]+\/>$/' , $result );
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
2007-10-04 18:16:44 +00:00
function testFormInput () {
2007-11-09 01:36:34 +00:00
$result = $this -> Form -> input ( 'Contact.email' , array ( 'id' => 'custom' ));
$expected = '<div class="input"><label for="custom">Email</label><input name="data[Contact][email]" type="text" id="custom" value="" /></div>' ;
$this -> assertEqual ( $result , $expected );
2007-11-06 00:27:20 +00:00
$result = $this -> Form -> hidden ( 'Contact/idontexist' );
$expected = '<input type="hidden" name="data[Contact][idontexist]" value="" id="ContactIdontexist" />' ;
$this -> assertEqual ( $result , $expected );
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact.email' , array ( 'type' => 'text' ));
$expected = '<div class="input"><label for="ContactEmail">Email</label><input name="data[Contact][email]" type="text" value="" id="ContactEmail" /></div>' ;
2007-04-06 17:33:49 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-06 17:18:23 +00:00
2007-11-04 18:07:59 +00:00
$result = $this -> Form -> input ( 'Contact/password' );
$expected = '<div class="input"><label for="ContactPassword">Password</label><input type="password" name="data[Contact][password]" value="" id="ContactPassword" /></div>' ;
2007-02-26 18:58:18 +00:00
$this -> assertEqual ( $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 ));
2007-04-01 04:55:56 +00:00
$this -> assertPattern ( '/<select [^<>]+>\s+<option value=""\s*><\/option>\s+<option value="0"/' , $result );
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' ));
2007-04-13 11:56:03 +00:00
$this -> assertPattern ( '/class="textbox"/' , $result );
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' );
$expected = '<div class="input"><label for="ContactPhone">Phone</label><input name="data[Contact][phone]" type="text" value="Hello & World > weird chars" id="ContactPhone" /></div>' ;
2007-04-28 07:48:31 +00:00
$this -> assertEqual ( $result , $expected );
unset ( $this -> Form -> data );
2007-07-07 23:30:40 +00:00
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 'Badness!' ;
$result = $this -> Form -> input ( 'Model.field' );
$expected = '<div class="input"><label for="ModelField">Field</label><input name="data[Model][field]" type="text" value="" id="ModelField" /></div>' ;
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="ModelField"[^<>]*>Field<\/label><input[^<>]+class="[^"]*form-error"[^<>]+\/><div[^<>]+class="error-message">Badness!<\/div><\/div>$/' , $result );
$result = $this -> Form -> input ( 'Model.field' , array ( 'after' => 'A message to you, Rudy' ));
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="ModelField"[^<>]*>Field<\/label><input[^<>]+class="[^"]*form-error"[^<>]+\/>A message to you, Rudy<div[^<>]+class="error-message">Badness!<\/div><\/div>$/' , $result );
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 ));
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="ModelField"[^<>]*>Field<\/label><input[^<>]+class="[^"]*form-error"[^<>]+\/>A message to you, Rudy<\/div>$/' , $result );
unset ( $this -> Form -> validationErrors [ 'Model' ][ 'field' ]);
$result = $this -> Form -> input ( 'Model.field' , array ( 'after' => 'A message to you, Rudy' ));
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="ModelField"[^<>]*>Field<\/label><input[^<>]+\/>A message to you, Rudy<\/div>$/' , $result );
$this -> assertNoPattern ( '/form-error/' , $result );
$this -> assertNoPattern ( '/error-message/' , $result );
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 ));
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="ModelUserId"[^<>]*>User<\/label>/' , $result );
$this -> assertPattern ( '/<select [^<>]+>\s+<option value=""\s*><\/option>\s+<option value="value"/' , $result );
$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 ));
$this -> assertPattern ( '/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="UserUser"[^<>]*>User<\/label>/' , $result );
$this -> assertPattern ( '/<select[^<>]+>\s+<option value=""\s*><\/option>\s+<option value="value"/' , $result );
$this -> assertPattern ( '/<select[^<>]+multiple="multiple"[^<>\/]*>/' , $result );
2007-11-17 04:27:24 +00:00
$this -> assertNoPattern ( '/<select[^<>]+[^(name|id|multipl)]=[^<>\/]*>/' , $result );
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' );
$this -> assertPattern ( '/<legend>The Legend<\/legend>/' , $result );
2007-11-09 00:17:44 +00:00
$View = ClassRegistry :: getObject ( 'view' );
$View -> testing = true ;
2007-11-04 18:07:59 +00:00
$this -> Form -> testing = true ;
2007-11-09 00:17:44 +00:00
unset ( $View -> testing , $this -> Form -> testing );
2007-11-04 18:07:59 +00:00
2007-10-14 23:41:05 +00:00
$this -> Form -> params [ 'prefix' ] = 'admin' ;
$this -> Form -> action = 'admin_edit' ;
$result = $this -> Form -> inputs ();
$this -> assertPattern ( '/<legend>Edit Contact<\/legend>/' , $result );
2007-10-16 04:41:00 +00:00
$result = $this -> Form -> inputs ( array ( 'fieldset' => true , 'legend' => false ));
$this -> assertPattern ( '/<fieldset[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<legend>[^<>]+<\/legend>/' , $result );
$result = $this -> Form -> inputs ( array ( 'fieldset' => false , 'legend' => false ));
$this -> assertNoPattern ( '/<fieldset[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<legend>[^<>]+<\/legend>/' , $result );
$result = $this -> Form -> inputs ( array ( 'fieldset' => false , 'legend' => 'Hello' ));
$this -> assertNoPattern ( '/<fieldset[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<legend>[^<>]+<\/legend>/' , $result );
$result = $this -> Form -> inputs ( array ( 'legend' => 'Hello' ));
$this -> assertPattern ( '/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s' , $result );
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' ));
$this -> assertPattern ( '/^(<input[^<>]+>\s*<label[^<>]*>\w+<\/label>\s*){3}$/' , $result );
$this -> assertNoPattern ( '/<label[^<>]*>[^(first|second)]<\/label>/' , $result );
/* $this -> assertPattern ( '/^<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="0"[^<>]+checked="checked">/' , $result );
$this -> assertPattern ( '/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="1"[^<>]+checked="checked">/' , $result );
$this -> assertPattern ( '/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="2">third/' , $result );
$this -> assertNoPattern ( '/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="[^012]"[^<>\/]*>$/' , $result ); */
$this -> assertNoPattern ( '/<select[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<\/select>/' , $result );
}
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 ();
$this -> assertEqual ( $result , '<label for="PersonName">Name</label>' );
2007-03-22 18:47:38 +00:00
$this -> Form -> text ( 'Person.name' );
$result = $this -> Form -> label ();
$this -> assertEqual ( $result , '<label for="PersonName">Name</label>' );
$this -> Form -> text ( 'Person.Name' );
$result = $this -> Form -> label ();
$this -> assertEqual ( $result , '<label for="PersonName">Name</label>' );
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' );
2007-04-29 03:10:44 +00:00
$this -> assertEqual ( $result , '<label 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' );
2007-04-29 03:10:44 +00:00
$this -> assertEqual ( $result , '<label 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' ));
2007-10-23 02:36:07 +00:00
$this -> assertPattern ( '/^<label[^<>]+>Your first name<\/label>$/' , $result );
$this -> assertPattern ( '/^<label[^<>]+for="PersonFirstName"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<label[^<>]+class="my-class"[^<>]*>/' , $result );
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' ));
2007-04-29 03:10:44 +00:00
$this -> assertEqual ( $result , '<label for="PersonFirstName" class="my-class" id="LabelID">Your first name</label>' );
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> label ( 'Person.first_name' , '' );
2007-04-29 03:10:44 +00:00
$this -> assertEqual ( $result , '<label for="PersonFirstName"></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' );
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="text"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value]=[^<>]*>/' , $result );
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' ));
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="password"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value]=[^<>]*>/' , $result );
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' ));
2007-02-26 18:58:18 +00:00
$expected = '<input name="data[Model][field]" type="text" id="theID" value="" />' ;
$this -> assertEqual ( $result , $expected );
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' );
$this -> assertPattern ( '/^<input[^<>]+type="text"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[text\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="test <strong>HTML<\/strong> values"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/' , $result );
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' ));
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[text\]"[^<>]+id="theID"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="test"[^<>]+class="form-error"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/' , $result );
}
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' ));
2007-03-23 17:32:02 +00:00
$this -> assertPattern ( '/^<input[^<>]+value="test"[^<>]+\/>$/' , $result );
unset ( $this -> Form -> data [ 'Model' ][ 'field' ]);
2007-05-24 21:44:05 +00:00
$result = $this -> Form -> text ( 'Model.field' , array ( 'default' => 'default value' ));
2007-03-23 17:32:02 +00:00
$this -> assertPattern ( '/^<input[^<>]+value="default value"[^<>]+\/>$/' , $result );
}
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' );
$this -> assertEqual ( $result , '<div class="error-message">Error in field Field</div>' );
$result = $this -> Form -> error ( 'Model.field' , null , array ( 'wrap' => false ));
$this -> assertEqual ( $result , 'Error in field Field' );
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = " This field contains invalid input " ;
$result = $this -> Form -> error ( 'Model.field' , null , array ( 'wrap' => false ));
$this -> assertEqual ( $result , 'This field contains invalid input' );
$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' );
2007-03-16 23:35:25 +00:00
$expected = '<input name="data[Model][field]" type="password" value="" id="ModelField" />' ;
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="password"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value]=[^<>]*>/' , $result );
$this -> Form -> validationErrors [ 'Model' ][ 'passwd' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'passwd' ] = 'test' ;
$result = $this -> Form -> password ( 'Model/passwd' , array ( 'id' => 'theID' ));
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[passwd\]"[^<>]+id="theID"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="test"[^<>]+class="form-error"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/' , $result );
}
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' ));
$this -> assertPattern ( '/id="Field0"/' , $result );
$this -> assertNoPattern ( '/id="ModelField"/' , $result );
$this -> assertNoPattern ( '/^<fieldset><legend>Field<\/legend>$/' , $result );
$this -> assertPattern ( '/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){1}/' , $result );
2007-08-17 08:50:16 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( 'option A' , 'option B' ));
2007-08-27 00:11:36 +00:00
$this -> assertPattern ( '/id="Field0"/' , $result );
$this -> assertPattern ( '/id="Field1"/' , $result );
2007-08-17 08:50:16 +00:00
$this -> assertNoPattern ( '/id="ModelField"/' , $result );
2007-08-17 09:15:19 +00:00
$this -> assertNoPattern ( '/checked="checked"/' , $result );
2007-10-15 07:47:13 +00:00
$this -> assertPattern ( '/^<fieldset><legend>Field<\/legend><input[^<>]+>(<input[^<>]+><label[^<>]+>option [AB]<\/label>)+<\/fieldset>$/' , $result );
2007-10-09 20:44:28 +00:00
$this -> assertPattern ( '/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/' , $result );
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/>' ));
$this -> assertPattern ( '/id="Field0"/' , $result );
$this -> assertPattern ( '/id="Field1"/' , $result );
$this -> assertNoPattern ( '/id="ModelField"/' , $result );
$this -> assertNoPattern ( '/checked="checked"/' , $result );
2007-10-15 07:47:13 +00:00
$this -> assertPattern ( '/^<fieldset><legend>Field<\/legend><input[^<>]+><input[^<>]+><label[^<>]+>option A<\/label><br[^<>+]><input[^<>]+><label[^<>]+>option B<\/label><\/fieldset>$/' , $result );
2007-10-11 16:45:23 +00:00
$this -> assertPattern ( '/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/' , $result );
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> radio ( 'Model.field' , array ( '1' => 'Yes' , '0' => 'No' ), array ( 'value' => '1' ));
2007-09-07 01:22:03 +00:00
$this -> assertPattern ( '/id="Field1".*checked="checked"/' , $result );
$this -> assertPattern ( '/id="Field0"/' , $result );
2007-10-15 07:47:13 +00:00
$this -> assertPattern ( '/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/' , $result );
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' ));
2007-09-07 01:22:03 +00:00
$this -> assertPattern ( '/id="Field1"/' , $result );
$this -> assertPattern ( '/id="Field0".*checked="checked"/' , $result );
2007-10-15 07:47:13 +00:00
$this -> assertPattern ( '/(<input[^<>]+name="data\[Model\]\[field\]"[^<>]+>.+){2}/' , $result );
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => 'Legend title' , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
$expected = '<div class="input"><fieldset><legend>Legend title</legend><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe0" value="0" /><label for="Subscribe0">Unsubscribe</label><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe1" value="1" /><label for="Subscribe1">Subscribe</label></fieldset></div>' ;
$this -> assertEqual ( $result , $expected );
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
$expected = '<div class="input"><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe0" value="0" /><label for="Subscribe0">Unsubscribe</label><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe1" value="1" /><label for="Subscribe1">Subscribe</label></div>' ;
$this -> assertEqual ( $result , $expected );
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => 'Legend title' , 'label' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
$expected = '<div class="input"><fieldset><legend>Legend title</legend><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe0" value="0" />Unsubscribe<input type="radio" name="data[Newsletter][subscribe]" id="Subscribe1" value="1" />Subscribe</fieldset></div>' ;
$this -> assertEqual ( $result , $expected );
$result = $this -> Form -> input ( 'Newsletter.subscribe' , array ( 'legend' => false , 'label' => false , 'type' => 'radio' , 'options' => array ( '0' => 'Unsubscribe' , '1' => 'Subscribe' )));
$expected = '<div class="input"><input type="hidden" name="data[Newsletter][subscribe]" value="" id="NewsletterSubscribe_" /><input type="radio" name="data[Newsletter][subscribe]" id="Subscribe0" value="0" />Unsubscribe<input type="radio" name="data[Newsletter][subscribe]" id="Subscribe1" value="1" />Subscribe</div>' ;
$this -> assertEqual ( $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 ());
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<select [^<>]+>\n<option [^<>]+>/' , $result );
2007-05-25 03:16:47 +00:00
$this -> assertPattern ( '/<option value=""><\/option>/' , $result );
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/<\/select>$/' , $result );
$this -> assertPattern ( '/<select[^<>]+name="data\[Model\]\[field\]"[^<>]*>/' , $result );
$this -> assertPattern ( '/<select[^<>]+id="ModelField"[^<>]*>/' , $result );
$this -> assertNoPattern ( '/^<select[^<>]+name="[^<>]+name="[^<>]+>$/' , $result );
$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' ));
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/option value=""/' , $result );
$this -> assertPattern ( '/option value="value"\s+selected="selected"/' , $result );
$this -> assertPattern ( '/option value="other"/' , $result );
$this -> assertPattern ( '/<\/option>\s+<option/' , $result );
$this -> assertPattern ( '/<\/option>\s+<\/select>/' , $result );
$this -> assertNoPattern ( '/option value="other"\s+selected="selected"/' , $result );
$this -> assertNoPattern ( '/<select[^<>]+[^name|id]=[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<option[^<>]+[^value|selected]=[^<>]*>/' , $result );
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' ));
2007-05-05 00:34:56 +00:00
$this -> assertPattern ( '/option value=""/' , $result );
$this -> assertPattern ( '/option value="value"/' , $result );
$this -> assertPattern ( '/option value="other"/' , $result );
$this -> assertPattern ( '/<\/option>\s+<option/' , $result );
$this -> assertPattern ( '/<\/option>\s+<\/select>/' , $result );
$this -> assertNoPattern ( '/option value="field"\s+selected="selected"/' , $result );
$this -> assertNoPattern ( '/option value="other"\s+selected="selected"/' , $result );
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 );
2007-05-05 00:34:56 +00:00
$this -> assertPattern ( '/' .
2007-08-13 20:20:01 +00:00
'<select[^>]*>\s*' .
2007-05-05 00:34:56 +00:00
'<option\s+value="first"[^>]*>first "html" <chars><\/option>\s+' .
'<option\s+value="second"[^>]*>value<\/option>\s+' .
2007-08-13 20:20:01 +00:00
'<\/select>/i' ,
$result );
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 );
2007-05-05 00:34:56 +00:00
$this -> assertPattern ( '/' .
2007-08-13 20:20:01 +00:00
'<select[^>]*>\s*' .
'<option[^<>\/]+value="first"[^>]*>first "html" <chars><\/option>\s+' .
'<option[^<>\/]+value="second"[^>]*>value<\/option>\s+' .
2007-05-05 00:34:56 +00:00
'<\/select>' .
2007-08-13 20:20:01 +00:00
'/i' ,
$result );
}
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 ));
$this -> assertPattern ( '/^<select[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>\/]*>/' , $result );
$this -> assertPattern ( '/^<select[^<>]+id="ModelMultiField"[^<>\/]*>/' , $result );
$this -> assertPattern ( '/^<select[^<>]+multiple="multiple"[^<>\/]*>/' , $result );
$this -> assertNoPattern ( '/^<select[^<>]+[^name|id|multiple]=[^<>\/]*>/' , $result );
$this -> assertNoPattern ( '/option value=""/' , $result );
$this -> assertNoPattern ( '/selected/' , $result );
$this -> assertPattern ( '/<option[^<>]+value="0">first/' , $result );
$this -> assertPattern ( '/<option[^<>]+value="1">second/' , $result );
$this -> assertPattern ( '/<option[^<>]+value="2">third/' , $result );
$this -> assertNoPattern ( '/<option[^<>]+value="[^012]"[^<>\/]*>/' , $result );
$this -> assertPattern ( '/<\/select>$/' , $result );
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), null , array ( 'multiple' => 'multiple' ));
$this -> assertPattern ( '/^<select[^<>]+multiple="multiple"[^<>\/]*>/' , $result );
$this -> assertNoPattern ( '/^<select[^<>]+[^name|id|multiple]=[^<>\/]*>/' , $result );
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'first' , 'second' , 'third' ), array ( 0 , 1 ), array ( 'multiple' => true ));
$this -> assertPattern ( '/<option[^<>]+value="0"[^<>]+selected="selected">first/' , $result );
$this -> assertPattern ( '/<option[^<>]+value="1"[^<>]+selected="selected">second/' , $result );
$this -> assertPattern ( '/<option[^<>]+value="2">third/' , $result );
$this -> assertNoPattern ( '/<option[^<>]+value="[^012]"[^<>\/]*>/' , $result );
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' ));
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="0"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="1"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="2"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+value="[^012]"[^<>\/]*>/' , $result );
$result = $this -> Form -> select ( 'Model.multi_field' , array ( 'a' => 'first' , 'b' => 'second' , 'c' => 'third' ), null , array ( 'multiple' => 'checkbox' ));
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="a"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="b"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="c"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+value="[^abc]"[^<>\/]*>/' , $result );
$result = $this -> Form -> select ( 'Model.multi_field' , array ( '1' => 'first' ), null , array ( 'multiple' => 'checkbox' ));
$this -> assertPattern ( '/^<input[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>$/' , $result );
$result = $this -> Form -> select ( 'Model.multi_field' , array ( '2' => 'second' ), null , array ( 'multiple' => 'checkbox' ));
$this -> assertPattern ( '/^<input[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>$/' , $result );
}
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' ));
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="0"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="1"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="2"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+value="[^012]"[^<>\/]*>/' , $result );
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( 'a' => 'first' , 'b' => 'second' , 'c' => 'third' ), 'multiple' => 'checkbox' ));
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="a"[^<>]+\/><label[^<>]+>first<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="b"[^<>]+\/><label[^<>]+>second<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="c"[^<>]+\/><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>third<\/label>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+value="[^abc]"[^<>\/]*>/' , $result );
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( '1' => 'first' ), 'multiple' => 'checkbox' , 'label' => false , 'div' => false ));
$this -> assertPattern ( '/^<input[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="1"[^<>]+\/><label[^<>]+>first<\/label>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>first<\/label>$/' , $result );
$result = $this -> Form -> input ( 'Model.multi_field' , array ( 'options' => array ( '2' => 'second' ), 'multiple' => 'checkbox' , 'label' => false , 'div' => false ));
$this -> assertPattern ( '/^<input[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[multi_field\]\[\]"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="checkbox"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="2"[^<>]+\/><label[^<>]+>second<\/label>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+[^name|type|value]=[^<>\/]*><label[^<>]+>second<\/label>$/' , $result );
}
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' ));
$this -> assertPattern ( '/^<input[^<>]+type="hidden"[^<>]+\/><input[^<>]+type="checkbox"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="hidden"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="theID_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+name="data\[Model\]\[field\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+type="checkbox"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="myvalue"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="theID"[^<>]+\/>$/' , $result );
$this -> Form -> validationErrors [ 'Model' ][ 'field' ] = 1 ;
$this -> Form -> data [ 'Model' ][ 'field' ] = 'myvalue' ;
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'id' => 'theID' , 'value' => 'myvalue' ));
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+class="form-error"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'value' => 'myvalue' ));
2007-10-28 04:18:18 +00:00
2007-07-26 14:23:38 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="myvalue"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> checkbox ( 'Model.field' , array ( 'id' => 'theID' ));
2007-10-28 04:18:18 +00:00
2007-10-24 02:51:15 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="theID_"[^<>]+\/><input[^<>]+\/>$/' , $result );
2007-07-26 14:23:38 +00:00
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
2007-10-24 02:51:15 +00:00
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="theID"[^<>]+\/>$/' , $result );
2007-07-26 14:23:38 +00:00
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
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' ));
2007-10-28 04:18:18 +00:00
2007-07-26 14:23:38 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
2007-10-24 02:51:15 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="myvalue"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
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' ));
$this -> assertEqual ( $result , '<input type="hidden" name="data[Contact][name]" value="0" id="ContactName_" /><input type="checkbox" name="data[Contact][name]" value="myvalue" id="ContactName" />' );
2007-07-26 14:23:38 +00:00
$result = $this -> Form -> checkbox ( 'Model.field' );
2007-10-24 02:51:15 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
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 ));
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ModelField_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="ModelField"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
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' ));
2007-10-28 04:18:18 +00:00
2007-10-24 02:51:15 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="theID_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="theID"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
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' ));
2007-10-28 04:18:18 +00:00
2007-10-24 02:51:15 +00:00
$this -> assertNoPattern ( '/^<input[^<>]+[^type|name|id|value]=[^<>]*\/><input[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+[^type|name|id|value|class|checked]=[^<>]*>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="theID_"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value="0"[^<>]+\/><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+id="theID"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+\/><input[^<>]+value="1"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/' , $result );
2007-07-26 14:23:38 +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' );
2007-11-09 01:36:34 +00:00
$this -> assertPattern ( '/^<select[^<>]+name="data\[Model\]\[field\]\[month\]"[^<>]*>/' , $result );
2007-11-04 18:07:59 +00:00
$this -> assertPattern ( '/<option\s+value="01"[^>]*>January<\/option>\s+/i' , $result );
$this -> assertPattern ( '/<option\s+value="02"[^>]*>February<\/option>\s+/i' , $result );
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 () {
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> day ( 'Model.field' , false );
$this -> assertPattern ( '/option value="12"/' , $result );
$this -> assertPattern ( '/option value="13"/' , $result );
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' );
$this -> assertPattern ( '/option value="10" selected="selected"/' , $result );
$this -> assertNoPattern ( '/option value="32"/' , $result );
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> day ( 'Model.field' , '10' );
$this -> assertPattern ( '/option value="10" selected="selected"/' , $result );
$this -> assertPattern ( '/option value="23"/' , $result );
$this -> assertPattern ( '/option value="24"/' , $result );
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 );
$this -> assertPattern ( '/option value="10" selected="selected"/' , $result );
$this -> assertPattern ( '/option value="23"/' , $result );
2007-04-25 00:24:19 +00:00
2007-04-01 04:55:56 +00:00
}
2007-10-04 18:16:44 +00:00
function testHour () {
2007-05-25 03:16:47 +00:00
$result = $this -> Form -> hour ( 'Model.field' , false );
2007-04-01 15:07:27 +00:00
$this -> assertPattern ( '/option value="12"/' , $result );
$this -> assertNoPattern ( '/option value="13"/' , $result );
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 );
$this -> assertPattern ( '/option value="12" selected="selected"/' , $result );
$this -> assertNoPattern ( '/option value="13"/' , $result );
$this -> Form -> data [ 'Model' ][ 'field' ] = '' ;
$result = $this -> Form -> hour ( 'Model.field' , true );
$this -> assertPattern ( '/option value="23"/' , $result );
$this -> assertNoPattern ( '/option value="24"/' , $result );
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 );
2007-04-01 15:07:27 +00:00
$this -> assertPattern ( '/option value="23"/' , $result );
2007-05-25 03:16:47 +00:00
$this -> assertPattern ( '/option value="00" selected="selected"/' , $result );
2007-04-01 15:07:27 +00:00
$this -> assertNoPattern ( '/option value="24"/' , $result );
}
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 );
$this -> assertPattern ( '/option value="2006"/' , $result );
$this -> assertPattern ( '/option value="2007"/' , $result );
$this -> assertNoPattern ( '/option value="2005"/' , $result );
$this -> assertNoPattern ( '/option value="2008"/' , $result );
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' ));
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" class= \" year \" id= \" ContactPublishedYear \" > \n <option value= \" \" ></option> \n <option value= \" 2007 \" >2007</option> \n <option value= \" 2006 \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
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 );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" 2007 \" >2007</option> \n <option value= \" 2006 \" selected= \" selected \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , false );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" \" ></option> \n <option value= \" 2007 \" >2007</option> \n <option value= \" 2006 \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
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 );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" 2007 \" >2007</option> \n <option value= \" 2006 \" selected= \" selected \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2007 , 2007 );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" \" ></option> \n <option value= \" 2007 \" selected= \" selected \" >2007</option> \n <option value= \" 2006 \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
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 );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" 2007 \" selected= \" selected \" >2007</option> \n <option value= \" 2006 \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
2007-11-04 18:07:59 +00:00
$this -> Form -> data [ 'Contact' ][ 'published' ] = '' ;
$result = $this -> Form -> year ( 'Contact.published' , 2006 , 2008 , 2007 , array (), false );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" 2008 \" >2008</option> \n <option value= \" 2007 \" selected= \" selected \" >2007</option> \n <option value= \" 2006 \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
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 );
Closes #2781, $form->input on date fields renders maxYear and minYear in $options as HTML attributes.
Closes #3181, Year list ordering in FormHelper order is now formated descending.
Fixes #3524, FormHelper->month, day, year, hour, and minute should use $selected if it is supplied.
Fixes #3558, post validation don't pass if form use only hidden fields.
Fixes #3568, Saving datetime fields is broken in scaffolding.
Fixes #3574, Typo in Session class.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5987 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-11-12 11:31:43 +00:00
$expecting = " <select name= \" data[Contact][published][year] \" id= \" ContactPublishedYear \" > \n <option value= \" 2008 \" >2008</option> \n <option value= \" 2007 \" >2007</option> \n <option value= \" 2006 \" selected= \" selected \" >2006</option> \n </select> " ;
2007-05-25 03:16:47 +00:00
$this -> assertEqual ( $result , $expecting );
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' );
2007-10-23 02:36:07 +00:00
$this -> assertPattern ( '/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<textarea[^<>]+id="ModelField"[^<>]*>/' , $result );
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<textarea[^<>]+>some test data<\/textarea>$/' , $result );
$this -> assertNoPattern ( '/^<textarea[^<>]+name="[^<>]+name="[^<>]+>$/' , $result );
$this -> assertNoPattern ( '/<textarea[^<>]+[^name|id]=[^<>]*>/' , $result );
$result = $this -> Form -> textarea ( 'Model/tmp' );
$this -> assertPattern ( '/^<textarea[^<>]+name="data\[Model\]\[tmp\]"[^<>]+><\/textarea>/' , $result );
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' );
2007-10-23 02:36:07 +00:00
$this -> assertPattern ( '/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<textarea[^<>]+id="ModelField"[^<>]*>/' , $result );
2007-10-17 17:08:34 +00:00
$this -> assertPattern ( '/^<textarea[^<>]+>some <strong>test<\/strong> data with <a href="#">HTML<\/a> chars<\/textarea>$/' , $result );
$this -> assertNoPattern ( '/^<textarea[^<>]+value="[^<>]+>/' , $result );
$this -> assertNoPattern ( '/^<textarea[^<>]+name="[^<>]+name="[^<>]+>$/' , $result );
$this -> assertNoPattern ( '/<textarea[^<>]+[^name|id]=[^<>]*>/' , $result );
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' ));
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<input[^<>]+type="hidden"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+id="theID"[^<>]+value="test"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
2007-05-21 05:15:26 +00:00
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/' , $result );
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' );
2007-03-16 23:35:25 +00:00
$this -> assertPattern ( '/^<input type="file"[^<>]+name="data\[Model\]\[upload\]"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input type="file"[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input type="file"[^<>]+id="ModelUpload"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/' , $result );
2007-04-01 04:55:56 +00:00
$this -> assertNoPattern ( '/<input[^<>]+[^type|name|value|id]=[^<>]*>$/' , $result );
2007-03-16 23:35:25 +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' );
$this -> assertPattern ( '/^<div\s+class="submit"><input type="submit"[^<>]+value="Test Submit"[^<>]+\/><\/div>$/' , $result );
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 ));
$this -> assertPattern ( '/^<input type="submit"[^<>]+value="Test Submit"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<[^<>]+class="save"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|class|value]=[^<>]*>/' , $result );
$result = $this -> Form -> submit ( 'Test Submit' , array ( 'div' => array ( 'id' => 'SaveButton' )));
$this -> assertPattern ( '/^<div[^<>]+id="SaveButton"[^<>]*><input type="submit"[^<>]+value="Test Submit"[^<>]+\/><\/div>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^type|value]=[^<>]*>/' , $result );
2007-04-29 03:10:44 +00:00
2007-04-28 07:42:54 +00:00
$result = $this -> Form -> submit ( 'Next >' );
$this -> assertPattern ( '/^<div\s+class="submit"><input type="submit"[^<>]+value="Next >"[^<>]+\/><\/div>$/' , $result );
2007-04-29 03:10:44 +00:00
2007-10-09 20:44:28 +00:00
$result = $this -> Form -> submit ( 'Next >' , array ( 'escape' => false ));
2007-04-28 07:42:54 +00:00
$this -> assertPattern ( '/^<div\s+class="submit"><input type="submit"[^<>]+value="Next >"[^<>]+\/><\/div>$/' , $result );
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' );
$this -> assertPattern ( '/^<form [^<>]+>/' , $result );
$this -> assertPattern ( '/\s+id="ContactAddForm"/' , $result );
$this -> assertPattern ( '/\s+method="post"/' , $result );
$this -> assertPattern ( '/\s+action="\/contacts\/add\/"/' , $result );
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'GET' ));
$this -> assertPattern ( '/^<form [^<>]+method="get"[^<>]+>$/' , $result );
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'get' ));
$this -> assertPattern ( '/^<form [^<>]+method="get"[^<>]+>$/' , $result );
$result = $this -> Form -> create ( 'Contact' , array ( 'type' => 'put' ));
$this -> assertPattern ( '/^<form [^<>]+method="post"[^<>]+>/' , $result );
$this -> Form -> data [ 'Contact' ][ 'id' ] = 1 ;
$result = $this -> Form -> create ( 'Contact' );
$this -> assertPattern ( '/^<form[^<>]+method="post"[^<>]+>/' , $result );
$this -> assertPattern ( '/^<form[^<>]+id="ContactEditForm"[^<>]+>/' , $result );
$this -> assertPattern ( '/^<form[^<>]+action="\/contacts\/edit\/1"[^<>]*>/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^id|method|action]=[^<>]*>/' , $result );
2007-04-29 03:10:44 +00:00
2007-04-28 09:20:35 +00:00
$result = $this -> Form -> create ( 'Contact' , array ( 'id' => 'TestId' ));
$this -> assertPattern ( '/id="TestId"/' , $result );
2007-08-15 14:18:39 +00:00
$result = $this -> Form -> create ( 'User' , array ( 'url' => array ( 'action' => 'login' )));
$this -> assertPattern ( '/id="UserAddForm"/' , $result );
2007-10-07 14:13:03 +00:00
$this -> assertPattern ( '/action="\/users\/login(\/)?"/' , $result );
2007-08-15 14:18:39 +00:00
$result = $this -> Form -> create ( 'User' , array ( 'action' => 'login' ));
$this -> assertPattern ( '/id="UserLoginForm"/' , $result );
2007-10-07 14:13:03 +00:00
$this -> assertPattern ( '/action="\/users\/login(\/)?"/' , $result );
$result = $this -> Form -> create ( 'User' , array ( 'url' => '/users/login' ));
$this -> assertPattern ( '/method="post"/' , $result );
$this -> assertPattern ( '/action="\/users\/login(\/)?"/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^method|action]=[^<>]*>/' , $result );
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' ));
$this -> assertPattern ( '/id="UserSignupForm"/' , $result );
$this -> assertPattern ( '/action="\/users\/signup[\/]"/' , $result );
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' ));
$this -> assertPattern ( '/^<form [^<>]+>/' , $result );
$this -> assertPattern ( '/\s+id="ContactAddForm"/' , $result );
$this -> assertPattern ( '/\s+method="get"/' , $result );
$this -> assertPattern ( '/\s+action="\/contacts\/add\/"/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^method|action|id]=[^<>]*>/' , $result );
$result = $this -> Form -> text ( 'Contact.name' );
$this -> assertPattern ( '/^<input[^<>]+name="name"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="text"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ContactName"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|name|type|value]=[^<>]*>$/' , $result );
$result = $this -> Form -> password ( 'password' );
$this -> assertPattern ( '/^<input[^<>]+name="password"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="password"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ContactPassword"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|name|type|value]=[^<>]*>$/' , $result );
2007-11-17 04:27:24 +00:00
$result = $this -> Form -> text ( 'user_form' );
$this -> assertPattern ( '/^<input[^<>]+name="user_form"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+type="text"[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+value=""[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/^<input[^<>]+id="ContactUserForm"[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|name|type|value]=[^<>]*>$/' , $result );
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' ,
'email' => 'nate@cakephp.org'
));
$this -> Form -> params = array (
'models' => array ( 'Person' ),
'controller' => 'people'
);
$options = array ( 1 => 'Nate' , 2 => 'Garrett' , 3 => 'Larry' );
$this -> Form -> create ();
$result = $this -> Form -> select ( 'People.People' , $options , null , array ( 'multiple' => true ));
$this -> assertPattern ( '/^<select[^<>]+>\s*(<option[^<>]+>.+<\/option>\s*){3}<\/select>$/' , $result );
$this -> assertPattern ( '/^<select[^<>]+name="data\[People\]\[People\]\[\]"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<select[^<>]+multiple="multiple"[^<>]*>/' , $result );
$this -> assertPattern ( '/^<select[^<>]+id="PeoplePeople"[^<>]*>/' , $result );
$this -> assertNoPattern ( '/<select[^<>]+[^id|name|multiple]=[^<>]*>$/' , $result );
}
2007-10-04 18:16:44 +00:00
function testFormMagicInput () {
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> create ( 'Contact' );
2007-10-28 05:28:45 +00:00
$this -> assertPattern ( '/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/' , $result );
2007-07-07 23:30:40 +00:00
$this -> assertNoPattern ( '/^<form[^<>]+[^id|method|action]=[^<>]*>/' , $result );
2007-05-21 05:15:26 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'name' );
2007-07-07 23:30:40 +00:00
$this -> assertPattern ( '/^<div[^<>]+><label[^<>]+>Name<\/label><input [^<>]+ \/><\/div>$/' , $result );
$this -> assertPattern ( '/^<div[^<>]+class="input">/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactName">/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[name\]"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+maxlength="255"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value=""[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactName"[^<>]+\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|maxlength|name|type|value]=[^<>]*>/' , $result );
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'Address.street' );
2007-09-16 18:32:02 +00:00
$this -> assertPattern ( '/^<div\s+[^<>]+><label\s+[^<>]+>[^<>]+<\/label><input\s+[^<>]+\/><\/div>$/' , $result );
$this -> assertPattern ( '/<div\s+class="input">/' , $result );
$this -> assertPattern ( '/<label\s+for="AddressStreet">Street<\/label>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Address\]\[street\]"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value=""[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="AddressStreet"[^<>]+\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|name|type|value]=[^<>]*>/' , $result );
2007-05-21 05:15:26 +00:00
2007-06-08 01:17:40 +00:00
$result = $this -> Form -> input ( 'name' , array ( 'div' => false ));
2007-09-16 18:32:02 +00:00
$this -> assertPattern ( '/^<label\s+[^<>]+>Name<\/label><input\s+[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactName"[^<>]*>Name<\/label>/' , $result );
$this -> assertNoPattern ( '/<label[^<>]+[^for]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[name\]"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+maxlength="255"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+value=""[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactName"[^<>]*\/>$/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^id|maxlength|name|type|value]=[^<>]*>/' , $result );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.non_existing' );
2007-11-04 18:07:59 +00:00
$this -> assertPattern ( '/^<div class="input required">' .
2007-05-13 12:07:23 +00:00
'<label for="ContactNonExisting">Non Existing<\/label>' .
'<input name="data\[Contact\]\[non_existing\]" type="text" value="" id="ContactNonExisting" \/>' .
'<\/div>$/' , $result );
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> input ( 'Contact.published' , array ( 'div' => false ));
$this -> assertPattern ( '/^<label for="ContactPublishedMonth">Published<\/label>' .
2007-11-04 18:07:59 +00:00
'<select name="data\[Contact\]\[published\]\[month\]"\s+id="ContactPublishedMonth">/' , $result );
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 ));
2007-05-21 05:15:26 +00:00
2007-05-13 12:07:23 +00:00
$this -> assertPattern ( '/^<label for="ContactUpdatedMonth">Updated<\/label>' .
2007-11-04 18:07:59 +00:00
'<select name="data\[Contact\]\[updated\]\[month\]"\s+id="ContactUpdatedMonth">/' , $result );
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' );
$this -> assertPattern ( '/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/' , $result );
$this -> assertNoPattern ( '/^<form[^<>]+[^id|method|action]=[^<>]*>/' , $result );
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false ));
$this -> assertPattern ( '/^<label\s+[^<>]+>Non Existing Nor Validated<\/label><input\s+[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactNonExistingNorValidated"[^<>]*>[^<>]+<\/label>/' , $result );
$this -> assertNoPattern ( '/<label[^<>]+[^for]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[non_existing_nor_validated\]"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+value=""[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactNonExistingNorValidated"[^<>]*\/>$/' , $result );
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false , 'value' => 'my value' ));
$this -> assertPattern ( '/^<label\s+[^<>]+>Non Existing Nor Validated<\/label><input\s+[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactNonExistingNorValidated"[^<>]*>[^<>]+<\/label>/' , $result );
$this -> assertNoPattern ( '/<label[^<>]+[^for]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[non_existing_nor_validated\]"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="my value"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactNonExistingNorValidated"[^<>]*\/>$/' , $result );
$this -> Form -> data = array ( 'Contact' => array ( 'non_existing_nor_validated' => 'CakePHP magic' ));
$result = $this -> Form -> input ( 'Contact.non_existing_nor_validated' , array ( 'div' => false ));
$this -> assertPattern ( '/^<label\s+[^<>]+>Non Existing Nor Validated<\/label><input\s+[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactNonExistingNorValidated"[^<>]*>[^<>]+<\/label>/' , $result );
$this -> assertNoPattern ( '/<label[^<>]+[^for]=[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[non_existing_nor_validated\]"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+value="CakePHP magic"[^<>]*\/>$/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactNonExistingNorValidated"[^<>]*\/>$/' , $result );
}
2007-10-04 18:16:44 +00:00
function testFormMagicInputLabel () {
2007-05-13 12:07:23 +00:00
$result = $this -> Form -> create ( 'Contact' );
2007-10-28 05:28:45 +00:00
$this -> assertPattern ( '/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*><input\s+[^<>]+\/>$/' , $result );
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 ));
$this -> assertPattern ( '/^<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/' , $result );
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' ));
$this -> assertPattern ( '/^<label for="ContactName">My label<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/' , $result );
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' )));
2007-09-16 18:32:02 +00:00
$this -> assertPattern ( '/^<label[^<>]+>Name<\/label><input [^<>]+ \/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactName"[^<>]*>/' , $result );
$this -> assertPattern ( '/<label[^<>]+class="mandatory"[^<>]*>/' , $result );
$this -> assertPattern ( '/<input[^<>]+name="data\[Contact\]\[name\]"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+type="text"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+maxlength="255"[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+value=""[^<>]+\/>/' , $result );
$this -> assertPattern ( '/<input[^<>]+id="ContactName"[^<>]+\/>/' , $result );
$this -> assertNoPattern ( '/<input[^<>]+[^name|type|maxlength|value|id]=[^<>]*>/' , $result );
$this -> assertNoPattern ( '/^<label[^<>]+[^for|class]=[^<>]*>/' , $result );
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' )));
2007-09-16 18:32:02 +00:00
$this -> assertPattern ( '/^<label[^<>]+>My label<\/label><input[^<>]+\/>$/' , $result );
$this -> assertPattern ( '/<label[^<>]+for="ContactName"[^<>]*>/' , $result );
$this -> assertPattern ( '/<label[^<>]+class="mandatory"[^<>]*>/' , $result );
$this -> assertNoPattern ( '/^<label[^<>]+[^for|class]=[^<>]*>/' , $result );
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' )));
$this -> assertPattern ( '/^<label for="my_id">Name<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" id="my_id" maxlength="255" value="" \/>$/' , $result );
}
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' );
$this -> assertEqual ( $result , '<div class="submit"><input type="submit" value="save" /></div></form>' );
2007-05-25 03:16:47 +00:00
2007-05-02 12:56:51 +00:00
$result = $this -> Form -> end ( array ( 'submit' => 'save' ));
$this -> assertEqual ( $result , '<div class="submit"><input type="submit" value="save" /></div></form>' );
2007-02-06 17:18:23 +00:00
}
2007-05-25 03:16:47 +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' );
ClassRegistry :: removeObject ( 'OpenidUrl' );
ClassRegistry :: removeObject ( 'UserForm' );
ClassRegistry :: removeObject ( 'ValidateItem' );
ClassRegistry :: removeObject ( 'ValidateUser' );
ClassRegistry :: removeObject ( 'ValidateProfile' );
2007-03-16 23:35:25 +00:00
unset ( $this -> Form );
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
?>