* Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org) * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests * @since CakePHP(tm) v 1.2.0.4206 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace Cake\Test\TestCase\View\Helper; use Cake\Controller\Controller; use Cake\Core\App; use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Network\Request; use Cake\ORM\Entity; use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\Routing\Router; use Cake\TestSuite\TestCase; use Cake\Utility\Security; use Cake\View\Helper\FormHelper; use Cake\View\Helper\HtmlHelper; use Cake\View\View; /** * Test stub. */ class Article extends Entity { } /** * ContactTestController class * */ class ContactTestController extends Controller { /** * uses property * * @var mixed null */ public $uses = null; } /** * Contact class * */ class ContactsTable extends Table { /** * 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'), '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), '_constraints' => array('primary' => ['type' => 'primary', 'columns' => ['id']]) ); /** * validate property * * @var array */ public $validate = array( 'non_existing' => array(), 'idontexist' => array(), 'imrequired' => array('_allowEmpty' => false, array('rule' => array('between', 5, 30))), 'imrequiredonupdate' => array('notEmpty' => array('rule' => 'alphaNumeric', 'on' => 'update')), 'imrequiredoncreate' => array('required' => array('rule' => 'alphaNumeric', 'on' => 'create')), 'imrequiredonboth' => array( 'required' => array('rule' => 'alphaNumeric'), ), 'string_required' => 'notEmpty', 'imalsorequired' => array('_allowEmpty' => false, array('rule' => 'alphaNumeric')), 'imrequiredtoo' => array('rule' => 'notEmpty'), 'required_one' => array('required' => array('rule' => array('notEmpty'))), 'imnotrequired' => array( '_allowEmpty' => true, array('rule' => 'alphaNumeric') ), 'imalsonotrequired' => array( '_allowEmpty' => true, 'alpha' => array('rule' => 'alphaNumeric'), 'between' => array('rule' => array('between', 5, 30)), ), 'imnotrequiredeither' => array( '_allowEmpty' => true, array('rule' => array('between', 5, 30)) ), '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') ); /** * hasAndBelongsToMany property * * @var array */ public $hasAndBelongsToMany = array( 'ContactTag' => array( 'className' => 'Cake\Test\TestCase\View\Helper\ContactTag', 'with' => 'Cake\Test\TestCase\View\Helper\ContactTagsContact' ) ); /** * hasAndBelongsToMany property * * @var array */ public $belongsTo = array( 'User' => array('className' => 'UserForm' )); /** * Initializes the schema and validation rules. * * @return void */ public function initialize(array $config) { $this->schema($this->_schema); } } /** * ContactTagsContact class * */ class ContactTagsContactsTable extends Table { /** * 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 * */ class ContactNonStandardPk extends ContactsTable { /** * 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 * */ class ContactTagsTable extends Table { /** * 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 * */ class UserFormsTable extends Table { /** * 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 * */ class OpenidUrlsTable extends Table { /** * 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 * */ class ValidateUsersTable extends Table { /** * 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'), '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), '_constraints' => array('primary' => ['type' => 'primary', 'columns' => ['id']]) ); /** * Initializes the schema * * @return void */ public function initialize(array $config) { $this->schema($this->_schema); } /** * beforeValidate method * * @param array $options * @return void */ public function beforeValidate($options = array()) { $this->invalidate('email'); return false; } } /** * ValidateProfile class * */ class ValidateProfilesTable extends Table { /** * useTable property * * @var boolean */ 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 * */ class ValidateItemsTable extends Table { /** * 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 * */ class TestMailsTable extends Table { } /** * FormHelperTest class * * @property FormHelper $Form */ class FormHelperTest extends TestCase { /** * Fixtures to be used * * @var array */ public $fixtures = array('core.article'); /** * Do not load the fixtures by default * * @var boolean */ public $autoFixtures = false; /** * setUp method * * @return void */ public function setUp() { parent::setUp(); Configure::write('Config.language', 'eng'); Configure::write('App.base', ''); Configure::write('App.namespace', 'Cake\Test\TestCase\View\Helper'); Configure::delete('Asset'); $this->View = new View(null); $this->Form = new FormHelper($this->View); $this->Form->Html = new HtmlHelper($this->View); $this->Form->request = new Request('articles/add'); $this->Form->request->here = '/articles/add'; $this->Form->request['controller'] = 'articles'; $this->Form->request['action'] = 'add'; $this->Form->request->webroot = ''; $this->Form->request->base = ''; $this->dateRegex = array( 'daysRegex' => 'preg:/(?: