* Copyright 2006-2010, Cake Software Foundation, Inc. * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2006-2010, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests * @package cake * @subpackage cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ App::import('Core', array('ClassRegistry', 'Controller', 'View', 'Model', 'Security')); App::import('Helper', 'Html'); App::import('Helper', 'Form'); /** * ContactTestController class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactTestController extends Controller { /** * name property * * @var string 'ContactTest' * @access public */ var $name = 'ContactTest'; /** * uses property * * @var mixed null * @access public */ var $uses = null; } /** * Contact class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class Contact extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'Contact' * @access public */ var $name = 'Contact'; /** * Default schema * * @var array * @access public */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'phone' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'password' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * validate property * * @var array * @access public */ var $validate = array( 'non_existing' => array(), 'idontexist' => array(), 'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false), 'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false), 'imrequiredtoo' => array('rule' => 'notEmpty'), 'required_one' => array('required' => array('rule' => array('notEmpty'))), 'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true), 'imalsonotrequired' => array( 'alpha' => array('rule' => 'alphaNumeric','allowEmpty' => true), 'between' => array('rule' => array('between', 5, 30)), ), 'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true), ); /** * schema method * * @access public * @return void */ function setSchema($schema) { $this->_schema = $schema; } /** * hasAndBelongsToMany property * * @var array * @access public */ var $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact')); /** * hasAndBelongsToMany property * * @var array * @access public */ var $belongsTo = array('User' => array('className' => 'UserForm')); } /** * ContactTagsContact class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactTagsContact extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'Contact' * @access public */ var $name = 'ContactTagsContact'; /** * Default schema * * @var array * @access public */ var $_schema = array( 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'contact_tag_id' => array( 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8' ) ); /** * schema method * * @access public * @return void */ function setSchema($schema) { $this->_schema = $schema; } } /** * ContactNonStandardPk class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactNonStandardPk extends Contact { /** * primaryKey property * * @var string 'pk' * @access public */ var $primaryKey = 'pk'; /** * name property * * @var string 'ContactNonStandardPk' * @access public */ var $name = 'ContactNonStandardPk'; /** * schema method * * @access public * @return void */ function schema() { $this->_schema = parent::schema(); $this->_schema['pk'] = $this->_schema['id']; unset($this->_schema['id']); return $this->_schema; } } /** * ContactTag class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ContactTag extends Model { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * schema definition * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'), 'name' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'), 'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null) ); } /** * UserForm class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class UserForm extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * name property * * @var string 'UserForm' * @access public */ var $name = 'UserForm'; /** * hasMany property * * @var array * @access public */ var $hasMany = array( 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id' )); /** * schema definition * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'published' => array('type' => 'date', 'null' => true, 'default' => null, 'length' => null), 'other' => array('type' => 'text', 'null' => true, 'default' => null, 'length' => null), 'stuff' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 10), 'something' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 255), 'active' => array('type' => 'boolean', 'null' => false, 'default' => false), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); } /** * OpenidUrl class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class OpenidUrl extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * name property * * @var string 'OpenidUrl' * @access public */ var $name = 'OpenidUrl'; /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('UserForm' => array( 'className' => 'UserForm', 'foreignKey' => 'user_form_id' )); /** * validate property * * @var array * @access public */ var $validate = array('openid_not_registered' => array()); /** * schema method * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'user_form_id' => array( 'type' => 'user_form_id', 'null' => '', 'default' => '', 'length' => '8' ), 'url' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), ); /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('openid_not_registered'); return true; } } /** * ValidateUser class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateUser extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'ValidateUser' * @access public */ var $name = 'ValidateUser'; /** * hasOne property * * @var array * @access public */ var $hasOne = array('ValidateProfile' => array( 'className' => 'ValidateProfile', 'foreignKey' => 'user_id' )); /** * schema method * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('email'); return false; } } /** * ValidateProfile class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateProfile extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * schema property * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'user_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'full_name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'city' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * name property * * @var string 'ValidateProfile' * @access public */ var $name = 'ValidateProfile'; /** * hasOne property * * @var array * @access public */ var $hasOne = array('ValidateItem' => array( 'className' => 'ValidateItem', 'foreignKey' => 'profile_id' )); /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('ValidateUser' => array( 'className' => 'ValidateUser', 'foreignKey' => 'user_id' )); /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('full_name'); $this->invalidate('city'); return false; } } /** * ValidateItem class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class ValidateItem extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'ValidateItem' * @access public */ var $name = 'ValidateItem'; /** * schema property * * @var array * @access protected */ var $_schema = array( 'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'profile_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'name' => array('type' => 'text', 'null' => '', 'default' => '', 'length' => '255'), 'description' => array( 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255' ), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * belongsTo property * * @var array * @access public */ var $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id')); /** * beforeValidate method * * @access public * @return void */ function beforeValidate() { $this->invalidate('description'); return false; } } /** * TestMail class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class TestMail extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ var $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ var $useTable = false; /** * name property * * @var string 'TestMail' * @access public */ var $name = 'TestMail'; } /** * FormHelperTest class * * @package cake * @subpackage cake.tests.cases.libs.view.helpers */ class FormHelperTest extends CakeTestCase { /** * fixtures property * * @var array * @access public */ var $fixtures = array(null); /** * setUp method * * @access public * @return void */ function setUp() { parent::setUp(); Router::reload(); $this->Form =& new FormHelper(); $this->Form->Html =& new HtmlHelper(); $this->Controller =& new ContactTestController(); $this->View =& new View($this->Controller); $this->Form->params['action'] = 'add'; ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk()); ClassRegistry::addObject('OpenidUrl', new OpenidUrl()); ClassRegistry::addObject('UserForm', new UserForm()); ClassRegistry::addObject('ValidateItem', new ValidateItem()); ClassRegistry::addObject('ValidateUser', new ValidateUser()); ClassRegistry::addObject('ValidateProfile', new ValidateProfile()); $this->oldSalt = Configure::read('Security.salt'); $this->dateRegex = array( 'daysRegex' => 'preg:/(?: