* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice * * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) * @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests * @package Cake.Test.Case.View.Helper * @since CakePHP(tm) v 1.2.0.4206 * @license https://opensource.org/licenses/mit-license.php MIT License */ 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.Test.Case.View.Helper */ class ContactTestController extends Controller { /** * uses property * * @var mixed */ public $uses = null; } /** * Contact class * * @package Cake.Test.Case.View.Helper */ class Contact extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * Default schema * * @var array */ 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'), 'lap_time' => array('type' => 'time', 'null' => '', 'default' => '', 'length' => '2'), 'last_seen' => array('type' => 'datetime', 'null' => '', 'default' => '', 'length' => '3'), '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), 'age' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => null) ); /** * validate property * * @var array */ public $validate = array( 'non_existing' => array(), 'idontexist' => array(), 'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false), 'imrequiredonupdate' => array('notBlank' => array('rule' => 'alphaNumeric', 'on' => 'update')), 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')), 'imrequiredonboth' => array( 'required' => array('rule' => 'alphaNumeric'), ), 'string_required' => 'notBlank', 'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false), 'imrequiredtoo' => array('rule' => 'notBlank'), 'required_one' => array('required' => array('rule' => array('notBlank'))), 'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true), 'imalsonotrequired' => array( 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true), 'between' => array('rule' => array('between', 5, 30)), ), 'imalsonotrequired2' => array( 'alpha' => array('rule' => 'alphaNumeric', 'allowEmpty' => true), 'between' => array('rule' => array('between', 5, 30), 'allowEmpty' => true), ), 'imnotrequiredeither' => array('required' => true, 'rule' => array('between', 5, 30), 'allowEmpty' => true), 'iamrequiredalways' => array( 'email' => array('rule' => 'email'), 'rule_on_create' => array('rule' => array('maxLength', 50), 'on' => 'create'), 'rule_on_update' => array('rule' => array('between', 1, 50), 'on' => 'update'), ), 'boolean_field' => array('rule' => 'boolean') ); /** * schema method * * @return void */ public function setSchema($schema) { $this->_schema = $schema; } /** * hasAndBelongsToMany property * * @var array */ public $hasAndBelongsToMany = array('ContactTag' => array('with' => 'ContactTagsContact')); /** * hasAndBelongsToMany property * * @var array */ public $belongsTo = array('User' => array('className' => 'UserForm')); } /** * ContactTagsContact class * * @package Cake.Test.Case.View.Helper */ class ContactTagsContact extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * Default schema * * @var array */ protected $_schema = array( 'contact_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'), 'contact_tag_id' => array( 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8' ) ); /** * schema method * * @return void */ public function setSchema($schema) { $this->_schema = $schema; } } /** * ContactNonStandardPk class * * @package Cake.Test.Case.View.Helper */ class ContactNonStandardPk extends Contact { /** * primaryKey property * * @var string */ public $primaryKey = 'pk'; /** * schema method * * @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.Test.Case.View.Helper */ class ContactTag extends Model { /** * useTable property * * @var bool */ public $useTable = false; /** * schema definition * * @var array */ 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.Test.Case.View.Helper */ class UserForm extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * hasMany property * * @var array */ public $hasMany = array( 'OpenidUrl' => array('className' => 'OpenidUrl', 'foreignKey' => 'user_form_id' )); /** * schema definition * * @var array */ 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.Test.Case.View.Helper */ class OpenidUrl extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * belongsTo property * * @var array */ public $belongsTo = array('UserForm' => array( 'className' => 'UserForm', 'foreignKey' => 'user_form_id' )); /** * validate property * * @var array */ public $validate = array('openid_not_registered' => array()); /** * schema method * * @var array */ 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 * * @return void */ public function beforeValidate($options = array()) { $this->invalidate('openid_not_registered'); return true; } } /** * ValidateUser class * * @package Cake.Test.Case.View.Helper */ class ValidateUser extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * hasOne property * * @var array */ public $hasOne = array('ValidateProfile' => array( 'className' => 'ValidateProfile', 'foreignKey' => 'user_id' )); /** * schema method * * @var array */ 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'), 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'), 'null_decimal' => array('type' => 'decimal', 'null' => false, 'length' => null), 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'), 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); /** * beforeValidate method * * @return void */ public function beforeValidate($options = array()) { $this->invalidate('email'); return false; } } /** * ValidateProfile class * * @package Cake.Test.Case.View.Helper */ class ValidateProfile extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * schema property * * @var array */ 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) ); /** * hasOne property * * @var array */ public $hasOne = array('ValidateItem' => array( 'className' => 'ValidateItem', 'foreignKey' => 'profile_id' )); /** * belongsTo property * * @var array */ public $belongsTo = array('ValidateUser' => array( 'className' => 'ValidateUser', 'foreignKey' => 'user_id' )); /** * beforeValidate method * * @return void */ public function beforeValidate($options = array()) { $this->invalidate('full_name'); $this->invalidate('city'); return false; } } /** * ValidateItem class * * @package Cake.Test.Case.View.Helper */ class ValidateItem extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; /** * schema property * * @var array */ 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 */ public $belongsTo = array('ValidateProfile' => array('foreignKey' => 'profile_id')); /** * beforeValidate method * * @return void */ public function beforeValidate($options = array()) { $this->invalidate('description'); return false; } } /** * TestMail class * * @package Cake.Test.Case.View.Helper */ class TestMail extends CakeTestModel { /** * useTable property * * @var bool */ public $useTable = false; } /** * FormHelperTest class * * @package Cake.Test.Case.View.Helper * @property FormHelper $Form */ class FormHelperTest extends CakeTestCase { /** * Fixtures to be used * * @var array */ public $fixtures = array('core.post'); /** * Do not load the fixtures by default * * @var bool */ public $autoFixtures = false; /** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Config.language', 'eng'); Configure::write('App.base', ''); Configure::delete('Asset'); $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 = ''; Router::setRequestInfo($this->Form->request); 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:/(?: