2007-02-03 22:20:13 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2008-01-01 22:18:17 +00:00
* Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* 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
2008-01-01 22:18:17 +00:00
* @ copyright Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* @ 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 $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
2007-08-17 19:03:49 +00:00
2008-02-21 15:36:13 +00:00
App :: import ( 'Core' , array ( 'AppModel' , 'Model' ));
require_once dirname ( __FILE__ ) . DS . 'models.php' ;
2007-11-26 18:00:06 +00:00
2007-02-03 22:20:13 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
2007-03-23 21:59:08 +00:00
class ModelTest extends CakeTestCase {
2008-01-11 03:16:19 +00:00
var $autoFixtures = false ;
2008-01-03 18:50:59 +00:00
2008-01-11 03:16:19 +00:00
var $fixtures = array (
2007-08-14 23:12:24 +00:00
'core.category' , 'core.category_thread' , 'core.user' , 'core.article' , 'core.featured' , 'core.article_featureds_tags' ,
2008-05-18 09:22:42 +00:00
'core.article_featured' , 'core.articles' , 'core.numeric_article' , 'core.tag' , 'core.articles_tag' , 'core.comment' , 'core.attachment' ,
2007-08-17 19:03:49 +00:00
'core.apple' , 'core.sample' , 'core.another_article' , 'core.advertisement' , 'core.home' , 'core.post' , 'core.author' ,
2008-02-21 15:36:13 +00:00
'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' ,
2008-02-26 06:20:16 +00:00
'core.something_else' , 'core.join_thing' , 'core.join_a' , 'core.join_b' , 'core.join_c' , 'core.join_a_b' , 'core.join_a_c' ,
2008-05-15 03:16:36 +00:00
'core.uuid' , 'core.data_test' , 'core.posts_tag' , 'core.the_paper_monkies' , 'core.person' , 'core.underscore_field' ,
'core.node' , 'core.dependency'
2008-01-11 03:16:19 +00:00
);
2007-03-30 00:08:10 +00:00
2007-03-27 02:22:35 +00:00
function start () {
parent :: start ();
2007-08-16 05:44:06 +00:00
$this -> debug = Configure :: read ( 'debug' );
2007-03-27 02:22:35 +00:00
Configure :: write ( 'debug' , 2 );
}
2007-03-30 00:08:10 +00:00
2007-03-27 02:22:35 +00:00
function end () {
parent :: end ();
2007-08-16 05:44:06 +00:00
Configure :: write ( 'debug' , $this -> debug );
2007-03-27 02:22:35 +00:00
}
2007-03-30 00:08:10 +00:00
2008-02-03 06:40:15 +00:00
function testAutoConstructAssociations () {
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new AssociationTest1 ();
2008-02-03 06:40:15 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasAndBelongsToMany ;
2008-02-03 06:40:15 +00:00
$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 );
}
2007-10-24 16:07:36 +00:00
function testMultipleBelongsToWithSameClass () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'DeviceType' , 'DeviceTypeCategory' , 'FeatureSet' , 'ExteriorTypeCategory' , 'Document' , 'Device' , 'DocumentDirectory' );
2008-05-13 16:42:39 +00:00
$DeviceType =& new DeviceType ();
2007-10-22 20:20:48 +00:00
2008-05-13 16:42:39 +00:00
$DeviceType -> recursive = 2 ;
$result = $DeviceType -> read ( null , 1 );
2008-03-11 02:44:33 +00:00
2007-10-22 20:20:48 +00:00
$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
),
2007-10-22 22:58:38 +00:00
'Image' => array ( 'id' => 1 , 'document_directory_id' => 1 , 'name' => 'Document 1' ,
'DocumentDirectory' => array ( 'id' => 1 , 'name' => 'DocumentDirectory 1' )),
2007-10-22 20:20:48 +00:00
'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 );
}
2007-10-24 16:07:36 +00:00
function testHabtmRecursiveBelongsTo () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Portfolio' , 'Item' , 'ItemsPortfolio' , 'Syfile' , 'Image' );
2008-05-13 16:42:39 +00:00
$Portfolio =& new Portfolio ();
2007-09-11 21:00:58 +00:00
2008-05-13 16:42:39 +00:00
$result = $Portfolio -> find ( array ( 'id' => 2 ), null , null , 3 );
2007-10-22 02:11:58 +00:00
$expected = array ( 'Portfolio' => array (
2008-02-02 04:50:44 +00:00
'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 ()))));
2007-09-11 21:00:58 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-03-08 20:08:15 +00:00
function testHabtmFinderQuery () {
$this -> loadFixtures ( 'Article' , 'Tag' , 'ArticlesTag' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
2008-03-11 05:22:17 +00:00
2008-05-11 23:08:47 +00:00
$sql = $this -> db -> buildStatement (
2008-03-11 05:22:17 +00:00
array (
2008-05-13 16:42:39 +00:00
'fields' => $this -> db -> fields ( $Article -> Tag , null , array ( 'Tag.id' , 'Tag.tag' , 'ArticlesTag.article_id' , 'ArticlesTag.tag_id' )),
2008-05-11 23:08:47 +00:00
'table' => $this -> db -> fullTableName ( 'tags' ),
2008-03-11 05:22:17 +00:00
'alias' => 'Tag' ,
'limit' => null ,
'offset' => null ,
'joins' => array ( array (
'alias' => 'ArticlesTag' ,
2008-05-11 23:08:47 +00:00
'table' => $this -> db -> fullTableName ( 'articles_tags' ),
2008-03-11 05:22:17 +00:00
'conditions' => array (
array ( " ArticlesTag.article_id " => '{$__cakeID__$}' ),
array ( " ArticlesTag.tag_id " => '{$__cakeIdentifier[Tag.id]__$}' )
)
)),
'conditions' => array (),
'order' => null
),
2008-05-13 16:42:39 +00:00
$Article
2008-03-11 05:22:17 +00:00
);
2008-05-13 16:42:39 +00:00
$Article -> hasAndBelongsToMany [ 'Tag' ][ 'finderQuery' ] = $sql ;
$result = $Article -> find ( 'first' );
2008-03-08 20:08:15 +00:00
$expected = array ( array ( 'id' => '1' , 'tag' => 'tag1' ), array ( 'id' => '2' , 'tag' => 'tag2' ));
$this -> assertEqual ( $result [ 'Tag' ], $expected );
}
2008-03-11 02:44:33 +00:00
function testHabtmLimitOptimization () {
2008-03-15 05:08:06 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Comment' , 'Tag' , 'ArticlesTag' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-03-11 02:44:33 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> hasAndBelongsToMany [ 'Tag' ][ 'limit' ] = 2 ;
$result = $TestModel -> read ( null , 2 );
2008-03-15 05:08:06 +00:00
$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' )
)
);
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> hasAndBelongsToMany [ 'Tag' ][ 'limit' ] = 1 ;
$result = $TestModel -> read ( null , 2 );
2008-03-15 05:08:06 +00:00
unset ( $expected [ 'Tag' ][ 1 ]);
$this -> assertEqual ( $result , $expected );
2008-03-11 02:44:33 +00:00
}
2008-05-15 07:08:16 +00:00
function testHabtmUniqueKey () {
$model =& new Item ();
$this -> assertFalse ( $model -> hasAndBelongsToMany [ 'Portfolio' ][ 'unique' ]);
}
2008-03-11 02:44:33 +00:00
function testHasManyLimitOptimization () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Project' , 'Thread' , 'Message' , 'Bid' );
2008-05-13 16:42:39 +00:00
$Project =& new Project ();
$Project -> recursive = 3 ;
2007-10-22 02:11:58 +00:00
2008-05-13 16:42:39 +00:00
$result = $Project -> find ( 'all' );
2008-03-01 03:12:12 +00:00
$expected = array (
array ( 'Project' => array ( 'id' => 1 , 'name' => 'Project 1' ),
'Thread' => array ( array ( 'id' => 1 , 'project_id' => 1 , 'name' => 'Project 1, Thread 1' ,
'Message' => array ( array ( 'id' => 1 , 'thread_id' => 1 , 'name' => 'Thread 1, Message 1' ,
'Bid' => array ( 'id' => 1 , 'message_id' => 1 , 'name' => 'Bid 1.1' )))),
array ( 'id' => 2 , 'project_id' => 1 , 'name' => 'Project 1, Thread 2' ,
'Message' => array ( array ( 'id' => 2 , 'thread_id' => 2 , 'name' => 'Thread 2, Message 1' ,
'Bid' => array ( 'id' => 4 , 'message_id' => 2 , 'name' => 'Bid 2.1' )))))),
array ( 'Project' => array ( 'id' => 2 , 'name' => 'Project 2' ),
'Thread' => array ( array ( 'id' => 3 , 'project_id' => 2 , 'name' => 'Project 2, Thread 1' ,
'Message' => array ( array ( 'id' => 3 , 'thread_id' => 3 , 'name' => 'Thread 3, Message 1' ,
'Bid' => array ( 'id' => 3 , 'message_id' => 3 , 'name' => 'Bid 3.1' )))))),
array ( 'Project' => array ( 'id' => 3 , 'name' => 'Project 3' ),
'Thread' => array ()));
2007-08-17 19:03:49 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-12-25 05:35:37 +00:00
2007-12-23 17:03:19 +00:00
function testWithAssociation () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Something' , 'SomethingElse' , 'JoinThing' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Something ();
$result = $TestModel -> SomethingElse -> find ( 'all' );
2007-12-23 17:03:19 +00:00
$expected = array (
array ( 'SomethingElse' => array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'Something' => array ( array ( 'id' => '3' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ,
'JoinThing' => array ( 'id' => '3' , 'something_id' => '3' , 'something_else_id' => '1' , 'doomed' => '1' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )))),
array ( 'SomethingElse' => array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ),
'Something' => array ( array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'JoinThing' => array ( 'id' => '1' , 'something_id' => '1' , 'something_else_id' => '2' , 'doomed' => '1' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )))),
array ( 'SomethingElse' => array ( 'id' => '3' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'Something' => array ( array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ,
'JoinThing' => array ( 'id' => '2' , 'something_id' => '2' , 'something_else_id' => '3' , 'doomed' => '0' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' )))));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2007-12-23 17:03:19 +00:00
$expected = array (
array ( 'Something' => array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'SomethingElse' => array (
array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ,
'JoinThing' => array ( 'doomed' => '1' , 'something_id' => '1' , 'something_else_id' => '2' )))),
array ( 'Something' => array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ),
'SomethingElse' => array (
array ( 'id' => '3' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ,
'JoinThing' => array ( 'doomed' => '0' , 'something_id' => '2' , 'something_else_id' => '3' )))),
array ( 'Something' => array ( 'id' => '3' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'SomethingElse' => array (
array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'JoinThing' => array ( 'doomed' => '1' , 'something_id' => '3' , 'something_else_id' => '1' )))));
$this -> assertEqual ( $result , $expected );
2008-01-01 23:57:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 1 );
2008-01-01 23:57:17 +00:00
$expected = array (
'Something' => array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'SomethingElse' => array ( array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ,
'JoinThing' => array ( 'doomed' => '1' , 'something_id' => '1' , 'something_else_id' => '2' ))));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> hasAndBelongsToMany [ 'SomethingElse' ][ 'unique' ] = false ;
$TestModel -> create ( array (
2008-01-01 23:57:17 +00:00
'Something' => array ( 'id' => 1 ),
'SomethingElse' => array ( 3 , array ( 'something_else_id' => 1 , 'doomed' => '1' ))
));
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$TestModel -> save ();
2008-01-01 23:57:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> hasAndBelongsToMany [ 'SomethingElse' ][ 'order' ] = 'SomethingElse.id ASC' ;
$result = $TestModel -> findById ( 1 );
2008-01-01 23:57:17 +00:00
$expected = array (
'Something' => array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => $ts ),
'SomethingElse' => array (
array ( 'id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'JoinThing' => array ( 'doomed' => '1' , 'something_id' => '1' , 'something_else_id' => '1' )),
2008-01-17 17:09:10 +00:00
array ( 'id' => '2' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ,
'JoinThing' => array ( 'doomed' => '1' , 'something_id' => '1' , 'something_else_id' => '2' )),
2008-01-01 23:57:17 +00:00
array ( 'id' => '3' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ,
2008-04-30 19:19:16 +00:00
'JoinThing' => array ( 'doomed' => '0' , 'something_id' => '1' , 'something_else_id' => '3' ))));
2008-01-01 23:57:17 +00:00
$this -> assertEqual ( $result , $expected );
2007-12-23 17:03:19 +00:00
}
2007-12-25 05:35:37 +00:00
2008-03-07 04:36:20 +00:00
function testDynamicAssociations () {
$this -> loadFixtures ( 'Article' , 'Comment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-03-07 04:36:20 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> belongsTo = $TestModel -> hasAndBelongsToMany = $TestModel -> hasOne = array ();
$TestModel -> hasMany [ 'Comment' ] = array_merge ( $TestModel -> hasMany [ 'Comment' ], array (
2008-03-07 04:36:20 +00:00
'foreignKey' => false ,
'conditions' => array ( 'Comment.user_id' => '= 2' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2008-03-07 04:36:20 +00:00
$expected = array (
array (
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47: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' )
)
),
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' ),
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47: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' )
)
),
array (
'Article' => array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47: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' )
)
)
);
$this -> assertEqual ( $result , $expected );
}
2008-01-03 18:50:59 +00:00
function testSaveMultipleHabtm () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'JoinA' , 'JoinB' , 'JoinC' , 'JoinAB' , 'JoinAC' );
2008-05-13 16:42:39 +00:00
$TestModel = new JoinA ();
$result = $TestModel -> findById ( 1 );
2008-01-11 06:45:00 +00:00
2008-01-03 18:50:59 +00:00
$expected = array (
'JoinA' => array ( 'id' => 1 , 'name' => 'Join A 1' , 'body' => 'Join A 1 Body' , 'created' => '2008-01-03 10:54:23' , 'updated' => '2008-01-03 10:54:23' ),
'JoinB' => array (
2008-01-11 03:16:19 +00:00
0 => array ( 'id' => 2 , 'name' => 'Join B 2' , 'created' => '2008-01-03 10:55:02' , 'updated' => '2008-01-03 10:55:02' ,
2008-01-03 18:50:59 +00:00
'JoinAsJoinB' => array ( 'id' => 1 , 'join_a_id' => 1 , 'join_b_id' => 2 , 'other' => 'Data for Join A 1 Join B 2' , 'created' => '2008-01-03 10:56:33' , 'updated' => '2008-01-03 10:56:33' ))),
'JoinC' => array (
0 => array ( 'id' => 2 , 'name' => 'Join C 2' , 'created' => '2008-01-03 10:56:12' , 'updated' => '2008-01-03 10:56:12' ,
'JoinAsJoinC' => array ( 'id' => 1 , 'join_a_id' => 1 , 'join_c_id' => 2 , 'other' => 'Data for Join A 1 Join C 2' , 'created' => '2008-01-03 10:57:22' , 'updated' => '2008-01-03 10:57:22' ))));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
2008-01-03 18:50:59 +00:00
$data = array (
'JoinA' => array ( 'id' => '1' , 'name' => 'New name for Join A 1' ),
'JoinB' => array ( array ( 'id' => 1 , 'join_b_id' => 2 , 'other' => 'New data for Join A 1 Join B 2' )),
'JoinC' => array ( array ( 'id' => 1 , 'join_c_id' => 2 , 'other' => 'New data for Join A 1 Join C 2' )));
2008-05-13 16:42:39 +00:00
$TestModel -> set ( $data );
$TestModel -> save ();
2008-01-03 18:50:59 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 1 );
2008-01-03 18:50:59 +00:00
$expected = array (
'JoinA' => array ( 'id' => 1 , 'name' => 'New name for Join A 1' , 'body' => 'Join A 1 Body' , 'created' => '2008-01-03 10:54:23' , 'updated' => $ts ),
'JoinB' => array (
2008-01-11 03:16:19 +00:00
0 => array ( 'id' => 2 , 'name' => 'Join B 2' , 'created' => '2008-01-03 10:55:02' , 'updated' => '2008-01-03 10:55:02' ,
2008-01-03 18:50:59 +00:00
'JoinAsJoinB' => array ( 'id' => 1 , 'join_a_id' => 1 , 'join_b_id' => 2 , 'other' => 'New data for Join A 1 Join B 2' , 'created' => $ts , 'updated' => $ts ))),
'JoinC' => array (
0 => array ( 'id' => 2 , 'name' => 'Join C 2' , 'created' => '2008-01-03 10:56:12' , 'updated' => '2008-01-03 10:56:12' ,
'JoinAsJoinC' => array ( 'id' => 1 , 'join_a_id' => 1 , 'join_c_id' => 2 , 'other' => 'New data for Join A 1 Join C 2' , 'created' => $ts , 'updated' => $ts ))));
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testFindAllRecursiveSelfJoin () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Home' , 'AnotherArticle' , 'Advertisement' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Home ();
$TestModel -> recursive = 2 ;
2007-04-29 02:25:57 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2007-10-22 02:11:58 +00:00
$expected = array ( array ( 'Home' => array (
'id' => '1' , 'another_article_id' => '1' , 'advertisement_id' => '1' , 'title' => 'First Home' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'AnotherArticle' => array ( 'id' => '1' , 'title' => 'First Article' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'Home' => array ( array ( 'id' => '1' , 'another_article_id' => '1' , 'advertisement_id' => '1' , 'title' => 'First Home' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ))),
'Advertisement' => array ( 'id' => '1' , 'title' => 'First Ad' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'Home' => array ( array ( 'id' => '1' , 'another_article_id' => '1' , 'advertisement_id' => '1' , 'title' => 'First Home' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
array ( 'id' => '2' , 'another_article_id' => '3' , 'advertisement_id' => '1' , 'title' => 'Second Home' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' )))),
array ( 'Home' => array (
'id' => '2' , 'another_article_id' => '3' , 'advertisement_id' => '1' , 'title' => 'Second Home' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ),
'AnotherArticle' => array ( 'id' => '3' , 'title' => 'Third Article' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ,
'Home' => array ( array ( 'id' => '2' , 'another_article_id' => '3' , 'advertisement_id' => '1' , 'title' => 'Second Home' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ))),
'Advertisement' => array ( 'id' => '1' , 'title' => 'First Ad' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
'Home' => array ( array ( 'id' => '1' , 'another_article_id' => '1' , 'advertisement_id' => '1' , 'title' => 'First Home' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
array ( 'id' => '2' , 'another_article_id' => '3' , 'advertisement_id' => '1' , 'title' => 'Second Home' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' )))));
2007-04-29 02:25:57 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-03-26 11:17:24 +00:00
function testFindSelfAssociations () {
2008-03-30 04:35:05 +00:00
$this -> loadFixtures ( 'Person' );
2008-04-17 13:10:27 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Person ();
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( null , 1 );
2008-03-26 11:17:24 +00:00
$expected = array (
'Person' => array ( 'id' => 1 , 'name' => 'person' , 'mother_id' => 2 , 'father_id' => 3 ),
'Mother' => array ( 'id' => 2 , 'name' => 'mother' , 'mother_id' => 4 , 'father_id' => 5 ,
'Mother' => array ( 'id' => 4 , 'name' => 'mother - grand mother' , 'mother_id' => 0 , 'father_id' => 0 ),
'Father' => array ( 'id' => 5 , 'name' => 'mother - grand father' , 'mother_id' => 0 , 'father_id' => 0 )),
'Father' => array ( 'id' => 3 , 'name' => 'father' , 'mother_id' => 6 , 'father_id' => 7 ,
'Father' => array ( 'id' => 7 , 'name' => 'father - grand father' , 'mother_id' => 0 , 'father_id' => 0 ),
'Mother' => array ( 'id' => 6 , 'name' => 'father - grand mother' , 'mother_id' => 0 , 'father_id' => 0 )));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 3 ;
$result = $TestModel -> read ( null , 1 );
2008-03-26 11:17:24 +00:00
$expected = array (
'Person' => array ( 'id' => 1 , 'name' => 'person' , 'mother_id' => 2 , 'father_id' => 3 ),
'Mother' => array ( 'id' => 2 , 'name' => 'mother' , 'mother_id' => 4 , 'father_id' => 5 ,
'Mother' => array ( 'id' => 4 , 'name' => 'mother - grand mother' , 'mother_id' => 0 , 'father_id' => 0 ,
'Mother' => array (),
'Father' => array ()),
'Father' => array ( 'id' => 5 , 'name' => 'mother - grand father' , 'mother_id' => 0 , 'father_id' => 0 ,
'Father' => array (),
'Mother' => array ())),
'Father' => array ( 'id' => 3 , 'name' => 'father' , 'mother_id' => 6 , 'father_id' => 7 ,
'Father' => array ( 'id' => 7 , 'name' => 'father - grand father' , 'mother_id' => 0 , 'father_id' => 0 ,
'Father' => array (),
'Mother' => array ()),
'Mother' => array ( 'id' => 6 , 'name' => 'father - grand mother' , 'mother_id' => 0 , 'father_id' => 0 ,
'Mother' => array (),
'Father' => array ())));
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testIdentity () {
2008-05-13 16:42:39 +00:00
$TestModel =& new Test ();
$result = $TestModel -> alias ;
2007-02-03 22:20:13 +00:00
$expected = 'Test' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel =& new TestAlias ();
$result = $TestModel -> alias ;
$expected = 'TestAlias' ;
$this -> assertEqual ( $result , $expected );
$TestModel =& new TestAlias ( array ( 'alias' => 'AnotherTest' ));
$result = $TestModel -> alias ;
$expected = 'AnotherTest' ;
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testCreation () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Test ();
$result = $TestModel -> create ();
2007-03-17 00:24:33 +00:00
$expected = array ( 'Test' => array ( 'notes' => 'write some notes here' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
$result = $TestModel -> schema ();
2007-06-03 21:54:11 +00:00
2008-05-11 23:08:47 +00:00
if ( isset ( $this -> db -> columns [ 'primary_key' ][ 'length' ])) {
$intLength = $this -> db -> columns [ 'primary_key' ][ 'length' ];
} elseif ( isset ( $this -> db -> columns [ 'integer' ][ 'length' ])) {
$intLength = $this -> db -> columns [ 'integer' ][ 'length' ];
2007-06-03 21:54:11 +00:00
} else {
$intLength = 11 ;
}
2007-08-14 23:12:24 +00:00
$expected = array (
2008-01-11 03:16:19 +00:00
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => $intLength , 'key' => 'primary' ),
2007-10-28 04:18:18 +00:00
'user' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => 255 ),
'password' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => 255 ),
'created' => array ( 'type' => 'datetime' , 'null' => true , 'default' => null , 'length' => null ),
'updated' => array ( 'type' => 'datetime' , 'null' => true , 'default' => null , 'length' => null ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
$result = $TestModel -> create ();
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array ( 'published' => 'N' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-17 00:24:33 +00:00
}
2007-10-24 16:06:00 +00:00
2007-12-19 02:05:15 +00:00
function testCreationOfEmptyRecord () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Author' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Author ();
$this -> assertEqual ( $TestModel -> find ( 'count' ), 4 );
2007-12-19 02:05:15 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> deleteAll ( true , false , false );
$this -> assertEqual ( $TestModel -> find ( 'count' ), 0 );
2007-12-19 02:05:15 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-12-19 02:05:15 +00:00
$this -> assertTrue ( isset ( $result [ 'Author' ][ 'created' ]));
$this -> assertTrue ( isset ( $result [ 'Author' ][ 'updated' ]));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> find ( 'count' ), 1 );
2007-12-19 02:05:15 +00:00
}
2008-02-06 02:35:12 +00:00
function testCreateWithPKFiltering () {
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-02-06 02:35:12 +00:00
$data = array ( 'id' => 5 , 'user_id' => 2 , 'title' => 'My article' , 'body' => 'Some text' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2008-02-06 02:35:12 +00:00
$expected = array ( 'Article' => array ( 'published' => 'N' , 'id' => 5 , 'user_id' => 2 , 'title' => 'My article' , 'body' => 'Some text' ));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> id , 5 );
2008-02-06 02:35:12 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data , true );
2008-02-06 02:35:12 +00:00
$expected = array ( 'Article' => array ( 'published' => 'N' , 'id' => false , 'user_id' => 2 , 'title' => 'My article' , 'body' => 'Some text' ));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> id );
2008-02-06 02:35:12 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( array ( 'Article' => $data ), true );
2008-02-06 02:35:12 +00:00
$expected = array ( 'Article' => array ( 'published' => 'N' , 'id' => false , 'user_id' => 2 , 'title' => 'My article' , 'body' => 'Some text' ));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> id );
2008-02-06 02:35:12 +00:00
}
2007-10-24 16:07:36 +00:00
function testCreationWithMultipleData () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'Comment' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
$Comment =& new Comment ();
2007-10-24 16:06:00 +00:00
2008-05-13 16:42:39 +00:00
$articles = $Article -> find ( 'all' , array ( 'fields' => array ( 'id' , 'title' ), 'recursive' => - 1 ));
$comments = $Comment -> find ( 'all' , array ( 'fields' => array ( 'id' , 'article_id' , 'user_id' , 'comment' , 'published' ), 'recursive' => - 1 ));
2007-10-24 03:32:34 +00:00
$this -> assertEqual ( $articles , array (
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
array ( 'Article' => array ( 'id' => 2 , 'title' => 'Second Article' )),
array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' ))));
$this -> assertEqual ( $comments , array (
array ( 'Comment' => array ( 'id' => 1 , 'article_id' => 1 , 'user_id' => 2 , 'comment' => 'First Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 2 , 'article_id' => 1 , 'user_id' => 4 , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 3 , 'article_id' => 1 , 'user_id' => 1 , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 4 , 'article_id' => 1 , 'user_id' => 1 , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' )),
array ( 'Comment' => array ( 'id' => 5 , 'article_id' => 2 , 'user_id' => 1 , 'comment' => 'First Comment for Second Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 6 , 'article_id' => 2 , 'user_id' => 2 , 'comment' => 'Second Comment for Second Article' , 'published' => 'Y' ))));
2007-10-24 16:06:00 +00:00
2007-10-24 03:32:34 +00:00
$data = array ( 'Comment' => array ( 'article_id' => 2 , 'user_id' => 4 , 'comment' => 'Brand New Comment' , 'published' => 'N' ),
'Article' => array ( 'id' => 2 , 'title' => 'Second Article Modified' ));
2008-05-13 16:42:39 +00:00
$result = $Comment -> create ( $data );
2007-10-24 03:32:34 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $Comment -> save ();
2007-10-24 03:32:34 +00:00
$this -> assertTrue ( $result );
2007-10-24 16:06:00 +00:00
2008-05-13 16:42:39 +00:00
$articles = $Article -> find ( 'all' , array ( 'fields' => array ( 'id' , 'title' ), 'recursive' => - 1 ));
$comments = $Comment -> find ( 'all' , array ( 'fields' => array ( 'id' , 'article_id' , 'user_id' , 'comment' , 'published' ), 'recursive' => - 1 ));
2007-10-24 03:32:34 +00:00
$this -> assertEqual ( $articles , array (
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
array ( 'Article' => array ( 'id' => 2 , 'title' => 'Second Article' )),
array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' ))));
$this -> assertEqual ( $comments , array (
array ( 'Comment' => array ( 'id' => 1 , 'article_id' => 1 , 'user_id' => 2 , 'comment' => 'First Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 2 , 'article_id' => 1 , 'user_id' => 4 , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 3 , 'article_id' => 1 , 'user_id' => 1 , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 4 , 'article_id' => 1 , 'user_id' => 1 , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' )),
array ( 'Comment' => array ( 'id' => 5 , 'article_id' => 2 , 'user_id' => 1 , 'comment' => 'First Comment for Second Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 6 , 'article_id' => 2 , 'user_id' => 2 , 'comment' => 'Second Comment for Second Article' , 'published' => 'Y' )),
array ( 'Comment' => array ( 'id' => 7 , 'article_id' => 2 , 'user_id' => 4 , 'comment' => 'Brand New Comment' , 'published' => 'N' ))));
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:06:00 +00:00
function testCreationWithMultipleDataSameModel () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
$SecondaryArticle =& new Article ();
2007-10-24 16:06:00 +00:00
2008-05-13 16:42:39 +00:00
$result = $Article -> field ( 'title' , array ( 'id' => 1 ));
2007-10-24 16:06:00 +00:00
$this -> assertEqual ( $result , 'First Article' );
2007-10-24 16:17:53 +00:00
$data = array ( 'Article' => array ( 'user_id' => 2 , 'title' => 'Brand New Article' , 'body' => 'Brand New Article Body' , 'published' => 'Y' ),
'SecondaryArticle' => array ( 'id' => 1 ));
2008-05-13 16:42:39 +00:00
$Article -> create ();
$result = $Article -> save ( $data );
2007-10-24 16:06:00 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $Article -> getInsertID ();
2007-10-24 16:06:00 +00:00
$this -> assertTrue ( ! empty ( $result ));
2008-05-13 16:42:39 +00:00
$result = $Article -> field ( 'title' , array ( 'id' => 1 ));
2007-10-24 16:06:00 +00:00
$this -> assertEqual ( $result , 'First Article' );
2008-05-13 16:42:39 +00:00
$articles = $Article -> find ( 'all' , array ( 'fields' => array ( 'id' , 'title' ), 'recursive' => - 1 ));
2007-10-24 16:06:00 +00:00
$this -> assertEqual ( $articles , array (
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
array ( 'Article' => array ( 'id' => 2 , 'title' => 'Second Article' )),
array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' )),
array ( 'Article' => array ( 'id' => 4 , 'title' => 'Brand New Article' ))));
}
2007-10-24 16:29:50 +00:00
function testCreationWithMultipleDataSameModelManualInstances () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'PrimaryModel' );
2007-10-24 16:29:50 +00:00
$Primary =& new PrimaryModel ();
$Secondary =& new PrimaryModel ();
$result = $Primary -> field ( 'primary_name' , array ( 'id' => 1 ));
$this -> assertEqual ( $result , 'Primary Name Existing' );
$data = array ( 'PrimaryModel' => array ( 'primary_name' => 'Primary Name New' ),
2007-10-24 22:08:19 +00:00
'SecondaryModel' => array ( 'id' => array ( 1 )));
2007-10-24 16:29:50 +00:00
$Primary -> create ();
$result = $Primary -> save ( $data );
$this -> assertTrue ( $result );
$result = $Primary -> field ( 'primary_name' , array ( 'id' => 1 ));
$this -> assertEqual ( $result , 'Primary Name Existing' );
$result = $Primary -> getInsertID ();
$this -> assertTrue ( ! empty ( $result ));
2007-10-24 17:04:14 +00:00
$result = $Primary -> field ( 'primary_name' , array ( 'id' => $result ));
$this -> assertEqual ( $result , 'Primary Name New' );
2007-10-24 16:29:50 +00:00
$result = $Primary -> findCount ();
$this -> assertEqual ( $result , 2 );
}
2007-10-24 16:07:36 +00:00
function testReadFakeThread () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2008-05-13 16:42:39 +00:00
$TestModel =& new CategoryThread ();
2007-03-29 02:16:00 +00:00
2007-03-30 00:08:10 +00:00
$this -> db -> fullDebug = true ;
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 6 ;
$TestModel -> id = 7 ;
$result = $TestModel -> read ();
2007-10-22 02:11:58 +00:00
$expected = array (
'CategoryThread' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 5 , 'parent_id' => 4 , 'name' => 'Category 1.1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )))))));
2007-03-30 00:08:10 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-29 02:16:00 +00:00
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testFindFakeThread () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2008-05-13 16:42:39 +00:00
$TestModel =& new CategoryThread ();
2007-04-29 02:25:57 +00:00
$this -> db -> fullDebug = true ;
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 6 ;
$result = $TestModel -> find ( array ( 'CategoryThread.id' => 7 ));
2007-04-29 02:25:57 +00:00
2007-10-22 02:11:58 +00:00
$expected = array (
'CategoryThread' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 5 , 'parent_id' => 4 , 'name' => 'Category 1.1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )))))));
2007-04-29 02:25:57 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testFindAllFakeThread () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2008-05-13 16:42:39 +00:00
$TestModel =& new CategoryThread ();
2007-04-29 02:25:57 +00:00
$this -> db -> fullDebug = true ;
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 6 ;
$result = $TestModel -> findAll ( null , null , 'CategoryThread.id ASC' );
2007-04-29 02:25:57 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => null , 'parent_id' => null , 'name' => null , 'created' => null , 'updated' => null , 'ParentCategory' => array ())),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ())),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ()))),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ())))),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 5 , 'parent_id' => 4 , 'name' => 'Category 1.1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ()))))),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 5 , 'parent_id' => 4 , 'name' => 'Category 1.1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
2008-03-26 11:17:24 +00:00
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ())))))),
2007-10-22 02:11:58 +00:00
array ( 'CategoryThread' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'ParentCategory' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 5 , 'parent_id' => 4 , 'name' => 'Category 1.1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 4 , 'parent_id' => 3 , 'name' => 'Category 1.1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 3 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ))))))));
2007-04-29 02:25:57 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-05-18 09:22:42 +00:00
function testConditionalNumerics () {
$this -> loadFixtures ( 'NumericArticle' );
$NumericArticle =& new NumericArticle ();
$data = array ( 'title' => '12345abcde' );
$result = $NumericArticle -> find ( $data );
$this -> assertTrue ( ! empty ( $result ));
// @TODO: make this pass in Cake 2.0 with passing the column around in db->value()
// SELECT * from articles WHERE title = 12345 // will find the article with title = 12345abcde, too : /
// $data = array('title' => '12345');
// $result = $NumericArticle->find($data);
// $this->assertTrue(empty($result));
}
2007-10-24 16:07:36 +00:00
function testFindAll () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( 'User.id > 2' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'User.id' => '!= 0' , 'User.user' => 'LIKE %arr%' ));
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'User.id' => '0' ));
2007-03-17 19:15:41 +00:00
$expected = array ();
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'or' => array ( 'User.id' => '0' , 'User.user' => 'LIKE %a%' )));
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.id, User.user' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.user' , 'User.user ASC' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'user' => 'garrett' )),
array ( 'User' => array ( 'user' => 'larry' )),
array ( 'User' => array ( 'user' => 'mariano' )),
array ( 'User' => array ( 'user' => 'nate' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.user' , 'User.user ASC' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'user' => 'garrett' )),
array ( 'User' => array ( 'user' => 'larry' )),
array ( 'User' => array ( 'user' => 'mariano' )),
array ( 'User' => array ( 'user' => 'nate' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.user' , 'User.user DESC' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'user' => 'nate' )),
array ( 'User' => array ( 'user' => 'mariano' )),
array ( 'User' => array ( 'user' => 'larry' )),
array ( 'User' => array ( 'user' => 'garrett' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , null , null , 3 , 1 );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-11 18:53:54 +00:00
// These tests are expected to fail on SQL Server since the LIMIT/OFFSET
// hack can't handle small record counts.
2008-05-11 23:08:47 +00:00
if ( $this -> db -> config [ 'driver' ] != 'mssql' ) {
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , null , null , 3 , 2 );
2008-05-11 18:53:54 +00:00
$expected = array (
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' )));
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , null , null , 3 , 3 );
2008-05-11 18:53:54 +00:00
$expected = array ();
$this -> assertEqual ( $result , $expected );
}
2007-03-17 19:15:41 +00:00
}
2007-03-26 18:38:54 +00:00
2007-10-24 16:07:36 +00:00
function testGenerateList () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'Apple' , 'Post' , 'Author' , 'User' );
2008-04-17 22:30:25 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
$TestModel -> displayField = 'title' ;
2007-07-01 03:43:05 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'list' , array ( 'order' => 'Article.title ASC' ));
2007-10-22 02:11:58 +00:00
$expected = array ( 1 => 'First Article' , 2 => 'Second Article' , 3 => 'Third Article' );
2007-07-01 03:43:05 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = Set :: combine ( $TestModel -> find ( 'all' , array ( 'order' => 'Article.title ASC' , 'fields' => array ( 'id' , 'title' ))), '{n}.Article.id' , '{n}.Article.title' );
2007-10-22 02:11:58 +00:00
$expected = array ( 1 => 'First Article' , 2 => 'Second Article' , 3 => 'Third Article' );
2007-07-01 03:43:05 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = Set :: combine ( $TestModel -> find ( 'all' , array ( 'order' => 'Article.title ASC' )), '{n}.Article.id' , '{n}.Article' );
2007-07-01 03:43:05 +00:00
$expected = array (
2007-10-22 02:11:58 +00:00
1 => array ( 'id' => 1 , 'user_id' => 1 , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
2 => 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' ),
3 => array ( 'id' => 3 , 'user_id' => 1 , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ));
2007-07-01 03:43:05 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = Set :: combine ( $TestModel -> find ( 'all' , array ( 'order' => 'Article.title ASC' )), '{n}.Article.id' , '{n}.Article' , '{n}.Article.user_id' );
2007-10-22 02:11:58 +00:00
$expected = array ( 1 => array (
1 => array ( 'id' => 1 , 'user_id' => 1 , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
3 => array ( 'id' => 3 , 'user_id' => 1 , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )),
3 => array ( 2 => 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' )));
2007-07-01 03:43:05 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = Set :: combine ( $TestModel -> find ( 'all' , array ( 'order' => 'Article.title ASC' , 'fields' => array ( 'id' , 'title' , 'user_id' ))), '{n}.Article.id' , '{n}.Article.title' , '{n}.Article.user_id' );
2008-01-01 19:34:40 +00:00
$expected = array ( 1 => array ( 1 => 'First Article' , 3 => 'Third Article' ), 3 => array ( 2 => 'Second Article' ));
2007-07-01 03:43:05 +00:00
$this -> assertEqual ( $result , $expected );
2008-01-01 23:57:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Apple ();
2008-01-11 03:16:19 +00:00
$expected = array ( 1 => 'Red Apple 1' , 2 => 'Bright Red Apple' , 3 => 'green blue' , 4 => 'Test Name' , 5 => 'Blue Green' , 6 => 'My new apple' , 7 => 'Some odd color' );
2008-01-02 02:30:19 +00:00
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> find ( 'list' ), $expected );
$this -> assertEqual ( $TestModel -> Parent -> find ( 'list' ), $expected );
2008-01-11 03:16:19 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Post ();
$result = $TestModel -> find ( 'list' , array ( 'fields' => 'Post.title' ));
2008-01-11 03:16:19 +00:00
$expected = array ( 1 => 'First Post' , 2 => 'Second Post' , 3 => 'Third Post' );
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'list' , array ( 'fields' => array ( 'Post.body' )));
2008-01-11 03:16:19 +00:00
$expected = array ( 1 => 'First Post Body' , 2 => 'Second Post Body' , 3 => 'Third Post Body' );
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'list' , array ( 'fields' => array ( 'Post.title' , 'Post.body' )));
2008-01-11 03:16:19 +00:00
$expected = array ( 'First Post' => 'First Post Body' , 'Second Post' => 'Second Post Body' , 'Third Post' => 'Third Post Body' );
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'list' , array ( 'fields' => array ( 'Post.id' , 'Post.title' , 'Author.user' ), 'recursive' => 1 ));
2008-01-11 03:16:19 +00:00
$expected = array ( 'mariano' => array ( 1 => 'First Post' , 3 => 'Third Post' ), 'larry' => array ( 2 => 'Second Post' ));
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
$result = $TestModel -> find ( 'list' , array ( 'fields' => array ( 'User.user' , 'User.password' )));
2008-01-11 03:16:19 +00:00
$expected = array ( 'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'nate' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'larry' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99' );
$this -> assertEqual ( $result , $expected );
2008-04-17 22:30:25 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new ModifiedAuthor ();
$result = $TestModel -> find ( 'list' , array ( 'fields' => array ( 'Author.id' , 'Author.user' )));
2008-04-17 22:30:25 +00:00
$expected = array ( 1 => 'mariano (CakePHP)' , 2 => 'nate (CakePHP)' , 3 => 'larry (CakePHP)' , 4 => 'garrett (CakePHP)' );
$this -> assertEqual ( $result , $expected );
2007-07-01 03:43:05 +00:00
}
2008-02-28 01:50:38 +00:00
function testRecordExists () {
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2008-02-28 01:50:38 +00:00
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> exists ());
$TestModel -> read ( null , 1 );
$this -> assertTrue ( $TestModel -> exists ());
$TestModel -> create ();
$this -> assertFalse ( $TestModel -> exists ());
$TestModel -> id = 4 ;
$this -> assertTrue ( $TestModel -> exists ());
2008-02-28 04:35:20 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new TheVoid ();
$this -> assertFalse ( $TestModel -> exists ());
$TestModel -> id = 5 ;
$this -> assertFalse ( $TestModel -> exists ());
2008-02-28 01:50:38 +00:00
}
2007-10-24 16:07:36 +00:00
function testFindField () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-26 18:38:54 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> field ( 'user' );
2007-03-26 18:38:54 +00:00
$this -> assertEqual ( $result , 'mariano' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> field ( 'User.user' );
2007-03-26 18:38:54 +00:00
$this -> assertEqual ( $result , 'mariano' );
2008-05-13 16:42:39 +00:00
$TestModel -> id = false ;
$result = $TestModel -> field ( 'user' , array ( 'user' => 'mariano' ));
2007-03-26 18:38:54 +00:00
$this -> assertEqual ( $result , 'mariano' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> field ( 'COUNT(*) AS count' , true );
2007-03-26 18:38:54 +00:00
$this -> assertEqual ( $result , 4 );
2007-03-27 01:34:59 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> field ( 'COUNT(*)' , true );
2007-03-27 01:34:59 +00:00
$this -> assertEqual ( $result , 4 );
2007-03-26 18:38:54 +00:00
}
2008-01-11 06:45:00 +00:00
function testFindUnique () {
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2008-03-26 11:17:24 +00:00
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> isUnique ( array ( 'user' => 'nate' )));
$TestModel -> id = 2 ;
$this -> assertTrue ( $TestModel -> isUnique ( array ( 'user' => 'nate' )));
$this -> assertFalse ( $TestModel -> isUnique ( array ( 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' )));
2008-01-11 06:45:00 +00:00
}
2007-10-24 16:07:36 +00:00
function testUpdateExisting () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
$TestModel -> create ();
2007-10-08 17:43:14 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> save ( array ( 'User' => array ( 'user' => 'some user' , 'password' => 'some password' )));
$this -> assertTrue ( is_int ( $TestModel -> id ) || ( intval ( $TestModel -> id ) === 5 ));
$id = $TestModel -> id ;
2007-10-08 17:43:14 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> save ( array ( 'User' => array ( 'user' => 'updated user' )));
$this -> assertEqual ( $TestModel -> id , $id );
2007-10-08 17:43:14 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( $id );
2008-05-11 18:53:54 +00:00
$this -> assertEqual ( $result [ 'User' ][ 'user' ], 'updated user' );
$this -> assertEqual ( $result [ 'User' ][ 'password' ], 'some password' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
$Comment =& new Comment ();
2007-10-19 03:33:19 +00:00
$data = array ( 'Comment' => array ( 'id' => 1 , 'comment' => 'First Comment for First Article' ),
2007-10-22 02:11:58 +00:00
'Article' => array ( 'id' => 2 , 'title' => 'Second Article' ));
2007-10-08 17:43:14 +00:00
2008-05-13 16:42:39 +00:00
$result = $Article -> save ( $data );
2007-10-19 03:33:19 +00:00
$this -> assertTrue ( $result );
2007-10-08 17:43:14 +00:00
2008-05-13 16:42:39 +00:00
$result = $Comment -> save ( $data );
2007-10-19 03:33:19 +00:00
$this -> assertTrue ( $result );
}
2007-10-08 17:43:14 +00:00
2008-03-01 03:12:12 +00:00
function testUpdateMultiple () {
$this -> loadFixtures ( 'Comment' , 'Article' , 'User' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Comment ();
$result = Set :: extract ( $TestModel -> find ( 'all' ), '{n}.Comment.user_id' );
2008-03-01 03:12:12 +00:00
$expected = array ( '2' , '4' , '1' , '1' , '1' , '2' );
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> updateAll ( array ( 'Comment.user_id' => 5 ), array ( 'Comment.user_id' => 2 ));
2008-05-15 05:17:23 +00:00
$result = Set :: combine ( $TestModel -> find ( 'all' ), '{n}.Comment.id' , '{n}.Comment.user_id' );
$expected = array ( 1 => 5 , 2 => 4 , 3 => 1 , 4 => 1 , 5 => 1 , 6 => 5 );
2008-03-01 03:12:12 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-05-15 05:17:23 +00:00
function testUpdateWithCalculation () {
$this -> loadFixtures ( 'DataTest' );
$model =& new DataTest ();
$result = $model -> saveAll ( array (
array ( 'count' => 5 , 'float' => 1.1 ),
array ( 'count' => 3 , 'float' => 1.2 ),
array ( 'count' => 4 , 'float' => 1.3 ),
array ( 'count' => 1 , 'float' => 2.0 ),
));
$this -> assertTrue ( $result );
$result = Set :: extract ( '/DataTest/count' , $model -> find ( 'all' , array ( 'fields' => 'count' )));
$this -> assertEqual ( $result , array ( 5 , 3 , 4 , 1 ));
$this -> assertTrue ( $model -> updateAll ( array ( 'count' => 'count + 2' )));
$result = Set :: extract ( '/DataTest/count' , $model -> find ( 'all' , array ( 'fields' => 'count' )));
$this -> assertEqual ( $result , array ( 7 , 5 , 6 , 3 ));
$this -> assertTrue ( $model -> updateAll ( array ( 'DataTest.count' => 'DataTest.count - 1' )));
$result = Set :: extract ( '/DataTest/count' , $model -> find ( 'all' , array ( 'fields' => 'count' )));
$this -> assertEqual ( $result , array ( 6 , 4 , 5 , 2 ));
}
2007-10-24 16:07:36 +00:00
function testBindUnbind () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'FeatureSet' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasMany ;
2007-03-17 19:15:41 +00:00
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )));
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-26 17:16:43 +00:00
2008-05-15 05:17:23 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.id, User.user' ));
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ), 'Comment' => array (
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ), 'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' ), 'Comment' => array ()),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' ), 'Comment' => array (
2007-10-22 02:11:58 +00:00
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ))));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-26 17:16:43 +00:00
2008-05-17 16:23:46 +00:00
$TestModel -> resetAssociations ();
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasMany ;
2007-03-26 17:16:43 +00:00
$this -> assertEqual ( $result , array ());
2008-05-13 16:42:39 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-15 05:17:23 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.id, User.user' ));
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ), 'Comment' => array (
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ), 'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' ), 'Comment' => array ()),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' ), 'Comment' => array (
2007-10-22 02:11:58 +00:00
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ))));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasMany ;
2007-08-14 23:12:24 +00:00
$expected = array ( 'Comment' => array ( 'className' => 'Comment' , 'foreignKey' => 'user_id' , 'conditions' => null , 'fields' => null , 'order' => null , 'limit' => null , 'offset' => null , 'dependent' => null , 'exclusive' => null , 'finderQuery' => null , 'counterQuery' => null ) );
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )));
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasMany ;
2007-03-17 19:15:41 +00:00
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-15 05:17:23 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.id, User.user' ));
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' )),
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.id, User.user' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ), 'Comment' => array (
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ), 'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' ), 'Comment' => array ()),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' ), 'Comment' => array (
2007-10-22 02:11:58 +00:00
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ))));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.id, User.user' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' )),
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' )),
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' )),
2007-10-22 02:11:58 +00:00
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> hasMany ;
2007-03-17 19:15:41 +00:00
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-26 17:16:43 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' => array ( 'className' => 'Comment' , 'conditions' => 'Comment.published = \'Y\'' ) )));
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( null , 'User.id, User.user' );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ), 'Comment' => array (
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ), 'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
2007-10-22 02:11:58 +00:00
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' ))),
2007-08-14 23:12:24 +00:00
array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' ), 'Comment' => array ()),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' ), 'Comment' => array (
2007-10-22 02:11:58 +00:00
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ))));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$TestModel2 =& new DeviceType ();
2008-01-01 19:34:40 +00:00
$expected = array ( 'className' => 'FeatureSet' , 'foreignKey' => 'feature_set_id' , 'conditions' => '' , 'fields' => '' , 'order' => '' , 'counterCache' => '' );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel2 -> belongsTo [ 'FeatureSet' ], $expected );
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$TestModel2 -> bind ( 'FeatureSet' , array ( 'conditions' => array ( 'active' => true )));
2008-01-01 19:34:40 +00:00
$expected [ 'conditions' ] = array ( 'active' => true );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel2 -> belongsTo [ 'FeatureSet' ], $expected );
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$TestModel2 -> bind ( 'FeatureSet' , array ( 'foreignKey' => false , 'conditions' => array ( 'Feature.name' => 'DeviceType.name' )));
2008-01-01 19:34:40 +00:00
$expected [ 'conditions' ] = array ( 'Feature.name' => 'DeviceType.name' );
$expected [ 'foreignKey' ] = false ;
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel2 -> belongsTo [ 'FeatureSet' ], $expected );
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$TestModel2 -> bind ( 'NewFeatureSet' , array ( 'type' => 'hasMany' , 'className' => 'FeatureSet' , 'conditions' => array ( 'active' => true )));
2008-01-01 19:34:40 +00:00
$expected = array ( 'className' => 'FeatureSet' , 'conditions' => array ( 'active' => true ), 'foreignKey' => 'device_type_id' , 'fields' => '' , 'order' => '' , 'limit' => '' , 'offset' => '' , 'dependent' => '' , 'exclusive' => '' , 'finderQuery' => '' , 'counterQuery' => '' );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel2 -> hasMany [ 'NewFeatureSet' ], $expected );
$this -> assertTrue ( is_object ( $TestModel2 -> NewFeatureSet ));
2007-03-17 19:15:41 +00:00
}
2007-03-25 18:17:15 +00:00
2007-10-24 16:07:36 +00:00
function testFindCount () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
$result = $TestModel -> findCount ();
2007-03-25 18:17:15 +00:00
$this -> assertEqual ( $result , 4 );
$this -> db -> fullDebug = true ;
2008-05-13 16:42:39 +00:00
$TestModel -> order = 'User.id' ;
2007-12-02 21:39:43 +00:00
$this -> db -> _queriesLog = array ();
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findCount ();
2007-03-25 18:17:15 +00:00
$this -> assertEqual ( $result , 4 );
$this -> assertTrue ( isset ( $this -> db -> _queriesLog [ 0 ][ 'query' ]));
$this -> assertNoPattern ( '/ORDER\s+BY/' , $this -> db -> _queriesLog [ 0 ][ 'query' ]);
$this -> db -> _queriesLog = array ();
$this -> db -> fullDebug = false ;
}
2007-10-24 16:07:36 +00:00
function testFindMagic () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findByUser ( 'mariano' );
2007-10-22 02:11:58 +00:00
$expected = array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findByPassword ( '5f4dcc3b5aa765d61d8327deb882cf99' );
2007-10-22 02:11:58 +00:00
$expected = array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testRead () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> read ();
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> read ();
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> read ( null , 2 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> read ( array ( 'id' , 'user' ));
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> read ( 'id, user' , 2 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Article' )));
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> read ( 'id, user' );
2007-10-22 02:11:58 +00:00
$expected = array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ),
2007-03-17 19:15:41 +00:00
'Article' => array (
2007-08-14 23:12:24 +00:00
array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
2007-10-22 02:11:58 +00:00
array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testRecursiveRead () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' , 'Tag' , 'ArticlesTag' , 'Featured' , 'ArticleFeatured' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-17 21:37:22 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Article' )), false );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-17 21:37:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 0 ;
$result = $TestModel -> read ( 'id, user' , 1 );
2007-03-17 19:15:41 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
'User' => array ( 'id' => '1' , 'user' => 'mariano' ),
2007-03-17 19:15:41 +00:00
);
$this -> assertEqual ( $result , $expected );
2007-03-17 21:37:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 1 ;
$result = $TestModel -> read ( 'id, user' , 1 );
2007-10-22 02:11:58 +00:00
$expected = array ( 'User' => array ( 'id' => '1' , 'user' => 'mariano' ),
2007-03-17 19:15:41 +00:00
'Article' => array (
2007-08-14 23:12:24 +00:00
array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
2007-10-22 02:11:58 +00:00
array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-17 21:37:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( 'id, user' , 3 );
2007-10-22 02:11:58 +00:00
$expected = array ( 'User' => array ( 'id' => '3' , 'user' => 'larry' ),
'Article' => array ( 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' )),
2007-03-17 19:15:41 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
2007-10-22 02:11:58 +00:00
array ( 'id' => '3' , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )))));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-01-17 17:09:10 +00:00
/**
* @ todo Figure out why Featured is not getting truncated properly
*/
2007-10-24 16:07:36 +00:00
function testRecursiveFindAll () {
2008-05-11 23:08:47 +00:00
$this -> db -> truncate ( new Featured ());
2008-01-17 17:09:10 +00:00
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' , 'Tag' , 'ArticlesTag' , 'Attachment' , 'ArticleFeatured' , 'Featured' , 'Category' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'Article.user_id' => 1 ));
2007-08-14 23:12:24 +00:00
$expected = array (
array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ),
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' )
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
2007-03-17 19:15:41 +00:00
)
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (),
'Tag' => array ()
2007-03-17 19:15:41 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'Article.user_id' => 3 ), null , null , null , 1 , 2 );
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Article' => array (
2007-03-17 19:15:41 +00:00
'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'
2007-03-30 00:08:10 +00:00
),
2008-01-11 06:45:00 +00:00
'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (
array (
2007-03-30 00:08:10 +00:00
'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' ,
2008-01-11 06:45:00 +00:00
'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' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Attachment' => array ( 'id' => '1' , 'comment_id' => 5 , 'attachment' => 'attachment.zip' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' )
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
2007-03-30 00:08:10 +00:00
'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' ,
2008-01-11 06:45:00 +00:00
'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' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ),
2007-03-17 19:15:41 +00:00
'Attachment' => false
)
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-03-17 19:15:41 +00:00
)
)
);
2007-03-23 21:59:08 +00:00
$this -> assertEqual ( $result , $expected );
2007-04-04 17:25:18 +00:00
2008-05-13 16:42:39 +00:00
$Featured = new Featured ();
2007-04-04 17:25:18 +00:00
2008-05-13 16:42:39 +00:00
$Featured -> recursive = 2 ;
$Featured -> bindModel ( array (
2007-04-01 16:15:44 +00:00
'belongsTo' => array (
'ArticleFeatured' => array (
2008-01-17 17:09:10 +00:00
'conditions' => " ArticleFeatured.published = 'Y' " ,
2007-04-01 16:15:44 +00:00
'fields' => 'id, title, user_id, published'
)
)
));
2007-04-04 17:25:18 +00:00
2008-05-13 16:42:39 +00:00
$Featured -> ArticleFeatured -> unbindModel ( array (
2007-04-04 17:25:18 +00:00
'hasMany' => array ( 'Attachment' , 'Comment' ),
2008-01-11 06:45:00 +00:00
'hasAndBelongsToMany' => array ( 'Tag' ))
2007-04-01 16:15:44 +00:00
);
2007-04-04 17:25:18 +00:00
2007-04-01 16:15:44 +00:00
$orderBy = 'ArticleFeatured.id ASC' ;
2008-05-13 16:42:39 +00:00
$result = $Featured -> findAll ( null , null , $orderBy , 3 );
2007-04-04 17:25:18 +00:00
2007-08-14 23:12:24 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
array ( 'Featured' => array ( 'id' => '1' , 'article_featured_id' => '1' , 'category_id' => '1' , 'published_date' => '2007-03-31 10:39:23' , 'end_date' => '2007-05-15 10:39:23' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'ArticleFeatured' => array ( 'id' => '1' , 'title' => 'First Article' , 'user_id' => '1' , 'published' => 'Y' ,
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
2007-04-04 19:55:57 +00:00
'Category' => array (),
2008-01-11 06:45:00 +00:00
'Featured' => array ( 'id' => '1' , 'article_featured_id' => '1' , 'category_id' => '1' , 'published_date' => '2007-03-31 10:39:23' , 'end_date' => '2007-05-15 10:39:23' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )),
'Category' => array ( 'id' => '1' , 'parent_id' => '0' , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )),
array ( 'Featured' => array ( 'id' => '2' , 'article_featured_id' => '2' , 'category_id' => '1' , 'published_date' => '2007-03-31 10:39:23' , 'end_date' => '2007-05-15 10:39:23' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'ArticleFeatured' => array ( 'id' => '2' , 'title' => 'Second Article' , 'user_id' => '3' , 'published' => 'Y' ,
'User' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' ),
2007-04-04 19:55:57 +00:00
'Category' => array (),
2008-01-11 06:45:00 +00:00
'Featured' => array ( 'id' => '2' , 'article_featured_id' => '2' , 'category_id' => '1' , 'published_date' => '2007-03-31 10:39:23' , 'end_date' => '2007-05-15 10:39:23' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )),
'Category' => array ( 'id' => '1' , 'parent_id' => '0' , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )
2007-04-01 04:40:18 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-03-17 19:15:41 +00:00
}
2007-04-29 02:25:57 +00:00
2007-10-24 16:07:36 +00:00
function testRecursiveFindAllWithLimit () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' , 'Comment' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-04-29 02:25:57 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> hasMany [ 'Comment' ][ 'limit' ] = 2 ;
2007-04-11 21:22:26 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'Article.user_id' => 1 ));
2007-08-14 23:12:24 +00:00
$expected = array (
array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ),
2007-04-11 21:22:26 +00:00
),
2007-08-14 23:12:24 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
2007-04-11 21:22:26 +00:00
)
),
2007-08-14 23:12:24 +00:00
array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (),
'Tag' => array ()
2007-04-11 21:22:26 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-04-29 02:25:57 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> hasMany [ 'Comment' ][ 'limit' ] = 1 ;
2007-04-11 21:22:26 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ( array ( 'Article.user_id' => 3 ), null , null , null , 1 , 2 );
2007-08-14 23:12:24 +00:00
$expected = array (
array (
2008-01-11 06:45:00 +00:00
'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' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (
array (
2007-04-11 21:22:26 +00:00
'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' ,
2008-01-11 06:45:00 +00:00
'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' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Attachment' => array ( 'id' => '1' , 'comment_id' => 5 , 'attachment' => 'attachment.zip' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' )
2007-04-11 21:22:26 +00:00
)
),
2007-08-14 23:12:24 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-04-11 21:22:26 +00:00
)
)
);
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testAssociationAfterFind () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Post' , 'Author' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Post ();
$result = $TestModel -> findAll ();
2007-06-03 21:54:11 +00:00
$expected = array (
array (
'Post' => array ( 'id' => '1' , 'author_id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'Author' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' , 'test' => 'working' ),
), array (
2007-08-14 23:12:24 +00:00
'Post' => array ( 'id' => '2' , 'author_id' => '3' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ),
2007-06-03 21:54:11 +00:00
'Author' => array ( 'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31' , 'test' => 'working' ),
), array (
'Post' => array ( 'id' => '3' , 'author_id' => '1' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'Author' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' , 'test' => 'working' )
)
);
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testValidatesBackwards () {
2008-05-13 16:42:39 +00:00
$TestModel =& new TestValidate ();
2007-05-02 07:48:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array (
2007-05-02 07:48:22 +00:00
'user_id' => VALID_NUMBER ,
'title' => VALID_NOT_EMPTY ,
'body' => VALID_NOT_EMPTY
);
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => '' , 'body' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '' , 'title' => 'title' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => 'not a number' , 'title' => 'title' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
}
2007-10-24 16:07:36 +00:00
function testValidates () {
2008-05-13 16:42:39 +00:00
$TestModel =& new TestValidate ();
2007-04-30 13:03:13 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array (
2007-05-02 07:48:22 +00:00
'user_id' => VALID_NUMBER ,
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY ),
'body' => VALID_NOT_EMPTY
);
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => '' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-04-30 13:03:13 +00:00
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data ) && $TestModel -> validates ();
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => '0' , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-04-30 13:03:13 +00:00
$this -> assertTrue ( $result );
2007-05-01 03:03:53 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate [ 'modified' ] = array ( 'allowEmpty' => true , 'rule' => 'date' );
2007-05-01 03:03:53 +00:00
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-01 03:03:53 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-01 03:03:53 +00:00
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => '2007-05-01' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-01 03:03:53 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-01 03:03:53 +00:00
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => 'invalid-date-here' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-01 03:03:53 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-01 03:03:53 +00:00
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => 0 ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => '0' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate [ 'modified' ] = array ( 'allowEmpty' => false , 'rule' => 'date' );
2007-09-21 00:16:38 +00:00
$data = array ( 'TestValidate' => array ( 'modified' => null ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:16:38 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:16:38 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'modified' => false ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:16:38 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:16:38 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'modified' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:16:38 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:16:38 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'modified' => '2007-05-01' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:16:38 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:16:38 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> validate [ 'slug' ] = array ( 'allowEmpty' => false , 'rule' => array ( 'maxLength' , 45 ));
2007-06-20 01:37:23 +00:00
2007-05-04 07:13:15 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'slug' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-04 07:13:15 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-04 07:13:15 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'slug' => 'slug-right-here' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-04 07:13:15 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-04 07:13:15 +00:00
$this -> assertTrue ( $result );
2007-06-20 01:37:23 +00:00
2007-05-04 07:13:15 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'slug' => 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-04 07:13:15 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-04 07:13:15 +00:00
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array (
2008-01-11 06:45:00 +00:00
'number' => array ( 'rule' => 'validateNumber' , 'min' => 3 , 'max' => 5 ),
2007-05-02 07:48:22 +00:00
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY )
);
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '0' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 0 ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '3' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 3 ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array (
2008-01-11 06:45:00 +00:00
'number' => array ( 'rule' => 'validateNumber' , 'min' => 5 , 'max' => 10 ),
2007-05-02 07:48:22 +00:00
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY )
);
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '3' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 3 ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-01 10:30:36 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-01 10:30:36 +00:00
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array (
2007-05-02 07:48:22 +00:00
'title' => array ( 'allowEmpty' => false , 'rule' => 'validateTitle' )
);
$data = array ( 'TestValidate' => array ( 'title' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-01 10:30:36 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-01 10:30:36 +00:00
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'title' => 'new title' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title-new' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => array ( 'allowEmpty' => true , 'rule' => 'validateTitle' ));
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'title' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-05-02 07:48:22 +00:00
$this -> assertTrue ( $result );
2007-09-21 00:42:34 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => array ( 'rule' => array ( 'userDefined' , 'Article' , 'titleDuplicate' )));
2007-09-21 00:42:34 +00:00
$data = array ( 'TestValidate' => array ( 'title' => 'My Article Title' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:42:34 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:42:34 +00:00
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'My Article With a Different Title' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data );
2007-09-21 00:42:34 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> validates ();
2007-09-21 00:42:34 +00:00
$this -> assertTrue ( $result );
2007-04-30 13:03:13 +00:00
}
2007-10-24 16:07:36 +00:00
function testSaveField () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> saveField ( 'title' , 'New First Article' );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' ), 1 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-06-28 03:27:47 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'New First Article' , 'body' => 'First Article Body'
));
2007-12-08 09:01:14 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> saveField ( 'title' , '' );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' ), 1 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-06-28 03:27:47 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => '' , 'body' => 'First Article Body'
));
2008-05-11 18:53:54 +00:00
$result [ 'Article' ][ 'title' ] = trim ( $result [ 'Article' ][ 'title' ]);
2007-12-08 09:01:14 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$TestModel -> set ( 'body' , 'Messed up data' );
$this -> assertTrue ( $TestModel -> saveField ( 'title' , 'First Article' ));
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' ), 1 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-06-28 03:27:47 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body'
));
2007-12-08 08:22:20 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' ), 1 );
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> saveField ( 'title' , '' , true );
2007-06-28 03:27:47 +00:00
$this -> assertFalse ( $result );
2008-05-15 03:16:36 +00:00
// Test bug #4511
$this -> loadFixtures ( 'Node' , 'Dependency' );
$Node =& new Node ();
$Node -> set ( 'id' , 1 );
$result = $Node -> read ();
$this -> assertEqual ( Set :: extract ( '/ParentNode/name' , $result ), array ( 'Second' ));
$Node -> saveField ( 'state' , 10 );
$result = $Node -> read ();
$this -> assertEqual ( Set :: extract ( '/ParentNode/name' , $result ), array ( 'Second' ));
2007-06-28 03:27:47 +00:00
}
2007-10-24 16:07:36 +00:00
function testSaveWithCreate () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'User' , 'Comment' , 'Tag' , 'ArticlesTag' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new User ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array ( 'User' => array ( 'user' => 'user' , 'password' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ( $data );
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( ! empty ( $TestModel -> validationErrors ));
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array ( 'Article' => array ( 'user_id' => '' , 'title' => '' , 'body' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data ) && $TestModel -> save ();
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( ! empty ( $TestModel -> validationErrors ));
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array ( 'Article' => array ( 'id' => 1 , 'user_id' => '1' , 'title' => 'New First Article' , 'body' => '' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create ( $data ) && $TestModel -> save ();
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array ( 'Article' => array ( 'id' => 1 , 'title' => 'New First Article' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create () && $TestModel -> save ( $data , false );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 1 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'New First Article' , 'body' => 'First Article Body' , 'published' => 'N'
));
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array ( 'Article' => array ( 'id' => 1 , 'user_id' => '2' , 'title' => 'First Article' , 'body' => 'New First Article Body' , 'published' => 'Y' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create () && $TestModel -> save ( $data , true , array ( 'id' , 'title' , 'published' ));
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 1 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y'
));
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$data = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'user_id' => '2' , 'title' => 'New Article' , 'body' => 'New Article Body' , 'created' => '2007-03-18 14:55:23' , 'updated' => '2007-03-18 14:57:31' ),
'Tag' => array ( 'Tag' => array ( 1 , 3 ))
2007-03-17 19:15:41 +00:00
);
2008-05-13 16:42:39 +00:00
$TestModel -> create ();
$result = $TestModel -> create () && $TestModel -> save ( $data );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( null , 4 );
2007-08-14 23:12:24 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '4' , 'user_id' => '2' , 'title' => 'New Article' , 'body' => 'New Article Body' , 'published' => 'N' , 'created' => '2007-03-18 14:55:23' , 'updated' => '2007-03-18 14:57:31' ),
'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (),
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-03-17 19:15:41 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-01-11 06:45:00 +00:00
$data = array ( 'Comment' => array ( 'article_id' => '4' , 'user_id' => '1' , 'comment' => 'Comment New Article' , 'published' => 'Y' , 'created' => '2007-03-18 14:57:23' , 'updated' => '2007-03-18 14:59:31' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> create () && $TestModel -> Comment -> save ( $data );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-01-01 23:57:17 +00:00
$data = array ( 'Attachment' => array ( 'comment_id' => '7' , 'attachment' => 'newattachment.zip' , 'created' => '2007-03-18 15:02:23' , 'updated' => '2007-03-18 15:04:31' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> Attachment -> save ( $data );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( null , 4 );
2007-08-14 23:12:24 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '4' , 'user_id' => '2' , 'title' => 'New Article' , 'body' => 'New Article Body' , 'published' => 'N' , 'created' => '2007-03-18 14:55:23' , 'updated' => '2007-03-18 14:57:31' ),
'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ),
2007-08-14 23:12:24 +00:00
'Comment' => array (
array (
2007-03-30 00:08:10 +00:00
'id' => '7' , 'article_id' => '4' , 'user_id' => '1' , 'comment' => 'Comment New Article' , 'published' => 'Y' , 'created' => '2007-03-18 14:57:23' , 'updated' => '2007-03-18 14:59:31' ,
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '4' , 'user_id' => '2' , 'title' => 'New Article' , 'body' => 'New Article Body' , 'published' => 'N' , 'created' => '2007-03-18 14:55:23' , 'updated' => '2007-03-18 14:57:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Attachment' => array ( 'id' => '2' , 'comment_id' => '7' , 'attachment' => 'newattachment.zip' , 'created' => '2007-03-18 15:02:23' , 'updated' => '2007-03-18 15:04:31' )
2007-03-17 19:15:41 +00:00
)
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-03-17 19:15:41 +00:00
)
);
$this -> assertEqual ( $result , $expected );
}
2007-06-20 01:37:23 +00:00
2007-10-24 16:07:36 +00:00
function testSaveWithSet () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// Create record we will be updating later
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$data = array ( 'Article' => array ( 'user_id' => '1' , 'title' => 'Fourth Article' , 'body' => 'Fourth Article Body' , 'published' => 'Y' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create () && $TestModel -> save ( $data );
2007-05-18 17:54:59 +00:00
$this -> assertTrue ( $result );
// Check record we created
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2008-01-11 06:45:00 +00:00
$expected = array ( 'Article' => array ( 'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article' , 'body' => 'Fourth Article Body' , 'published' => 'Y' ));
2007-05-18 17:54:59 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// Create new record just to overlap Model->id on previously created record
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$data = array ( 'Article' => array ( 'user_id' => '4' , 'title' => 'Fifth Article' , 'body' => 'Fifth Article Body' , 'published' => 'Y' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create () && $TestModel -> save ( $data );
2007-05-18 17:54:59 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 5 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-05-18 17:54:59 +00:00
'id' => '5' , 'user_id' => '4' , 'title' => 'Fifth Article' , 'body' => 'Fifth Article Body' , 'published' => 'Y'
));
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// Go back and edit the first article we created, starting by checking it's still there
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2008-01-11 06:45:00 +00:00
$expected = array ( 'Article' => array ( 'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article' , 'body' => 'Fourth Article Body' , 'published' => 'Y' ));
2007-05-18 17:54:59 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// And now do the update with set()
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$data = array ( 'Article' => array ( 'id' => '4' , 'title' => 'Fourth Article - New Title' , 'published' => 'N' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data ) && $TestModel -> save ();
2007-05-18 17:54:59 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2008-01-11 06:45:00 +00:00
$expected = array ( 'Article' => array ( 'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article - New Title' , 'body' => 'Fourth Article Body' , 'published' => 'N' ));
2007-05-18 17:54:59 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 5 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-05-18 17:54:59 +00:00
'id' => '5' , 'user_id' => '4' , 'title' => 'Fifth Article' , 'body' => 'Fifth Article Body' , 'published' => 'Y'
));
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$data = array ( 'Article' => array ( 'id' => '5' , 'title' => 'Fifth Article - New Title 5' ));
2008-05-13 16:42:39 +00:00
$result = ( $TestModel -> set ( $data ) && $TestModel -> save ());
2007-05-18 17:54:59 +00:00
$this -> assertTrue ( $result );
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 5 );
2008-01-11 06:45:00 +00:00
$expected = array ( 'Article' => array ( 'id' => '5' , 'user_id' => '4' , 'title' => 'Fifth Article - New Title 5' , 'body' => 'Fifth Article Body' , 'published' => 'Y' ));
2007-05-18 17:54:59 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'title' ));
2007-05-18 17:54:59 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
array ( 'Article' => array ( 'id' => 2 , 'title' => 'Second Article' )),
array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' )),
array ( 'Article' => array ( 'id' => 4 , 'title' => 'Fourth Article - New Title' )),
array ( 'Article' => array ( 'id' => 5 , 'title' => 'Fifth Article - New Title 5' ))
2007-06-27 19:16:11 +00:00
);
$this -> assertEqual ( $result , $expected );
}
2007-12-29 20:24:10 +00:00
function testSaveFromXml () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-02-02 20:45:37 +00:00
App :: import ( 'Core' , 'Xml' );
2007-12-29 20:24:10 +00:00
$Article = new Article ();
2008-02-02 20:45:37 +00:00
$Article -> save ( new Xml ( '<article title="test xml" user_id="5" />' ));
2008-01-17 17:09:10 +00:00
$this -> assertTrue ( $Article -> save ( new Xml ( '<article title="test xml" user_id="5" />' )));
2007-12-29 20:24:10 +00:00
$results = $Article -> find ( array ( 'Article.title' => 'test xml' ));
$this -> assertTrue ( $results );
}
2007-10-24 16:07:36 +00:00
function testSaveHabtm () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Comment' , 'Tag' , 'ArticlesTag' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 2 );
2007-06-28 03:27:47 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'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' ),
2007-06-28 03:27:47 +00:00
'Comment' => array (
2007-08-14 23:12:24 +00:00
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' )
2007-06-28 03:27:47 +00:00
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-06-28 03:27:47 +00:00
)
);
$this -> assertEqual ( $result , $expected );
// Save with parent model data
$data = array (
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' , 'title' => 'New Second Article' ),
'Tag' => array ( 'Tag' => array ( 1 , 2 ))
2007-06-28 03:27:47 +00:00
);
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> set ( $data ));
$this -> assertTrue ( $TestModel -> save ());
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array ( 'belongsTo' => array ( 'User' ), 'hasMany' => array ( 'Comment' )));
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:27:47 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body' ),
2007-06-28 03:27:47 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
2007-06-28 03:27:47 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2008-01-11 06:45:00 +00:00
$data = array ( 'Article' => array ( 'id' => '2' ), 'Tag' => array ( 'Tag' => array ( 2 , 3 )));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array ( 'belongsTo' => array ( 'User' ), 'hasMany' => array ( 'Comment' )));
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:27:47 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body' ),
2007-06-28 03:27:47 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
array ( 'id' => '3' , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )
2007-06-28 03:27:47 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2008-01-11 06:45:00 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ( 1 , 2 , 3 )));
2007-06-28 03:27:47 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:27:47 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:27:47 +00:00
$expected = array (
2008-01-11 06:45:00 +00:00
'Article' => array ( 'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body' ),
2007-06-28 03:27:47 +00:00
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
array ( 'id' => '3' , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )
2007-06-28 03:27:47 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2008-01-11 06:45:00 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ()));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:27:47 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:27:47 +00:00
$expected = array (
2008-03-15 05:08:06 +00:00
'Article' => array ( 'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body' ),
2007-06-28 03:27:47 +00:00
'Tag' => array ()
);
$this -> assertEqual ( $result , $expected );
2008-02-06 15:48:31 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ( 2 , 3 )));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-06-28 03:27:47 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:27:47 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:27:47 +00:00
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
array ( 'id' => '3' , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )
2007-06-28 03:27:47 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-06-28 03:36:54 +00:00
// Parent data after HABTM data
2008-03-07 04:36:20 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ( 1 , 2 )), 'Article' => array ( 'id' => '2' , 'title' => 'New Second Article' ));
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> set ( $data ));
$this -> assertTrue ( $TestModel -> save ());
2007-06-28 03:36:54 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:36:54 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:36:54 +00:00
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
2007-06-28 03:36:54 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2008-03-07 04:36:20 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ( 1 , 2 )), 'Article' => array ( 'id' => '2' , 'title' => 'New Second Article Title' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:36:54 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> save ());
2007-06-28 03:36:54 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:36:54 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:36:54 +00:00
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article Title' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
2007-06-28 03:36:54 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2008-03-07 04:36:20 +00:00
$data = array ( 'Tag' => array ( 'Tag' => array ( 2 , 3 )), 'Article' => array ( 'id' => '2' , 'title' => 'Changed Second Article' ));
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> set ( $data ));
$this -> assertTrue ( $TestModel -> save ());
2007-06-28 03:36:54 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:36:54 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:36:54 +00:00
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'Changed Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
array ( 'id' => '3' , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )
2007-06-28 03:36:54 +00:00
)
);
$this -> assertEqual ( $result , $expected );
$data = array (
'Tag' => array (
'Tag' => array ( 1 , 3 )
),
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' ),
2007-06-28 03:36:54 +00:00
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data );
2007-06-28 03:36:54 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> save ();
2007-06-28 03:36:54 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array (
2007-06-28 03:36:54 +00:00
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
2007-06-28 03:36:54 +00:00
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'Changed Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-09-15 19:40:12 +00:00
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' )
2007-06-28 03:36:54 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-10-17 21:19:30 +00:00
2008-03-07 01:29:19 +00:00
$data = array (
'Article' => array ( 'id' => 10 , 'user_id' => '2' , 'title' => 'New Article With Tags and fieldList' , 'body' => 'New Article Body with Tags and fieldList' , 'created' => '2007-03-18 14:55:23' , 'updated' => '2007-03-18 14:57:31' ),
'Tag' => array ( 'Tag' => array ( 1 , 2 , 3 ))
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> create () && $TestModel -> save ( $data , true , array ( 'user_id' , 'title' , 'published' ));
2007-10-17 21:19:30 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> unbindModel ( array ( 'belongsTo' => array ( 'User' ), 'hasMany' => array ( 'Comment' )));
$result = $TestModel -> read ();
2008-03-07 01:29:19 +00:00
$expected = array (
'Article' => array ( 'id' => 4 , 'user_id' => 2 , 'title' => 'New Article With Tags and fieldList' , 'body' => '' , 'published' => 'N' , 'created' => '' , 'updated' => '' ),
'Tag' => array (
0 => array ( 'id' => 1 , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
1 => array ( 'id' => 2 , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
2 => array ( 'id' => 3 , 'tag' => 'tag3' , 'created' => '2007-03-18 12:26:23' , 'updated' => '2007-03-18 12:28:31' )
)
);
2007-10-17 21:19:30 +00:00
$this -> assertEqual ( $result , $expected );
2007-06-28 03:27:47 +00:00
}
2008-03-15 05:08:06 +00:00
/**
* @ todo This is technically incorrect ( ThePaperMonkies . apple_id should be ThePaperMonkies . the_paper_id ),
* the foreign key name should come from the association name , not the table name ... but that ' s the existing
* functionality at this point .
*/
function testHabtmSaveKeyResolution () {
$this -> loadFixtures ( 'Apple' , 'Device' , 'ThePaperMonkies' );
2008-05-13 16:42:39 +00:00
$ThePaper =& new ThePaper ();
$ThePaper -> id = 1 ;
2008-03-15 05:08:06 +00:00
2008-05-13 16:42:39 +00:00
$ThePaper -> save ( array ( 'Monkey' => array ( 2 , 3 )));
$result = $ThePaper -> findById ( 1 );
2008-03-15 05:08:06 +00:00
$expected = array (
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 [ 'Monkey' ], $expected );
}
2008-01-01 19:34:40 +00:00
function testSaveAll () {
2008-01-27 01:57:39 +00:00
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Post ();
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2008-01-01 19:34:40 +00:00
$this -> assertEqual ( count ( $result ), 3 );
$this -> assertFalse ( isset ( $result [ 3 ]));
$ts = date ( 'Y-m-d H:i:s' );
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> saveAll ( array (
2008-01-01 19:34:40 +00:00
'Post' => array ( 'title' => 'Post with Author' , 'body' => 'This post will be saved with an author' ),
'Author' => array ( 'user' => 'bob' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' )
));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2008-01-01 19:34:40 +00:00
$expected = array (
'Post' => array ( 'id' => '4' , 'author_id' => '5' , 'title' => 'Post with Author' , 'body' => 'This post will be saved with an author' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ),
'Author' => array ( 'id' => '5' , 'user' => 'bob' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf90' , 'created' => $ts , 'updated' => $ts , 'test' => 'working' )
);
$this -> assertEqual ( $result [ 3 ], $expected );
$this -> assertEqual ( count ( $result ), 4 );
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> deleteAll ( true );
$this -> assertEqual ( $TestModel -> find ( 'all' ), array ());
2008-04-19 17:33:17 +00:00
2008-01-27 01:57:39 +00:00
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
2008-05-13 16:42:39 +00:00
$this -> db -> truncate ( $TestModel );
2008-04-19 17:33:17 +00:00
2008-01-01 19:34:40 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$TestModel -> saveAll ( array (
2008-01-01 19:34:40 +00:00
array ( 'title' => 'Multi-record post 1' , 'body' => 'First multi-record post' , 'author_id' => 2 ),
array ( 'title' => 'Multi-record post 2' , 'body' => 'Second multi-record post' , 'author_id' => 2 )
));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 , 'order' => 'Post.id ASC' ));
2008-01-01 19:34:40 +00:00
$expected = array (
2008-01-27 01:57:39 +00:00
array ( 'Post' => array ( 'id' => '1' , 'author_id' => '2' , 'title' => 'Multi-record post 1' , 'body' => 'First multi-record post' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts )),
array ( 'Post' => array ( 'id' => '2' , 'author_id' => '2' , 'title' => 'Multi-record post 2' , 'body' => 'Second multi-record post' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ))
2008-01-01 19:34:40 +00:00
);
$this -> assertEqual ( $result , $expected );
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel =& new Comment ();
2008-01-27 01:57:39 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( array (
2008-01-27 01:57:39 +00:00
'Comment' => array ( 'article_id' => 2 , 'user_id' => 2 , 'comment' => 'New comment with attachment' , 'published' => 'Y' ),
'Attachment' => array ( 'attachment' => 'some_file.tgz' )
));
$this -> assertTrue ( $result );
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2008-05-16 05:31:14 +00:00
$expected = array ( 'id' => '7' , 'article_id' => '2' , 'user_id' => '2' , 'comment' => 'New comment with attachment' , 'published' => 'Y' , 'created' => $ts , 'updated' => $ts );
2008-01-27 01:57:39 +00:00
$this -> assertEqual ( $result [ 6 ][ 'Comment' ], $expected );
2008-04-19 17:33:17 +00:00
2008-05-16 05:31:14 +00:00
$expected = array ( 'id' => '7' , 'article_id' => '2' , 'user_id' => '2' , 'comment' => 'New comment with attachment' , 'published' => 'Y' , 'created' => $ts , 'updated' => $ts );
2008-01-27 01:57:39 +00:00
$this -> assertEqual ( $result [ 6 ][ 'Comment' ], $expected );
2008-04-19 17:33:17 +00:00
2008-01-27 01:57:39 +00:00
$expected = array ( 'id' => '2' , 'comment_id' => '7' , 'attachment' => 'some_file.tgz' , 'created' => $ts , 'updated' => $ts );
$this -> assertEqual ( $result [ 6 ][ 'Attachment' ], $expected );
2008-01-01 19:34:40 +00:00
}
2008-05-16 05:31:14 +00:00
function testSaveAllHasOne () {
$model = new Comment ();
$model -> deleteAll ( true );
$this -> assertEqual ( $model -> find ( 'all' ), array ());
$model -> Attachment -> deleteAll ( true );
$this -> assertEqual ( $model -> Attachment -> find ( 'all' ), array ());
$this -> assertTrue ( $model -> saveAll ( array (
'Comment' => array ( 'comment' => 'Comment with attachment' , 'article_id' => 1 , 'user_id' => 1 ),
'Attachment' => array ( 'attachment' => 'some_file.zip' )
)));
$result = $model -> find ( 'all' , array ( 'fields' => array (
'Comment.id' , 'Comment.comment' , 'Attachment.id' , 'Attachment.comment_id' , 'Attachment.attachment'
)));
$expected = array ( array (
'Comment' => array ( 'id' => '1' , 'comment' => 'Comment with attachment' ),
'Attachment' => array ( 'id' => '1' , 'comment_id' => '1' , 'attachment' => 'some_file.zip' )
));
$this -> assertEqual ( $result , $expected );
}
function testSaveAllBelongsTo () {
$model = new Comment ();
$model -> deleteAll ( true );
$this -> assertEqual ( $model -> find ( 'all' ), array ());
$model -> Article -> deleteAll ( true );
$this -> assertEqual ( $model -> Article -> find ( 'all' ), array ());
$this -> assertTrue ( $model -> saveAll ( array (
'Comment' => array ( 'comment' => 'Article comment' , 'article_id' => 1 , 'user_id' => 1 ),
'Article' => array ( 'title' => 'Model Associations 101' , 'user_id' => 1 )
)));
$result = $model -> find ( 'all' , array ( 'fields' => array (
'Comment.id' , 'Comment.comment' , 'Comment.article_id' , 'Article.id' , 'Article.title'
)));
$expected = array ( array (
'Comment' => array ( 'id' => '1' , 'article_id' => '1' , 'comment' => 'Article comment' ),
'Article' => array ( 'id' => '1' , 'title' => 'Model Associations 101' )
));
$this -> assertEqual ( $result , $expected );
}
2008-05-16 06:03:33 +00:00
function testSaveAllHasOneValidation () {
$model = new Comment ();
$model -> deleteAll ( true );
$this -> assertEqual ( $model -> find ( 'all' ), array ());
$model -> Attachment -> deleteAll ( true );
$this -> assertEqual ( $model -> Attachment -> find ( 'all' ), array ());
$model -> validate = array ( 'comment' => VALID_NOT_EMPTY );
$model -> Attachment -> validate = array ( 'attachment' => VALID_NOT_EMPTY );
$model -> Attachment -> bind ( 'Comment' );
$this -> assertFalse ( $model -> saveAll (
array (
'Comment' => array ( 'comment' => '' , 'article_id' => 1 , 'user_id' => 1 ),
'Attachment' => array ( 'attachment' => '' )
),
array ( 'validate' => 'first' )
));
$expected = array (
'Comment' => array ( 'comment' => 'This field cannot be left blank' ),
'Attachment' => array ( 'attachment' => 'This field cannot be left blank' )
);
$this -> assertEqual ( $model -> validationErrors , $expected );
$this -> assertFalse ( $model -> saveAll (
array (
'Comment' => array ( 'comment' => '' , 'article_id' => 1 , 'user_id' => 1 ),
'Attachment' => array ( 'attachment' => '' )
),
array ( 'validate' => 'only' )
));
$this -> assertEqual ( $model -> validationErrors , $expected );
}
2008-05-11 18:53:54 +00:00
function testSaveAllAtomic () {
$this -> loadFixtures ( 'Article' , 'User' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( array (
2008-05-11 18:53:54 +00:00
'Article' => array ( 'title' => 'Post with Author' , 'body' => 'This post will be saved with an author' , 'user_id' => 2 ),
'Comment' => array ( array ( 'comment' => 'First new comment' , 'user_id' => 2 ))
2008-04-18 11:06:41 +00:00
), array ( 'atomic' => false ));
$this -> assertIdentical ( $result , array ( 'Article' => array ( true ), 'Comment' => array ( true )));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( array (
2008-04-18 11:06:41 +00:00
array ( 'id' => '1' , 'title' => 'Baleeted First Post' , 'body' => 'Baleeted!' , 'published' => 'N' ),
array ( 'id' => '2' , 'title' => 'Just update the title' ),
2008-05-11 18:53:54 +00:00
array ( 'title' => 'Creating a fourth post' , 'body' => 'Fourth post body' , 'user_id' => 2 )
2008-04-18 11:06:41 +00:00
), array ( 'atomic' => false ));
$this -> assertIdentical ( $result , array ( true , true , true ));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => VALID_NOT_EMPTY , 'author_id' => 'numeric' );
$result = $TestModel -> saveAll ( array (
2008-04-18 11:06:41 +00:00
array ( 'id' => '1' , 'title' => 'Un-Baleeted First Post' , 'body' => 'Not Baleeted!' , 'published' => 'Y' ),
array ( 'id' => '2' , 'title' => '' , 'body' => 'Trying to get away with an empty title' ),
), array ( 'atomic' => false ));
$this -> assertIdentical ( $result , array ( true , false ));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( array (
2008-04-18 11:06:41 +00:00
'Article' => array ( 'id' => 2 ),
'Comment' => array (
array ( 'comment' => 'First new comment' , 'published' => 'Y' , 'user_id' => 1 ),
array ( 'comment' => 'Second new comment' , 'published' => 'Y' , 'user_id' => 2 )
)
), array ( 'atomic' => false ));
$this -> assertIdentical ( $result , array ( 'Article' => array ( true ), 'Comment' => array ( true , true )));
}
2008-03-09 07:59:23 +00:00
function testSaveAllHasMany () {
$this -> loadFixtures ( 'Article' , 'Comment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
$TestModel -> belongsTo = $TestModel -> hasAndBelongsToMany = array ();
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( array (
2008-04-18 11:06:41 +00:00
'Article' => array ( 'id' => 2 ),
'Comment' => array (
array ( 'comment' => 'First new comment' , 'published' => 'Y' , 'user_id' => 1 ),
array ( 'comment' => 'Second new comment' , 'published' => 'Y' , 'user_id' => 2 )
)
2008-03-11 02:44:33 +00:00
));
2008-04-18 11:06:41 +00:00
$this -> assertTrue ( $result );
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 2 );
2008-03-09 07:59:23 +00:00
$expected = array ( 'First Comment for Second Article' , 'Second Comment for Second Article' , 'First new comment' , 'Second new comment' );
$this -> assertEqual ( Set :: extract ( $result [ 'Comment' ], '{n}.comment' ), $expected );
2008-05-13 00:39:29 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll (
2008-05-13 00:39:29 +00:00
array (
'Article' => array ( 'id' => 2 ),
'Comment' => array (
array ( 'comment' => 'Third new comment' , 'published' => 'Y' , 'user_id' => 1 ),
)
),
array ( 'atomic' => false )
);
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 2 );
2008-05-13 00:39:29 +00:00
$expected = array ( 'First Comment for Second Article' , 'Second Comment for Second Article' , 'First new comment' , 'Second new comment' , 'Third new comment' );
$this -> assertEqual ( Set :: extract ( $result [ 'Comment' ], '{n}.comment' ), $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> beforeSaveReturn = false ;
$result = $TestModel -> saveAll (
2008-05-13 00:39:29 +00:00
array (
'Article' => array ( 'id' => 2 ),
'Comment' => array (
array ( 'comment' => 'Fourth new comment' , 'published' => 'Y' , 'user_id' => 1 ),
)
),
array ( 'atomic' => false )
);
$this -> assertEqual ( $result , array ( 'Article' => array ( 0 => false )));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 2 );
2008-05-13 00:39:29 +00:00
$expected = array ( 'First Comment for Second Article' , 'Second Comment for Second Article' , 'First new comment' , 'Second new comment' , 'Third new comment' );
$this -> assertEqual ( Set :: extract ( $result [ 'Comment' ], '{n}.comment' ), $expected );
2008-03-09 07:59:23 +00:00
}
2008-04-19 17:33:17 +00:00
function testSaveAllTransaction () {
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Post ();
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => VALID_NOT_EMPTY );
2008-04-19 17:33:17 +00:00
$data = array (
array ( 'author_id' => 1 , 'title' => 'New Fourth Post' ),
array ( 'author_id' => 1 , 'title' => 'New Fifth Post' ),
array ( 'author_id' => 1 , 'title' => '' )
);
2008-04-21 12:31:28 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> saveAll ( $data ));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-04-19 17:33:17 +00:00
$expected = array (
array ( 'Post' => array ( 'id' => '1' , 'author_id' => 1 , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )),
array ( 'Post' => array ( 'id' => '2' , 'author_id' => 3 , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' )),
array ( 'Post' => array ( 'id' => '3' , 'author_id' => 1 , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ))
);
2008-04-21 12:31:28 +00:00
if ( count ( $result ) != 3 ) {
// Database doesn't support transactions
$expected [] = array ( 'Post' => array ( 'id' => '4' , 'author_id' => 1 , 'title' => 'New Fourth Post' , 'body' => null , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ));
$expected [] = array ( 'Post' => array ( 'id' => '5' , 'author_id' => 1 , 'title' => 'New Fifth Post' , 'body' => null , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ));
$this -> assertEqual ( $result , $expected );
// Skip the rest of the transactional tests
return ;
}
2008-04-19 17:33:17 +00:00
$this -> assertEqual ( $result , $expected );
$data = array (
array ( 'author_id' => 1 , 'title' => 'New Fourth Post' ),
array ( 'author_id' => 1 , 'title' => '' ),
array ( 'author_id' => 1 , 'title' => 'New Sixth Post' )
);
2008-04-21 12:31:28 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> saveAll ( $data ));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-04-19 17:33:17 +00:00
$expected = array (
array ( 'Post' => array ( 'id' => '1' , 'author_id' => 1 , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )),
array ( 'Post' => array ( 'id' => '2' , 'author_id' => 3 , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' )),
array ( 'Post' => array ( 'id' => '3' , 'author_id' => 1 , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ))
);
2008-04-21 12:31:28 +00:00
if ( count ( $result ) != 3 ) {
// Database doesn't support transactions
$expected [] = array ( 'Post' => array ( 'id' => '4' , 'author_id' => 1 , 'title' => 'New Fourth Post' , 'body' => 'Third Post Body' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ));
$expected [] = array ( 'Post' => array ( 'id' => '5' , 'author_id' => 1 , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ));
}
2008-04-19 17:33:17 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => VALID_NOT_EMPTY );
2008-04-19 17:33:17 +00:00
$data = array (
array ( 'author_id' => 1 , 'title' => 'New Fourth Post' ),
array ( 'author_id' => 1 , 'title' => 'New Fifth Post' ),
array ( 'author_id' => 1 , 'title' => 'New Sixth Post' )
);
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> saveAll ( $data ));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 , 'fields' => array ( 'author_id' , 'title' , 'body' , 'published' )));
2008-04-19 17:33:17 +00:00
$expected = array (
array ( 'Post' => array ( 'author_id' => 1 , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' )),
array ( 'Post' => array ( 'author_id' => 3 , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' )),
array ( 'Post' => array ( 'author_id' => 1 , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' )),
array ( 'Post' => array ( 'author_id' => 1 , 'title' => 'New Fourth Post' , 'body' => '' , 'published' => 'N' )),
array ( 'Post' => array ( 'author_id' => 1 , 'title' => 'New Fifth Post' , 'body' => '' , 'published' => 'N' )),
array ( 'Post' => array ( 'author_id' => 1 , 'title' => 'New Sixth Post' , 'body' => '' , 'published' => 'N' ))
);
$this -> assertEqual ( $result , $expected );
}
2008-03-07 01:29:19 +00:00
function testSaveAllValidation () {
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Post ();
2008-04-19 17:33:17 +00:00
2008-03-07 01:29:19 +00:00
$data = array (
array ( 'id' => '1' , 'title' => 'Baleeted First Post' , 'body' => 'Baleeted!' , 'published' => 'N' ),
array ( 'id' => '2' , 'title' => 'Just update the title' ),
2008-03-11 02:44:33 +00:00
array ( 'title' => 'Creating a fourth post' , 'body' => 'Fourth post body' , 'author_id' => 2 )
2008-03-07 01:29:19 +00:00
);
2008-05-13 16:42:39 +00:00
$this -> assertTrue ( $TestModel -> saveAll ( $data ));
2008-04-19 13:30:11 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-05-11 23:08:47 +00:00
$ts = date ( 'Y-m-d H:i:s' );
2008-03-07 01:29:19 +00:00
$expected = array (
array ( 'Post' => array ( 'id' => '1' , 'author_id' => '1' , 'title' => 'Baleeted First Post' , 'body' => 'Baleeted!' , 'published' => 'N' , 'created' => '2007-03-18 10:39:23' , 'updated' => $ts )),
2008-04-19 13:30:11 +00:00
array ( 'Post' => array ( 'id' => '2' , 'author_id' => '3' , 'title' => 'Just update the title' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => $ts )),
2008-03-07 01:29:19 +00:00
array ( 'Post' => array ( 'id' => '3' , 'author_id' => '1' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )),
2008-03-11 02:44:33 +00:00
array ( 'Post' => array ( 'id' => '4' , 'author_id' => '2' , 'title' => 'Creating a fourth post' , 'body' => 'Fourth post body' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ))
2008-03-07 01:29:19 +00:00
);
$this -> assertEqual ( $result , $expected );
2008-04-19 13:30:11 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => VALID_NOT_EMPTY , 'author_id' => 'numeric' );
2008-03-07 01:29:19 +00:00
$data = array (
array ( 'id' => '1' , 'title' => 'Un-Baleeted First Post' , 'body' => 'Not Baleeted!' , 'published' => 'Y' ),
array ( 'id' => '2' , 'title' => '' , 'body' => 'Trying to get away with an empty title' ),
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( $data );
2008-05-12 15:47:20 +00:00
$this -> assertEqual ( $result , false );
2008-05-15 02:05:05 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-05-11 23:08:47 +00:00
$errors = array ( 2 => array ( 'title' => 'This field cannot be left blank' ));
2008-05-15 02:05:05 +00:00
$transactionWorked = Set :: matches ( '/Post[1][title=Baleeted First Post]' , $result );
if ( ! $transactionWorked ) {
$this -> assertTrue ( Set :: matches ( '/Post[1][title=Un-Baleeted First Post]' , $result ));
$this -> assertTrue ( Set :: matches ( '/Post[2][title=Just update the title]' , $result ));
}
2008-05-18 09:22:42 +00:00
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> validationErrors , $errors );
2008-05-11 23:08:47 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> validate = array ( 'title' => VALID_NOT_EMPTY , 'author_id' => 'numeric' );
2008-05-11 23:08:47 +00:00
$data = array (
array ( 'id' => '1' , 'title' => 'Un-Baleeted First Post' , 'body' => 'Not Baleeted!' , 'published' => 'Y' ),
array ( 'id' => '2' , 'title' => '' , 'body' => 'Trying to get away with an empty title' ),
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( $data , array ( 'atomic' => false ));
2008-05-11 23:08:47 +00:00
$this -> assertEqual ( $result , array ( true , false ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-05-12 15:47:20 +00:00
$errors = array ( 2 => array ( 'title' => 'This field cannot be left blank' ));
2008-05-11 23:30:41 +00:00
$newTs = date ( 'Y-m-d H:i:s' );
$expected = array (
2008-05-12 15:47:20 +00:00
array ( 'Post' => array ( 'id' => '1' , 'author_id' => '1' , 'title' => 'Un-Baleeted First Post' , 'body' => 'Not Baleeted!' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => $newTs )),
2008-05-11 23:30:41 +00:00
array ( 'Post' => array ( 'id' => '2' , 'author_id' => '3' , 'title' => 'Just update the title' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => $ts )),
array ( 'Post' => array ( 'id' => '3' , 'author_id' => '1' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' )),
array ( 'Post' => array ( 'id' => '4' , 'author_id' => '2' , 'title' => 'Creating a fourth post' , 'body' => 'Fourth post body' , 'published' => 'N' , 'created' => $ts , 'updated' => $ts ))
);
2008-03-07 01:29:19 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> validationErrors , $errors );
2008-04-19 17:33:17 +00:00
2008-03-07 01:29:19 +00:00
$data = array (
array ( 'id' => '1' , 'title' => 'Re-Baleeted First Post' , 'body' => 'Baleeted!' , 'published' => 'N' ),
array ( 'id' => '2' , 'title' => '' , 'body' => 'Trying to get away with an empty title' ),
);
2008-05-13 16:42:39 +00:00
$this -> assertFalse ( $TestModel -> saveAll ( $data , array ( 'validate' => 'first' )));
2008-04-19 17:33:17 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' , array ( 'recursive' => - 1 ));
2008-03-07 01:29:19 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> validationErrors , $errors );
2008-04-19 17:33:17 +00:00
2008-03-07 01:29:19 +00:00
$data = array (
array ( 'title' => 'First new post' , 'body' => 'Woohoo!' , 'published' => 'Y' ),
array ( 'title' => 'Empty body' , 'body' => '' )
);
2008-05-13 16:42:39 +00:00
$TestModel -> validate [ 'body' ] = VALID_NOT_EMPTY ;
2008-03-07 01:29:19 +00:00
}
2008-05-13 01:03:11 +00:00
function testSaveAllValidationOnly () {
2008-05-13 16:42:39 +00:00
$TestModel =& new Comment ();
$TestModel -> Attachment -> validate = array ( 'attachment' => VALID_NOT_EMPTY );
2008-05-13 01:03:11 +00:00
$data = array (
'Comment' => array (
'comment' => 'This is the comment'
),
'Attachment' => array (
'attachment' => ''
)
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> saveAll ( $data , array ( 'validate' => 'only' ));
2008-05-13 01:03:11 +00:00
$this -> assertFalse ( $result );
}
2008-05-13 16:42:39 +00:00
2008-05-13 01:39:06 +00:00
function testSaveAllValidateFirst () {
2008-05-16 05:31:14 +00:00
$model =& new Article ();
$model -> deleteAll ( true );
2008-05-13 16:42:39 +00:00
2008-05-16 05:31:14 +00:00
$model -> Comment -> validate = array ( 'comment' => VALID_NOT_EMPTY );
$result = $model -> saveAll ( array (
2008-05-13 01:39:06 +00:00
'Article' => array ( 'title' => 'Post with Author' , 'body' => 'This post will be saved author' ),
'Comment' => array (
array ( 'comment' => 'First new comment' ),
array ( 'comment' => '' )
)
), array ( 'validate' => 'first' ));
$this -> assertFalse ( $result );
2008-05-16 05:31:14 +00:00
$result = $model -> find ( 'all' );
2008-05-13 01:39:06 +00:00
$this -> assertEqual ( $result , array ());
$expected = array ( 'Comment' => array ( 0 => array ( 'comment' => 'This field cannot be left blank' )));
2008-05-16 05:31:14 +00:00
$this -> assertEqual ( $model -> validationErrors , $expected );
$this -> assertIdentical ( $model -> Comment -> find ( 'count' ), 0 );
2008-05-18 06:42:36 +00:00
$result = $model -> saveAll (
array (
'Article' => array ( 'title' => 'Post with Author' , 'body' => 'This post will be saved with an author' , 'user_id' => 2 ),
'Comment' => array ( array ( 'comment' => 'Only new comment' , 'user_id' => 2 ))
),
array ( 'validate' => 'first' )
);
2008-05-16 05:31:14 +00:00
$this -> assertIdentical ( $result , true );
$result = $model -> Comment -> find ( 'all' );
$this -> assertIdentical ( count ( $result ), 1 );
$result = Set :: extract ( '/Comment/article_id' , $result );
$this -> assertTrue ( $result [ 0 ] === 1 || $result [ 0 ] === '1' );
2008-05-13 01:39:06 +00:00
}
2008-05-13 01:03:11 +00:00
2008-01-01 19:34:40 +00:00
function testSaveWithCounterCache () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Syfile' , 'Item' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Syfile ();
$TestModel2 =& new Item ();
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 1 );
2008-01-01 19:34:40 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], null );
2008-05-13 16:42:39 +00:00
$TestModel2 -> save ( array ( 'name' => 'Item 7' , 'syfile_id' => 1 , 'published' => false ));
$result = $TestModel -> findById ( 1 );
2008-01-01 19:34:40 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], '2' );
2008-05-13 16:42:39 +00:00
$TestModel2 -> delete ( 1 );
$result = $TestModel -> findById ( 1 );
2008-01-01 19:34:40 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], '1' );
2008-03-01 03:41:43 +00:00
2008-05-13 16:42:39 +00:00
$TestModel2 -> id = 2 ;
$TestModel2 -> saveField ( 'syfile_id' , 1 );
2008-03-01 03:41:43 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 1 );
2008-03-01 03:41:43 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], '2' );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 2 );
2008-03-01 03:41:43 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], null );
2008-01-01 19:34:40 +00:00
}
2008-05-16 05:31:14 +00:00
function testSaveWithCounterCacheScope () {
2008-02-02 04:50:44 +00:00
$this -> loadFixtures ( 'Syfile' , 'Item' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Syfile ();
$TestModel2 =& new Item ();
$TestModel2 -> belongsTo [ 'Syfile' ][ 'counterCache' ] = true ;
$TestModel2 -> belongsTo [ 'Syfile' ][ 'counterScope' ] = array ( 'published' => true );
2008-02-02 04:50:44 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findById ( 1 );
2008-02-02 04:50:44 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], null );
2008-05-13 16:42:39 +00:00
$TestModel2 -> save ( array ( 'name' => 'Item 7' , 'syfile_id' => 1 , 'published' => true ));
$result = $TestModel -> findById ( 1 );
2008-02-02 04:50:44 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], '1' );
2008-05-13 16:42:39 +00:00
$TestModel2 -> id = 1 ;
$TestModel2 -> saveField ( 'published' , true );
$result = $TestModel -> findById ( 1 );
2008-02-02 04:50:44 +00:00
$this -> assertIdentical ( $result [ 'Syfile' ][ 'item_count' ], '2' );
}
2007-10-24 16:07:36 +00:00
function testDel () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-06-27 19:16:11 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> del ( 2 );
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> read ( null , 2 );
2007-06-27 19:16:11 +00:00
$this -> assertFalse ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'title' ));
2007-06-27 19:16:11 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' ))
2007-06-27 19:16:11 +00:00
);
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> del ( 3 );
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> read ( null , 3 );
2007-06-27 19:16:11 +00:00
$this -> assertFalse ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'title' ));
2007-06-27 19:16:11 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' ))
2007-06-27 19:16:11 +00:00
);
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testDeleteAll () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-06-27 19:16:11 +00:00
$data = array ( 'Article' => array ( 'user_id' => 2 , 'id' => 4 , 'title' => 'Fourth Article' , 'published' => 'N' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data ) && $TestModel -> save ();
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
$data = array ( 'Article' => array ( 'user_id' => 2 , 'id' => 5 , 'title' => 'Fifth Article' , 'published' => 'Y' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data ) && $TestModel -> save ();
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
$data = array ( 'Article' => array ( 'user_id' => 1 , 'id' => 6 , 'title' => 'Sixth Article' , 'published' => 'N' ));
2008-05-13 16:42:39 +00:00
$result = $TestModel -> set ( $data ) && $TestModel -> save ();
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
2007-06-27 19:16:11 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'user_id' => 1 , 'title' => 'First Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 2 , 'user_id' => 3 , 'title' => 'Second Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 3 , 'user_id' => 1 , 'title' => 'Third Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 4 , 'user_id' => 2 , 'title' => 'Fourth Article' , 'published' => 'N' )),
array ( 'Article' => array ( 'id' => 5 , 'user_id' => 2 , 'title' => 'Fifth Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 6 , 'user_id' => 1 , 'title' => 'Sixth Article' , 'published' => 'N' ))
2007-06-27 19:16:11 +00:00
);
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> deleteAll ( array ( 'Article.published' => 'N' ));
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
2007-06-27 19:16:11 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'user_id' => 1 , 'title' => 'First Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 2 , 'user_id' => 3 , 'title' => 'Second Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 3 , 'user_id' => 1 , 'title' => 'Third Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 5 , 'user_id' => 2 , 'title' => 'Fifth Article' , 'published' => 'Y' ))
2007-06-27 19:16:11 +00:00
);
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> deleteAll ( array ( 'Article.user_id' => array ( 2 , 3 )));
2007-06-27 19:16:11 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = - 1 ;
$result = $TestModel -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
2007-06-27 19:16:11 +00:00
$expected = array (
2007-08-14 23:12:24 +00:00
array ( 'Article' => array ( 'id' => 1 , 'user_id' => 1 , 'title' => 'First Article' , 'published' => 'Y' )),
array ( 'Article' => array ( 'id' => 3 , 'user_id' => 1 , 'title' => 'Third Article' , 'published' => 'Y' ))
2007-05-18 17:54:59 +00:00
);
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-10-24 16:07:36 +00:00
function testRecursiveDel () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'Comment' , 'Attachment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> del ( 2 );
2007-03-17 19:15:41 +00:00
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( null , 2 );
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> read ( null , 5 );
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> read ( null , 6 );
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> Attachment -> read ( null , 1 );
2007-03-17 19:15:41 +00:00
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findCount ();
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , 2 );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> findCount ();
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , 4 );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Comment -> Attachment -> findCount ();
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , 0 );
}
2007-03-30 00:08:10 +00:00
2008-01-01 19:34:40 +00:00
function testDependentExclusiveDelete () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Article' , 'Comment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article10 ();
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> find ( 'all' );
2008-01-01 19:34:40 +00:00
$this -> assertEqual ( count ( $result [ 0 ][ 'Comment' ]), 4 );
$this -> assertEqual ( count ( $result [ 1 ][ 'Comment' ]), 2 );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> Comment -> find ( 'count' ), 6 );
2008-01-01 19:34:40 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> delete ( 1 );
$this -> assertEqual ( $TestModel -> Comment -> find ( 'count' ), 2 );
2008-01-01 19:34:40 +00:00
}
2008-03-11 02:44:33 +00:00
function testDeleteLinks () {
$this -> loadFixtures ( 'Article' , 'ArticlesTag' , 'Tag' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-03-11 02:44:33 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> ArticlesTag -> find ( 'all' );
2008-03-11 02:44:33 +00:00
$expected = array (
array ( 'ArticlesTag' => array ( 'article_id' => '1' , 'tag_id' => '1' )),
array ( 'ArticlesTag' => array ( 'article_id' => '1' , 'tag_id' => '2' )),
array ( 'ArticlesTag' => array ( 'article_id' => '2' , 'tag_id' => '1' )),
array ( 'ArticlesTag' => array ( 'article_id' => '2' , 'tag_id' => '3' ))
);
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$TestModel -> delete ( 1 );
$result = $TestModel -> ArticlesTag -> find ( 'all' );
2008-03-11 02:44:33 +00:00
$expected = array (
array ( 'ArticlesTag' => array ( 'article_id' => '2' , 'tag_id' => '1' )),
array ( 'ArticlesTag' => array ( 'article_id' => '2' , 'tag_id' => '3' ))
);
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testFindAllThreaded () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Category' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Category ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAllThreaded ();
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Category' => array ( 'id' => '1' , 'parent_id' => '0' , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array (
array (
'Category' => array ( 'id' => '2' , 'parent_id' => '1' , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '3' , 'parent_id' => '1' , 'name' => 'Category 1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-17 19:15:41 +00:00
)
)
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '4' , 'parent_id' => '0' , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '5' , 'parent_id' => '0' , 'name' => 'Category 3' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array (
array (
'Category' => array ( 'id' => '6' , 'parent_id' => '5' , 'name' => 'Category 3.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-17 19:15:41 +00:00
)
)
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAllThreaded ( array ( 'Category.name' => 'LIKE Category 1%' ));
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Category' => array ( 'id' => '1' , 'parent_id' => '0' , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array (
array (
'Category' => array ( 'id' => '2' , 'parent_id' => '1' , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '3' , 'parent_id' => '1' , 'name' => 'Category 1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
2007-03-17 19:15:41 +00:00
)
)
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAllThreaded ( null , 'id, parent_id, name' );
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Category' => array ( 'id' => '1' , 'parent_id' => '0' , 'name' => 'Category 1' ),
'children' => array (
array (
'Category' => array ( 'id' => '2' , 'parent_id' => '1' , 'name' => 'Category 1.1' ),
'children' => array ()
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '3' , 'parent_id' => '1' , 'name' => 'Category 1.2' ),
'children' => array ()
2007-03-17 19:15:41 +00:00
)
)
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '4' , 'parent_id' => '0' , 'name' => 'Category 2' ),
'children' => array ()
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Category' => array ( 'id' => '5' , 'parent_id' => '0' , 'name' => 'Category 3' ),
'children' => array (
array (
'Category' => array ( 'id' => '6' , 'parent_id' => '5' , 'name' => 'Category 3.1' ),
'children' => array ()
2007-03-17 19:15:41 +00:00
)
)
)
);
$this -> assertEqual ( $result , $expected );
2008-01-09 01:04:14 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAllThreaded ( null , null , 'id DESC' );
2008-01-09 01:04:14 +00:00
$expected = array (
array (
'Category' => array ( 'id' => 5 , 'parent_id' => 0 , 'name' => 'Category 3' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array (
array (
'Category' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 3.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
)
)
),
array (
'Category' => array ( 'id' => 4 , 'parent_id' => 0 , 'name' => 'Category 2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
),
array (
'Category' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array (
array (
'Category' => array ( 'id' => 3 , 'parent_id' => 1 , 'name' => 'Category 1.2' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
),
array (
'Category' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ),
'children' => array ()
)
)
)
2008-01-11 03:16:19 +00:00
);
2008-01-09 01:04:14 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-17 19:15:41 +00:00
}
2007-03-30 00:08:10 +00:00
2008-04-24 14:12:36 +00:00
function testDoThread () {
2008-05-13 16:42:39 +00:00
$TestModel =& new Category ();
2008-04-24 14:12:36 +00:00
$this -> db -> fullDebug = true ;
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$result = array (
array ( 'Category' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' )),
array ( 'Category' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' )),
array ( 'Category' => array ( 'id' => 3 , 'parent_id' => 1 , 'name' => 'Category 1.2' )),
array ( 'Category' => array ( 'id' => 4 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' )),
array ( 'Category' => array ( 'id' => 5 , 'parent_id' => 0 , 'name' => 'Category 2' )),
array ( 'Category' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2.1' )),
array ( 'Category' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1.1' ))
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> __doThread ( $result , null );
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$expected = array (
array (
'Category' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' ),
'children' => array (
array (
'Category' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' ),
'children' => array (
array (
'Category' => array ( 'id' => 4 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' ),
'children' => array ()
)
)
),
array (
'Category' => array ( 'id' => 3 , 'parent_id' => 1 , 'name' => 'Category 1.2' ),
'children' => array ()
)
)
),
array (
'Category' => array ( 'id' => 5 , 'parent_id' => 0 , 'name' => 'Category 2' ),
'children' => array (
array (
'Category' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2.1' ),
'children' => array (
array (
'Category' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1.1' ),
'children' => array ()
)
)
)
)
)
);
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$this -> assertEqual ( $result , $expected );
}
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
function testDoThreadOrdered () {
2008-05-13 16:42:39 +00:00
$TestModel =& new Category ();
2008-04-24 14:12:36 +00:00
$this -> db -> fullDebug = true ;
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$result = array (
array ( 'Category' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1.1' )),
2008-05-11 23:08:47 +00:00
array ( 'Category' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2.1' )),
2008-04-24 14:12:36 +00:00
array ( 'Category' => array ( 'id' => 5 , 'parent_id' => 0 , 'name' => 'Category 2' )),
array ( 'Category' => array ( 'id' => 4 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' )),
array ( 'Category' => array ( 'id' => 3 , 'parent_id' => 1 , 'name' => 'Category 1.2' )),
array ( 'Category' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' )),
array ( 'Category' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' ))
);
2008-05-13 16:42:39 +00:00
$result = $TestModel -> __doThread ( $result , null );
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$expected = array (
array (
'Category' => array ( 'id' => 5 , 'parent_id' => 0 , 'name' => 'Category 2' ),
'children' => array (
array (
'Category' => array ( 'id' => 6 , 'parent_id' => 5 , 'name' => 'Category 2.1' ),
'children' => array (
array (
'Category' => array ( 'id' => 7 , 'parent_id' => 6 , 'name' => 'Category 2.1.1' ),
'children' => array ()
)
)
)
)
),
array (
'Category' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' ),
'children' => array (
array (
'Category' => array ( 'id' => 3 , 'parent_id' => 1 , 'name' => 'Category 1.2' ),
'children' => array ()
),
array (
'Category' => array ( 'id' => 2 , 'parent_id' => 1 , 'name' => 'Category 1.1' ),
'children' => array (
array (
'Category' => array ( 'id' => 4 , 'parent_id' => 2 , 'name' => 'Category 1.1.1' ),
'children' => array ()
)
)
)
)
)
);
2008-05-11 23:08:47 +00:00
2008-04-24 14:12:36 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testFindNeighbours () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'User' , 'Article' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findNeighbours ( null , 'Article.id' , '2' );
2007-10-22 02:11:58 +00:00
$expected = array ( 'prev' => array ( 'Article' => array ( 'id' => 1 )), 'next' => array ( 'Article' => array ( 'id' => 3 )));
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findNeighbours ( null , 'Article.id' , '3' );
2007-10-22 02:11:58 +00:00
$expected = array ( 'prev' => array ( 'Article' => array ( 'id' => 2 )), 'next' => array ());
2007-03-17 19:15:41 +00:00
$this -> assertEqual ( $result , $expected );
2007-10-23 13:41:25 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findNeighbours ( array ( 'User.id' => 1 ), array ( 'Article.id' , 'Article.title' ), 2 );
2007-10-23 13:41:25 +00:00
$expected = array (
'prev' => array ( 'Article' => array ( 'id' => 1 , 'title' => 'First Article' )),
'next' => array ( 'Article' => array ( 'id' => 3 , 'title' => 'Third Article' )),
);
$this -> assertEqual ( $result , $expected );
2007-03-17 19:15:41 +00:00
}
2007-04-09 08:54:25 +00:00
2007-10-24 16:07:36 +00:00
function testFindCombinedRelations () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Apple' , 'Sample' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Apple ();
2007-04-09 08:54:25 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2007-04-09 08:54:25 +00:00
2008-01-11 03:16:19 +00:00
$expected = array (
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => '1' , 'apple_id' => '2' , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '2' , 'apple_id' => '1' , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => null , 'apple_id' => null , 'name' => null ),
2007-12-23 05:40:25 +00:00
'Child' => array ( array ( 'id' => '2' , 'apple_id' => '1' , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => '2' , 'apple_id' => '1' , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '1' , 'apple_id' => '2' , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '2' , 'apple_id' => '2' , 'name' => 'sample2' ),
2007-12-23 05:40:25 +00:00
'Child' => array ( array ( 'id' => '1' , 'apple_id' => '2' , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => '3' , 'apple_id' => '2' , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => '4' , 'apple_id' => '2' , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => '3' , 'apple_id' => '2' , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '2' , 'apple_id' => '1' , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '1' , 'apple_id' => '3' , 'name' => 'sample1' ),
'Child' => array ()),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => '4' , 'apple_id' => '2' , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => '2' , 'apple_id' => '1' , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
'Sample' => array ( 'id' => '3' , 'apple_id' => '4' , 'name' => 'sample3' ),
'Child' => array ( array ( 'id' => '6' , 'apple_id' => '4' , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => '5' , 'apple_id' => '5' , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '5' , 'apple_id' => '5' , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => '4' , 'apple_id' => '5' , 'name' => 'sample4' ),
'Child' => array ( array ( 'id' => '5' , 'apple_id' => '5' , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => '6' , 'apple_id' => '4' , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '4' , 'apple_id' => '2' , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => null , 'apple_id' => null , 'name' => null ),
'Child' => array ( array ( 'id' => '7' , 'apple_id' => '6' , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => '7' , 'apple_id' => '6' , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => '6' , 'apple_id' => '4' , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => null , 'apple_id' => null , 'name' => null ),
'Child' => array ()));
2007-04-05 04:04:55 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-06-03 21:54:11 +00:00
2007-10-24 16:07:36 +00:00
function testSaveEmpty () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Thread' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Thread ();
2007-10-19 21:05:34 +00:00
$data = array ();
2008-05-13 16:42:39 +00:00
$expected = $TestModel -> save ( $data );
2007-10-19 21:05:34 +00:00
$this -> assertFalse ( $expected );
2007-10-19 21:43:48 +00:00
}
2007-10-19 21:05:34 +00:00
2007-12-19 02:05:15 +00:00
// function testBasicValidation() {
2008-05-13 16:42:39 +00:00
// $TestModel =& new ValidationTest();
// $TestModel->testing = true;
// $TestModel->set(array('title' => '', 'published' => 1));
// $this->assertEqual($TestModel->invalidFields(), array('title' => 'This field cannot be left blank'));
2007-12-23 05:40:25 +00:00
//
2008-05-13 16:42:39 +00:00
// $TestModel->create();
// $TestModel->set(array('title' => 'Hello', 'published' => 0));
// $this->assertEqual($TestModel->invalidFields(), array('published' => 'This field cannot be left blank'));
2007-12-23 05:40:25 +00:00
//
2008-05-13 16:42:39 +00:00
// $TestModel->create();
// $TestModel->set(array('title' => 'Hello', 'published' => 1, 'body' => ''));
// $this->assertEqual($TestModel->invalidFields(), array('body' => 'This field cannot be left blank'));
2007-12-19 02:05:15 +00:00
// }
2007-06-03 21:54:11 +00:00
2008-05-18 09:22:42 +00:00
function testFindAllWithConditionsHavingMixedDataTypes () {
$this -> loadFixtures ( 'Article' );
$TestModel =& new Article ();
$expected = array (
array (
'Article' => array (
'id' => 1 ,
'user_id' => 1 ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
),
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'
)
)
);
$conditions = array ( 'id' => array ( '1' , 2 ));
$recursive = - 1 ;
$result = $TestModel -> find ( 'all' , compact ( 'conditions' , 'recursive' ));
$this -> assertEqual ( $result , $expected );
$conditions = array ( 'id' => array ( '1' , 2 , '3.0' ));
$result = $TestModel -> find ( 'all' , compact ( 'recursive' , 'conditions' ));
$expected = array (
array (
'Article' => array (
'id' => 1 ,
'user_id' => 1 ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
),
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'
)
),
array (
'Article' => array (
'id' => 3 ,
'user_id' => 1 ,
'title' => 'Third Article' ,
'body' => 'Third Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
)
)
);
$this -> assertEqual ( $result , $expected );
}
2007-10-24 16:07:36 +00:00
function testMultipleValidation () {
2008-05-13 16:42:39 +00:00
$TestModel =& new ValidationTest ();
2007-06-03 21:54:11 +00:00
}
2007-08-29 04:38:48 +00:00
2007-12-19 02:05:15 +00:00
function testLoadModelSecondIteration () {
2007-08-29 04:38:48 +00:00
$model = new ModelA ();
$this -> assertIsA ( $model , 'ModelA' );
$this -> assertIsA ( $model -> ModelB , 'ModelB' );
$this -> assertIsA ( $model -> ModelB -> ModelD , 'ModelD' );
$this -> assertIsA ( $model -> ModelC , 'ModelC' );
$this -> assertIsA ( $model -> ModelC -> ModelD , 'ModelD' );
}
2007-10-22 02:11:58 +00:00
2007-10-24 16:07:36 +00:00
function testRecursiveUnbind () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Apple' , 'Sample' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Apple ();
$TestModel -> recursive = 2 ;
2007-10-22 02:11:58 +00:00
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2008-01-11 03:16:19 +00:00
$expected = array (
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' )),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' )),
2007-10-22 02:11:58 +00:00
'Child' => array ()),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ,
'Apple' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ,
'Apple' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ()))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
'Child' => array ()));
2007-10-22 02:11:58 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'hasOne' => array ( 'Sample' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2008-01-11 03:16:19 +00:00
$expected = array (
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' )),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' )),
2007-10-22 02:11:58 +00:00
'Child' => array ()),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ,
'Apple' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ,
'Apple' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' )),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ()))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' ),
'Child' => array ()));
2007-10-22 02:11:58 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'hasOne' => array ( 'Sample' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Child' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2007-10-22 02:11:58 +00:00
$expected = array ( array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ,
'Apple' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ,
'Apple' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )));
2007-10-22 02:11:58 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Child' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Sample -> unbindModel ( array ( 'belongsTo' => array ( 'Apple' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2008-01-11 03:16:19 +00:00
$expected = array (
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' )),
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' )),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' )),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' )),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )));
2007-10-22 02:11:58 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'belongsTo' => array ( 'Parent' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Child' )));
2007-10-22 02:11:58 +00:00
$this -> assertTrue ( $result );
2008-05-13 16:42:39 +00:00
$result = $TestModel -> findAll ();
2007-10-22 02:11:58 +00:00
$expected = array ( array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ,
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2007-12-23 05:40:25 +00:00
'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => 1 , 'apple_id' => 3 , 'name' => 'sample1' ,
2007-12-23 05:40:25 +00:00
'Apple' => array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ),
2007-12-23 05:40:25 +00:00
'Parent' => array ( 'id' => 2 , 'apple_id' => 1 , 'color' => 'Bright Red 1' , 'name' => 'Bright Red Apple' , 'created' => '2006-11-22 10:43:13' , 'date' => '2014-01-01' , 'modified' => '2006-11-30 18:38:10' , 'mytime' => '22:57:17' ,
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
2007-12-23 05:40:25 +00:00
array ( 'id' => 1 , 'apple_id' => 2 , 'color' => 'Red 1' , 'name' => 'Red Apple 1' , 'created' => '2006-11-22 10:38:58' , 'date' => '1951-01-04' , 'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
array ( 'id' => 3 , 'apple_id' => 2 , 'color' => 'blue green' , 'name' => 'green blue' , 'created' => '2006-12-25 05:13:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:24' , 'mytime' => '22:57:17' ),
2008-01-11 03:16:19 +00:00
array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ,
'Apple' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ,
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
'Sample' => array ( 'id' => 4 , 'apple_id' => 5 , 'name' => 'sample4' ,
'Apple' => array ( 'id' => 5 , 'apple_id' => 5 , 'color' => 'Green' , 'name' => 'Blue Green' , 'created' => '2006-12-25 05:24:06' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:16' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 4 , 'apple_id' => 2 , 'color' => 'Blue Green' , 'name' => 'Test Name' , 'created' => '2006-12-25 05:23:36' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:23:36' , 'mytime' => '22:57:17' ,
'Sample' => array ( 'id' => 3 , 'apple_id' => 4 , 'name' => 'sample3' ),
2007-10-26 08:40:10 +00:00
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ))),
2007-10-22 02:11:58 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )),
array ( 'Apple' => array (
2008-01-11 03:16:19 +00:00
'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ),
'Parent' => array ( 'id' => 6 , 'apple_id' => 4 , 'color' => 'My new appleOrange' , 'name' => 'My new apple' , 'created' => '2006-12-25 05:29:39' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:29:39' , 'mytime' => '22:57:17' ,
2007-10-26 08:40:10 +00:00
'Sample' => array (),
'Child' => array (
2008-01-11 03:16:19 +00:00
array ( 'id' => 7 , 'apple_id' => 6 , 'color' => 'Some wierd color' , 'name' => 'Some odd color' , 'created' => '2006-12-25 05:34:21' , 'date' => '2006-12-25' , 'modified' => '2006-12-25 05:34:21' , 'mytime' => '22:57:17' ))),
2007-10-26 08:40:10 +00:00
'Sample' => array ( 'id' => '' , 'apple_id' => '' , 'name' => '' )));
2007-10-22 02:11:58 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-10-22 22:58:38 +00:00
2007-10-24 16:07:36 +00:00
function testSelfAssociationAfterFind () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Apple' );
2007-10-22 02:11:58 +00:00
$afterFindModel = new NodeAfterFind ();
$afterFindModel -> recursive = 3 ;
2008-03-10 03:41:04 +00:00
$afterFindData = $afterFindModel -> find ( 'all' );
2007-10-22 02:11:58 +00:00
$duplicateModel = new NodeAfterFind ();
$duplicateModel -> recursive = 3 ;
2008-03-10 03:41:04 +00:00
$duplicateModelData = $duplicateModel -> find ( 'all' );
2007-10-22 02:11:58 +00:00
$noAfterFindModel = new NodeNoAfterFind ();
$noAfterFindModel -> recursive = 3 ;
2008-03-10 03:41:04 +00:00
$noAfterFindData = $noAfterFindModel -> find ( 'all' );
2007-10-22 02:11:58 +00:00
$this -> assertFalse ( $afterFindModel == $noAfterFindModel );
// Limitation of PHP 4 and PHP 5 > 5.1.6 when comparing recursive objects
if ( PHP_VERSION === '5.1.6' ) {
$this -> assertFalse ( $afterFindModel != $duplicateModel );
}
$this -> assertEqual ( $afterFindData , $noAfterFindData );
}
2007-10-22 20:58:55 +00:00
2008-02-26 06:20:16 +00:00
function testAutoSaveUuid () {
2008-05-11 18:53:54 +00:00
// SQLite does not support non-integer primary keys, and SQL Server
// is still having problems with custom PK's
2008-05-11 23:08:47 +00:00
if ( $this -> db -> config [ 'driver' ] == 'sqlite' || $this -> db -> config [ 'driver' ] == 'mssql' ) {
2008-03-01 03:12:12 +00:00
return ;
}
2008-02-26 06:20:16 +00:00
$this -> loadFixtures ( 'Uuid' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Uuid ();
2008-03-01 05:15:53 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> save ( array ( 'title' => 'Test record' ));
$result = $TestModel -> findByTitle ( 'Test record' );
2008-03-08 17:27:32 +00:00
$this -> assertEqual ( array_keys ( $result [ 'Uuid' ]), array ( 'id' , 'title' , 'count' , 'created' , 'updated' ));
2008-02-26 06:20:16 +00:00
$this -> assertEqual ( strlen ( $result [ 'Uuid' ][ 'id' ]), 36 );
}
2008-03-08 17:27:32 +00:00
function testZeroDefaultFieldValue () {
2008-03-13 03:11:29 +00:00
$this -> loadFixtures ( 'DataTest' );
2008-05-13 16:42:39 +00:00
$TestModel =& new DataTest ();
2008-03-08 17:27:32 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> create ( array ( 'float' => '' )) && $TestModel -> save ();
$result = $TestModel -> findById ( $TestModel -> id );
2008-03-13 03:11:29 +00:00
$this -> assertIdentical ( $result [ 'DataTest' ][ 'count' ], '0' );
$this -> assertIdentical ( $result [ 'DataTest' ][ 'float' ], '0' );
2008-03-08 17:27:32 +00:00
}
2008-03-13 03:11:29 +00:00
function testNonNumericHabtmJoinKey () {
$this -> loadFixtures ( 'Post' , 'Tag' , 'PostsTag' );
2008-05-13 16:42:39 +00:00
$Post =& new Post ();
$Post -> bind ( 'Tag' , array ( 'type' => 'hasAndBelongsToMany' ));
$Post -> Tag -> primaryKey = 'tag' ;
2008-01-03 18:50:59 +00:00
2008-05-13 16:42:39 +00:00
$result = $Post -> find ( 'all' );
2008-03-13 03:11:29 +00:00
$expected = array (
array (
'Post' => array ( 'id' => '1' , 'author_id' => '1' , 'title' => 'First Post' , 'body' => 'First Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'Author' => array ( 'id' => null , 'user' => null , 'password' => null , 'created' => null , 'updated' => null , 'test' => 'working' ),
'Tag' => array (
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' ),
)
),
array (
'Post' => array ( 'id' => '2' , 'author_id' => '3' , 'title' => 'Second Post' , 'body' => 'Second Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31' ),
'Author' => array ( 'id' => null , 'user' => null , 'password' => null , 'created' => null , 'updated' => null , 'test' => 'working' ),
'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' )
)
),
array (
'Post' => array ( 'id' => '3' , 'author_id' => '1' , 'title' => 'Third Post' , 'body' => 'Third Post Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'Author' => array ( 'id' => null , 'user' => null , 'password' => null , 'created' => null , 'updated' => null , 'test' => 'working' ),
'Tag' => array ()
)
);
$this -> assertEqual ( $result , $expected );
}
function testAfterFindAssociation () {
2008-03-26 11:17:24 +00:00
2008-01-01 23:57:17 +00:00
}
2007-12-14 04:21:58 +00:00
function testDeconstructFields () {
2008-01-11 06:45:00 +00:00
$this -> loadFixtures ( 'Apple' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Apple ();
2007-12-14 04:21:58 +00:00
$data [ 'Apple' ][ 'created' ][ 'year' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '2007' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '08' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '2007-08-20 00:00:00' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '2007' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '08' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '10' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '12' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '2007-08-20 10:12:00' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '2007' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '12' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '33' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '33' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '33' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '13' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '00' ;
$data [ 'Apple' ][ 'date' ][ 'year' ] = '2006' ;
$data [ 'Apple' ][ 'date' ][ 'month' ] = '12' ;
$data [ 'Apple' ][ 'date' ][ 'day' ] = '25' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' , 'date' => '2006-12-25' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '2007' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '08' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '10' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '12' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '09' ;
$data [ 'Apple' ][ 'date' ][ 'year' ] = '2006' ;
$data [ 'Apple' ][ 'date' ][ 'month' ] = '12' ;
$data [ 'Apple' ][ 'date' ][ 'day' ] = '25' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '2007-08-20 10:12:09' , 'date' => '2006-12-25' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '--' ;
$data [ 'Apple' ][ 'date' ][ 'year' ] = '--' ;
$data [ 'Apple' ][ 'date' ][ 'month' ] = '--' ;
$data [ 'Apple' ][ 'date' ][ 'day' ] = '--' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' , 'date' => '' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'created' ][ 'year' ] = '2007' ;
$data [ 'Apple' ][ 'created' ][ 'month' ] = '--' ;
$data [ 'Apple' ][ 'created' ][ 'day' ] = '20' ;
$data [ 'Apple' ][ 'created' ][ 'hour' ] = '10' ;
$data [ 'Apple' ][ 'created' ][ 'min' ] = '12' ;
$data [ 'Apple' ][ 'created' ][ 'sec' ] = '09' ;
$data [ 'Apple' ][ 'date' ][ 'year' ] = '2006' ;
$data [ 'Apple' ][ 'date' ][ 'month' ] = '12' ;
$data [ 'Apple' ][ 'date' ][ 'day' ] = '25' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'created' => '' , 'date' => '2006-12-25' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
$data = array ();
$data [ 'Apple' ][ 'date' ][ 'year' ] = '2006' ;
$data [ 'Apple' ][ 'date' ][ 'month' ] = '12' ;
$data [ 'Apple' ][ 'date' ][ 'day' ] = '25' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-14 04:21:58 +00:00
$expected = array ( 'Apple' => array ( 'date' => '2006-12-25' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-23 05:40:25 +00:00
$data = array ();
$data [ 'Apple' ][ 'mytime' ][ 'hour' ] = '03' ;
$data [ 'Apple' ][ 'mytime' ][ 'min' ] = '04' ;
$data [ 'Apple' ][ 'mytime' ][ 'sec' ] = '04' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-23 05:40:25 +00:00
$expected = array ( 'Apple' => array ( 'mytime' => '03:04:04' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-23 05:40:25 +00:00
$data = array ();
$data [ 'Apple' ][ 'mytime' ][ 'hour' ] = '3' ;
$data [ 'Apple' ][ 'mytime' ][ 'min' ] = '4' ;
$data [ 'Apple' ][ 'mytime' ][ 'sec' ] = '4' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2008-02-21 15:36:13 +00:00
$expected = array ( 'Apple' => array ( 'mytime' => '03:04:04' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-23 05:40:25 +00:00
$data = array ();
$data [ 'Apple' ][ 'mytime' ][ 'hour' ] = '03' ;
$data [ 'Apple' ][ 'mytime' ][ 'min' ] = '4' ;
$data [ 'Apple' ][ 'mytime' ][ 'sec' ] = '4' ;
2008-05-13 16:42:39 +00:00
$TestModel -> data = null ;
$TestModel -> set ( $data );
2007-12-23 05:40:25 +00:00
$expected = array ( 'Apple' => array ( 'mytime' => '03:04:04' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> data , $expected );
2007-12-14 04:21:58 +00:00
}
2008-03-01 05:15:53 +00:00
function testTablePrefixSwitching () {
2008-05-11 23:08:47 +00:00
ConnectionManager :: create ( 'database1' , array_merge ( $this -> db -> config , array ( 'prefix' => 'aaa_' )));
ConnectionManager :: create ( 'database2' , array_merge ( $this -> db -> config , array ( 'prefix' => 'bbb_' )));
2008-03-01 05:15:53 +00:00
$db1 = ConnectionManager :: getDataSource ( 'database1' );
$db2 = ConnectionManager :: getDataSource ( 'database2' );
2008-05-13 16:42:39 +00:00
$TestModel = new Apple ();
$TestModel -> setDataSource ( 'database1' );
$this -> assertEqual ( $this -> db -> fullTableName ( $TestModel , false ), 'aaa_apples' );
$this -> assertEqual ( $db1 -> fullTableName ( $TestModel , false ), 'aaa_apples' );
$this -> assertEqual ( $db2 -> fullTableName ( $TestModel , false ), 'aaa_apples' );
2008-03-01 05:15:53 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> setDataSource ( 'database2' );
$this -> assertEqual ( $this -> db -> fullTableName ( $TestModel , false ), 'bbb_apples' );
$this -> assertEqual ( $db1 -> fullTableName ( $TestModel , false ), 'bbb_apples' );
$this -> assertEqual ( $db2 -> fullTableName ( $TestModel , false ), 'bbb_apples' );
2008-03-01 05:15:53 +00:00
2008-05-13 16:42:39 +00:00
$TestModel = new Apple ();
$TestModel -> tablePrefix = 'custom_' ;
$this -> assertEqual ( $this -> db -> fullTableName ( $TestModel , false ), 'custom_apples' );
$TestModel -> setDataSource ( 'database1' );
$this -> assertEqual ( $this -> db -> fullTableName ( $TestModel , false ), 'custom_apples' );
$this -> assertEqual ( $db1 -> fullTableName ( $TestModel , false ), 'custom_apples' );
2008-03-01 05:15:53 +00:00
}
2008-01-28 18:56:22 +00:00
function testDynamicBehaviorAttachment () {
$this -> loadFixtures ( 'Apple' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Apple ();
$this -> assertEqual ( $TestModel -> Behaviors -> attached (), array ());
2008-01-28 18:56:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> Behaviors -> attach ( 'Tree' , array ( 'left' => 'left_field' , 'right' => 'right_field' ));
$this -> assertTrue ( is_object ( $TestModel -> Behaviors -> Tree ));
$this -> assertEqual ( $TestModel -> Behaviors -> attached (), array ( 'Tree' ));
2008-01-28 18:56:22 +00:00
2008-03-19 00:54:32 +00:00
$expected = array ( 'parent' => 'parent_id' , 'left' => 'left_field' , 'right' => 'right_field' , 'scope' => '1 = 1' , 'type' => 'nested' , '__parentChange' => false );
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> Behaviors -> Tree -> settings [ 'Apple' ], $expected );
2008-01-28 18:56:22 +00:00
$expected [ 'enabled' ] = false ;
2008-05-13 16:42:39 +00:00
$TestModel -> Behaviors -> attach ( 'Tree' , array ( 'enabled' => false ));
$this -> assertEqual ( $TestModel -> Behaviors -> Tree -> settings [ 'Apple' ], $expected );
$this -> assertEqual ( $TestModel -> Behaviors -> attached (), array ( 'Tree' ));
2008-01-28 18:56:22 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> Behaviors -> detach ( 'Tree' );
$this -> assertEqual ( $TestModel -> Behaviors -> attached (), array ());
$this -> assertFalse ( isset ( $TestModel -> Behaviors -> Tree ));
2008-01-28 18:56:22 +00:00
}
2008-03-07 01:29:19 +00:00
/**
* Tests cross database joins . Requires $test and $test2 to both be set in DATABASE_CONFIG
* NOTE : When testing on MySQL , you must set 'persistent' => false on * both * database connections ,
* or one connection will step on the other .
*/
function testCrossDatabaseJoins () {
$config = new DATABASE_CONFIG ();
if ( ! isset ( $config -> test ) || ! isset ( $config -> test2 )) {
echo " <br />Primary and secondary test databases not configured, skipping cross-database join tests<br /> " ;
2008-04-30 19:19:16 +00:00
echo " To run these tests, you must define \$ test and \$ test2 in your database configuration.<br /> " ;
2008-03-07 01:29:19 +00:00
return ;
}
$this -> loadFixtures ( 'Article' , 'Tag' , 'ArticlesTag' , 'User' , 'Comment' );
2008-05-13 16:42:39 +00:00
$TestModel =& new Article ();
2008-03-07 01:29:19 +00:00
$expected = array (
array (
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Comment' => array (
array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ),
array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' )
),
'Tag' => array (
array ( 'id' => '1' , 'tag' => 'tag1' , 'created' => '2007-03-18 12:22:23' , 'updated' => '2007-03-18 12:24:31' ),
array ( 'id' => '2' , 'tag' => 'tag2' , 'created' => '2007-03-18 12:24:23' , 'updated' => '2007-03-18 12:26:31' )
)
),
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' )
)
),
array (
'Article' => array ( 'id' => '3' , 'user_id' => '1' , 'title' => 'Third Article' , 'body' => 'Third Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Comment' => array (),
'Tag' => array ()
)
);
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> find ( 'all' ), $expected );
2008-03-07 01:29:19 +00:00
$db2 =& ConnectionManager :: getDataSource ( 'test2' );
foreach ( array ( 'User' , 'Comment' ) as $class ) {
$this -> _fixtures [ $this -> _fixtureClassMap [ $class ]] -> create ( $db2 );
$this -> _fixtures [ $this -> _fixtureClassMap [ $class ]] -> insert ( $db2 );
$this -> db -> truncate ( Inflector :: pluralize ( Inflector :: underscore ( $class )));
}
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> User -> find ( 'all' ), array ());
$this -> assertEqual ( $TestModel -> Comment -> find ( 'all' ), array ());
$this -> assertEqual ( $TestModel -> find ( 'count' ), 3 );
2008-03-07 01:29:19 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> User -> setDataSource ( 'test2' );
$TestModel -> Comment -> setDataSource ( 'test2' );
2008-03-07 01:29:19 +00:00
2008-05-13 16:42:39 +00:00
$result = Set :: extract ( $TestModel -> User -> find ( 'all' ), '{n}.User.id' );
2008-03-07 01:29:19 +00:00
$this -> assertEqual ( $result , array ( '1' , '2' , '3' , '4' ));
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> find ( 'all' ), $expected );
2008-03-07 01:29:19 +00:00
2008-05-13 16:42:39 +00:00
$TestModel -> Comment -> unbindModel ( array ( 'hasOne' => array ( 'Attachment' )));
2008-03-07 01:29:19 +00:00
$expected = array (
array (
'Comment' => array ( 'id' => '1' , 'article_id' => '1' , 'user_id' => '2' , 'comment' => 'First Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:45:23' , 'updated' => '2007-03-18 10:47:31' ),
'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ),
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )
),
array (
'Comment' => array ( 'id' => '2' , 'article_id' => '1' , 'user_id' => '4' , 'comment' => 'Second Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:47:23' , 'updated' => '2007-03-18 10:49:31' ),
'User' => array ( 'id' => '4' , 'user' => 'garrett' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:22:23' , 'updated' => '2007-03-17 01:24:31' ),
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )
),
array (
'Comment' => array ( 'id' => '3' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Third Comment for First Article' , 'published' => 'Y' , 'created' => '2007-03-18 10:49:23' , 'updated' => '2007-03-18 10:51:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )
),
array (
'Comment' => array ( 'id' => '4' , 'article_id' => '1' , 'user_id' => '1' , 'comment' => 'Fourth Comment for First Article' , 'published' => 'N' , 'created' => '2007-03-18 10:51:23' , 'updated' => '2007-03-18 10:53:31' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'Article' => array ( 'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' )
),
array (
'Comment' => 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' ),
'User' => array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ),
'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' )
),
array (
'Comment' => 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' ),
'User' => array ( 'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31' ),
'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' )
)
);
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $TestModel -> Comment -> find ( 'all' ), $expected );
2008-03-07 01:29:19 +00:00
foreach ( array ( 'User' , 'Comment' ) as $class ) {
2008-03-09 06:24:40 +00:00
$this -> _fixtures [ $this -> _fixtureClassMap [ $class ]] -> drop ( $db2 );
2008-03-07 01:29:19 +00:00
}
}
2008-05-15 05:17:23 +00:00
function testDisplayField () {
$this -> loadFixtures ( 'Post' , 'Comment' , 'Person' );
$Post = new Post ();
$Comment = new Comment ();
$Person = new Person ();
2008-04-17 13:10:27 +00:00
2008-05-15 05:17:23 +00:00
$this -> assertEqual ( $Post -> displayField , 'title' );
$this -> assertEqual ( $Person -> displayField , 'name' );
$this -> assertEqual ( $Comment -> displayField , 'id' );
2008-05-16 05:31:14 +00:00
}
2008-04-17 13:10:27 +00:00
2008-04-26 14:39:34 +00:00
function testSchema () {
2008-05-13 16:42:39 +00:00
$Post = new Post ();
2008-04-26 14:39:34 +00:00
2008-05-13 16:42:39 +00:00
$result = $Post -> schema ();
2008-04-26 14:39:34 +00:00
$columns = array ( 'id' , 'author_id' , 'title' , 'body' , 'published' , 'created' , 'updated' );
$this -> assertEqual ( array_keys ( $result ), $columns );
$types = array ( 'integer' , 'integer' , 'string' , 'text' , 'string' , 'datetime' , 'datetime' );
$this -> assertEqual ( Set :: extract ( array_values ( $result ), '{n}.type' ), $types );
$this -> expectError ( '(Model::loadInfo) Deprecated - See Model::schema()' );
2008-05-13 16:42:39 +00:00
$result = $Post -> loadInfo ();
2008-04-26 14:39:34 +00:00
$this -> assertEqual ( $result -> extract ( " { n}.name " ), $columns );
$this -> assertEqual ( $result -> extract ( '{n}.type' ), $types );
2008-05-13 16:42:39 +00:00
$result = $Post -> schema ( 'body' );
2008-04-26 14:39:34 +00:00
$this -> assertEqual ( $result [ 'type' ], 'text' );
2008-05-13 16:42:39 +00:00
$this -> assertNull ( $Post -> schema ( 'foo' ));
2008-04-26 14:39:34 +00:00
2008-05-13 16:42:39 +00:00
$this -> assertEqual ( $Post -> getColumnTypes (), array_combine ( $columns , $types ));
2008-04-26 14:39:34 +00:00
}
2008-04-18 00:30:32 +00:00
function testOldQuery () {
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
2008-04-19 17:33:17 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT title FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id IN (1,2)' ;
2008-05-13 16:42:39 +00:00
$results = $Article -> query ( $query );
2008-04-18 00:30:32 +00:00
$this -> assertTrue ( is_array ( $results ));
$this -> assertEqual ( count ( $results ), 2 );
2008-04-19 17:33:17 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT title, body FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id = 1' ;
2008-05-13 16:42:39 +00:00
$results = $Article -> query ( $query , false );
2008-05-11 23:08:47 +00:00
$this -> assertTrue ( ! isset ( $this -> db -> _queryCache [ $query ]));
2008-04-18 00:30:32 +00:00
$this -> assertTrue ( is_array ( $results ));
2008-04-19 17:33:17 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT title, id FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.published = ' . $this -> db -> value ( 'Y' );
2008-05-13 16:42:39 +00:00
$results = $Article -> query ( $query , true );
2008-05-11 23:08:47 +00:00
$this -> assertTrue ( isset ( $this -> db -> _queryCache [ $query ]));
2008-04-19 17:33:17 +00:00
$this -> assertTrue ( is_array ( $results ));
2008-04-18 00:30:32 +00:00
}
function testPreparedQuery () {
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
2008-05-15 05:17:23 +00:00
$this -> db -> _queryCache = array ();
2008-04-18 00:30:32 +00:00
2008-05-18 09:22:42 +00:00
$finalQuery = 'SELECT title, published FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id = ' . $this -> db -> value ( 1 ) . ' AND ' . $this -> db -> fullTableName ( 'articles' ) . '.published = ' . $this -> db -> value ( 'Y' );
2008-05-11 23:08:47 +00:00
$query = 'SELECT title, published FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id = ? AND ' . $this -> db -> fullTableName ( 'articles' ) . '.published = ?' ;
2008-05-18 09:22:42 +00:00
2008-04-18 00:30:32 +00:00
$params = array ( 1 , 'Y' );
2008-05-13 16:42:39 +00:00
$result = $Article -> query ( $query , $params );
2008-05-11 23:08:47 +00:00
$expected = array ( '0' => array ( $this -> db -> fullTableName ( 'articles' , false ) => array ( 'title' => 'First Article' , 'published' => 'Y' )));
2008-05-11 18:53:54 +00:00
if ( isset ( $result [ 0 ][ 0 ])) {
2008-05-11 23:08:47 +00:00
$expected [ 0 ][ 0 ] = $expected [ 0 ][ $this -> db -> fullTableName ( 'articles' , false )];
unset ( $expected [ 0 ][ $this -> db -> fullTableName ( 'articles' , false )]);
2008-05-11 18:53:54 +00:00
}
2008-04-18 00:30:32 +00:00
$this -> assertEqual ( $result , $expected );
2008-05-11 23:08:47 +00:00
$this -> assertTrue ( isset ( $this -> db -> _queryCache [ $finalQuery ]));
2008-04-18 00:30:32 +00:00
2008-05-11 23:08:47 +00:00
$finalQuery = 'SELECT id, created FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.title = ' . $this -> db -> value ( 'First Article' );
$query = 'SELECT id, created FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.title = ?' ;
2008-04-18 00:30:32 +00:00
$params = array ( 'First Article' );
2008-05-13 16:42:39 +00:00
$result = $Article -> query ( $query , $params , false );
2008-04-18 00:30:32 +00:00
$this -> assertTrue ( is_array ( $result ));
2008-05-11 23:08:47 +00:00
$this -> assertTrue ( isset ( $result [ 0 ][ $this -> db -> fullTableName ( 'articles' , false )]) || isset ( $result [ 0 ][ 0 ]));
$this -> assertFalse ( isset ( $this -> db -> _queryCache [ $finalQuery ]));
2008-04-18 00:30:32 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT title FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.title LIKE ?' ;
2008-04-18 00:30:32 +00:00
$params = array ( '%First%' );
2008-05-13 16:42:39 +00:00
$result = $Article -> query ( $query , $params );
2008-04-18 00:30:32 +00:00
$this -> assertTrue ( is_array ( $result ));
2008-05-15 05:17:23 +00:00
$this -> assertTrue (
isset ( $result [ 0 ][ $this -> db -> fullTableName ( 'articles' , false )][ 'title' ]) ||
isset ( $result [ 0 ][ 0 ][ 'title' ])
);
2008-04-18 00:30:32 +00:00
}
function testParameterMismatch () {
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
2008-04-18 00:30:32 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT * FROM ' . $this -> db -> fullTableName ( 'articles' ) . ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.published = ? AND ' . $this -> db -> fullTableName ( 'articles' ) . '.user_id = ?' ;
2008-04-18 00:30:32 +00:00
$params = array ( 'Y' );
2008-05-13 16:42:39 +00:00
$result = $Article -> query ( $query , $params );
2008-04-18 00:30:32 +00:00
$this -> assertEqual ( $result , null );
}
function testVeryStrangeUseCase () {
2008-05-11 23:08:47 +00:00
if ( $this -> db -> config [ 'driver' ] != 'mssql' ) {
2008-05-11 18:53:54 +00:00
return ;
}
2008-04-18 00:30:32 +00:00
$this -> loadFixtures ( 'Article' );
2008-05-13 16:42:39 +00:00
$Article =& new Article ();
2008-04-19 17:33:17 +00:00
2008-05-11 23:08:47 +00:00
$query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?' ;
$param = array ( $this -> db -> fullTableName ( 'articles' ), $this -> db -> fullTableName ( 'articles' ) . '.user_id' , '3' , $this -> db -> fullTableName ( 'articles' ) . '.published' , 'Y' );
2008-04-18 00:30:32 +00:00
$this -> expectError ();
ob_start ();
2008-05-13 16:42:39 +00:00
$result = $Article -> query ( $query , $param );
2008-04-18 00:30:32 +00:00
ob_end_clean ();
}
2008-05-11 23:08:47 +00:00
2008-05-11 20:07:04 +00:00
function testUnderscoreFieldSave () {
$this -> loadFixtures ( 'UnderscoreField' );
2008-05-13 16:42:39 +00:00
$UnderscoreField =& new UnderscoreField ();
2008-05-11 23:08:47 +00:00
2008-05-13 16:42:39 +00:00
$currentCount = $UnderscoreField -> find ( 'count' );
2008-05-11 20:07:04 +00:00
$this -> assertEqual ( $currentCount , 3 );
2008-05-15 05:17:23 +00:00
$data = array ( 'UnderscoreField' => array (
'user_id' => '1' ,
'my_model_has_a_field' => 'Content here' ,
'body' => 'Body' ,
'published' => 'Y' ,
'another_field' => 4
));
2008-05-13 16:42:39 +00:00
$ret = $UnderscoreField -> save ( $data );
2008-05-11 20:07:04 +00:00
$this -> assertTrue ( $ret );
2008-05-11 23:08:47 +00:00
2008-05-13 16:42:39 +00:00
$currentCount = $UnderscoreField -> find ( 'count' );
2008-05-11 20:07:04 +00:00
$this -> assertEqual ( $currentCount , 4 );
}
2008-05-11 23:08:47 +00:00
2007-10-22 20:58:55 +00:00
function endTest () {
ClassRegistry :: flush ();
}
2007-06-03 21:54:11 +00:00
}
2008-05-11 23:08:47 +00:00
?>