📄 model.test.php
字号:
<?php/* SVN FILE: $Id: model.test.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * Copyright 2005-2008, Cake Software Foundation, Inc. * 1785 E. Sahara Avenue, Suite 490-204 * Las Vegas, Nevada 89104 * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package cake.tests * @subpackage cake.tests.cases.libs.model * @since CakePHP(tm) v 1.2.0.4206 * @version $Revision: 7118 $ * @modifiedby $LastChangedBy: gwoo $ * @lastmodified $Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */App::import('Core', array('AppModel', 'Model'));require_once dirname(__FILE__) . DS . 'models.php';/** * Short description for class. * * @package cake.tests * @subpackage cake.tests.cases.libs.model */class ModelTest extends CakeTestCase {/** * autoFixtures property * * @var bool false * @access public */ var $autoFixtures = false;/** * fixtures property * * @var array * @access public */ var $fixtures = array( 'core.category', 'core.category_thread', 'core.user', 'core.article', 'core.featured', 'core.article_featureds_tags', 'core.article_featured', 'core.articles', 'core.numeric_article', 'core.tag', 'core.articles_tag', 'core.comment', 'core.attachment', 'core.apple', 'core.sample', 'core.another_article', 'core.advertisement', 'core.home', 'core.post', 'core.author', 'core.product', 'core.project', 'core.thread', 'core.message', 'core.bid', 'core.portfolio', 'core.item', 'core.items_portfolio', 'core.syfile', 'core.image', 'core.device_type', 'core.device_type_category', 'core.feature_set', 'core.exterior_type_category', 'core.document', 'core.device', 'core.document_directory', 'core.primary_model', 'core.secondary_model', 'core.something', 'core.something_else', 'core.join_thing', 'core.join_a', 'core.join_b', 'core.join_c', 'core.join_a_b', 'core.join_a_c', 'core.uuid', 'core.data_test', 'core.posts_tag', 'core.the_paper_monkies', 'core.person', 'core.underscore_field', 'core.node', 'core.dependency', 'core.story', 'core.stories_tag' );/** * start method * * @access public * @return void */ function start() { parent::start(); $this->debug = Configure::read('debug'); Configure::write('debug', 2); }/** * end method * * @access public * @return void */ function end() { parent::end(); Configure::write('debug', $this->debug); }/** * testAutoConstructAssociations method * * @access public * @return void */ function testAutoConstructAssociations() { $this->loadFixtures('User'); $TestModel =& new AssociationTest1(); $result = $TestModel->hasAndBelongsToMany; $expected = array('AssociationTest2' => array( 'unique' => false, 'joinTable' => 'join_as_join_bs', 'foreignKey' => false, 'className' => 'AssociationTest2', 'with' => 'JoinAsJoinB', 'associationForeignKey' => 'join_b_id', 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'finderQuery' => '', 'deleteQuery' => '', 'insertQuery' => '' )); $this->assertEqual($result, $expected); }/** * testColumnTypeFetching method * * @access public * @return void */ function testColumnTypeFetching() { $model =& new Test(); $this->assertEqual($model->getColumnType('id'), 'integer'); $this->assertEqual($model->getColumnType('notes'), 'text'); $this->assertEqual($model->getColumnType('updated'), 'datetime'); $this->assertEqual($model->getColumnType('unknown'), null); $model =& new Article(); $this->assertEqual($model->getColumnType('User.created'), 'datetime'); $this->assertEqual($model->getColumnType('Tag.id'), 'integer'); $this->assertEqual($model->getColumnType('Article.id'), 'integer'); }/** * testMultipleBelongsToWithSameClass method * * @access public * @return void */ function testMultipleBelongsToWithSameClass() { $this->loadFixtures('DeviceType', 'DeviceTypeCategory', 'FeatureSet', 'ExteriorTypeCategory', 'Document', 'Device', 'DocumentDirectory'); $DeviceType =& new DeviceType(); $DeviceType->recursive = 2; $result = $DeviceType->read(null, 1); $expected = array( 'DeviceType' => array( 'id' => 1, 'device_type_category_id' => 1, 'feature_set_id' => 1, 'exterior_type_category_id' => 1, 'image_id' => 1, 'extra1_id' => 1, 'extra2_id' => 1, 'name' => 'DeviceType 1', 'order' => 0 ), 'Image' => array('id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1')), 'Extra1' => array( 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') ), 'Extra2' => array( 'id' => 1, 'document_directory_id' => 1, 'name' => 'Document 1', 'DocumentDirectory' => array('id' => 1, 'name' => 'DocumentDirectory 1') ), 'DeviceTypeCategory' => array('id' => 1, 'name' => 'DeviceTypeCategory 1'), 'FeatureSet' => array('id' => 1, 'name' => 'FeatureSet 1'), 'ExteriorTypeCategory' => array( 'id' => 1, 'image_id' => 1, 'name' => 'ExteriorTypeCategory 1', 'Image' => array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1) ), 'Device' => array( array('id' => 1, 'device_type_id' => 1, 'name' => 'Device 1', 'typ' => 1), array('id' => 2, 'device_type_id' => 1, 'name' => 'Device 2', 'typ' => 1), array('id' => 3, 'device_type_id' => 1, 'name' => 'Device 3', 'typ' => 2) ) ); $this->assertEqual($result, $expected); }/** * testHabtmRecursiveBelongsTo method * * @access public * @return void */ function testHabtmRecursiveBelongsTo() { $this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image'); $Portfolio =& new Portfolio(); $result = $Portfolio->find(array('id' => 2), null, null, 3); $expected = array('Portfolio' => array( 'id' => 2, 'seller_id' => 1, 'name' => 'Portfolio 2'), 'Item' => array( array('id' => 2, 'syfile_id' => 2, 'published' => 0, 'name' => 'Item 2', 'ItemsPortfolio' => array('id' => 2, 'item_id' => 2, 'portfolio_id' => 2), 'Syfile' => array('id' => 2, 'image_id' => 2, 'name' => 'Syfile 2', 'item_count' => null, 'Image' => array('id' => 2, 'name' => 'Image 2'))), array('id' => 6, 'syfile_id' => 6, 'published' => 0, 'name' => 'Item 6', 'ItemsPortfolio' => array('id' => 6, 'item_id' => 6, 'portfolio_id' => 2), 'Syfile' => array('id' => 6, 'image_id' => null, 'name' => 'Syfile 6', 'item_count' => null, 'Image' => array())))); $this->assertEqual($result, $expected); }/** * testHabtmFinderQuery method * * @access public * @return void */ function testHabtmFinderQuery() { $this->loadFixtures('Article', 'Tag', 'ArticlesTag'); $Article =& new Article(); $sql = $this->db->buildStatement( array( 'fields' => $this->db->fields($Article->Tag, null, array('Tag.id', 'Tag.tag', 'ArticlesTag.article_id', 'ArticlesTag.tag_id')), 'table' => $this->db->fullTableName('tags'), 'alias' => 'Tag', 'limit' => null, 'offset' => null, 'group' => null, 'joins' => array(array( 'alias' => 'ArticlesTag', 'table' => $this->db->fullTableName('articles_tags'), 'conditions' => array( array("ArticlesTag.article_id" => '{$__cakeID__$}'), array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id')) ) )), 'conditions' => array(), 'order' => null ), $Article ); $Article->hasAndBelongsToMany['Tag']['finderQuery'] = $sql; $result = $Article->find('first'); $expected = array(array('id' => '1', 'tag' => 'tag1'), array('id' => '2', 'tag' => 'tag2')); $this->assertEqual($result['Tag'], $expected); }/** * testHabtmLimitOptimization method * * @access public * @return void */ function testHabtmLimitOptimization() { $this->loadFixtures('Article', 'User', 'Comment', 'Tag', 'ArticlesTag'); $TestModel =& new Article(); $TestModel->hasAndBelongsToMany['Tag']['limit'] = 2; $result = $TestModel->read(null, 2); $expected = array( 'Article' => array('id' => '2', 'user_id' => '3', 'title' => 'Second Article', 'body' => 'Second Article Body', 'published' => 'Y', 'created' => '2007-03-18 10:41:23', 'updated' => '2007-03-18 10:43:31'), 'User' => array('id' => '3', 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'), 'Comment' => array( array('id' => '5', 'article_id' => '2', 'user_id' => '1', 'comment' => 'First Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:53:23', 'updated' => '2007-03-18 10:55:31'), array('id' => '6', 'article_id' => '2', 'user_id' => '2', 'comment' => 'Second Comment for Second Article', 'published' => 'Y', 'created' => '2007-03-18 10:55:23', 'updated' => '2007-03-18 10:57:31') ), 'Tag' => array( array('id' => '1', 'tag' => 'tag1', 'created' => '2007-03-18 12:22:23', 'updated' => '2007-03-18 12:24:31'), array('id' => '3', 'tag' => 'tag3', 'created' => '2007-03-18 12:26:23', 'updated' => '2007-03-18 12:28:31')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -