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 >
* Copyright 2005 - 2007 , Cake Software Foundation , Inc .
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
* @ copyright Copyright 2005 - 2007 , Cake Software Foundation , Inc .
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
2007-07-08 01:17:57 +00:00
if ( ! defined ( 'CAKEPHP_UNIT_TEST_EXECUTION' )) {
define ( 'CAKEPHP_UNIT_TEST_EXECUTION' , 1 );
}
uses ( 'model' . DS . 'model' , 'model' . DS . 'datasources' . DS . 'datasource' , 'model' . DS . 'datasources' . DS . 'dbo_source' ,
'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_mysql' );
2007-08-17 19:03:49 +00:00
if ( ! class_exists ( 'AppModel' )) {
loadModel ();
}
2007-07-08 01:17:57 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Test extends Model {
var $useTable = false ;
var $name = 'Test' ;
2007-03-17 00:24:33 +00:00
2007-07-08 01:17:57 +00:00
function loadInfo () {
return new Set ( array (
2007-08-21 21:46:59 +00:00
array ( 'name' => 'id' , 'type' => 'integer' , 'null' => '' , 'default' => '1' , 'length' => '8' , 'key' => 'primary' ),
2007-07-08 01:17:57 +00:00
array ( 'name' => 'name' , 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
array ( 'name' => 'email' , 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
array ( 'name' => 'notes' , 'type' => 'text' , 'null' => '1' , 'default' => 'write some notes here' , 'length' => '' ),
array ( 'name' => 'created' , 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
array ( 'name' => 'updated' , 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
));
2007-02-04 04:38:42 +00:00
}
2007-08-29 02:56:53 +00:00
2007-08-21 21:46:59 +00:00
function schema () {
return new Set ( array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '1' , 'length' => '8' , 'key' => 'primary' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'email' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'notes' => array ( 'type' => 'text' , 'null' => '1' , 'default' => 'write some notes here' , 'length' => '' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
));
}
2007-07-08 01:17:57 +00:00
}
2007-03-17 21:37:22 +00:00
2007-07-08 01:17:57 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class TestValidate extends Model {
var $useTable = false ;
var $name = 'TestValidate' ;
2007-05-02 07:48:22 +00:00
2007-07-08 01:17:57 +00:00
function validateNumber ( $value , $options ) {
$options = am ( array (
'min' => 0 ,
'max' => 100
), $options );
2007-05-02 07:48:22 +00:00
2007-07-08 01:17:57 +00:00
$valid = ( $value >= $options [ 'min' ] && $value <= $options [ 'max' ]);
2007-05-02 07:48:22 +00:00
2007-07-08 01:17:57 +00:00
return $valid ;
}
2007-05-02 07:48:22 +00:00
2007-07-08 01:17:57 +00:00
function validateTitle ( $title ) {
if ( ! empty ( $title ) && strpos ( low ( $title ), 'title-' ) === 0 ) {
return true ;
2007-05-02 07:48:22 +00:00
}
2007-07-08 01:17:57 +00:00
return false ;
2007-04-01 04:40:18 +00:00
}
2007-04-04 17:25:18 +00:00
2007-07-08 01:17:57 +00:00
function loadInfo () {
return new Set ( array (
array ( 'name' => 'id' , 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
array ( 'name' => 'title' , 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
array ( 'name' => 'body' , 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '' ),
array ( 'name' => 'number' , 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
array ( 'name' => 'created' , 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
array ( 'name' => 'modified' , 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
2007-04-05 04:04:55 +00:00
));
2007-04-29 02:25:57 +00:00
}
2007-07-08 01:17:57 +00:00
}
2007-06-20 01:37:23 +00:00
2007-07-08 01:17:57 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class User extends CakeTestModel {
var $name = 'User' ;
var $validate = array (
'user' => VALID_NOT_EMPTY ,
'password' => VALID_NOT_EMPTY
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Article extends CakeTestModel {
var $name = 'Article' ;
var $belongsTo = array ( 'User' );
var $hasMany = array (
'Comment' => array ( 'className' => 'Comment' , 'dependent' => true )
);
var $hasAndBelongsToMany = array ( 'Tag' );
var $validate = array (
'user_id' => VALID_NUMBER ,
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY ),
'body' => VALID_NOT_EMPTY
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class ArticleFeatured extends CakeTestModel {
var $name = 'ArticleFeatured' ;
var $belongsTo = array ( 'User' , 'Category' );
var $hasOne = array ( 'Featured' );
var $hasMany = array (
'Comment' => array ( 'className' => 'Comment' , 'dependent' => true )
);
var $hasAndBelongsToMany = array ( 'Tag' );
var $validate = array (
'user_id' => VALID_NUMBER ,
'title' => VALID_NOT_EMPTY ,
'body' => VALID_NOT_EMPTY
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Featured extends CakeTestModel {
var $name = 'Featured' ;
var $belongsTo = array (
'ArticleFeatured' => array ( 'className' => 'ArticleFeatured' ),
'Category' => array ( 'className' => 'Category' )
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Tag extends CakeTestModel {
var $name = 'Tag' ;
}
2007-08-21 21:46:59 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
2007-08-30 00:58:19 +00:00
class ArticlesTag extends CakeTestModel {
2007-09-03 04:48:58 +00:00
var $name = 'ArticlesTag' ;
2007-08-21 21:46:59 +00:00
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
2007-08-30 00:58:19 +00:00
class ArticleFeaturedsTag extends CakeTestModel {
2007-09-03 04:48:58 +00:00
var $name = 'ArticleFeaturedsTag' ;
2007-08-21 21:46:59 +00:00
}
2007-07-08 01:17:57 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Comment extends CakeTestModel {
var $name = 'Comment' ;
var $belongsTo = array ( 'Article' , 'User' );
var $hasOne = array (
'Attachment' => array ( 'className' => 'Attachment' , 'dependent' => true )
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Attachment extends CakeTestModel {
var $name = 'Attachment' ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Category extends CakeTestModel {
var $name = 'Category' ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class CategoryThread extends CakeTestModel {
var $name = 'CategoryThread' ;
var $belongsTo = array (
'ParentCategory' => array (
'className' => 'CategoryThread' ,
'foreignKey' => 'parent_id'
)
);
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Apple extends CakeTestModel {
var $name = 'Apple' ;
var $validate = array ( 'name' => VALID_NOT_EMPTY );
var $hasOne = array ( 'Sample' );
var $hasMany = array ( 'Child' => array (
'className' => 'Apple' ,
'dependent' => true
));
var $belongsTo = array ( 'Parent' => array (
'className' => 'Apple' ,
'foreignKey' => 'apple_id'
));
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Sample extends CakeTestModel {
var $name = 'Sample' ;
var $belongsTo = 'Apple' ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class AnotherArticle extends CakeTestModel {
var $name = 'AnotherArticle' ;
var $hasMany = 'Home' ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Advertisement extends CakeTestModel {
var $name = 'Advertisement' ;
var $hasMany = 'Home' ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Home extends CakeTestModel {
var $name = 'Home' ;
var $belongsTo = array ( 'AnotherArticle' , 'Advertisement' );
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Post extends CakeTestModel {
var $name = 'Post' ;
var $belongsTo = array ( 'Author' );
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Author extends CakeTestModel {
var $name = 'Author' ;
var $hasMany = array ( 'Post' );
function afterFind ( $results ) {
$results [ 0 ][ 'Author' ][ 'test' ] = 'working' ;
return $results ;
2007-04-29 02:25:57 +00:00
}
2007-07-08 01:17:57 +00:00
}
2007-08-17 19:03:49 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Project extends CakeTestModel {
var $name = 'Project' ;
var $hasMany = array ( 'Thread' );
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Thread extends CakeTestModel {
var $name = 'Thread' ;
var $hasMany = array ( 'Message' );
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Message extends CakeTestModel {
var $name = 'Message' ;
var $hasOne = array ( 'Bid' );
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class Bid extends CakeTestModel {
var $name = 'Bid' ;
var $belongsTo = array ( 'Message' );
}
2007-08-29 02:56:53 +00:00
class NodeAfterFind extends CakeTestModel {
var $name = 'NodeAfterFind' ;
var $validate = array ( 'name' => VALID_NOT_EMPTY );
var $useTable = 'apples' ;
var $hasOne = array ( 'Sample' );
var $hasMany = array ( 'Child' => array (
'className' => 'NodeAfterFind' ,
'dependent' => true ));
var $belongsTo = array ( 'Parent' => array (
'className' => 'NodeAfterFind' ,
'foreignKey' => 'apple_id' ));
function afterFind ( $results ) {
return $results ;
}
}
class NodeNoAfterFind extends CakeTestModel {
var $name = 'NodeAfterFind' ;
var $validate = array ( 'name' => VALID_NOT_EMPTY );
var $useTable = 'apples' ;
var $hasOne = array ( 'Sample' );
var $hasMany = array ( 'Child' => array (
'className' => 'NodeAfterFind' ,
'dependent' => true ));
var $belongsTo = array ( 'Parent' => array (
'className' => 'NodeAfterFind' ,
'foreignKey' => 'apple_id' ));
}
2007-08-29 04:38:48 +00:00
class ModelA extends CakeTestModel {
var $name = 'ModelA' ;
var $useTable = 'apples' ;
var $hasMany = array ( 'ModelB' , 'ModelC' );
}
class ModelB extends CakeTestModel {
var $name = 'ModelB' ;
var $useTable = 'messages' ;
var $hasMany = array ( 'ModelD' );
}
class ModelC extends CakeTestModel {
var $name = 'ModelC' ;
var $useTable = 'bids' ;
var $hasMany = array ( 'ModelD' );
}
class ModelD extends CakeTestModel {
var $useTable = 'threads' ;
}
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 {
2007-06-03 21:54:11 +00:00
2007-04-09 08:54:25 +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' ,
2007-08-21 21:46:59 +00:00
'core.article_featured' , 'core.articles' , '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' ,
'core.project' , 'core.thread' , 'core.message' , 'core.bid'
2007-04-05 04:04:55 +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
2007-08-17 19:03:49 +00:00
function testHasManyOptimization () {
$this -> Project =& new Project ();
$this -> Project -> recursive = 3 ;
$result = $this -> Project -> findAll ();
$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 (
2007-08-17 20:27:55 +00:00
'id' => 1 , 'thread_id' => 1 , 'name' => 'Thread 1, Message 1' ,
2007-08-17 19:03:49 +00:00
'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 (
2007-08-17 20:27:55 +00:00
'id' => 2 , 'thread_id' => 2 , 'name' => 'Thread 2, Message 1' ,
2007-08-17 19:03:49 +00:00
'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 (
2007-08-17 20:27:55 +00:00
'id' => 3 , 'thread_id' => 3 , 'name' => 'Thread 3, Message 1' ,
2007-08-17 19:03:49 +00:00
'Bid' => array (
'id' => 3 , 'message_id' => 3 , 'name' => 'Bid 3.1'
)
)
)
)
)
),
array (
'Project' => array (
'id' => 3 , 'name' => 'Project 3'
),
'Thread' => array ()
)
);
$this -> assertEqual ( $result , $expected );
unset ( $this -> Project );
}
2007-05-01 03:04:44 +00:00
function testFindAllRecursiveSelfJoin () {
2007-04-29 02:25:57 +00:00
$this -> model =& new Home ();
$this -> model -> recursive = 2 ;
$result = $this -> model -> findAll ();
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Home' => array (
2007-04-29 02:25:57 +00:00
'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'
),
2007-08-14 23:12:24 +00:00
'AnotherArticle' => array (
2007-04-29 02:25:57 +00:00
'id' => '1' , 'title' => 'First Article' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
2007-08-14 23:12:24 +00:00
'Home' => array (
array (
2007-04-29 02:25:57 +00:00
'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'
)
)
),
2007-08-14 23:12:24 +00:00
'Advertisement' => array (
2007-04-29 02:25:57 +00:00
'id' => '1' , 'title' => 'First Ad' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
2007-08-14 23:12:24 +00:00
'Home' => array (
array (
2007-04-29 02:25:57 +00:00
'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'
),
2007-08-14 23:12:24 +00:00
array (
2007-04-29 02:25:57 +00:00
'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-08-14 23:12:24 +00:00
array (
'Home' => array (
2007-04-29 02:25:57 +00:00
'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-08-14 23:12:24 +00:00
'AnotherArticle' => array (
2007-04-29 02:25:57 +00:00
'id' => '3' , 'title' => 'Third Article' , 'created' => '2007-03-18 10:43:23' , 'updated' => '2007-03-18 10:45:31' ,
2007-08-14 23:12:24 +00:00
'Home' => array (
array (
2007-04-29 02:25:57 +00:00
'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-08-14 23:12:24 +00:00
'Advertisement' => array (
2007-04-29 02:25:57 +00:00
'id' => '1' , 'title' => 'First Ad' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31' ,
2007-08-14 23:12:24 +00:00
'Home' => array (
array (
2007-04-29 02:25:57 +00:00
'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'
),
2007-08-14 23:12:24 +00:00
array (
2007-04-29 02:25:57 +00:00
'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'
)
)
)
)
);
$this -> assertEqual ( $result , $expected );
}
2007-05-01 03:04:44 +00:00
function testIdentity () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Test ();
$result = $this -> model -> name ;
2007-02-03 22:20:13 +00:00
$expected = 'Test' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
}
2007-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testCreation () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Test ();
$result = $this -> model -> 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 );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
$result = $this -> model -> _tableInfo -> value ;
2007-06-03 21:54:11 +00:00
$db =& ConnectionManager :: getDataSource ( 'test_suite' );
if ( isset ( $db -> columns [ 'primary_key' ][ 'length' ])) {
$intLength = $db -> columns [ 'primary_key' ][ 'length' ];
} elseif ( isset ( $db -> columns [ 'integer' ][ 'length' ])) {
$intLength = $db -> columns [ 'integer' ][ 'length' ];
} else {
$intLength = 11 ;
}
2007-08-14 23:12:24 +00:00
$expected = array (
2007-08-21 21:46:59 +00:00
array ( 'name' => 'id' , 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => $intLength , 'key' => 'primary' , 'extra' => 'auto_increment' ),
2007-04-01 04:55:56 +00:00
array ( 'name' => 'user' , 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => 255 ),
array ( 'name' => 'password' , 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => 255 ),
array ( 'name' => 'created' , 'type' => 'datetime' , 'null' => true , 'default' => null , 'length' => null ),
array ( 'name' => 'updated' , '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
2007-03-17 19:15:41 +00:00
$this -> model =& new Article ();
$result = $this -> model -> 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-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testReadFakeThread () {
2007-03-29 02:16:00 +00:00
$this -> model =& new CategoryThread ();
2007-03-30 00:08:10 +00:00
$this -> db -> fullDebug = true ;
$this -> model -> recursive = 6 ;
$this -> model -> id = 7 ;
$result = $this -> model -> read ();
$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' )))))));
$this -> assertEqual ( $result , $expected );
2007-03-29 02:16:00 +00:00
}
2007-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testFindFakeThread () {
2007-04-29 02:25:57 +00:00
$this -> model =& new CategoryThread ();
$this -> db -> fullDebug = true ;
$this -> model -> recursive = 6 ;
$result = $this -> model -> find ( array ( 'CategoryThread.id' => 7 ));
$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' )))))));
$this -> assertEqual ( $result , $expected );
}
2007-05-01 03:04:44 +00:00
function testFindAllFakeThread () {
2007-04-29 02:25:57 +00:00
$this -> model =& new CategoryThread ();
$this -> db -> fullDebug = true ;
$this -> model -> recursive = 6 ;
2007-06-03 21:54:11 +00:00
$result = $this -> model -> findAll ( null , null , 'CategoryThread.id ASC' );
2007-04-29 02:25:57 +00:00
$expected = array (
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' ),
'ParentCategory' => array ( 'id' => null , 'parent_id' => null , 'name' => null , 'created' => null , 'updated' => null )
),
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' ),
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )
),
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' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ))
),
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' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )))
),
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' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' ))))
),
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' ,
'ParentCategory' => array ( 'id' => 1 , 'parent_id' => 0 , 'name' => 'Category 1' , 'created' => '2007-03-18 15:30:23' , 'updated' => '2007-03-18 15:32:31' )))))
),
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' ))))))
)
);
$this -> assertEqual ( $result , $expected );
}
2007-05-01 03:04:44 +00:00
function testFindAll () {
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ();
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( 'User.id > 2' );
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( array ( 'User.id' => '!= 0' , 'User.user' => 'LIKE %arr%' ));
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( array ( 'User.id' => '0' ));
$expected = array ();
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> findAll ( array ( 'or' => array ( 'User.id' => '0' , 'User.user' => 'LIKE %a%' )));
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' )),
array ( 'User' => array ( 'id' => '4' , 'user' => 'garrett' ))
2007-03-17 19:15:41 +00:00
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> findAll ( null , 'User.user' , 'User.user ASC' );
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.user' , 'User.user ASC' );
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.user' , 'User.user DESC' );
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , null , null , 3 , 1 );
$expected = array (
2007-08-14 23:12:24 +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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , null , null , 3 , 2 );
$expected = array (
2007-08-14 23:12:24 +00:00
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , null , null , 3 , 3 );
$expected = array ();
$this -> assertEqual ( $result , $expected );
}
2007-03-26 18:38:54 +00:00
2007-07-01 03:43:05 +00:00
function testGenerateList () {
$this -> model =& new Article ();
$this -> model -> displayField = 'title' ;
$result = $this -> model -> generateList ( null , 'Article.title ASC' );
$expected = array (
1 => 'First Article' ,
2 => 'Second Article' ,
3 => 'Third Article'
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> generateList ( null , 'Article.title ASC' , null , '{n}.Article.id' );
$expected = array (
1 => 'First Article' ,
2 => 'Second Article' ,
3 => 'Third Article'
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> generateList ( null , 'Article.title ASC' , null , '{n}.Article.id' , '{n}.Article' );
$expected = 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'
),
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'
)
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> generateList ( null , 'Article.title ASC' , null , '{n}.Article.id' , '{n}.Article.title' );
$expected = array (
1 => 'First Article' ,
2 => 'Second Article' ,
3 => 'Third Article'
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> generateList ( null , 'Article.title ASC' , null , '{n}.Article.id' , '{n}.Article' , '{n}.Article.user_id' );
$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'
)
)
);
$this -> assertEqual ( $result , $expected );
$result = $this -> model -> generateList ( null , 'Article.title ASC' , null , '{n}.Article.id' , '{n}.Article.title' , '{n}.Article.user_id' );
$expected = array (
1 => array (
1 => 'First Article' ,
3 => 'Third Article'
),
3 => array (
2 => 'Second Article'
)
);
$this -> assertEqual ( $result , $expected );
}
2007-05-01 03:04:44 +00:00
function testFindField () {
2007-03-26 18:38:54 +00:00
$this -> model =& new User ();
$this -> model -> id = 1 ;
$result = $this -> model -> field ( 'user' );
$this -> assertEqual ( $result , 'mariano' );
$result = $this -> model -> field ( 'User.user' );
$this -> assertEqual ( $result , 'mariano' );
$this -> model -> id = false ;
$result = $this -> model -> field ( 'user' , array ( 'user' => 'mariano' ));
$this -> assertEqual ( $result , 'mariano' );
$result = $this -> model -> field ( 'COUNT(*) AS count' , true );
$this -> assertEqual ( $result , 4 );
2007-03-27 01:34:59 +00:00
$result = $this -> model -> field ( 'COUNT(*)' , true );
$this -> assertEqual ( $result , 4 );
2007-03-26 18:38:54 +00:00
}
2007-05-01 03:04:44 +00:00
function testBindUnbind () {
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> hasMany ;
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> bindModel ( array ( 'hasMany' => array ( 'Comment' )));
$this -> assertTrue ( $result );
2007-03-26 17:16:43 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' ),
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-03-17 19:15:41 +00:00
)),
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' ),
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
)),
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 (
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
$this -> model -> __resetAssociations ();
2007-03-17 19:15:41 +00:00
$result = $this -> model -> hasMany ;
2007-03-26 17:16:43 +00:00
$this -> assertEqual ( $result , array ());
2007-03-17 19:15:41 +00:00
$result = $this -> model -> bindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' ),
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-03-17 19:15:41 +00:00
)),
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' ),
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
)),
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 (
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )));
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> hasMany ;
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' )),
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' ),
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-03-17 19:15:41 +00:00
)),
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' ),
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
)),
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 (
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' )),
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> hasMany ;
$expected = array ();
$this -> assertEqual ( $result , $expected );
2007-03-26 17:16:43 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> bindModel ( array ( 'hasMany' => array ( 'Comment' => array ( 'className' => 'Comment' , 'conditions' => 'Comment.published = \'Y\'' ) )));
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( null , 'User.id, User.user' );
$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' => '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-03-17 19:15:41 +00:00
)),
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' ),
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
)),
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 (
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-25 18:17:15 +00:00
2007-05-01 03:04:44 +00:00
function testFindCount () {
2007-03-25 18:17:15 +00:00
$this -> model =& new User ();
$result = $this -> model -> findCount ();
$this -> assertEqual ( $result , 4 );
$this -> db -> fullDebug = true ;
$this -> model -> order = 'User.id' ;
$result = $this -> model -> findCount ();
$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-05-01 03:04:44 +00:00
function testFindMagic () {
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findByUser ( 'mariano' );
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
));
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findByPassword ( '5f4dcc3b5aa765d61d8327deb882cf99' );
2007-08-14 23:12:24 +00:00
$expected = array ( 'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
));
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testRead () {
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> read ();
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> id = 2 ;
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$this -> model -> id = 2 ;
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> bindModel ( array ( 'hasMany' => array ( 'Article' )));
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> id = 1 ;
$result = $this -> model -> read ( 'id, user' );
$expected = array (
2007-08-14 23:12:24 +00:00
'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' ),
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-05-01 03:04:44 +00:00
function testRecursiveRead () {
2007-03-17 19:15:41 +00:00
$this -> model =& new User ();
2007-03-17 21:37:22 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> bindModel ( array ( 'hasMany' => array ( 'Article' )), false );
$this -> assertTrue ( $result );
2007-03-17 21:37:22 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 0 ;
$result = $this -> model -> read ( 'id, user' , 1 );
$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
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 1 ;
$result = $this -> model -> read ( 'id, user' , 1 );
$expected = array (
2007-08-14 23:12:24 +00:00
'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' ),
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
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 2 ;
$result = $this -> model -> read ( 'id, user' , 3 );
$expected = array (
2007-08-14 23:12:24 +00:00
'User' => array ( 'id' => '3' , 'user' => 'larry' ),
2007-03-17 19:15:41 +00:00
'Article' => array (
2007-03-30 00:08:10 +00:00
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-08-14 23:12:24 +00:00
'User' => array (
2007-03-30 00:08:10 +00:00
'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
),
'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-03-17 19:15:41 +00:00
),
'Tag' => array (
2007-08-14 23:12:24 +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
2007-05-01 03:04:44 +00:00
function testRecursiveFindAll () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Article ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findAll ( array ( 'Article.user_id' => 1 ));
2007-08-14 23:12:24 +00:00
$expected = array (
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' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
2007-03-30 00:08:10 +00:00
),
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 (
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 (
'Article' => array (
2007-03-17 19:15:41 +00:00
'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-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
2007-03-30 00:08:10 +00:00
),
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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31'
2007-03-30 00:08:10 +00:00
),
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' ,
2007-08-14 23:12:24 +00:00
'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
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
2007-03-30 00:08:10 +00:00
),
2007-03-17 19:15:41 +00:00
'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' ,
2007-08-14 23:12:24 +00:00
'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
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31'
2007-03-30 00:08:10 +00:00
),
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 (
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
2007-04-01 16:15:44 +00:00
$this -> Featured = new Featured ();
2007-04-04 17:25:18 +00:00
2007-04-01 16:15:44 +00:00
$this -> Featured -> recursive = 2 ;
$this -> Featured -> bindModel ( array (
'belongsTo' => array (
'ArticleFeatured' => array (
'conditions' => 'ArticleFeatured.published = \'Y\'' ,
'fields' => 'id, title, user_id, published'
)
)
));
2007-04-04 17:25:18 +00:00
2007-04-01 16:15:44 +00:00
$this -> Featured -> ArticleFeatured -> unbindModel ( array (
2007-04-04 17:25:18 +00:00
'hasMany' => array ( 'Attachment' , 'Comment' ),
2007-04-01 16:15:44 +00:00
'hasAndBelongsToMany' => array ( 'Tag' ))
);
2007-04-04 17:25:18 +00:00
2007-04-01 16:15:44 +00:00
$orderBy = 'ArticleFeatured.id ASC' ;
$result = $this -> Featured -> findAll ( null , null , $orderBy , 3 );
2007-04-04 17:25:18 +00:00
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Featured' => array (
2007-04-04 17:25:18 +00:00
'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' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 10:41:31'
2007-04-04 17:25:18 +00:00
),
2007-08-14 23:12:24 +00:00
'ArticleFeatured' => array (
2007-04-04 17:25:18 +00:00
'id' => '1' ,
'title' => 'First Article' ,
'user_id' => '1' ,
'published' => 'Y' ,
2007-08-14 23:12:24 +00:00
'User' => array (
2007-04-04 17:25:18 +00:00
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-17 01:18:31'
2007-04-04 17:25:18 +00:00
),
2007-04-04 19:55:57 +00:00
'Category' => array (),
2007-08-14 23:12:24 +00:00
'Featured' => array (
2007-04-04 17:25:18 +00:00
'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' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 10:41:31'
)
2007-04-04 17:25:18 +00:00
),
2007-08-14 23:12:24 +00:00
'Category' => array (
2007-04-04 17:25:18 +00:00
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 15:32:31'
)
2007-04-04 17:25:18 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Featured' => array (
2007-04-04 17:25:18 +00:00
'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' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 10:41:31'
2007-04-04 17:25:18 +00:00
),
2007-08-14 23:12:24 +00:00
'ArticleFeatured' => array (
2007-04-04 17:25:18 +00:00
'id' => '2' ,
'title' => 'Second Article' ,
'user_id' => '3' ,
'published' => 'Y' ,
2007-08-14 23:12:24 +00:00
'User' => array (
2007-04-04 17:25:18 +00:00
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-17 01:22:31'
2007-04-04 17:25:18 +00:00
),
2007-04-04 19:55:57 +00:00
'Category' => array (),
2007-08-14 23:12:24 +00:00
'Featured' => array (
2007-04-04 17:25:18 +00:00
'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' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 10:41:31'
)
2007-04-04 17:25:18 +00:00
),
2007-08-14 23:12:24 +00:00
'Category' => array (
2007-04-04 17:25:18 +00:00
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
2007-04-01 04:40:18 +00:00
'updated' => '2007-03-18 15:32:31'
)
)
);
2007-04-04 17:25:18 +00:00
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-05-01 03:04:44 +00:00
function testRecursiveFindAllWithLimit () {
2007-04-11 21:22:26 +00:00
$this -> model =& new Article ();
2007-04-29 02:25:57 +00:00
2007-04-11 21:22:26 +00:00
$this -> model -> hasMany [ 'Comment' ][ 'limit' ] = 2 ;
$result = $this -> model -> findAll ( array ( 'Article.user_id' => 1 ));
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Article' => array (
2007-04-11 21:22:26 +00:00
'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-08-14 23:12:24 +00:00
'User' => array (
2007-04-11 21:22:26 +00:00
'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 (
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 (
'Article' => array (
2007-04-11 21:22:26 +00:00
'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-08-14 23:12:24 +00:00
'User' => array (
2007-04-11 21:22:26 +00:00
'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
2007-04-11 21:22:26 +00:00
$this -> model -> hasMany [ 'Comment' ][ 'limit' ] = 1 ;
$result = $this -> model -> 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-04-11 21:22:26 +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-08-14 23:12:24 +00:00
'User' => array (
2007-04-11 21:22:26 +00:00
'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' ,
2007-08-14 23:12:24 +00:00
'Article' => array (
2007-04-11 21:22:26 +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-08-14 23:12:24 +00:00
'User' => array (
2007-04-11 21:22:26 +00:00
'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-08-14 23:12:24 +00:00
'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' )
2007-04-11 21:22:26 +00:00
)
)
);
$this -> assertEqual ( $result , $expected );
}
2007-03-30 00:08:10 +00:00
2007-06-03 21:54:11 +00:00
function testAssociationAfterFind () {
$this -> model =& new Post ();
$result = $this -> model -> findAll ();
$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-08-29 04:38:48 +00:00
function testSelfAssociationAfterFind () {
$afterFindModel = new NodeAfterFind ();
2007-08-29 03:06:40 +00:00
$afterFindModel -> recursive = 3 ;
2007-08-29 02:56:53 +00:00
$afterFindData = $afterFindModel -> findAll ();
2007-08-29 04:38:48 +00:00
$duplicateModel = new NodeAfterFind ();
$duplicateModel -> recursive = 3 ;
$duplicateModelData = $duplicateModel -> findAll ();
$noAfterFindModel = new NodeNoAfterFind ();
2007-08-29 03:06:40 +00:00
$noAfterFindModel -> recursive = 3 ;
2007-08-29 02:56:53 +00:00
$noAfterFindData = $noAfterFindModel -> findAll ();
2007-08-29 04:38:48 +00:00
$this -> assertFalse ( $afterFindModel == $noAfterFindModel );
2007-08-29 04:59:57 +00:00
// Limitation of PHP 4 and PHP 5 > 5.1.6 when comparing recursive objects
if ( PHP_VERSION === '5.1.6' ) {
$this -> assertFalse ( $afterFindModel != $duplicateModel );
2007-08-29 04:38:48 +00:00
}
2007-08-29 02:56:53 +00:00
$this -> assertEqual ( $afterFindData , $noAfterFindData );
}
2007-05-02 07:48:22 +00:00
function testValidatesBackwards () {
$this -> model =& new TestValidate ();
$this -> model -> validate = array (
'user_id' => VALID_NUMBER ,
'title' => VALID_NOT_EMPTY ,
'body' => VALID_NOT_EMPTY
);
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => '' , 'body' => '' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => '' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '' , 'title' => 'title' , 'body' => 'body' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => 'not a number' , 'title' => 'title' , 'body' => 'body' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => 'body' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
}
2007-04-30 13:03:13 +00:00
function testValidates () {
2007-05-02 07:48:22 +00:00
$this -> model =& new TestValidate ();
2007-04-30 13:03:13 +00:00
2007-05-02 07:48:22 +00:00
$this -> model -> validate = array (
'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' ));
2007-04-30 13:03:13 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 'title' , 'body' => 'body' ));
2007-04-30 13:03:13 +00:00
$result = $this -> model -> create ( $data ) && $this -> model -> validates ();
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => '0' , 'body' => 'body' ));
2007-04-30 13:03:13 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' ));
2007-04-30 13:03:13 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
2007-05-01 03:03:53 +00:00
$this -> model -> validate [ 'modified' ] = array ( 'allowEmpty' => true , 'rule' => 'date' );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => '' ));
2007-05-01 03:03:53 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$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' ));
2007-05-01 03:03:53 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$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' ));
2007-05-01 03:03:53 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => 0 ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'modified' => '0' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-06-20 01:37:23 +00:00
2007-05-04 07:13:15 +00:00
$this -> model -> 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' => '' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'user_id' => '1' , 'title' => 0 , 'body' => 'body' , 'slug' => 'slug-right-here' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$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' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$this -> model -> validate = array (
'number' => array (
'rule' => 'validateNumber' ,
'min' => 3 ,
'max' => 5
),
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY )
);
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '0' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 0 ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '3' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 3 ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
$this -> model -> validate = array (
'number' => array (
'rule' => 'validateNumber' ,
'min' => 5 ,
'max' => 10
),
'title' => array ( 'allowEmpty' => false , 'rule' => VALID_NOT_EMPTY )
);
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => '3' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title' , 'number' => 3 ));
2007-05-01 10:30:36 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$this -> model -> validate = array (
'title' => array ( 'allowEmpty' => false , 'rule' => 'validateTitle' )
);
$data = array ( 'TestValidate' => array ( 'title' => '' ));
2007-05-01 10:30:36 +00:00
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
2007-05-02 07:48:22 +00:00
$data = array ( 'TestValidate' => array ( 'title' => 'new title' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertFalse ( $result );
$data = array ( 'TestValidate' => array ( 'title' => 'title-new' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
$this -> model -> validate = array (
'title' => array ( 'allowEmpty' => true , 'rule' => 'validateTitle' )
);
$data = array ( 'TestValidate' => array ( 'title' => '' ));
$result = $this -> model -> create ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> validates ();
$this -> assertTrue ( $result );
2007-04-30 13:03:13 +00:00
}
2007-06-28 03:27:47 +00:00
function testSaveField () {
$this -> model =& new Article ();
$this -> model -> id = 1 ;
$result = $this -> model -> saveField ( 'title' , 'New First Article' );
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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'
));
$this -> model -> id = 1 ;
$result = $this -> model -> saveField ( 'title' , '' );
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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'
));
$this -> model -> id = 1 ;
$result = $this -> model -> saveField ( 'title' , 'First Article' );
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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'
));
$this -> model -> id = 1 ;
$result = $this -> model -> saveField ( 'title' , '' , true );
$this -> assertFalse ( $result );
}
2007-05-18 17:54:59 +00:00
function testSaveWithCreate () {
2007-03-17 19:15:41 +00:00
$this -> model =& 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' => '' ));
$result = $this -> model -> save ( $data );
$this -> assertFalse ( $result );
$this -> assertTrue ( ! empty ( $this -> model -> validationErrors ));
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model =& 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' => '' ));
$result = $this -> model -> create ( $data ) && $this -> model -> save ();
$this -> assertFalse ( $result );
$this -> assertTrue ( ! empty ( $this -> model -> 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' => '' ));
$result = $this -> model -> create ( $data ) && $this -> model -> save ();
$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' ));
$result = $this -> model -> create () && $this -> model -> save ( $data , false );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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' ));
$result = $this -> model -> create () && $this -> model -> save ( $data , true , array ( 'title' , 'published' ));
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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 (
'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 )
)
);
$result = $this -> model -> create () && $this -> model -> save ( $data );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 2 ;
$result = $this -> model -> read ( null , 4 );
2007-08-14 23:12:24 +00:00
$expected = array (
'Article' => array (
2007-03-17 19:15:41 +00:00
'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'
2007-03-30 00:08:10 +00:00
),
2007-03-17 19:15:41 +00:00
'User' => array (
'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31'
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'Comment' => array (),
'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' )
2007-03-17 19:15:41 +00:00
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +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'
));
$result = $this -> model -> Comment -> create () && $this -> model -> Comment -> save ( $data );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +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'
));
$result = $this -> model -> Comment -> Attachment -> save ( $data );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 2 ;
$result = $this -> model -> read ( null , 4 );
2007-08-14 23:12:24 +00:00
$expected = array (
'Article' => array (
2007-03-17 19:15:41 +00:00
'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'
2007-03-30 00:08:10 +00:00
),
2007-03-17 19:15:41 +00:00
'User' => array (
'id' => '2' , 'user' => 'nate' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:18:23' , 'updated' => '2007-03-17 01:20:31'
2007-03-30 00:08:10 +00:00
),
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' ,
2007-08-14 23:12:24 +00:00
'Article' => array (
2007-03-17 19:15:41 +00:00
'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'
2007-03-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-03-17 19:15:41 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
2007-03-30 00:08:10 +00:00
),
2007-03-17 19:15:41 +00:00
'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-30 00:08:10 +00:00
),
2007-08-14 23:12:24 +00:00
'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' )
2007-03-17 19:15:41 +00:00
)
);
$this -> assertEqual ( $result , $expected );
}
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
function testSaveWithSet () {
$this -> model =& 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' ));
$result = $this -> model -> create () && $this -> model -> save ( $data );
$this -> assertTrue ( $result );
// Check record we created
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-05-18 17:54:59 +00:00
'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article' , 'body' => 'Fourth Article Body' , 'published' => 'Y'
));
$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' ));
$result = $this -> model -> create () && $this -> model -> save ( $data );
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-05-18 17:54:59 +00:00
'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article' , 'body' => 'Fourth Article Body' , 'published' => 'Y'
));
$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' ));
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$result = $this -> model -> set ( $data ) && $this -> model -> save ();
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// THIS WORKS, but it just looks awful and should not be needed
// $result = $this->model->set($data) && $this->model->save($data);
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// THIS WORKS, but should not be used for editing since create() uses default DB values for fields I am not editing:
// $result = $this->model->create() && $this->model->save($data);
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> assertTrue ( $result );
// And see if it got edited
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> read ( array ( 'id' , 'user_id' , 'title' , 'body' , 'published' ), 4 );
2007-08-14 23:12:24 +00:00
$expected = array ( 'Article' => array (
2007-05-18 17:54:59 +00:00
'id' => '4' , 'user_id' => '1' , 'title' => 'Fourth Article - New Title' , 'body' => 'Fourth Article Body' , 'published' => 'N'
));
$this -> assertEqual ( $result , $expected );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// Make sure article we created to overlap is still intact
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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
// Edit new this overlapped article
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' ));
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$result = $this -> model -> set ( $data ) && $this -> model -> save ();
$this -> assertTrue ( $result );
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
// Check it's now updated
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> 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 - New Title 5' , '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
// And now do a final check on all article titles
2007-06-20 01:37:23 +00:00
2007-05-18 17:54:59 +00:00
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'title' ));
$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-06-28 03:27:47 +00:00
function testSaveHabtm () {
$this -> model =& new Article ();
$result = $this -> model -> findById ( 2 );
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'Second Article' , 'body' => 'Second Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:41:23' , 'updated' => '2007-03-18 10:43:31'
),
2007-08-14 23:12:24 +00:00
'User' => array (
2007-06-28 03:27:47 +00:00
'id' => '3' , 'user' => 'larry' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:20:23' , 'updated' => '2007-03-17 01:22:31'
),
'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-08-14 23:12:24 +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
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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 );
// Setting just parent ID
$data = array (
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' ),
2007-06-28 03:27:47 +00:00
'Tag' => array (
'Tag' => array ( 2 , 3 )
)
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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 );
// Setting no parent data
$data = array (
'Tag' => array (
'Tag' => array ( 1 , 2 , 3 )
)
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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 );
$data = array (
'Tag' => array (
'Tag' => array ( )
)
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array ()
);
$this -> assertEqual ( $result , $expected );
$data = array (
'Tag' => array (
'Tag' => array ( 2 , 3 )
)
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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
$data = array (
'Tag' => array (
'Tag' => array ( 1 , 2 )
),
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' , 'title' => 'New Second Article' ),
2007-06-28 03:36:54 +00:00
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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 );
$data = array (
'Tag' => array (
'Tag' => array ( 1 , 2 )
),
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' , 'title' => 'New Second Article Title' ),
2007-06-28 03:36:54 +00:00
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'New Second Article Title' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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 );
$data = array (
'Tag' => array (
'Tag' => array ( 2 , 3 )
),
2007-08-14 23:12:24 +00:00
'Article' => array ( 'id' => '2' , 'title' => 'Changed Second Article' ),
2007-06-28 03:36:54 +00:00
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'Changed Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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
);
$result = $this -> model -> set ( $data );
$this -> assertTrue ( $result );
$result = $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> unbindModel ( array (
'belongsTo' => array ( 'User' ),
'hasMany' => array ( 'Comment' )
));
$result = $this -> model -> find ( array ( 'Article.id' => 2 ), array ( 'id' , 'user_id' , 'title' , 'body' ));
$expected = array (
'Article' => array (
'id' => '2' , 'user_id' => '3' , 'title' => 'Changed Second Article' , 'body' => 'Second Article Body'
),
'Tag' => array (
2007-08-14 23:12:24 +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-06-28 03:27:47 +00:00
}
2007-06-27 19:16:11 +00:00
function testDel () {
$this -> model =& new Article ();
$result = $this -> model -> del ( 2 );
$this -> assertTrue ( $result );
$result = $this -> model -> read ( null , 2 );
$this -> assertFalse ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'title' ));
$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 );
$result = $this -> model -> del ( 3 );
$this -> assertTrue ( $result );
$result = $this -> model -> read ( null , 3 );
$this -> assertFalse ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'title' ));
$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 );
}
function testDeleteAll () {
$this -> model =& new Article ();
// Add some more articles
$data = array ( 'Article' => array ( 'user_id' => 2 , 'id' => 4 , 'title' => 'Fourth Article' , 'published' => 'N' ));
$result = $this -> model -> set ( $data ) && $this -> model -> save ();
$this -> assertTrue ( $result );
$data = array ( 'Article' => array ( 'user_id' => 2 , 'id' => 5 , 'title' => 'Fifth Article' , 'published' => 'Y' ));
$result = $this -> model -> set ( $data ) && $this -> model -> save ();
$this -> assertTrue ( $result );
$data = array ( 'Article' => array ( 'user_id' => 1 , 'id' => 6 , 'title' => 'Sixth Article' , 'published' => 'N' ));
$result = $this -> model -> set ( $data ) && $this -> model -> save ();
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
$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 );
// Delete with conditions
$result = $this -> model -> deleteAll ( array ( 'Article.published' => 'N' ));
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
$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 );
$result = $this -> model -> deleteAll ( array ( 'Article.user_id' => array ( 2 , 3 )));
$this -> assertTrue ( $result );
$this -> model -> recursive = - 1 ;
$result = $this -> model -> findAll ( null , array ( 'id' , 'user_id' , 'title' , 'published' ));
$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-05-01 03:04:44 +00:00
function testRecursiveDel () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Article ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> del ( 2 );
$this -> assertTrue ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$this -> model -> recursive = 2 ;
$result = $this -> model -> read ( null , 2 );
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> Comment -> read ( null , 5 );
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> Comment -> read ( null , 6 );
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> Comment -> Attachment -> read ( null , 1 );
$this -> assertFalse ( $result );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findCount ();
$this -> assertEqual ( $result , 2 );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> Comment -> findCount ();
$this -> assertEqual ( $result , 4 );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> Comment -> Attachment -> findCount ();
$this -> assertEqual ( $result , 0 );
}
2007-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testFindAllThreaded () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Category ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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
2007-03-17 19:15:41 +00:00
$result = $this -> model -> 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 );
}
2007-03-30 00:08:10 +00:00
2007-05-01 03:04:44 +00:00
function testFindNeighbours () {
2007-03-17 19:15:41 +00:00
$this -> model =& new Article ();
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findNeighbours ( null , 'Article.id' , '2' );
$expected = array (
'prev' => array (
'Article' => array ( 'id' => 1 )
),
'next' => array (
'Article' => array ( 'id' => 3 )
)
);
$this -> assertEqual ( $result , $expected );
2007-03-30 00:08:10 +00:00
2007-03-17 19:15:41 +00:00
$result = $this -> model -> findNeighbours ( null , 'Article.id' , '3' );
$expected = array (
2007-08-14 23:12:24 +00:00
'prev' => array ( 'Article' => array ( 'id' => 2 )),
2007-03-17 19:15:41 +00:00
'next' => array ()
);
$this -> assertEqual ( $result , $expected );
}
2007-04-09 08:54:25 +00:00
2007-05-01 03:04:44 +00:00
function testFindCombinedRelations () {
2007-04-05 04:04:55 +00:00
$this -> model =& new Apple ();
2007-04-09 08:54:25 +00:00
2007-04-05 04:04:55 +00:00
$result = $this -> model -> findAll ();
2007-04-09 08:54:25 +00:00
2007-08-14 23:12:24 +00:00
$expected = array (
array (
'Apple' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-01 13:31:26'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-11-30 18:38:10'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => null ,
'apple_id' => null ,
2007-04-05 04:04:55 +00:00
'name' => null
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array (
array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-11-30 18:38:10'
)
)
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-11-30 18:38:10'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-01 13:31:26'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => '2' ,
'apple_id' => '2' ,
2007-04-05 04:04:55 +00:00
'name' => 'sample2'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array (
array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-01 13:31:26'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:23:24'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
2007-04-09 08:54:25 +00:00
'id' => '6' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:23:36'
)
)
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:23:24'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-11-30 18:38:10'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => '1' ,
'apple_id' => '3' ,
2007-04-05 04:04:55 +00:00
'name' => 'sample1'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array ()
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54:25 +00:00
'id' => '6' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:23:36'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54: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' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-11-30 18:38:10'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => '3' ,
'apple_id' => '6' ,
2007-04-05 04:04:55 +00:00
'name' => 'sample3'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array (
array (
2007-04-09 08:54:25 +00:00
'id' => '8' ,
'apple_id' => '6' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:39'
)
)
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54:25 +00:00
'id' => '7' ,
'apple_id' => '7' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:16'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54:25 +00:00
'id' => '7' ,
'apple_id' => '7' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:16'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => '4' ,
'apple_id' => '7' ,
2007-04-05 04:04:55 +00:00
'name' => 'sample4'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array (
array (
2007-04-09 08:54:25 +00:00
'id' => '7' ,
'apple_id' => '7' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:16'
)
)
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54:25 +00:00
'id' => '8' ,
'apple_id' => '6' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:39'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54:25 +00:00
'id' => '6' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:23:36'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => null ,
'apple_id' => null ,
2007-04-05 04:04:55 +00:00
'name' => null
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array (
array (
2007-04-09 08:54:25 +00:00
'id' => '9' ,
'apple_id' => '8' ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:34:21'
)
)
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
array (
'Apple' => array (
2007-04-09 08:54:25 +00:00
'id' => '9' ,
'apple_id' => '8' ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:34:21'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Parent' => array (
2007-04-09 08:54:25 +00:00
'id' => '8' ,
'apple_id' => '6' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
2007-04-05 04:04:55 +00:00
'modified' => '2006-12-25 05:29:39'
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Sample' => array (
2007-04-09 08:54:25 +00:00
'id' => null ,
'apple_id' => null ,
2007-04-05 04:04:55 +00:00
'name' => null
2007-04-09 08:54:25 +00:00
),
2007-08-14 23:12:24 +00:00
'Child' => array ()
2007-04-05 04:04:55 +00:00
)
);
2007-04-09 08:54:25 +00:00
2007-04-05 04:04:55 +00:00
$this -> assertEqual ( $result , $expected );
}
2007-06-03 21:54:11 +00:00
/* function testBasicValidation () {
$this -> model =& new ValidationTest ();
$this -> model -> set ( array ( 'title' => '' , 'published' => 1 ));
$this -> assertEqual ( $this -> model -> invalidFields (), array ( 'title' => 'This field cannot be left blank' ));
$this -> model -> create ();
$this -> model -> set ( array ( 'title' => 'Hello' , 'published' => 0 ));
$this -> assertEqual ( $this -> model -> invalidFields (), array ( 'published' => 'This field cannot be left blank' ));
$this -> model -> create ();
$this -> model -> set ( array ( 'title' => 'Hello' , 'published' => 1 , 'body' => '' ));
$this -> assertEqual ( $this -> model -> invalidFields (), array ( 'body' => 'This field cannot be left blank' ));
} */
function testMultipleValidation () {
$this -> model =& new ValidationTest ();
}
2007-08-29 04:38:48 +00:00
function testLoadModelSecondIteration (){
$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-06-03 21:54:11 +00:00
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model
*/
class ValidationTest extends CakeTestModel {
var $name = 'ValidationTest' ;
var $useTable = false ;
2007-06-20 01:37:23 +00:00
2007-06-03 21:54:11 +00:00
var $validate = array (
'title' => VALID_NOT_EMPTY ,
'published' => 'customValidationMethod' ,
'body' => array (
VALID_NOT_EMPTY ,
'/^.{5,}$/s' => 'no matchy' ,
'/^[0-9A-Za-z \\.]{1,}$/s'
)
);
function customValidationMethod ( $data ) {
return $data === 1 ;
}
function loadInfo () {
return new Set ();
}
2007-02-03 22:20:13 +00:00
}
2007-06-03 21:54:11 +00:00
?>