* Copyright 2005-2011, Cake Software Foundation, Inc. * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice * * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests * @package cake.tests.cases.libs.view.helpers * @since CakePHP(tm) v 1.2.0.4206 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ App::uses('ClassRegistry', 'Utility'); App::uses('Controller', 'Controller'); App::uses('View', 'View'); App::uses('Model', 'Model'); App::uses('Security', 'Utility'); App::uses('CakeRequest', 'Network'); App::uses('HtmlHelper', 'View/Helper'); App::uses('FormHelper', 'View/Helper'); App::uses('Router', 'Routing'); /** * ContactTestController class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ContactTestController extends Controller { /** * name property * * @var string 'ContactTest' * @access public */ public $name = 'ContactTest'; /** * uses property * * @var mixed null * @access public */ public $uses = null; } /** * Contact class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class Contact extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * name property * * @var string 'Contact' * @access public */ public $name = 'Contact'; /** * Default schema * * @var array * @access public */ protected $_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 */ public $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 */ public function setSchema($schema) { $this->_schema = $schema; } /** * hasAndBelongsToMany property * * @var array * @access public */ public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact')); /** * hasAndBelongsToMany property * * @var array * @access public */ public $belongsTo = array('User' => array('className' => 'UserForm')); } /** * ContactTagsContact class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ContactTagsContact extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * name property * * @var string 'Contact' * @access public */ public $name = 'ContactTagsContact'; /** * Default schema * * @var array * @access public */ protected $_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 */ public function setSchema($schema) { $this->_schema = $schema; } } /** * ContactNonStandardPk class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ContactNonStandardPk extends Contact { /** * primaryKey property * * @var string 'pk' * @access public */ public $primaryKey = 'pk'; /** * name property * * @var string 'ContactNonStandardPk' * @access public */ public $name = 'ContactNonStandardPk'; /** * schema method * * @access public * @return void */ public function schema($field = false) { $this->_schema = parent::schema(); $this->_schema['pk'] = $this->_schema['id']; unset($this->_schema['id']); return $this->_schema; } } /** * ContactTag class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ContactTag extends Model { /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * schema definition * * @var array * @access protected */ protected $_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 * @package cake.tests.cases.libs.view.helpers */ class UserForm extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * name property * * @var string 'UserForm' * @access public */ public $name = 'UserForm'; /** * hasMany property * * @var array * @access public */ public $hasMany = array( 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id' )); /** * schema definition * * @var array * @access protected */ protected $_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 * @package cake.tests.cases.libs.view.helpers */ class OpenidUrl extends CakeTestModel { /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * name property * * @var string 'OpenidUrl' * @access public */ public $name = 'OpenidUrl'; /** * belongsTo property * * @var array * @access public */ public $belongsTo = array('UserForm' => array( 'className' => 'UserForm', 'foreignKey' => 'user_form_id' )); /** * validate property * * @var array * @access public */ public $validate = array('openid_not_registered' => array()); /** * schema method * * @var array * @access protected */ protected $_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 */ public function beforeValidate($options = array()) { $this->invalidate('openid_not_registered'); return true; } } /** * ValidateUser class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ValidateUser extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * name property * * @var string 'ValidateUser' * @access public */ public $name = 'ValidateUser'; /** * hasOne property * * @var array * @access public */ public $hasOne = array('ValidateProfile' => array( 'className' => 'ValidateProfile', 'foreignKey' => 'user_id' )); /** * schema method * * @var array * @access protected */ protected $_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 */ public function beforeValidate($options = array()) { $this->invalidate('email'); return false; } } /** * ValidateProfile class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ValidateProfile extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * schema property * * @var array * @access protected */ protected $_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 */ public $name = 'ValidateProfile'; /** * hasOne property * * @var array * @access public */ public $hasOne = array('ValidateItem' => array( 'className' => 'ValidateItem', 'foreignKey' => 'profile_id' )); /** * belongsTo property * * @var array * @access public */ public $belongsTo = array('ValidateUser' => array( 'className' => 'ValidateUser', 'foreignKey' => 'user_id' )); /** * beforeValidate method * * @access public * @return void */ public function beforeValidate($options = array()) { $this->invalidate('full_name'); $this->invalidate('city'); return false; } } /** * ValidateItem class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class ValidateItem extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * name property * * @var string 'ValidateItem' * @access public */ public $name = 'ValidateItem'; /** * schema property * * @var array * @access protected */ protected $_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 */ public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id')); /** * beforeValidate method * * @access public * @return void */ public function beforeValidate($options = array()) { $this->invalidate('description'); return false; } } /** * TestMail class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class TestMail extends CakeTestModel { /** * primaryKey property * * @var string 'id' * @access public */ public $primaryKey = 'id'; /** * useTable property * * @var bool false * @access public */ public $useTable = false; /** * name property * * @var string 'TestMail' * @access public */ public $name = 'TestMail'; } /** * FormHelperTest class * * @package cake * @package cake.tests.cases.libs.view.helpers */ class FormHelperTest extends CakeTestCase { /** * Fixtures to be used * * @var array */ public $fixtures = array('core.post'); /** * Do not load the fixtures by default * * @var boolean */ public $autoFixtures = false; /** * setUp method * * @access public * @return void */ public function setUp() { parent::setUp(); Configure::write('App.base', ''); $this->Controller = new ContactTestController(); $this->View = new View($this->Controller); $this->Form = new FormHelper($this->View); $this->Form->Html = new HtmlHelper($this->View); $this->Form->request = new CakeRequest('contacts/add', false); $this->Form->request->here = '/contacts/add'; $this->Form->request['action'] = 'add'; $this->Form->request->webroot = ''; $this->Form->request->base = ''; ClassRegistry::addObject('Contact', new Contact()); ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk()); ClassRegistry::addObject('OpenidUrl', new OpenidUrl()); ClassRegistry::addObject('User', 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:/(?: