2009-07-24 22:17:14 +00:00
< ? php
/**
* ModelReadTest file
*
2012-04-27 02:49:18 +00:00
* CakePHP ( tm ) Tests < http :// book . cakephp . org / 2.0 / en / development / testing . html >
2013-02-08 11:59:49 +00:00
* Copyright ( c ) Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2009-07-24 22:17:14 +00:00
*
2010-10-03 16:31:21 +00:00
* Licensed under The MIT License
2013-02-08 12:22:51 +00:00
* For full copyright and license information , please see the LICENSE . txt
2010-10-03 16:31:21 +00:00
* Redistributions of files must retain the above copyright notice
2009-07-24 22:17:14 +00:00
*
2013-02-08 11:59:49 +00:00
* @ copyright Copyright ( c ) Cake Software Foundation , Inc . ( http :// cakefoundation . org )
2012-04-27 02:49:18 +00:00
* @ link http :// book . cakephp . org / 2.0 / en / development / testing . html CakePHP ( tm ) Tests
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Model
2009-07-24 22:17:14 +00:00
* @ since CakePHP ( tm ) v 1.2 . 0.4206
2013-05-30 22:11:14 +00:00
* @ license http :// www . opensource . org / licenses / mit - license . php MIT License
2009-07-24 22:17:14 +00:00
*/
2013-05-30 22:11:14 +00:00
2011-04-10 21:10:30 +00:00
require_once dirname ( __FILE__ ) . DS . 'ModelTestBase.php' ;
2013-05-30 22:11:14 +00:00
2009-07-24 22:17:14 +00:00
/**
* ModelReadTest
*
2011-07-26 06:16:14 +00:00
* @ package Cake . Test . Case . Model
2009-07-24 22:17:14 +00:00
*/
class ModelReadTest extends BaseModelTest {
2009-07-26 09:59:51 +00:00
2012-02-23 06:12:08 +00:00
/**
* testExists function
2013-05-30 22:11:14 +00:00
* @ return void
2012-02-23 06:12:08 +00:00
*/
public function testExists () {
$this -> loadFixtures ( 'User' );
$TestModel = new User ();
$this -> assertTrue ( $TestModel -> exists ( 1 ));
$TestModel -> id = 2 ;
$this -> assertTrue ( $TestModel -> exists ());
$TestModel -> delete ();
$this -> assertFalse ( $TestModel -> exists ());
$this -> assertFalse ( $TestModel -> exists ( 2 ));
}
2009-07-24 22:17:14 +00:00
/**
* testFetchingNonUniqueFKJoinTableRecords ()
*
* Tests if the results are properly returned in the case there are non - unique FK ' s
* in the join table but another fields value is different . For example :
* something_id | something_else_id | doomed = 1
* something_id | something_else_id | doomed = 0
* Should return both records and not just one .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFetchingNonUniqueFKJoinTableRecords () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Something' , 'SomethingElse' , 'JoinThing' );
$Something = new Something ();
$joinThingData = array (
'JoinThing' => array (
'something_id' => 1 ,
'something_else_id' => 2 ,
'doomed' => '0' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
);
2010-03-16 19:42:27 +00:00
2009-07-24 22:17:14 +00:00
$Something -> JoinThing -> create ( $joinThingData );
$Something -> JoinThing -> save ();
$result = $Something -> JoinThing -> find ( 'all' , array ( 'conditions' => array ( 'something_else_id' => 2 )));
2010-06-05 03:37:29 +00:00
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( true , $result [ 0 ][ 'JoinThing' ][ 'doomed' ]);
$this -> assertEquals ( false , $result [ 1 ][ 'JoinThing' ][ 'doomed' ]);
2009-07-24 22:17:14 +00:00
$result = $Something -> find ( 'first' );
2010-11-27 04:16:34 +00:00
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , count ( $result [ 'SomethingElse' ]));
2010-03-16 19:42:27 +00:00
2012-04-04 23:33:57 +00:00
$doomed = Hash :: extract ( $result [ 'SomethingElse' ], '{n}.JoinThing.doomed' );
2010-03-16 19:42:27 +00:00
$this -> assertTrue ( in_array ( true , $doomed ));
$this -> assertTrue ( in_array ( false , $doomed ));
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2016-01-28 19:34:08 +00:00
/**
* Test IN operator
*
* @ return void
*/
public function testInOperator () {
$this -> loadFixtures ( 'Product' );
$Product = new Product ();
$expected = array (
array (
'Product' => array (
'id' => 1 ,
'name' => " Park's Great Hits " ,
'type' => 'Music' ,
'price' => 19
)
)
);
$result = $Product -> find ( 'all' , array ( 'conditions' => array ( 'Product.id IN' => array ( 1 ))));
$this -> assertEquals ( $expected , $result );
$expected = array (
array (
'Product' => array (
'id' => 2 ,
'name' => " Silly Puddy " ,
'type' => 'Toy' ,
'price' => 3
)
),
array (
'Product' => array (
'id' => 3 ,
'name' => " Playstation " ,
'type' => 'Toy' ,
'price' => 89
)
),
array (
'Product' => array (
'id' => 4 ,
'name' => " Men's T-Shirt " ,
'type' => 'Clothing' ,
'price' => 32
)
),
array (
'Product' => array (
'id' => 5 ,
'name' => " Blouse " ,
'type' => 'Clothing' ,
'price' => 34
)
),
array (
'Product' => array (
'id' => 6 ,
'name' => " Electronica 2002 " ,
'type' => 'Music' ,
'price' => 4
)
),
array (
'Product' => array (
'id' => 7 ,
'name' => " Country Tunes " ,
'type' => 'Music' ,
'price' => 21
)
),
array (
'Product' => array (
'id' => 8 ,
'name' => " Watermelon " ,
'type' => 'Food' ,
'price' => 9
)
)
);
$result = $Product -> find ( 'all' , array ( 'conditions' => array ( 'Product.id NOT IN' => array ( 1 ))));
$this -> assertEquals ( $expected , $result );
$expected = array (
array (
'Product' => array (
'id' => 1 ,
'name' => " Park's Great Hits " ,
'type' => 'Music' ,
'price' => 19
)
),
array (
'Product' => array (
'id' => 2 ,
'name' => " Silly Puddy " ,
'type' => 'Toy' ,
'price' => 3
)
),
);
2016-01-28 19:55:19 +00:00
$result = $Product -> find ( 'all' , array ( 'conditions' => array ( 'Product.id IN' => array ( 1 , 2 ))));
2016-01-28 19:34:08 +00:00
$this -> assertEquals ( $expected , $result );
}
2009-07-24 22:17:14 +00:00
/**
* testGroupBy method
*
* These tests will never pass with Postgres or Oracle as all fields in a select must be
* part of an aggregate function or in the GROUP BY statement .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testGroupBy () {
2011-05-23 03:19:13 +00:00
$isStrictGroupBy = $this -> db instanceof Postgres || $this -> db instanceof Sqlite || $this -> db instanceof Oracle || $this -> db instanceof Sqlserver ;
2011-05-22 04:51:05 +00:00
$message = 'Postgres, Oracle, SQLite and SQL Server have strict GROUP BY and are incompatible with this test.' ;
2009-07-24 22:17:14 +00:00
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $isStrictGroupBy , $message );
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Project' , 'Product' , 'Thread' , 'Message' , 'Bid' );
2010-06-05 03:37:29 +00:00
$Thread = new Thread ();
$Product = new Product ();
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'group' => 'Thread.project_id' ,
'order' => 'Thread.id ASC'
));
$expected = array (
array (
'Thread' => array (
'id' => 1 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 1'
),
'Project' => array (
'id' => 1 ,
'name' => 'Project 1'
),
'Message' => array (
array (
'id' => 1 ,
'thread_id' => 1 ,
'name' => 'Thread 1, Message 1'
))),
array (
'Thread' => array (
'id' => 3 ,
'project_id' => 2 ,
'name' => 'Project 2, Thread 1'
),
'Project' => array (
'id' => 2 ,
'name' => 'Project 2'
),
'Message' => array (
array (
'id' => 3 ,
'thread_id' => 3 ,
'name' => 'Thread 3, Message 1'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$rows = $Thread -> find ( 'all' , array (
'group' => 'Thread.project_id' ,
'fields' => array ( 'Thread.project_id' , 'COUNT(*) AS total' )
));
$result = array ();
2011-11-30 15:44:11 +00:00
foreach ( $rows as $row ) {
2009-07-24 22:17:14 +00:00
$result [ $row [ 'Thread' ][ 'project_id' ]] = $row [ 0 ][ 'total' ];
}
$expected = array (
1 => 2 ,
2 => 1
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$rows = $Thread -> find ( 'all' , array (
'group' => 'Thread.project_id' ,
'fields' => array ( 'Thread.project_id' , 'COUNT(*) AS total' ),
2011-12-01 07:21:31 +00:00
'order' => 'Thread.project_id'
2009-07-24 22:17:14 +00:00
));
$result = array ();
2011-11-30 15:44:11 +00:00
foreach ( $rows as $row ) {
2009-07-24 22:17:14 +00:00
$result [ $row [ 'Thread' ][ 'project_id' ]] = $row [ 0 ][ 'total' ];
}
$expected = array (
1 => 2 ,
2 => 1
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => 'Thread.project_id'
));
$expected = array (
array (
'Thread' => array (
'id' => 1 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 1'
),
'Project' => array (
'id' => 1 ,
'name' => 'Project 1'
),
'Message' => array (
array (
'id' => 1 ,
'thread_id' => 1 ,
'name' => 'Thread 1, Message 1'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => 'Thread.project_id, Project.id'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => 'project_id'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => array ( 'project_id' )
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => array ( 'project_id' , 'Project.id' )
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Thread -> find ( 'all' , array (
'conditions' => array ( 'Thread.project_id' => 1 ),
'group' => array ( 'Thread.project_id' , 'Project.id' )
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$expected = array (
array ( 'Product' => array ( 'type' => 'Clothing' ), array ( 'price' => 32 )),
array ( 'Product' => array ( 'type' => 'Food' ), array ( 'price' => 9 )),
2011-12-01 07:21:31 +00:00
array ( 'Product' => array ( 'type' => 'Music' ), array ( 'price' => 4 )),
2009-07-24 22:17:14 +00:00
array ( 'Product' => array ( 'type' => 'Toy' ), array ( 'price' => 3 ))
);
2013-05-17 08:36:17 +00:00
$result = $Product -> find ( 'all' , array (
2011-12-01 07:21:31 +00:00
'fields' => array ( 'Product.type' , 'MIN(Product.price) as price' ),
'group' => 'Product.type' ,
2009-07-24 22:17:14 +00:00
'order' => 'Product.type ASC'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $Product -> find ( 'all' , array (
2011-12-01 07:21:31 +00:00
'fields' => array ( 'Product.type' , 'MIN(Product.price) as price' ),
'group' => array ( 'Product.type' ),
2009-07-24 22:17:14 +00:00
'order' => 'Product.type ASC' ));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testOldQuery method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testOldQuery () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' , 'Comment' , 'Attachment' );
$Article = new Article ();
2009-07-24 22:17:14 +00:00
2012-11-21 14:39:03 +00:00
$query = 'SELECT title FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id IN (1,2)' ;
$results = $Article -> query ( $query );
$this -> assertTrue ( is_array ( $results ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , count ( $results ));
2009-07-24 22:17:14 +00:00
2012-11-21 14:39:03 +00:00
$query = 'SELECT title, body FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.id = 1' ;
$results = $Article -> query ( $query , false );
2010-06-05 03:37:29 +00:00
$this -> assertFalse ( $this -> db -> getQueryCache ( $query ));
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( is_array ( $results ));
2012-11-21 14:39:03 +00:00
$query = 'SELECT title, id FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' );
$query .= '.published = ' . $this -> db -> value ( 'Y' );
$results = $Article -> query ( $query , true );
2010-06-05 03:37:29 +00:00
$result = $this -> db -> getQueryCache ( $query );
$this -> assertFalse ( empty ( $result ));
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( is_array ( $results ));
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testPreparedQuery method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testPreparedQuery () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' );
$Article = new Article ();
2009-07-24 22:17:14 +00:00
$query = 'SELECT title, published FROM ' ;
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' );
$query .= '.id = ? AND ' . $this -> db -> fullTableName ( 'articles' ) . '.published = ?' ;
$params = array ( 1 , 'Y' );
2016-10-09 11:43:27 +00:00
$result = $Article -> query ( $query , $params , true );
2009-07-24 22:17:14 +00:00
$expected = array (
'0' => array (
2011-11-08 05:38:36 +00:00
$this -> db -> fullTableName ( 'articles' , false , false ) => array (
2009-07-24 22:17:14 +00:00
'title' => 'First Article' , 'published' => 'Y' )
));
if ( isset ( $result [ 0 ][ 0 ])) {
2011-11-08 05:38:36 +00:00
$expected [ 0 ][ 0 ] = $expected [ 0 ][ $this -> db -> fullTableName ( 'articles' , false , false )];
unset ( $expected [ 0 ][ $this -> db -> fullTableName ( 'articles' , false , false )]);
2009-07-24 22:17:14 +00:00
}
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-10-17 15:21:54 +00:00
$result = $this -> db -> getQueryCache ( $query , $params );
2010-06-05 03:37:29 +00:00
$this -> assertFalse ( empty ( $result ));
2009-07-24 22:17:14 +00:00
2012-11-21 14:39:03 +00:00
$query = 'SELECT id, created FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.title = ?' ;
$params = array ( 'First Article' );
$result = $Article -> query ( $query , $params , false );
$this -> assertTrue ( is_array ( $result ));
$this -> assertTrue (
2012-05-12 01:38:21 +00:00
isset ( $result [ 0 ][ $this -> db -> fullTableName ( 'articles' , false , false )]) ||
isset ( $result [ 0 ][ 0 ])
2009-07-24 22:17:14 +00:00
);
2010-10-17 15:21:54 +00:00
$result = $this -> db -> getQueryCache ( $query , $params );
2010-06-05 03:37:29 +00:00
$this -> assertTrue ( empty ( $result ));
2009-07-24 22:17:14 +00:00
2012-11-21 14:39:03 +00:00
$query = 'SELECT title FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' );
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' ) . '.title LIKE ?' ;
$params = array ( '%First%' );
2016-10-09 11:43:27 +00:00
$result = $Article -> query ( $query , $params , true );
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( is_array ( $result ));
$this -> assertTrue (
2012-05-12 01:38:21 +00:00
isset ( $result [ 0 ][ $this -> db -> fullTableName ( 'articles' , false , false )][ 'title' ]) ||
isset ( $result [ 0 ][ 0 ][ 'title' ])
2009-07-24 22:17:14 +00:00
);
//related to ticket #5035
2012-11-21 14:39:03 +00:00
$query = 'SELECT title FROM ' ;
2009-07-24 22:17:14 +00:00
$query .= $this -> db -> fullTableName ( 'articles' ) . ' WHERE title = ? AND published = ?' ;
$params = array ( 'First? Article' , 'Y' );
2016-10-09 11:43:27 +00:00
$Article -> query ( $query , $params , true );
2009-07-24 22:17:14 +00:00
2010-10-17 15:21:54 +00:00
$result = $this -> db -> getQueryCache ( $query , $params );
2010-06-05 03:37:29 +00:00
$this -> assertFalse ( $result === false );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testParameterMismatch method
*
2011-09-03 21:35:09 +00:00
* @ expectedException PDOException
2009-07-24 22:17:14 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testParameterMismatch () {
2011-09-04 01:37:40 +00:00
$this -> skipIf ( $this -> db instanceof Sqlite , 'Sqlite does not accept real prepared statements, no way to check this' );
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' );
$Article = new Article ();
2009-07-24 22:17:14 +00:00
2012-11-21 14:39:03 +00:00
$query = 'SELECT * FROM ' . $this -> db -> fullTableName ( 'articles' );
2009-07-24 22:17:14 +00:00
$query .= ' WHERE ' . $this -> db -> fullTableName ( 'articles' );
$query .= '.published = ? AND ' . $this -> db -> fullTableName ( 'articles' ) . '.user_id = ?' ;
$params = array ( 'Y' );
2013-01-23 12:45:50 +00:00
$Article -> query ( $query , $params );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testVeryStrangeUseCase method
*
2011-09-03 21:07:45 +00:00
* @ expectedException PDOException
2009-07-24 22:17:14 +00:00
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testVeryStrangeUseCase () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' );
$Article = new Article ();
2009-07-24 22:17:14 +00:00
$query = 'SELECT * FROM ? WHERE ? = ? AND ? = ?' ;
$param = array (
$this -> db -> fullTableName ( 'articles' ),
$this -> db -> fullTableName ( 'articles' ) . '.user_id' , '3' ,
$this -> db -> fullTableName ( 'articles' ) . '.published' , 'Y'
);
2013-01-23 12:45:50 +00:00
$Article -> query ( $query , $param );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testRecursiveUnbind method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testRecursiveUnbind () {
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $this -> db instanceof Sqlserver , 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.' );
2011-08-14 01:59:21 +00:00
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Apple' , 'Sample' );
2010-06-05 03:37:29 +00:00
$TestModel = new Apple ();
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
2011-12-01 07:21:31 +00:00
'Apple' => array (
2009-07-24 22:17:14 +00:00
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
2011-12-01 07:21:31 +00:00
'id' => '' ,
2009-07-24 22:17:14 +00:00
'apple_id' => '' ,
'name' => ''
),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2' ,
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1'
)),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1' ,
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
)),
'Child' => array ()
),
array (
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' , 'mytime' => '22:57:17' ),
'Sample' => array ( 'id' => 2 , 'apple_id' => 2 , 'name' => 'sample2' ),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3' ,
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4' ,
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Sample' => array ()
))),
array (
'Apple' => array (
'id' => 7 ,
'apple_id' => 6 ,
'color' =>
'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
),
'Child' => array ()));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'hasOne' => array ( 'Sample' )));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
'Apple' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
2011-12-01 07:21:31 +00:00
'id' => '' ,
2009-07-24 22:17:14 +00:00
'apple_id' => '' ,
'name' => ''
),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2' ,
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' , 'modified' =>
'2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1'
)),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1' ,
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
)),
'Child' => array ()
),
array (
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3' ,
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4' ,
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
)),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))))),
array (
'Apple' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Sample' => array ()
))),
array (
'Apple' => array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
),
'Child' => array ()
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'hasOne' => array ( 'Sample' )));
$this -> assertTrue ( $result );
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Child' )));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
2011-12-01 07:21:31 +00:00
'Apple' => array (
2009-07-24 22:17:14 +00:00
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
2011-12-01 07:21:31 +00:00
'id' => '' ,
2009-07-24 22:17:14 +00:00
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2' ,
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1' ,
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3' ,
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4' ,
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2013-10-24 13:13:22 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => 'Child' ));
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( $result );
2013-10-24 13:13:22 +00:00
$result = $TestModel -> Sample -> unbindModel ( array ( 'belongsTo' => 'Apple' ));
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
'Apple' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
2011-12-01 07:21:31 +00:00
'id' => '' ,
2009-07-24 22:17:14 +00:00
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
)),
array (
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1'
)),
array (
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
)),
array (
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
)),
array (
'Apple' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Sample' => array (),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> Parent -> unbindModel ( array ( 'belongsTo' => array ( 'Parent' )));
$this -> assertTrue ( $result );
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Child' )));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
'Apple' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
2011-12-01 07:21:31 +00:00
'id' => '' ,
2009-07-24 22:17:14 +00:00
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17' ,
'Sample' => array (),
'Child' => array (
array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2' ,
'Apple' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 1 ,
'apple_id' => 3 ,
'name' => 'sample1' ,
'Apple' => array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 2 ,
'apple_id' => 1 ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17' ,
'Sample' => array (
'id' => 2 ,
'apple_id' => 2 ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => 1 ,
'apple_id' => 2 ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => 3 ,
'apple_id' => 2 ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3' ,
'Apple' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' =>
'2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17' ,
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => 4 ,
'apple_id' => 5 ,
'name' => 'sample4' ,
'Apple' => array (
'id' => 5 ,
'apple_id' => 5 ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ),
'Parent' => array (
'id' => 4 ,
'apple_id' => 2 ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17' ,
'Sample' => array (
'id' => 3 ,
'apple_id' => 4 ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)),
array (
'Apple' => array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => 6 ,
'apple_id' => 4 ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17' ,
'Sample' => array (),
'Child' => array (
array (
'id' => 7 ,
'apple_id' => 6 ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' , 'modified' =>
'2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
'Sample' => array (
'id' => '' ,
'apple_id' => '' ,
'name' => ''
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testSelfAssociationAfterFind method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testSelfAssociationAfterFind () {
2011-05-18 18:12:36 +00:00
$this -> loadFixtures ( 'Apple' , 'Sample' );
2009-07-24 22:17:14 +00:00
$afterFindModel = new NodeAfterFind ();
$afterFindModel -> recursive = 3 ;
$afterFindData = $afterFindModel -> find ( 'all' );
$duplicateModel = new NodeAfterFind ();
$duplicateModel -> recursive = 3 ;
$noAfterFindModel = new NodeNoAfterFind ();
$noAfterFindModel -> recursive = 3 ;
$noAfterFindData = $noAfterFindModel -> find ( 'all' );
$this -> assertFalse ( $afterFindModel == $noAfterFindModel );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $afterFindData , $noAfterFindData );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2013-01-18 01:35:37 +00:00
/**
* Test that afterFind can completely unset data .
*
* @ return void
*/
public function testAfterFindUnset () {
$this -> loadFixtures ( 'Article' , 'Comment' , 'User' );
$model = new CustomArticle ();
$model -> bindModel ( array (
'hasMany' => array (
'ModifiedComment' => array (
'className' => 'ModifiedComment' ,
'foreignKey' => 'article_id' ,
)
)
));
$model -> ModifiedComment -> remove = true ;
$result = $model -> find ( 'all' );
$this -> assertTrue (
empty ( $result [ 0 ][ 'ModifiedComment' ]),
'Zeroith row should be removed by afterFind'
);
}
2012-01-19 22:20:15 +00:00
/**
* testFindThreadedNoParent method
*
* @ return void
*/
public function testFindThreadedNoParent () {
$this -> loadFixtures ( 'Apple' , 'Sample' );
$Apple = new Apple ();
$result = $Apple -> find ( 'threaded' );
2012-03-11 01:57:18 +00:00
$result = Hash :: extract ( $result , '{n}.children' );
2013-06-09 19:01:01 +00:00
$expected = array ( array (), array (), array (), array (), array (), array (), array ());
2012-01-19 22:20:15 +00:00
$this -> assertEquals ( $expected , $result );
}
/**
* testFindThreaded method
*
* @ return void
*/
public function testFindThreaded () {
$this -> loadFixtures ( 'Person' );
$Model = new Person ();
$Model -> recursive = - 1 ;
$result = $Model -> find ( 'threaded' );
2012-03-11 01:57:18 +00:00
$result = Hash :: extract ( $result , '{n}.children' );
2013-06-09 19:01:01 +00:00
$expected = array ( array (), array (), array (), array (), array (), array (), array ());
2012-01-19 22:20:15 +00:00
$this -> assertEquals ( $expected , $result );
$result = $Model -> find ( 'threaded' , array ( 'parent' => 'mother_id' ));
$expected = array (
array (
'Person' => array (
'id' => '4' ,
'name' => 'mother - grand mother' ,
'mother_id' => '0' ,
'father_id' => '0'
),
'children' => array (
array (
'Person' => array (
'id' => '2' ,
'name' => 'mother' ,
'mother_id' => '4' ,
'father_id' => '5'
),
'children' => array (
array (
'Person' => array (
'id' => '1' ,
'name' => 'person' ,
'mother_id' => '2' ,
'father_id' => '3'
),
'children' => array ()
)
)
)
)
),
array (
'Person' => array (
'id' => '5' ,
'name' => 'mother - grand father' ,
'mother_id' => '0' ,
'father_id' => '0'
),
'children' => array ()
),
array (
'Person' => array (
'id' => '6' ,
'name' => 'father - grand mother' ,
'mother_id' => '0' ,
'father_id' => '0'
),
'children' => array (
array (
'Person' => array (
'id' => '3' ,
'name' => 'father' ,
'mother_id' => '6' ,
'father_id' => '7'
),
'children' => array ()
)
)
),
array (
'Person' => array (
'id' => '7' ,
'name' => 'father - grand father' ,
'mother_id' => '0' ,
'father_id' => '0'
),
'children' => array ()
)
);
$this -> assertEquals ( $expected , $result );
}
2009-07-24 22:17:14 +00:00
/**
* testFindAllThreaded method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAllThreaded () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Category' );
2010-06-05 03:37:29 +00:00
$TestModel = new Category ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' );
$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 (
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()))
),
array (
'Category' => array (
'id' => '3' ,
'parent_id' => '1' ,
'name' => 'Category 1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
)
)
),
array (
'Category' => array (
'id' => '4' ,
'parent_id' => '0' ,
'name' => 'Category 2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
),
array (
'Category' => array (
'id' => '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 ()
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'conditions' => array ( 'Category.name LIKE' => 'Category 1%' )
));
$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 (
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()))
),
array (
'Category' => array (
'id' => '3' ,
'parent_id' => '1' ,
'name' => 'Category 1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'fields' => 'id, parent_id, name'
));
$expected = array (
array (
'Category' => array (
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1'
),
'children' => array (
array (
'Category' => array (
'id' => '2' ,
'parent_id' => '1' ,
'name' => 'Category 1.1'
),
'children' => array (
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ),
'children' => array ()))
),
array (
'Category' => array (
'id' => '3' ,
'parent_id' => '1' ,
'name' => 'Category 1.2'
),
'children' => array ()
)
)
),
array (
'Category' => array (
'id' => '4' ,
'parent_id' => '0' ,
'name' => 'Category 2'
),
'children' => array ()
),
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 ()
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array ( 'order' => 'id DESC' ));
$expected = array (
array (
'Category' => array (
'id' => 5 ,
'parent_id' => 0 ,
'name' => 'Category 3' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array (
array (
'Category' => array (
'id' => 6 ,
'parent_id' => 5 ,
'name' => 'Category 3.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
)
)
),
array (
'Category' => array (
'id' => 4 ,
'parent_id' => 0 ,
'name' => 'Category 2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
),
array (
'Category' => array (
'id' => 1 ,
'parent_id' => 0 ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array (
array (
'Category' => array (
'id' => 3 ,
'parent_id' => 1 ,
'name' => 'Category 1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
),
array (
'Category' => array (
'id' => 2 ,
'parent_id' => 1 ,
'name' => 'Category 1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array (
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()))
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'conditions' => array ( 'Category.name LIKE' => 'Category 3%' )
));
$expected = array (
array (
'Category' => array (
'id' => '5' ,
'parent_id' => '0' ,
'name' => 'Category 3' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array (
array (
'Category' => array (
'id' => '6' ,
'parent_id' => '5' ,
'name' => 'Category 3.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'children' => array ()
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'conditions' => array ( 'Category.name LIKE' => 'Category 1.1%' )
));
$expected = 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 (
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ),
'children' => array ()))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'fields' => 'id, parent_id, name' ,
'conditions' => array ( 'Category.id !=' => 2 )
));
$expected = array (
array (
'Category' => array (
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1'
),
'children' => array (
array (
'Category' => array (
'id' => '3' ,
'parent_id' => '1' ,
'name' => 'Category 1.2'
),
'children' => array ()
)
)
),
array (
'Category' => array (
'id' => '4' ,
'parent_id' => '0' ,
'name' => 'Category 2'
),
'children' => array ()
),
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 ()
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
'fields' => 'id, name, parent_id' ,
'conditions' => array ( 'Category.id !=' => 1 )
));
2011-12-01 07:21:31 +00:00
$expected = array (
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '2' ,
'name' => 'Category 1.1' ,
'parent_id' => '1'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '3' ,
'name' => 'Category 1.2' ,
'parent_id' => '1'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '4' ,
'name' => 'Category 2' ,
'parent_id' => '0'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '5' ,
'name' => 'Category 3' ,
'parent_id' => '0'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '6' ,
'name' => 'Category 3.1' ,
'parent_id' => '5'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '7' ,
'name' => 'Category 1.1.1' ,
'parent_id' => '2'
)),
2011-12-01 07:21:31 +00:00
array ( 'Category' => array (
2009-07-24 22:17:14 +00:00
'id' => '8' ,
'name' => 'Category 1.1.2' ,
'parent_id' => '2'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'threaded' , array (
'fields' => 'id, parent_id, name' ,
'conditions' => array ( 'Category.id !=' => 1 )
));
$expected = array (
array (
'Category' => array (
'id' => '2' ,
'parent_id' => '1' ,
'name' => 'Category 1.1'
),
'children' => array (
array ( 'Category' => array (
'id' => '7' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.1' ),
'children' => array ()),
array ( 'Category' => array (
'id' => '8' ,
'parent_id' => '2' ,
'name' => 'Category 1.1.2' ),
'children' => array ()))
),
array (
'Category' => array (
'id' => '3' ,
'parent_id' => '1' ,
'name' => 'Category 1.2'
),
'children' => array ()
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* test find ( 'neighbors' )
*
* @ return void
*/
2010-04-05 03:19:38 +00:00
public function testFindNeighbors () {
2011-02-23 05:13:56 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' , 'Tag' , 'ArticlesTag' , 'Attachment' );
2010-06-05 03:37:29 +00:00
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'fields' => array ( 'id' )));
2011-02-23 05:13:56 +00:00
$this -> assertNull ( $result [ 'prev' ]);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( array ( 'id' => 2 ), $result [ 'next' ][ 'Article' ]);
$this -> assertEquals ( 2 , count ( $result [ 'next' ][ 'Comment' ]));
$this -> assertEquals ( 2 , count ( $result [ 'next' ][ 'Tag' ]));
2009-07-24 22:17:14 +00:00
$TestModel -> id = 2 ;
2011-01-29 22:43:01 +00:00
$TestModel -> recursive = 0 ;
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'neighbors' , array (
'fields' => array ( 'id' )
));
$expected = array (
'prev' => array (
'Article' => array (
'id' => 1
)),
'next' => array (
'Article' => array (
'id' => 3
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 3 ;
2011-01-29 22:43:01 +00:00
$TestModel -> recursive = 1 ;
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'neighbors' , array ( 'fields' => array ( 'id' )));
2011-02-23 05:13:56 +00:00
$this -> assertNull ( $result [ 'next' ]);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( array ( 'id' => 2 ), $result [ 'prev' ][ 'Article' ]);
$this -> assertEquals ( 2 , count ( $result [ 'prev' ][ 'Comment' ]));
$this -> assertEquals ( 2 , count ( $result [ 'prev' ][ 'Tag' ]));
2009-07-24 22:17:14 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => - 1 ));
$expected = array (
'prev' => null ,
'next' => 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'
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => - 1 ));
$expected = array (
'prev' => array (
'Article' => array (
'id' => 1 ,
'user_id' => 1 ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
),
'next' => array (
'Article' => array (
'id' => 3 ,
'user_id' => 1 ,
'title' => 'Third Article' ,
'body' => 'Third Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 3 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => - 1 ));
$expected = array (
'prev' => 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'
)
),
'next' => null
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 0 ;
$TestModel -> id = 1 ;
$one = $TestModel -> read ();
$TestModel -> id = 2 ;
$two = $TestModel -> read ();
$TestModel -> id = 3 ;
$three = $TestModel -> read ();
$TestModel -> id = 1 ;
$result = $TestModel -> find ( 'neighbors' );
$expected = array ( 'prev' => null , 'next' => $two );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> find ( 'neighbors' );
$expected = array ( 'prev' => $one , 'next' => $three );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 3 ;
$result = $TestModel -> find ( 'neighbors' );
$expected = array ( 'prev' => $two , 'next' => null );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 2 ;
$TestModel -> id = 1 ;
$one = $TestModel -> read ();
$TestModel -> id = 2 ;
$two = $TestModel -> read ();
$TestModel -> id = 3 ;
$three = $TestModel -> read ();
$TestModel -> id = 1 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => 2 ));
$expected = array ( 'prev' => null , 'next' => $two );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => 2 ));
$expected = array ( 'prev' => $one , 'next' => $three );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 3 ;
$result = $TestModel -> find ( 'neighbors' , array ( 'recursive' => 2 ));
$expected = array ( 'prev' => $two , 'next' => null );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2012-08-02 03:05:48 +00:00
/**
* Test find ( neighbors ) with missing fields so no neighbors are found .
*
2013-07-05 15:19:22 +00:00
* @ return void
2012-08-02 03:05:48 +00:00
*/
public function testFindNeighborsNoPrev () {
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' , 'Tag' , 'ArticlesTag' , 'Attachment' );
$Article = new Article ();
$result = $Article -> find ( 'neighbors' , array (
'field' => 'Article.title' ,
'value' => 'Second Article' ,
'fields' => array ( 'id' ),
'conditions' => array (
'Article.title LIKE' => '%Article%'
),
'recursive' => 0 ,
));
$expected = array (
'prev' => null ,
'next' => null
);
$this -> assertEquals ( $expected , $result );
}
2013-07-05 15:19:22 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindCombinedRelations method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindCombinedRelations () {
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $this -> db instanceof Sqlserver , 'The test of testRecursiveUnbind test is not compatible with SQL Server, because it check for time columns.' );
2011-08-14 01:59:21 +00:00
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Apple' , 'Sample' );
2010-06-05 03:37:29 +00:00
$TestModel = new Apple ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' );
$expected = array (
array (
'Apple' => array (
'id' => '1' ,
'apple_id' => '2' ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '2' ,
'apple_id' => '1' ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => null ,
'apple_id' => null ,
'name' => null
),
'Child' => array (
array (
'id' => '2' ,
'apple_id' => '1' ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => '2' ,
'apple_id' => '1' ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '1' ,
'apple_id' => '2' ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => '2' ,
'apple_id' => '2' ,
'name' => 'sample2'
),
'Child' => array (
array (
'id' => '1' ,
'apple_id' => '2' ,
'color' => 'Red 1' ,
'name' => 'Red Apple 1' ,
'created' => '2006-11-22 10:38:58' ,
'date' => '1951-01-04' ,
'modified' => '2006-12-01 13:31:26' ,
'mytime' => '22:57:17'
),
array (
'id' => '3' ,
'apple_id' => '2' ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
array (
'id' => '4' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => '3' ,
'apple_id' => '2' ,
'color' => 'blue green' ,
'name' => 'green blue' ,
'created' => '2006-12-25 05:13:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:24' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '2' ,
'apple_id' => '1' ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => '1' ,
'apple_id' => '3' ,
'name' => 'sample1'
),
'Child' => array ()
),
array (
'Apple' => array (
'id' => '4' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '2' ,
'apple_id' => '1' ,
'color' => 'Bright Red 1' ,
'name' => 'Bright Red Apple' ,
'created' => '2006-11-22 10:43:13' ,
'date' => '2014-01-01' ,
'modified' => '2006-11-30 18:38:10' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => '3' ,
'apple_id' => '4' ,
'name' => 'sample3'
),
'Child' => array (
array (
'id' => '6' ,
'apple_id' => '4' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => '5' ,
'apple_id' => '5' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '5' ,
'apple_id' => '5' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => '4' ,
'apple_id' => '5' ,
'name' => 'sample4'
),
'Child' => array (
array (
'id' => '5' ,
'apple_id' => '5' ,
'color' => 'Green' ,
'name' => 'Blue Green' ,
'created' => '2006-12-25 05:24:06' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:16' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => '6' ,
'apple_id' => '4' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '4' ,
'apple_id' => '2' ,
'color' => 'Blue Green' ,
'name' => 'Test Name' ,
'created' => '2006-12-25 05:23:36' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:23:36' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => null ,
'apple_id' => null ,
'name' => null
),
'Child' => array (
array (
'id' => '7' ,
'apple_id' => '6' ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
))),
array (
'Apple' => array (
'id' => '7' ,
'apple_id' => '6' ,
'color' => 'Some wierd color' ,
'name' => 'Some odd color' ,
'created' => '2006-12-25 05:34:21' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:34:21' ,
'mytime' => '22:57:17'
),
'Parent' => array (
'id' => '6' ,
'apple_id' => '4' ,
'color' => 'My new appleOrange' ,
'name' => 'My new apple' ,
'created' => '2006-12-25 05:29:39' ,
'date' => '2006-12-25' ,
'modified' => '2006-12-25 05:29:39' ,
'mytime' => '22:57:17'
),
'Sample' => array (
'id' => null ,
'apple_id' => null ,
'name' => null
),
'Child' => array ()
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testSaveEmpty method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testSaveEmpty () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Thread' );
2010-06-05 03:37:29 +00:00
$TestModel = new Thread ();
2009-07-24 22:17:14 +00:00
$data = array ();
$expected = $TestModel -> save ( $data );
$this -> assertFalse ( $expected );
}
/**
* testFindAllWithConditionInChildQuery
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAllWithConditionInChildQuery () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Basket' , 'FilmFile' );
2010-06-05 03:37:29 +00:00
$TestModel = new Basket ();
2009-07-24 22:17:14 +00:00
$recursive = 3 ;
2011-05-22 04:51:05 +00:00
$result = $TestModel -> find ( 'all' , compact ( 'recursive' ));
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'Basket' => array (
'id' => 1 ,
'type' => 'nonfile' ,
'name' => 'basket1' ,
'object_id' => 1 ,
'user_id' => 1 ,
),
'FilmFile' => array (
'id' => '' ,
'name' => '' ,
)
),
array (
'Basket' => array (
'id' => 2 ,
'type' => 'file' ,
'name' => 'basket2' ,
'object_id' => 2 ,
'user_id' => 1 ,
),
'FilmFile' => array (
'id' => 2 ,
'name' => 'two' ,
)
),
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
/**
* testFindAllWithConditionsHavingMixedDataTypes method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAllWithConditionsHavingMixedDataTypes () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' );
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'Article' => array (
'id' => 1 ,
'user_id' => 1 ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
),
array (
'Article' => array (
'id' => 2 ,
'user_id' => 3 ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
)
)
);
$conditions = array ( 'id' => array ( '1' , 2 ));
$recursive = - 1 ;
$order = 'Article.id ASC' ;
$result = $TestModel -> find ( 'all' , compact ( 'conditions' , 'recursive' , 'order' ));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $this -> db instanceof Postgres , 'The rest of testFindAllWithConditionsHavingMixedDataTypes test is not compatible with Postgres.' );
2009-07-24 22:17:14 +00:00
$conditions = array ( 'id' => array ( '1' , 2 , '3.0' ));
$order = 'Article.id ASC' ;
$result = $TestModel -> find ( 'all' , compact ( 'recursive' , 'conditions' , 'order' ));
$expected = array (
array (
'Article' => array (
'id' => 1 ,
'user_id' => 1 ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)
),
array (
'Article' => array (
'id' => 2 ,
'user_id' => 3 ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
)
),
array (
'Article' => array (
'id' => 3 ,
'user_id' => 1 ,
'title' => 'Third Article' ,
'body' => 'Third Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testBindUnbind method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testBindUnbind () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures (
'User' ,
'Comment' ,
'FeatureSet' ,
'DeviceType' ,
'DeviceTypeCategory' ,
'ExteriorTypeCategory' ,
'Device' ,
'Document' ,
'DocumentDirectory'
);
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> hasMany ;
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' , array (
2012-11-02 22:06:59 +00:00
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
2009-07-24 22:17:14 +00:00
));
$expected = array (
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'
))),
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'
))),
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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> resetAssociations ();
$result = $TestModel -> hasMany ;
2012-10-26 22:18:05 +00:00
$this -> assertSame ( array (), $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' , array (
2012-11-02 22:06:59 +00:00
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
2009-07-24 22:17:14 +00:00
));
$expected = array (
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'
))),
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'
))),
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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> hasMany ;
$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
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )));
$this -> assertTrue ( $result );
$result = $TestModel -> hasMany ;
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
2012-11-02 22:06:59 +00:00
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
2009-07-24 22:17:14 +00:00
));
$expected = array (
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' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
2012-11-02 22:06:59 +00:00
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
2009-07-24 22:17:14 +00:00
));
$expected = array (
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'
))),
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'
))),
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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )), false );
$this -> assertTrue ( $result );
2012-11-02 22:06:59 +00:00
$result = $TestModel -> find ( 'all' , array (
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
));
2009-07-24 22:17:14 +00:00
$expected = array (
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' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> hasMany ;
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array (
'Comment' => array ( 'className' => 'Comment' , 'conditions' => 'Comment.published = \'Y\'' )
)));
$this -> assertTrue ( $result );
2012-11-02 22:06:59 +00:00
$result = $TestModel -> find ( 'all' , array (
'fields' => 'User.id, User.user' ,
'order' => array ( 'User.id' => 'ASC' ),
));
2009-07-24 22:17:14 +00:00
$expected = array (
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'
))),
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'
))),
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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel2 = new DeviceType ();
2009-07-24 22:17:14 +00:00
$expected = array (
'className' => 'FeatureSet' ,
'foreignKey' => 'feature_set_id' ,
'conditions' => '' ,
'fields' => '' ,
'order' => '' ,
'counterCache' => ''
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $TestModel2 -> belongsTo [ 'FeatureSet' ]);
2009-07-24 22:17:14 +00:00
2009-09-01 03:40:47 +00:00
$TestModel2 -> bindModel ( array (
'belongsTo' => array (
'FeatureSet' => array (
'className' => 'FeatureSet' ,
'conditions' => array ( 'active' => true )
)
)
2009-07-24 22:17:14 +00:00
));
$expected [ 'conditions' ] = array ( 'active' => true );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $TestModel2 -> belongsTo [ 'FeatureSet' ]);
2009-07-24 22:17:14 +00:00
2009-09-01 03:40:47 +00:00
$TestModel2 -> bindModel ( array (
'belongsTo' => array (
'FeatureSet' => array (
'className' => 'FeatureSet' ,
'foreignKey' => false ,
'conditions' => array ( 'Feature.name' => 'DeviceType.name' )
)
)
2009-07-24 22:17:14 +00:00
));
$expected [ 'conditions' ] = array ( 'Feature.name' => 'DeviceType.name' );
$expected [ 'foreignKey' ] = false ;
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $TestModel2 -> belongsTo [ 'FeatureSet' ]);
2009-07-24 22:17:14 +00:00
2009-09-01 03:40:47 +00:00
$TestModel2 -> bindModel ( array (
'hasMany' => array (
'NewFeatureSet' => array (
'className' => 'FeatureSet' ,
'conditions' => array ( 'active' => true )
)
)
2009-07-24 22:17:14 +00:00
));
2009-09-01 03:40:47 +00:00
2009-07-24 22:17:14 +00:00
$expected = array (
'className' => 'FeatureSet' ,
'conditions' => array ( 'active' => true ),
'foreignKey' => 'device_type_id' ,
'fields' => '' ,
'order' => '' ,
'limit' => '' ,
'offset' => '' ,
'dependent' => '' ,
'exclusive' => '' ,
'finderQuery' => '' ,
'counterQuery' => ''
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $TestModel2 -> hasMany [ 'NewFeatureSet' ]);
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( is_object ( $TestModel2 -> NewFeatureSet ));
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testBindMultipleTimes method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testBindMultipleTimes () {
2010-07-14 21:28:12 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' , 'Tag' , 'ArticlesTag' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> hasMany ;
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array (
'hasMany' => array (
'Items' => array ( 'className' => 'Comment' )
)));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' , array (
'fields' => 'User.id, User.user'
));
2010-07-14 21:28:12 +00:00
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'User' => array (
'id' => '1' ,
'user' => 'mariano'
),
'Items' => 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'
))),
array (
'User' => array (
'id' => '2' ,
'user' => 'nate'
),
'Items' => array (
array (
'id' => '1' ,
'article_id' => '1' ,
'user_id' => '2' ,
'comment' => 'First Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:45:23' ,
'updated' => '2007-03-18 10:47:31'
),
array (
'id' => '6' ,
'article_id' => '2' ,
'user_id' => '2' ,
'comment' => 'Second Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:55:23' ,
'updated' => '2007-03-18 10:57:31'
))),
array (
'User' => array (
'id' => '3' ,
'user' => 'larry'
),
'Items' => array ()
),
array (
'User' => array (
2010-07-14 21:28:12 +00:00
'id' => '4' ,
'user' => 'garrett'
),
2009-07-24 22:17:14 +00:00
'Items' => 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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array (
'hasMany' => array (
'Items' => array ( 'className' => 'Article' )
)));
$this -> assertTrue ( $result );
$result = $TestModel -> find ( 'all' , array (
'fields' => 'User.id, User.user'
));
$expected = array (
array (
'User' => array (
'id' => '1' ,
'user' => 'mariano'
),
'Items' => array (
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'
))),
array (
'User' => array (
'id' => '2' ,
'user' => 'nate'
),
'Items' => array ()
),
array (
'User' => array (
'id' => '3' ,
'user' => 'larry'
),
'Items' => array (
array (
'id' => 2 ,
'user_id' => 3 ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
))),
array (
'User' => array (
'id' => '4' ,
'user' => 'garrett'
),
'Items' => array ()
));
2010-07-14 21:28:12 +00:00
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2010-07-03 22:05:14 +00:00
/**
* test that multiple reset = true calls to bindModel () result in the original associations .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testBindModelMultipleTimesResetCorrectly () {
2010-07-03 22:05:14 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' );
2010-11-13 04:05:44 +00:00
$TestModel = new User ();
2010-07-03 22:05:14 +00:00
$TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )));
$TestModel -> bindModel ( array ( 'hasMany' => array ( 'Comment' )));
$TestModel -> resetAssociations ();
$this -> assertFalse ( isset ( $TestModel -> hasMany [ 'Comment' ]), 'Association left behind' );
}
2010-07-01 16:39:50 +00:00
/**
* testBindMultipleTimes method with different reset settings
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testBindMultipleTimesWithDifferentResetSettings () {
2010-07-01 16:39:50 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' );
2010-11-13 04:05:44 +00:00
$TestModel = new User ();
2010-07-01 16:39:50 +00:00
$result = $TestModel -> hasMany ;
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-01 16:39:50 +00:00
$result = $TestModel -> bindModel ( array (
'hasMany' => array ( 'Comment' )
));
$this -> assertTrue ( $result );
$result = $TestModel -> bindModel (
array ( 'hasMany' => array ( 'Article' )),
false
);
$this -> assertTrue ( $result );
$result = array_keys ( $TestModel -> hasMany );
$expected = array ( 'Comment' , 'Article' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-01 16:39:50 +00:00
$TestModel -> resetAssociations ();
$result = array_keys ( $TestModel -> hasMany );
$expected = array ( 'Article' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-01 16:39:50 +00:00
}
2009-07-24 22:17:14 +00:00
/**
* test that bindModel behaves with Custom primary Key associations
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2011-10-02 02:38:20 +00:00
public function testBindWithCustomPrimaryKey () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Story' , 'StoriesTag' , 'Tag' );
2010-06-05 03:37:29 +00:00
$Model = ClassRegistry :: init ( 'StoriesTag' );
2009-07-24 22:17:14 +00:00
$Model -> bindModel ( array (
'belongsTo' => array (
'Tag' => array (
'className' => 'Tag' ,
'foreignKey' => 'story'
))));
$result = $Model -> find ( 'all' );
$this -> assertFalse ( empty ( $result ));
}
2010-07-03 22:05:14 +00:00
/**
2011-01-29 22:43:01 +00:00
* test that calling unbindModel () with reset == true multiple times
2010-07-03 22:05:14 +00:00
* leaves associations in the correct state .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testUnbindMultipleTimesResetCorrectly () {
2010-07-03 22:05:14 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' );
2010-11-13 04:05:44 +00:00
$TestModel = new Article10 ();
2010-07-03 22:05:14 +00:00
$TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )));
$TestModel -> unbindModel ( array ( 'hasMany' => array ( 'Comment' )));
$TestModel -> resetAssociations ();
$this -> assertTrue ( isset ( $TestModel -> hasMany [ 'Comment' ]), 'Association permanently removed' );
}
/**
* testBindMultipleTimes method with different reset settings
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testUnBindMultipleTimesWithDifferentResetSettings () {
2010-07-03 22:05:14 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' );
2010-11-13 04:05:44 +00:00
$TestModel = new Comment ();
2010-07-03 22:05:14 +00:00
$result = array_keys ( $TestModel -> belongsTo );
$expected = array ( 'Article' , 'User' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-03 22:05:14 +00:00
$result = $TestModel -> unbindModel ( array (
'belongsTo' => array ( 'User' )
));
$this -> assertTrue ( $result );
$result = $TestModel -> unbindModel (
array ( 'belongsTo' => array ( 'Article' )),
false
);
$this -> assertTrue ( $result );
$result = array_keys ( $TestModel -> belongsTo );
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-03 22:05:14 +00:00
$TestModel -> resetAssociations ();
$result = array_keys ( $TestModel -> belongsTo );
$expected = array ( 'User' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-03 22:05:14 +00:00
}
2009-07-24 22:17:14 +00:00
/**
* testAssociationAfterFind method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testAssociationAfterFind () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' );
2010-06-05 03:37:29 +00:00
$TestModel = new Post ();
2012-10-25 01:25:44 +00:00
$result = $TestModel -> find ( 'all' , array (
'order' => array ( 'Post.id' => 'ASC' )
));
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'Post' => array (
'id' => '1' ,
'author_id' => '1' ,
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'Author' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31' ,
'test' => 'working'
)),
array (
'Post' => array (
'id' => '2' ,
'author_id' => '3' ,
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'Author' => array (
'id' => '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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
unset ( $TestModel );
2010-06-05 03:37:29 +00:00
$Author = new Author ();
2009-07-24 22:17:14 +00:00
$Author -> Post -> bindModel ( array (
'hasMany' => array (
'Comment' => array (
'className' => 'ModifiedComment' ,
'foreignKey' => 'article_id' ,
)
)));
$result = $Author -> find ( 'all' , array (
'conditions' => array ( 'Author.id' => 1 ),
2012-10-28 20:11:07 +00:00
'order' => array ( 'Author.id' => 'ASC' ),
2009-07-24 22:17:14 +00:00
'recursive' => 2
));
$expected = 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' ,
'callback' => 'Fire'
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $result [ 0 ][ 'Post' ][ 0 ][ 'Comment' ][ 0 ]);
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2012-04-04 14:18:37 +00:00
/**
* testDeeperAssociationAfterFind method
*
* @ return void
*/
public function testDeeperAssociationAfterFind () {
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' , 'Attachment' , 'Article' );
$Post = new Post ();
$Post -> bindModel ( array (
'hasMany' => array (
'Comment' => array (
'className' => 'ModifiedComment' ,
'foreignKey' => 'article_id' ,
)
)));
$Post -> Comment -> bindModel ( array (
'hasOne' => array (
'Attachment' => array (
'className' => 'ModifiedAttachment' ,
)
)));
$result = $Post -> find ( 'first' , array (
'conditions' => array ( 'Post.id' => 2 ),
'recursive' => 2
));
$this -> assertTrue ( isset ( $result [ 'Comment' ][ 0 ][ 'callback' ]));
$this -> assertEquals ( 'Fire' , $result [ 'Comment' ][ 0 ][ 'callback' ]);
$this -> assertTrue ( isset ( $result [ 'Comment' ][ 0 ][ 'Attachment' ][ 'callback' ]));
$this -> assertEquals ( 'Fired' , $result [ 'Comment' ][ 0 ][ 'Attachment' ][ 'callback' ]);
}
2009-07-24 22:17:14 +00:00
/**
* Tests that callbacks can be properly disabled
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCallbackDisabling () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Author' );
$TestModel = new ModifiedAuthor ();
2012-04-04 23:33:57 +00:00
$result = Hash :: extract ( $TestModel -> find ( 'all' ), '{n}.Author.user' );
2009-07-24 22:17:14 +00:00
$expected = array ( 'mariano (CakePHP)' , 'nate (CakePHP)' , 'larry (CakePHP)' , 'garrett (CakePHP)' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-04-04 23:33:57 +00:00
$result = Hash :: extract ( $TestModel -> find ( 'all' , array ( 'callbacks' => 'after' )), '{n}.Author.user' );
2009-07-24 22:17:14 +00:00
$expected = array ( 'mariano (CakePHP)' , 'nate (CakePHP)' , 'larry (CakePHP)' , 'garrett (CakePHP)' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-04-04 23:33:57 +00:00
$result = Hash :: extract ( $TestModel -> find ( 'all' , array ( 'callbacks' => 'before' )), '{n}.Author.user' );
2009-07-24 22:17:14 +00:00
$expected = array ( 'mariano' , 'nate' , 'larry' , 'garrett' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-04-04 23:33:57 +00:00
$result = Hash :: extract ( $TestModel -> find ( 'all' , array ( 'callbacks' => false )), '{n}.Author.user' );
2009-07-24 22:17:14 +00:00
$expected = array ( 'mariano' , 'nate' , 'larry' , 'garrett' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2011-10-23 19:03:29 +00:00
/**
* testAssociationAfterFindCallbacksDisabled method
*
* @ return void
*/
public function testAssociationAfterFindCalbacksDisabled () {
$this -> loadFixtures ( 'Post' , 'Author' , 'Comment' );
$TestModel = new Post ();
2012-11-03 00:46:05 +00:00
$result = $TestModel -> find ( 'all' , array (
'callbacks' => false ,
'order' => array ( 'Post.id' => 'ASC' ),
));
2011-10-23 19:03:29 +00:00
$expected = array (
array (
'Post' => array (
'id' => '1' ,
'author_id' => '1' ,
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'Author' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
)),
array (
'Post' => array (
'id' => '2' ,
'author_id' => '3' ,
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'Author' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
)),
array (
'Post' => array (
'id' => '3' ,
'author_id' => '1' ,
'title' => 'Third Post' ,
'body' => 'Third Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
),
'Author' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2011-10-23 19:03:29 +00:00
unset ( $TestModel );
$Author = new Author ();
$Author -> Post -> bindModel ( array (
'hasMany' => array (
'Comment' => array (
'className' => 'ModifiedComment' ,
'foreignKey' => 'article_id' ,
)
)));
$result = $Author -> find ( 'all' , array (
'conditions' => array ( 'Author.id' => 1 ),
'recursive' => 2 ,
2012-11-03 05:51:39 +00:00
'order' => array ( 'Author.id' => 'ASC' ),
2011-10-23 19:03:29 +00:00
'callbacks' => false
));
$expected = 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'
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $result [ 0 ][ 'Post' ][ 0 ][ 'Comment' ][ 0 ]);
2011-10-23 19:03:29 +00:00
}
2009-10-05 02:12:13 +00:00
/**
* Tests that the database configuration assigned to the model can be changed using
* ( before | after ) Find callbacks
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testCallbackSourceChange () {
2009-09-10 13:28:55 +00:00
$this -> loadFixtures ( 'Post' );
$TestModel = new Post ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( 3 , count ( $TestModel -> find ( 'all' )));
2011-09-10 16:23:28 +00:00
}
2009-09-10 13:28:55 +00:00
2011-09-10 16:23:28 +00:00
/**
* testCallbackSourceChangeUnknownDatasource method
*
* @ expectedException MissingDatasourceConfigException
* @ return void
*/
public function testCallbackSourceChangeUnknownDatasource () {
2011-12-26 17:36:48 +00:00
$this -> loadFixtures ( 'Post' , 'Author' );
2011-09-10 16:23:28 +00:00
$TestModel = new Post ();
2009-09-10 13:28:55 +00:00
$this -> assertFalse ( $TestModel -> find ( 'all' , array ( 'connection' => 'foo' )));
}
2009-07-24 22:17:14 +00:00
/**
* testMultipleBelongsToWithSameClass method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testMultipleBelongsToWithSameClass () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures (
'DeviceType' ,
'DeviceTypeCategory' ,
'FeatureSet' ,
'ExteriorTypeCategory' ,
'Document' ,
'Device' ,
'DocumentDirectory'
);
2010-06-05 03:37:29 +00:00
$DeviceType = new DeviceType ();
2009-07-24 22:17:14 +00:00
$DeviceType -> recursive = 2 ;
$result = $DeviceType -> read ( null , 1 );
$expected = array (
'DeviceType' => array (
'id' => 1 ,
'device_type_category_id' => 1 ,
'feature_set_id' => 1 ,
'exterior_type_category_id' => 1 ,
'image_id' => 1 ,
'extra1_id' => 1 ,
'extra2_id' => 1 ,
'name' => 'DeviceType 1' ,
'order' => 0
),
'Image' => array (
'id' => 1 ,
'document_directory_id' => 1 ,
'name' => 'Document 1' ,
'DocumentDirectory' => array (
'id' => 1 ,
'name' => 'DocumentDirectory 1'
)),
'Extra1' => array (
'id' => 1 ,
'document_directory_id' => 1 ,
'name' => 'Document 1' ,
'DocumentDirectory' => array (
'id' => 1 ,
'name' => 'DocumentDirectory 1'
)),
'Extra2' => array (
'id' => 1 ,
'document_directory_id' => 1 ,
'name' => 'Document 1' ,
'DocumentDirectory' => array (
'id' => 1 ,
'name' => 'DocumentDirectory 1'
)),
'DeviceTypeCategory' => array (
'id' => 1 ,
'name' => 'DeviceTypeCategory 1'
),
'FeatureSet' => array (
'id' => 1 ,
'name' => 'FeatureSet 1'
),
'ExteriorTypeCategory' => array (
'id' => 1 ,
'image_id' => 1 ,
'name' => 'ExteriorTypeCategory 1' ,
'Image' => array (
'id' => 1 ,
'device_type_id' => 1 ,
'name' => 'Device 1' ,
'typ' => 1
)),
'Device' => array (
array (
'id' => 1 ,
'device_type_id' => 1 ,
'name' => 'Device 1' ,
'typ' => 1
),
array (
'id' => 2 ,
'device_type_id' => 1 ,
'name' => 'Device 2' ,
'typ' => 1
),
array (
'id' => 3 ,
'device_type_id' => 1 ,
'name' => 'Device 3' ,
'typ' => 2
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testHabtmRecursiveBelongsTo method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testHabtmRecursiveBelongsTo () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Portfolio' , 'Item' , 'ItemsPortfolio' , 'Syfile' , 'Image' );
2010-06-05 03:37:29 +00:00
$Portfolio = new Portfolio ();
2009-07-24 22:17:14 +00:00
2011-02-26 00:26:35 +00:00
$result = $Portfolio -> find ( 'first' , array ( 'conditions' => array ( 'id' => 2 ), 'recursive' => 3 ));
2009-07-24 22:17:14 +00:00
$expected = array (
'Portfolio' => array (
'id' => 2 ,
'seller_id' => 1 ,
'name' => 'Portfolio 2'
),
'Item' => array (
array (
'id' => 2 ,
'syfile_id' => 2 ,
2011-01-02 02:37:27 +00:00
'published' => false ,
2009-07-24 22:17:14 +00:00
'name' => 'Item 2' ,
'ItemsPortfolio' => array (
'id' => 2 ,
'item_id' => 2 ,
'portfolio_id' => 2
),
'Syfile' => array (
'id' => 2 ,
'image_id' => 2 ,
'name' => 'Syfile 2' ,
'item_count' => null ,
'Image' => array (
'id' => 2 ,
'name' => 'Image 2'
)
)),
array (
'id' => 6 ,
'syfile_id' => 6 ,
2011-01-02 02:37:27 +00:00
'published' => false ,
2009-07-24 22:17:14 +00:00
'name' => 'Item 6' ,
'ItemsPortfolio' => array (
'id' => 6 ,
'item_id' => 6 ,
'portfolio_id' => 2
),
'Syfile' => array (
'id' => 6 ,
'image_id' => null ,
'name' => 'Syfile 6' ,
'item_count' => null ,
'Image' => array ()
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2010-06-05 03:37:29 +00:00
/**
* testNonNumericHabtmJoinKey method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testNonNumericHabtmJoinKey () {
2010-06-05 03:37:29 +00:00
$this -> loadFixtures ( 'Post' , 'Tag' , 'PostsTag' , 'Author' );
$Post = new Post ();
$Post -> bindModel ( array (
'hasAndBelongsToMany' => array ( 'Tag' )
));
$Post -> Tag -> primaryKey = 'tag' ;
2012-10-25 01:25:44 +00:00
$result = $Post -> find ( 'all' , array (
2012-11-22 02:52:23 +00:00
'order' => 'Post.id ASC' ,
2012-10-25 01:25:44 +00:00
));
2010-06-05 03:37:29 +00:00
$expected = array (
array (
'Post' => array (
'id' => '1' ,
'author_id' => '1' ,
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'Author' => array (
'id' => 1 ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31' ,
'test' => 'working'
),
'Tag' => array (
array (
'id' => '1' ,
'tag' => 'tag1' ,
'created' => '2007-03-18 12:22:23' ,
'updated' => '2007-03-18 12:24:31'
),
array (
'id' => '2' ,
'tag' => 'tag2' ,
'created' => '2007-03-18 12:24:23' ,
'updated' => '2007-03-18 12:26:31'
))),
array (
'Post' => array (
'id' => '2' ,
'author_id' => '3' ,
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'Author' => array (
'id' => 3 ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31' ,
'test' => 'working'
),
'Tag' => array (
array (
'id' => '1' ,
'tag' => 'tag1' ,
'created' => '2007-03-18 12:22:23' ,
'updated' => '2007-03-18 12:24:31'
),
array (
'id' => '3' ,
'tag' => 'tag3' ,
'created' => '2007-03-18 12:26:23' ,
'updated' => '2007-03-18 12:28:31'
))),
array (
'Post' => array (
'id' => '3' ,
'author_id' => '1' ,
'title' => 'Third Post' ,
'body' => 'Third Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
),
'Author' => array (
'id' => 1 ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31' ,
'test' => 'working'
),
'Tag' => array ()
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-06-05 03:37:29 +00:00
}
2009-07-24 22:17:14 +00:00
/**
* testHabtmFinderQuery method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testHabtmFinderQuery () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Article' , 'Tag' , 'ArticlesTag' );
2010-06-05 03:37:29 +00:00
$Article = new Article ();
2009-07-24 22:17:14 +00:00
$sql = $this -> db -> buildStatement (
array (
'fields' => $this -> db -> fields ( $Article -> Tag , null , array (
'Tag.id' , 'Tag.tag' , 'ArticlesTag.article_id' , 'ArticlesTag.tag_id'
)),
'table' => $this -> db -> fullTableName ( 'tags' ),
'alias' => 'Tag' ,
'limit' => null ,
'offset' => null ,
'group' => null ,
'joins' => array ( array (
'alias' => 'ArticlesTag' ,
2011-09-25 02:05:22 +00:00
'table' => 'articles_tags' ,
2009-07-24 22:17:14 +00:00
'conditions' => array (
array ( " ArticlesTag.article_id " => '{$__cakeID__$}' ),
array ( " ArticlesTag.tag_id " => $this -> db -> identifier ( 'Tag.id' ))
)
)),
'conditions' => array (),
'order' => null
),
$Article
);
$Article -> hasAndBelongsToMany [ 'Tag' ][ 'finderQuery' ] = $sql ;
$result = $Article -> find ( 'first' );
$expected = array (
array (
'id' => '1' ,
'tag' => 'tag1'
),
array (
'id' => '2' ,
'tag' => 'tag2'
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $result [ 'Tag' ]);
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testHabtmLimitOptimization method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testHabtmLimitOptimization () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Comment' , 'Tag' , 'ArticlesTag' );
2010-06-05 03:37:29 +00:00
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$TestModel -> hasAndBelongsToMany [ 'Tag' ][ 'limit' ] = 2 ;
$result = $TestModel -> read ( null , 2 );
$expected = array (
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
),
'Comment' => array (
array (
'id' => '5' ,
'article_id' => '2' ,
'user_id' => '1' ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31'
),
array (
'id' => '6' ,
'article_id' => '2' ,
'user_id' => '2' ,
'comment' => 'Second Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:55:23' ,
'updated' => '2007-03-18 10:57:31'
)),
'Tag' => array (
array (
'id' => '1' ,
'tag' => 'tag1' ,
'created' => '2007-03-18 12:22:23' ,
'updated' => '2007-03-18 12:24:31'
),
array (
'id' => '3' ,
'tag' => 'tag3' ,
'created' => '2007-03-18 12:26:23' ,
'updated' => '2007-03-18 12:28:31'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> hasAndBelongsToMany [ 'Tag' ][ 'limit' ] = 1 ;
$result = $TestModel -> read ( null , 2 );
unset ( $expected [ 'Tag' ][ 1 ]);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testHasManyLimitOptimization method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testHasManyLimitOptimization () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Project' , 'Thread' , 'Message' , 'Bid' );
2010-06-05 03:37:29 +00:00
$Project = new Project ();
2009-07-24 22:17:14 +00:00
$Project -> recursive = 3 ;
2012-11-22 02:52:23 +00:00
$result = $Project -> find ( 'all' , array (
'order' => 'Project.id ASC' ,
));
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'Project' => array (
'id' => 1 ,
'name' => 'Project 1'
),
'Thread' => array (
array (
'id' => 1 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 1' ,
'Project' => array (
'id' => 1 ,
'name' => 'Project 1' ,
'Thread' => array (
array (
'id' => 1 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 1'
),
array (
'id' => 2 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 2'
))),
'Message' => array (
array (
'id' => 1 ,
'thread_id' => 1 ,
'name' => 'Thread 1, Message 1' ,
'Bid' => array (
'id' => 1 ,
'message_id' => 1 ,
'name' => 'Bid 1.1'
)))),
array (
'id' => 2 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 2' ,
'Project' => array (
'id' => 1 ,
'name' => 'Project 1' ,
'Thread' => array (
array (
'id' => 1 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 1'
),
array (
'id' => 2 ,
'project_id' => 1 ,
'name' => 'Project 1, Thread 2'
))),
'Message' => array (
array (
'id' => 2 ,
'thread_id' => 2 ,
'name' => 'Thread 2, Message 1' ,
'Bid' => array (
'id' => 4 ,
'message_id' => 2 ,
'name' => 'Bid 2.1'
)))))),
array (
'Project' => array (
'id' => 2 ,
'name' => 'Project 2'
),
'Thread' => array (
array (
'id' => 3 ,
'project_id' => 2 ,
'name' => 'Project 2, Thread 1' ,
'Project' => array (
'id' => 2 ,
'name' => 'Project 2' ,
'Thread' => array (
array (
'id' => 3 ,
'project_id' => 2 ,
'name' => 'Project 2, Thread 1'
))),
'Message' => array (
array (
'id' => 3 ,
'thread_id' => 3 ,
'name' => 'Thread 3, Message 1' ,
'Bid' => array (
'id' => 3 ,
'message_id' => 3 ,
'name' => 'Bid 3.1'
)))))),
array (
'Project' => array (
'id' => 3 ,
'name' => 'Project 3'
),
'Thread' => array ()
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindAllRecursiveSelfJoin method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAllRecursiveSelfJoin () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Home' , 'AnotherArticle' , 'Advertisement' );
2010-06-05 03:37:29 +00:00
$TestModel = new Home ();
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 2 ;
2012-11-22 02:52:23 +00:00
$result = $TestModel -> find ( 'all' , array (
'order' => 'Home.id ASC' ,
));
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'Home' => array (
'id' => '1' ,
'another_article_id' => '1' ,
'advertisement_id' => '1' ,
'title' => 'First Home' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'AnotherArticle' => array (
'id' => '1' ,
'title' => 'First Article' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
'Home' => array (
array (
'id' => '1' ,
'another_article_id' => '1' ,
'advertisement_id' => '1' ,
'title' => 'First Home' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
))),
'Advertisement' => array (
'id' => '1' ,
'title' => 'First Ad' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
'Home' => array (
array (
'id' => '1' ,
'another_article_id' => '1' ,
'advertisement_id' => '1' ,
'title' => 'First Home' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
array (
'id' => '2' ,
'another_article_id' => '3' ,
'advertisement_id' => '1' ,
'title' => 'Second Home' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
)))),
array (
'Home' => array (
'id' => '2' ,
'another_article_id' => '3' ,
'advertisement_id' => '1' ,
'title' => 'Second Home' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'AnotherArticle' => array (
'id' => '3' ,
'title' => 'Third Article' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
'Home' => array (
array (
'id' => '2' ,
'another_article_id' => '3' ,
'advertisement_id' => '1' ,
'title' => 'Second Home' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
))),
'Advertisement' => array (
'id' => '1' ,
'title' => 'First Ad' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
'Home' => array (
array (
'id' => '1' ,
'another_article_id' => '1' ,
'advertisement_id' => '1' ,
'title' => 'First Home' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
array (
'id' => '2' ,
'another_article_id' => '3' ,
'advertisement_id' => '1' ,
'title' => 'Second Home' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
)))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-08-02 22:59:54 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindAllRecursiveWithHabtm method
*
* @ return void
*/
2010-04-05 03:19:38 +00:00
public function testFindAllRecursiveWithHabtm () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures (
'MyCategoriesMyUsers' ,
'MyCategoriesMyProducts' ,
'MyCategory' ,
'MyUser' ,
'MyProduct'
);
2010-06-05 03:37:29 +00:00
$MyUser = new MyUser ();
2009-07-24 22:17:14 +00:00
$MyUser -> recursive = 2 ;
2012-11-22 02:52:23 +00:00
$result = $MyUser -> find ( 'all' , array (
'order' => 'MyUser.id ASC'
));
2009-07-24 22:17:14 +00:00
$expected = array (
array (
'MyUser' => array ( 'id' => '1' , 'firstname' => 'userA' ),
'MyCategory' => array (
array (
'id' => '1' ,
'name' => 'A' ,
'MyProduct' => array (
array (
'id' => '1' ,
'name' => 'book'
))),
array (
'id' => '3' ,
'name' => 'C' ,
'MyProduct' => array (
array (
'id' => '2' ,
'name' => 'computer'
))))),
array (
'MyUser' => array (
'id' => '2' ,
'firstname' => 'userB'
),
'MyCategory' => array (
array (
'id' => '1' ,
'name' => 'A' ,
'MyProduct' => array (
array (
'id' => '1' ,
'name' => 'book'
))),
array (
'id' => '2' ,
'name' => 'B' ,
'MyProduct' => array (
array (
'id' => '1' ,
'name' => 'book'
),
array (
'id' => '2' ,
'name' => 'computer'
))))));
2011-05-16 22:49:00 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testReadFakeThread method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testReadFakeThread () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2010-06-05 03:37:29 +00:00
$TestModel = new CategoryThread ();
2009-07-24 22:17:14 +00:00
$fullDebug = $this -> db -> fullDebug ;
$this -> db -> fullDebug = true ;
$TestModel -> recursive = 6 ;
$TestModel -> id = 7 ;
$result = $TestModel -> 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 -> db -> fullDebug = $fullDebug ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindFakeThread method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindFakeThread () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2010-06-05 03:37:29 +00:00
$TestModel = new CategoryThread ();
2009-07-24 22:17:14 +00:00
$fullDebug = $this -> db -> fullDebug ;
$this -> db -> fullDebug = true ;
$TestModel -> recursive = 6 ;
2011-02-26 00:26:35 +00:00
$result = $TestModel -> find ( 'first' , array ( 'conditions' => array ( 'CategoryThread.id' => 7 )));
2009-07-24 22:17:14 +00:00
$expected = array (
'CategoryThread' => array (
'id' => 7 ,
'parent_id' => 6 ,
'name' => 'Category 2.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
),
'ParentCategory' => array (
'id' => 6 ,
'parent_id' => 5 ,
'name' => 'Category 2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array (
'id' => 5 ,
'parent_id' => 4 ,
'name' => 'Category 1.1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array (
'id' => 4 ,
'parent_id' => 3 ,
'name' => 'Category 1.1.2' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array (
'id' => 3 ,
'parent_id' => 2 ,
'name' => 'Category 1.1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array (
'id' => 2 ,
'parent_id' => 1 ,
'name' => 'Category 1.1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31' ,
'ParentCategory' => array (
'id' => 1 ,
'parent_id' => 0 ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
)))))));
$this -> db -> fullDebug = $fullDebug ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindAllFakeThread method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAllFakeThread () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'CategoryThread' );
2010-06-05 03:37:29 +00:00
$TestModel = new CategoryThread ();
2009-07-24 22:17:14 +00:00
$fullDebug = $this -> db -> fullDebug ;
$this -> db -> fullDebug = true ;
$TestModel -> recursive = 6 ;
2012-11-22 02:52:23 +00:00
$result = $TestModel -> find ( 'all' );
2009-07-24 22:17:14 +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 ,
'ParentCategory' => array ()
)),
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' ,
'ParentCategory' => array ()
)),
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' ,
'ParentCategory' => array ()
))),
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' ,
'ParentCategory' => array ()
)))),
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' ,
'ParentCategory' => array ()
))))),
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' ,
'ParentCategory' => array ()
)))))),
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 -> db -> fullDebug = $fullDebug ;
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testConditionalNumerics method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testConditionalNumerics () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'NumericArticle' );
2010-06-05 03:37:29 +00:00
$NumericArticle = new NumericArticle ();
2011-02-26 00:26:35 +00:00
$data = array ( 'conditions' => array ( 'title' => '12345abcde' ));
$result = $NumericArticle -> find ( 'first' , $data );
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( ! empty ( $result ));
2011-02-26 00:26:35 +00:00
$data = array ( 'conditions' => array ( 'title' => '12345' ));
$result = $NumericArticle -> find ( 'first' , $data );
2009-07-24 22:17:14 +00:00
$this -> assertTrue ( empty ( $result ));
}
2011-07-11 22:54:24 +00:00
/**
2011-07-12 21:31:07 +00:00
* test buildQuery ()
2011-07-11 22:54:24 +00:00
*
* @ return void
*/
2011-07-12 21:31:07 +00:00
public function testBuildQuery () {
2011-07-11 22:54:24 +00:00
$this -> loadFixtures ( 'User' );
$TestModel = new User ();
$TestModel -> cacheQueries = false ;
2013-07-19 20:31:09 +00:00
$TestModel -> order = null ;
2011-07-11 22:54:24 +00:00
$expected = array (
'conditions' => array (
2012-03-19 01:20:17 +00:00
'user' => 'larry'
),
'fields' => null ,
2011-12-01 07:21:31 +00:00
'joins' => array (),
2012-03-19 01:20:17 +00:00
'limit' => null ,
'offset' => null ,
2015-09-22 12:21:04 +00:00
'order' => array (),
2011-07-11 22:54:24 +00:00
'page' => 1 ,
2012-03-19 01:20:17 +00:00
'group' => null ,
2011-07-11 22:54:24 +00:00
'callbacks' => true ,
2012-03-19 01:20:17 +00:00
'returnQuery' => true
);
2011-07-12 21:31:07 +00:00
$result = $TestModel -> buildQuery ( 'all' , array ( 'returnQuery' => true , 'conditions' => array ( 'user' => 'larry' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2011-07-11 22:54:24 +00:00
}
2009-07-24 22:17:14 +00:00
/**
* test find ( 'all' ) method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindAll () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'User' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$TestModel -> cacheQueries = false ;
$result = $TestModel -> find ( 'all' );
$expected = array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'conditions' => 'User.id > 2' ));
$expected = array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'User.id !=' => '0' , 'User.user LIKE' => '%arr%' )
));
$expected = array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'conditions' => array ( 'User.id' => '0' )));
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'or' => array ( 'User.id' => '0' , 'User.user LIKE' => '%a%' )
)));
$expected = array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.id, User.user' ));
$expected = array (
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' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.user' , 'order' => 'User.user ASC' ));
$expected = array (
array ( 'User' => array ( 'user' => 'garrett' )),
array ( 'User' => array ( 'user' => 'larry' )),
array ( 'User' => array ( 'user' => 'mariano' )),
array ( 'User' => array ( 'user' => 'nate' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'fields' => 'User.user' , 'order' => 'User.user DESC' ));
$expected = array (
array ( 'User' => array ( 'user' => 'nate' )),
array ( 'User' => array ( 'user' => 'mariano' )),
array ( 'User' => array ( 'user' => 'larry' )),
array ( 'User' => array ( 'user' => 'garrett' )));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'limit' => 3 , 'page' => 1 ));
$expected = array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$ids = array ( 4 => 1 , 5 => 3 );
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'User.id' => $ids ),
'order' => 'User.id'
));
$expected = array (
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' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
// These tests are expected to fail on SQL Server since the LIMIT/OFFSET
// hack can't handle small record counts.
2011-05-23 03:19:13 +00:00
if ( ! ( $this -> db instanceof Sqlserver )) {
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'limit' => 3 , 'page' => 2 ));
$expected = array (
array (
'User' => array (
'id' => '4' ,
'user' => 'garrett' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:22:23' ,
'updated' => '2007-03-17 01:24:31'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'limit' => 3 , 'page' => 3 ));
$expected = array ();
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
}
2009-07-26 09:59:51 +00:00
2014-10-09 23:56:00 +00:00
/**
* Test that find () with array conditions works when there is only one element .
*
* @ return void
*/
public function testFindAllArrayConditions () {
$this -> loadFixtures ( 'User' );
$TestModel = new User ();
$TestModel -> cacheQueries = false ;
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'User.id' => array ( 3 )),
));
$expected = array (
array (
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
))
);
$this -> assertEquals ( $expected , $result );
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'User.user' => array ( 'larry' )),
));
$this -> assertEquals ( $expected , $result );
}
2009-07-24 22:17:14 +00:00
/**
* test find ( 'list' ) method
*
* @ return void
*/
2014-10-09 23:56:00 +00:00
public function testFindList () {
2011-01-06 03:14:32 +00:00
$this -> loadFixtures ( 'Article' , 'Apple' , 'Post' , 'Author' , 'User' , 'Comment' );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$TestModel -> displayField = 'title' ;
$result = $TestModel -> find ( 'list' , array (
'order' => 'Article.title ASC'
));
$expected = array (
1 => 'First Article' ,
2 => 'Second Article' ,
3 => 'Third Article'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2010-09-20 02:58:30 +00:00
$db = ConnectionManager :: getDataSource ( 'test' );
2011-01-06 03:14:32 +00:00
if ( $db instanceof Mysql ) {
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'order' => array ( 'FIELD(Article.id, 3, 2) ASC' , 'Article.title ASC' )
));
$expected = array (
1 => 'First Article' ,
3 => 'Third Article' ,
2 => 'Second Article'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2012-03-11 01:57:18 +00:00
$result = Hash :: combine (
2009-07-24 22:17:14 +00:00
$TestModel -> find ( 'all' , array (
'order' => 'Article.title ASC' ,
'fields' => array ( 'id' , 'title' )
)),
'{n}.Article.id' , '{n}.Article.title'
);
$expected = array (
1 => 'First Article' ,
2 => 'Second Article' ,
3 => 'Third Article'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-03-11 01:57:18 +00:00
$result = Hash :: combine (
2009-07-24 22:17:14 +00:00
$TestModel -> find ( 'all' , array (
'order' => 'Article.title ASC'
)),
'{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'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-03-11 01:57:18 +00:00
$result = Hash :: combine (
2009-07-24 22:17:14 +00:00
$TestModel -> find ( 'all' , array (
'order' => 'Article.title ASC'
)),
'{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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2012-03-11 01:57:18 +00:00
$result = Hash :: combine (
2009-07-24 22:17:14 +00:00
$TestModel -> find ( 'all' , array (
'order' => 'Article.title ASC' ,
'fields' => array ( 'id' , 'title' , 'user_id' )
)),
'{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'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new Apple ();
2009-07-24 22:17:14 +00:00
$expected = array (
1 => 'Red Apple 1' ,
2 => 'Bright Red Apple' ,
3 => 'green blue' ,
4 => 'Test Name' ,
5 => 'Blue Green' ,
6 => 'My new apple' ,
7 => 'Some odd color'
);
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expected , $TestModel -> find ( 'list' ));
$this -> assertEquals ( $expected , $TestModel -> Parent -> find ( 'list' ));
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new Post ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => 'Post.title'
));
$expected = array (
1 => 'First Post' ,
2 => 'Second Post' ,
3 => 'Third Post'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => 'title'
));
$expected = array (
1 => 'First Post' ,
2 => 'Second Post' ,
3 => 'Third Post'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'title' , 'id' )
));
$expected = array (
'First Post' => '1' ,
'Second Post' => '2' ,
'Third Post' => '3'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'title' , 'id' , 'created' )
));
$expected = array (
'2007-03-18 10:39:23' => array (
'First Post' => '1'
),
'2007-03-18 10:41:23' => array (
'Second Post' => '2'
),
'2007-03-18 10:43:23' => array (
'Third Post' => '3'
),
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'Post.body' )
));
$expected = array (
1 => 'First Post Body' ,
2 => 'Second Post Body' ,
3 => 'Third Post Body'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'Post.title' , 'Post.body' )
));
$expected = array (
'First Post' => 'First Post Body' ,
'Second Post' => 'Second Post Body' ,
'Third Post' => 'Third Post Body'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'Post.id' , 'Post.title' , 'Author.user' ),
'recursive' => 1
));
$expected = array (
'mariano' => array (
1 => 'First Post' ,
3 => 'Third Post'
),
'larry' => array (
2 => 'Second Post'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'User.user' , 'User.password' )
));
$expected = array (
'mariano' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'nate' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'larry' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'garrett' => '5f4dcc3b5aa765d61d8327deb882cf99'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new ModifiedAuthor ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'Author.id' , 'Author.user' )
));
$expected = array (
1 => 'mariano (CakePHP)' ,
2 => 'nate (CakePHP)' ,
3 => 'larry (CakePHP)' ,
4 => 'garrett (CakePHP)'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2010-07-11 22:38:27 +00:00
2010-11-13 04:05:44 +00:00
$TestModel = new Article ();
2010-07-11 22:38:27 +00:00
$TestModel -> displayField = 'title' ;
$result = $TestModel -> find ( 'list' , array (
'conditions' => array ( 'User.user' => 'mariano' ),
'recursive' => 0
));
$expected = array (
1 => 'First Article' ,
3 => 'Third Article'
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2017-03-15 19:58:54 +00:00
/**
* test find ( 'list' ) method
*
* @ return void
*/
2017-03-16 01:33:19 +00:00
public function testFindListZeroValue () {
2017-03-15 19:58:54 +00:00
$this -> loadFixtures ( 'Article' );
$model = new Article ();
$model -> displayField = 'title' ;
$model -> save ( array (
'title' => 'Zeroth Article' ,
'user_id' => 0 ,
'published' => 'Y'
));
$result = $model -> find ( 'list' , array (
2017-03-16 01:33:19 +00:00
'fields' => array ( 'title' , 'user_id' )
2017-03-15 19:58:54 +00:00
));
$expected = array (
2017-03-16 01:33:19 +00:00
'Zeroth Article' => 0 ,
'First Article' => 1 ,
'Second Article' => 3 ,
'Third Article' => 1 ,
2017-03-15 19:58:54 +00:00
);
$this -> assertEquals ( $expected , $result );
}
2014-10-09 23:56:00 +00:00
/**
* Test that find ( list ) works with array conditions that have only one element .
*
* @ return void
*/
public function testFindListArrayCondition () {
$this -> loadFixtures ( 'User' );
$TestModel = new User ();
$TestModel -> cacheQueries = false ;
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'id' , 'user' ),
'conditions' => array ( 'User.id' => array ( 3 )),
));
$expected = array (
3 => 'larry'
);
$this -> assertEquals ( $expected , $result );
$result = $TestModel -> find ( 'list' , array (
'fields' => array ( 'id' , 'user' ),
'conditions' => array ( 'User.user' => array ( 'larry' )),
));
$this -> assertEquals ( $expected , $result );
}
2009-07-24 22:17:14 +00:00
/**
* testFindField method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindField () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'User' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$TestModel -> id = 1 ;
$result = $TestModel -> field ( 'user' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'mariano' , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> field ( 'User.user' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'mariano' , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = false ;
$result = $TestModel -> field ( 'user' , array (
'user' => 'mariano'
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'mariano' , $result );
2013-07-19 20:31:09 +00:00
$TestModel -> order = null ;
2009-07-24 22:17:14 +00:00
$result = $TestModel -> field ( 'COUNT(*) AS count' , true );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> field ( 'COUNT(*)' , true );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindUnique method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindUnique () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'User' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$this -> assertFalse ( $TestModel -> isUnique ( array (
'user' => 'nate'
)));
$TestModel -> id = 2 ;
$this -> assertTrue ( $TestModel -> isUnique ( array (
'user' => 'nate'
)));
$this -> assertFalse ( $TestModel -> isUnique ( array (
'user' => 'nate' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99'
)));
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* test find ( 'count' ) method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindCount () {
2011-09-03 17:37:29 +00:00
$this -> loadFixtures ( 'User' , 'Article' , 'Comment' , 'Tag' , 'ArticlesTag' );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
$this -> db -> getLog ( false , true );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'count' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2009-07-24 22:17:14 +00:00
2011-09-03 17:37:29 +00:00
$this -> db -> getLog ( false , true );
2009-07-24 22:17:14 +00:00
$fullDebug = $this -> db -> fullDebug ;
$this -> db -> fullDebug = true ;
$TestModel -> order = 'User.id' ;
$result = $TestModel -> find ( 'count' );
2012-02-16 18:28:21 +00:00
$this -> db -> fullDebug = $fullDebug ;
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2009-07-24 22:17:14 +00:00
2010-06-05 03:37:29 +00:00
$log = $this -> db -> getLog ();
$this -> assertTrue ( isset ( $log [ 'log' ][ 0 ][ 'query' ]));
2011-11-16 00:07:56 +00:00
$this -> assertNotRegExp ( '/ORDER\s+BY/' , $log [ 'log' ][ 0 ][ 'query' ]);
2011-08-14 01:59:21 +00:00
$Article = new Article ();
2013-07-19 20:31:09 +00:00
$Article -> order = null ;
2011-09-27 21:28:48 +00:00
$Article -> recursive = - 1 ;
2011-10-01 13:08:12 +00:00
$expected = count ( $Article -> find ( 'all' , array (
'fields' => array ( 'Article.user_id' ),
'group' => 'Article.user_id' )
));
$result = $Article -> find ( 'count' , array ( 'group' => array ( 'Article.user_id' )));
2011-09-27 21:28:48 +00:00
$this -> assertEquals ( $expected , $result );
2012-10-09 05:13:27 +00:00
$expected = count ( $Article -> find ( 'all' , array (
'fields' => array ( 'Article.user_id' ),
'conditions' => array ( 'Article.user_id' => 1 ),
'group' => 'Article.user_id' )
));
$result = $Article -> find ( 'count' , array (
'conditions' => array ( 'Article.user_id' => 1 ),
'group' => array ( 'Article.user_id' ),
));
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2010-02-27 16:32:29 +00:00
/**
* Test that find ( 'first' ) does not use the id set to the object .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindFirstNoIdUsed () {
2010-02-27 16:32:29 +00:00
$this -> loadFixtures ( 'Project' );
2010-06-05 03:37:29 +00:00
$Project = new Project ();
2010-02-27 16:32:29 +00:00
$Project -> id = 3 ;
$result = $Project -> find ( 'first' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'Project 1' , $result [ 'Project' ][ 'name' ], 'Wrong record retrieved' );
2010-02-27 16:32:29 +00:00
}
2009-07-24 22:17:14 +00:00
/**
* test find with COUNT ( DISTINCT field )
*
* @ return void
2009-11-14 12:19:25 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testFindCountDistinct () {
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $this -> db instanceof Sqlite , 'SELECT COUNT(DISTINCT field) is not compatible with SQLite.' );
2011-05-23 03:19:13 +00:00
$this -> skipIf ( $this -> db instanceof Sqlserver , 'This test is not compatible with SQL Server.' );
2011-05-22 04:51:05 +00:00
2012-10-09 05:13:27 +00:00
$this -> loadFixtures ( 'Project' , 'Thread' );
2010-06-05 03:37:29 +00:00
$TestModel = new Project ();
2009-07-24 22:17:14 +00:00
$TestModel -> create ( array ( 'name' => 'project' )) && $TestModel -> save ();
$TestModel -> create ( array ( 'name' => 'project' )) && $TestModel -> save ();
$TestModel -> create ( array ( 'name' => 'project' )) && $TestModel -> save ();
$result = $TestModel -> find ( 'count' , array ( 'fields' => 'DISTINCT name' ));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* Test find ( count ) with Db :: expression
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindCountWithDbExpressions () {
2011-05-31 00:49:46 +00:00
$this -> skipIf ( $this -> db instanceof Postgres , 'testFindCountWithDbExpressions is not compatible with Postgres.' );
2011-09-03 17:37:29 +00:00
$this -> loadFixtures ( 'Project' , 'Thread' );
2010-09-20 02:58:30 +00:00
$db = ConnectionManager :: getDataSource ( 'test' );
2010-06-05 03:37:29 +00:00
$TestModel = new Project ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'count' , array ( 'conditions' => array (
$db -> expression ( 'Project.name = \'Project 3\'' )
)));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 1 , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'count' , array ( 'conditions' => array (
'Project.name' => $db -> expression ( '\'Project 3\'' )
)));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 1 , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testFindMagic method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testFindMagic () {
2015-11-11 13:43:19 +00:00
$this -> loadFixtures ( 'User' , 'Comment' , 'Article' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> findByUser ( 'mariano' );
$expected = array (
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> findByPassword ( '5f4dcc3b5aa765d61d8327deb882cf99' );
$expected = array ( 'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2015-11-11 13:43:19 +00:00
$Comment = new Comment ();
$Comment -> recursive = - 1 ;
$results = $Comment -> findAllByUserId ( 1 );
$expected = array (
array (
'Comment' => array (
'id' => 3 ,
'article_id' => 1 ,
'user_id' => 1 ,
'comment' => 'Third Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:49:23' ,
'updated' => '2007-03-18 10:51:31'
)
),
array (
'Comment' => array (
'id' => 4 ,
'article_id' => 1 ,
'user_id' => 1 ,
'comment' => 'Fourth Comment for First Article' ,
'published' => 'N' ,
'created' => '2007-03-18 10:51:23' ,
'updated' => '2007-03-18 10:53:31'
)
),
array (
'Comment' => array (
'id' => 5 ,
'article_id' => 2 ,
'user_id' => 1 ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31'
)
)
);
$this -> assertEquals ( $expected , $results );
$results = $Comment -> findAllByUserIdAndPublished ( 1 , 'Y' );
$expected = array (
array (
'Comment' => array (
'id' => 3 ,
'article_id' => 1 ,
'user_id' => 1 ,
'comment' => 'Third Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:49:23' ,
'updated' => '2007-03-18 10:51:31'
)
),
array (
'Comment' => array (
'id' => 5 ,
'article_id' => 2 ,
'user_id' => 1 ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31'
)
)
);
$this -> assertEquals ( $expected , $results );
$Article = new CustomArticle ();
$Article -> recursive = - 1 ;
$results = $Article -> findListByUserId ( 1 );
$expected = array (
1 => 'First Article' ,
3 => 'Third Article'
);
$this -> assertEquals ( $expected , $results );
$results = $Article -> findPublishedByUserId ( 1 );
$expected = array (
array (
'CustomArticle' => 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 (
'CustomArticle' => 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 -> assertEquals ( $expected , $results );
$results = $Article -> findUnPublishedByUserId ( 1 );
$expected = array ();
$this -> assertEquals ( $expected , $results );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testRead method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testRead () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'User' , 'Article' );
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> read ();
$this -> assertFalse ( $result );
$TestModel -> id = 2 ;
$result = $TestModel -> read ();
$expected = array (
'User' => array (
'id' => '2' ,
'user' => 'nate' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:18:23' ,
'updated' => '2007-03-17 01:20:31'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> read ( null , 2 );
$expected = array (
'User' => array (
'id' => '2' ,
'user' => 'nate' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:18:23' ,
'updated' => '2007-03-17 01:20:31'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> id = 2 ;
$result = $TestModel -> read ( array ( 'id' , 'user' ));
$expected = array ( 'User' => array ( 'id' => '2' , 'user' => 'nate' ));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> read ( 'id, user' , 2 );
$expected = array (
'User' => array (
'id' => '2' ,
'user' => 'nate'
));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Article' )));
$this -> assertTrue ( $result );
$TestModel -> id = 1 ;
$result = $TestModel -> read ( 'id, user' );
$expected = array (
'User' => array (
'id' => '1' ,
'user' => 'mariano'
),
'Article' => array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testRecursiveRead method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testRecursiveRead () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures (
'User' ,
'Article' ,
'Comment' ,
'Tag' ,
'ArticlesTag' ,
'Featured' ,
'ArticleFeatured'
);
2010-06-05 03:37:29 +00:00
$TestModel = new User ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> bindModel ( array ( 'hasMany' => array ( 'Article' )), false );
$this -> assertTrue ( $result );
$TestModel -> recursive = 0 ;
$result = $TestModel -> read ( 'id, user' , 1 );
$expected = array (
'User' => array ( 'id' => '1' , 'user' => 'mariano' ),
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 1 ;
$result = $TestModel -> read ( 'id, user' , 1 );
$expected = array (
'User' => array (
'id' => '1' ,
'user' => 'mariano'
),
'Article' => array (
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'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> recursive = 2 ;
$result = $TestModel -> read ( 'id, user' , 3 );
$expected = array (
'User' => array (
'id' => '3' ,
'user' => 'larry'
),
'Article' => array (
array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
),
'Comment' => array (
array (
'id' => '5' ,
'article_id' => '2' ,
'user_id' => '1' ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31'
),
array (
'id' => '6' ,
'article_id' => '2' ,
'user_id' => '2' ,
'comment' => 'Second Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:55:23' ,
'updated' => '2007-03-18 10:57:31'
)),
'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'
)))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2011-05-30 20:02:32 +00:00
public function testRecursiveFindAll () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures (
'User' ,
'Article' ,
'Comment' ,
'Tag' ,
'ArticlesTag' ,
'Attachment' ,
'ArticleFeatured' ,
2010-06-05 03:37:29 +00:00
'ArticleFeaturedsTags' ,
2009-07-24 22:17:14 +00:00
'Featured' ,
'Category'
);
2010-06-05 03:37:29 +00:00
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array ( 'conditions' => array ( 'Article.user_id' => 1 )));
$expected = array (
array (
'Article' => array (
'id' => '1' ,
'user_id' => '1' ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array (
array (
'id' => '1' ,
'article_id' => '1' ,
'user_id' => '2' ,
'comment' => 'First Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:45:23' ,
'updated' => '2007-03-18 10:47:31'
),
array (
'id' => '2' ,
'article_id' => '1' ,
'user_id' => '4' ,
'comment' => 'Second Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:47:23' ,
'updated' => '2007-03-18 10:49:31'
),
array (
'id' => '3' ,
'article_id' => '1' ,
'user_id' => '1' ,
'comment' => 'Third Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:49:23' ,
'updated' => '2007-03-18 10:51:31'
),
array (
'id' => '4' ,
'article_id' => '1' ,
'user_id' => '1' ,
'comment' => 'Fourth Comment for First Article' ,
'published' => 'N' ,
'created' => '2007-03-18 10:51:23' ,
'updated' => '2007-03-18 10:53:31'
)
),
'Tag' => array (
array (
'id' => '1' ,
'tag' => 'tag1' ,
'created' => '2007-03-18 12:22:23' ,
'updated' => '2007-03-18 12:24:31'
),
array (
'id' => '2' ,
'tag' => 'tag2' ,
'created' => '2007-03-18 12:24:23' ,
'updated' => '2007-03-18 12:26:31'
))),
array (
'Article' => array (
'id' => '3' ,
'user_id' => '1' ,
'title' => 'Third Article' ,
'body' => 'Third Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array (),
'Tag' => array ()
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'Article.user_id' => 3 ),
'limit' => 1 ,
'recursive' => 2
));
$expected = array (
array (
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
),
'Comment' => array (
array (
'id' => '5' ,
'article_id' => '2' ,
'user_id' => '1' ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31' ,
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Attachment' => array (
'id' => '1' ,
'comment_id' => 5 ,
'attachment' => 'attachment.zip' ,
'created' => '2007-03-18 10:51:23' ,
'updated' => '2007-03-18 10:53:31'
)
),
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' ,
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '2' ,
'user' => 'nate' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:18:23' ,
'updated' => '2007-03-17 01:20:31'
),
2010-06-05 03:37:29 +00:00
'Attachment' => array ()
2009-07-24 22:17:14 +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'
))));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$Featured = new Featured ();
$Featured -> recursive = 2 ;
$Featured -> bindModel ( array (
'belongsTo' => array (
'ArticleFeatured' => array (
'conditions' => " ArticleFeatured.published = 'Y' " ,
'fields' => 'id, title, user_id, published'
)
)
));
$Featured -> ArticleFeatured -> unbindModel ( array (
'hasMany' => array ( 'Attachment' , 'Comment' ),
'hasAndBelongsToMany' => array ( 'Tag' ))
);
$orderBy = 'ArticleFeatured.id ASC' ;
$result = $Featured -> find ( 'all' , array (
'order' => $orderBy , 'limit' => 3
));
$expected = array (
array (
'Featured' => array (
'id' => '1' ,
'article_featured_id' => '1' ,
'category_id' => '1' ,
'published_date' => '2007-03-31 10:39:23' ,
'end_date' => '2007-05-15 10:39:23' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'ArticleFeatured' => array (
'id' => '1' ,
'title' => 'First Article' ,
'user_id' => '1' ,
'published' => 'Y' ,
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Category' => array (),
'Featured' => array (
'id' => '1' ,
'article_featured_id' => '1' ,
'category_id' => '1' ,
'published_date' => '2007-03-31 10:39:23' ,
'end_date' => '2007-05-15 10:39:23' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)),
'Category' => array (
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
)),
array (
'Featured' => array (
'id' => '2' ,
'article_featured_id' => '2' ,
'category_id' => '1' ,
'published_date' => '2007-03-31 10:39:23' ,
'end_date' => '2007-05-15 10:39:23' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'ArticleFeatured' => array (
'id' => '2' ,
'title' => 'Second Article' ,
'user_id' => '3' ,
'published' => 'Y' ,
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
),
'Category' => array (),
'Featured' => array (
'id' => '2' ,
'article_featured_id' => '2' ,
'category_id' => '1' ,
'published_date' => '2007-03-31 10:39:23' ,
'end_date' => '2007-05-15 10:39:23' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
)),
'Category' => array (
'id' => '1' ,
'parent_id' => '0' ,
'name' => 'Category 1' ,
'created' => '2007-03-18 15:30:23' ,
'updated' => '2007-03-18 15:32:31'
)));
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2009-07-26 09:59:51 +00:00
2009-07-24 22:17:14 +00:00
/**
* testRecursiveFindAllWithLimit method
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testRecursiveFindAllWithLimit () {
2009-07-24 22:17:14 +00:00
$this -> loadFixtures ( 'Article' , 'User' , 'Tag' , 'ArticlesTag' , 'Comment' , 'Attachment' );
2010-06-05 03:37:29 +00:00
$TestModel = new Article ();
2009-07-24 22:17:14 +00:00
$TestModel -> hasMany [ 'Comment' ][ 'limit' ] = 2 ;
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'Article.user_id' => 1 )
));
$expected = array (
array (
'Article' => array (
'id' => '1' ,
'user_id' => '1' ,
'title' => 'First Article' ,
'body' => 'First Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array (
array (
'id' => '1' ,
'article_id' => '1' ,
'user_id' => '2' ,
'comment' => 'First Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:45:23' ,
'updated' => '2007-03-18 10:47:31'
),
array (
'id' => '2' ,
'article_id' => '1' ,
'user_id' => '4' ,
'comment' => 'Second Comment for First Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:47:23' ,
'updated' => '2007-03-18 10:49:31'
),
),
'Tag' => array (
array (
'id' => '1' ,
'tag' => 'tag1' ,
'created' => '2007-03-18 12:22:23' ,
'updated' => '2007-03-18 12:24:31'
),
array (
'id' => '2' ,
'tag' => 'tag2' ,
'created' => '2007-03-18 12:24:23' ,
'updated' => '2007-03-18 12:26:31'
))),
array (
'Article' => array (
'id' => '3' ,
'user_id' => '1' ,
'title' => 'Third Article' ,
'body' => 'Third Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Comment' => array (),
'Tag' => array ()
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
$TestModel -> hasMany [ 'Comment' ][ 'limit' ] = 1 ;
$result = $TestModel -> find ( 'all' , array (
'conditions' => array ( 'Article.user_id' => 3 ),
'limit' => 1 ,
'recursive' => 2
));
$expected = array (
array (
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '3' ,
'user' => 'larry' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:20:23' ,
'updated' => '2007-03-17 01:22:31'
),
'Comment' => array (
array (
'id' => '5' ,
'article_id' => '2' ,
'user_id' => '1' ,
'comment' => 'First Comment for Second Article' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:53:23' ,
'updated' => '2007-03-18 10:55:31' ,
'Article' => array (
'id' => '2' ,
'user_id' => '3' ,
'title' => 'Second Article' ,
'body' => 'Second Article Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
),
'User' => array (
'id' => '1' ,
'user' => 'mariano' ,
'password' => '5f4dcc3b5aa765d61d8327deb882cf99' ,
'created' => '2007-03-17 01:16:23' ,
'updated' => '2007-03-17 01:18:31'
),
'Attachment' => array (
'id' => '1' ,
'comment_id' => 5 ,
'attachment' => 'attachment.zip' ,
'created' => '2007-03-18 10:51:23' ,
'updated' => '2007-03-18 10:53:31'
)
)
),
'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'
)
)
)
);
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $expected , $result );
2009-07-24 22:17:14 +00:00
}
2011-12-06 20:52:48 +00:00
2009-11-01 14:08:39 +00:00
/**
* Testing availability of $this -> findQueryType in Model callbacks
2010-01-20 20:12:54 +00:00
*
* @ return void
2009-11-01 14:08:39 +00:00
*/
2011-05-30 20:02:32 +00:00
public function testFindQueryTypeInCallbacks () {
2009-11-01 14:08:39 +00:00
$this -> loadFixtures ( 'Comment' );
2010-06-05 03:37:29 +00:00
$Comment = new AgainModifiedComment ();
2009-11-01 14:08:39 +00:00
$comments = $Comment -> find ( 'all' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'all' , $comments [ 0 ][ 'Comment' ][ 'querytype' ]);
2009-11-01 14:08:39 +00:00
$comments = $Comment -> find ( 'first' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 'first' , $comments [ 'Comment' ][ 'querytype' ]);
2009-11-01 14:08:39 +00:00
}
2009-12-11 00:43:09 +00:00
/**
* testVirtualFields ()
*
* Test correct fetching of virtual fields
* currently is not possible to do Relation . virtualField
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testVirtualFields () {
2010-01-19 14:22:13 +00:00
$this -> loadFixtures ( 'Post' , 'Author' );
2010-06-05 03:37:29 +00:00
$Post = ClassRegistry :: init ( 'Post' );
2010-01-15 04:38:24 +00:00
$Post -> virtualFields = array ( 'two' => " 1 + 1 " );
$result = $Post -> find ( 'first' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2010-01-15 04:38:24 +00:00
2011-05-18 18:12:36 +00:00
// SQL Server does not support operators in expressions
2011-05-23 03:19:13 +00:00
if ( ! ( $this -> db instanceof Sqlserver )) {
2011-05-18 18:12:36 +00:00
$Post -> Author -> virtualFields = array ( 'false' => '1 = 2' );
$result = $Post -> find ( 'first' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2011-05-18 18:12:36 +00:00
$this -> assertFalse (( bool ) $result [ 'Author' ][ 'false' ]);
}
2010-01-15 04:38:24 +00:00
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array ( 'fields' => array ( 'author_id' )));
2010-01-15 04:38:24 +00:00
$this -> assertFalse ( isset ( $result [ 'Post' ][ 'two' ]));
$this -> assertFalse ( isset ( $result [ 'Author' ][ 'false' ]));
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array ( 'fields' => array ( 'author_id' , 'two' )));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2010-01-15 04:38:24 +00:00
$this -> assertFalse ( isset ( $result [ 'Author' ][ 'false' ]));
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array ( 'fields' => array ( 'two' )));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2010-01-15 04:38:24 +00:00
$Post -> id = 1 ;
$result = $Post -> field ( 'two' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result );
2010-01-15 04:38:24 +00:00
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array (
2010-01-15 04:38:24 +00:00
'conditions' => array ( 'two' => 2 ),
'limit' => 1
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2009-12-11 01:16:55 +00:00
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array (
2010-01-15 04:38:24 +00:00
'conditions' => array ( 'two <' => 3 ),
'limit' => 1
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2009-12-11 01:16:55 +00:00
2013-05-17 08:36:17 +00:00
$result = $Post -> find ( 'first' , array (
2010-01-15 04:38:24 +00:00
'conditions' => array ( 'NOT' => array ( 'two >' => 3 )),
'limit' => 1
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'two' ]);
2009-12-11 01:16:55 +00:00
2010-06-05 03:37:29 +00:00
$dbo = $Post -> getDataSource ();
2010-01-15 04:38:24 +00:00
$Post -> virtualFields = array ( 'other_field' => 'Post.id + 1' );
2010-05-30 16:51:48 +00:00
$result = $Post -> find ( 'first' , array (
2010-01-15 04:38:24 +00:00
'conditions' => array ( 'other_field' => 3 ),
'limit' => 1
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Post' ][ 'id' ]);
2013-07-19 20:31:09 +00:00
$Post -> order = null ;
2009-12-11 01:16:55 +00:00
2010-01-15 04:38:24 +00:00
$Post -> virtualFields = array ( 'other_field' => 'Post.id + 1' );
2010-05-31 00:28:00 +00:00
$result = $Post -> find ( 'all' , array (
2010-05-30 16:51:48 +00:00
'fields' => array ( $dbo -> calculate ( $Post , 'max' , array ( 'other_field' )))
2010-01-15 04:38:24 +00:00
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result [ 0 ][ 0 ][ 'other_field' ]);
2010-01-15 04:38:24 +00:00
ClassRegistry :: flush ();
2013-04-22 09:36:17 +00:00
$Writing = ClassRegistry :: init ( array ( 'class' => 'Post' , 'alias' => 'Writing' ));
2010-01-15 04:38:24 +00:00
$Writing -> virtualFields = array ( 'two' => " 1 + 1 " );
$result = $Writing -> find ( 'first' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 2 , $result [ 'Writing' ][ 'two' ]);
2010-01-19 14:22:13 +00:00
2010-01-15 04:38:24 +00:00
$Post -> create ();
$Post -> virtualFields = array ( 'other_field' => 'COUNT(Post.id) + 1' );
$result = $Post -> field ( 'other_field' );
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( 4 , $result );
2011-01-02 02:37:27 +00:00
}
2010-01-09 19:29:49 +00:00
2015-05-21 02:22:38 +00:00
/**
* Test virtualfields that contain subqueries get correctly
* quoted allowing reserved words to be used .
*
* @ return void
*/
public function testVirtualFieldSubqueryReservedWords () {
$this -> loadFixtures ( 'User' );
$user = ClassRegistry :: init ( 'User' );
$user -> cacheMethods = false ;
$ds = $user -> getDataSource ();
$sub = $ds -> buildStatement (
array (
'fields' => array ( 'Table.user' ),
'table' => $ds -> fullTableName ( $user ),
'alias' => 'Table' ,
'limit' => 1 ,
'conditions' => array (
" Table.id > 1 "
)
),
$user
);
$user -> virtualFields = array (
'sub_test' => $sub
);
2015-05-22 01:58:12 +00:00
$result = $user -> find ( 'first' );
2015-05-21 02:22:38 +00:00
$this -> assertNotEmpty ( $result );
}
2011-11-14 00:34:49 +00:00
/**
* testVirtualFieldsOrder ()
*
* Test correct order on virtual fields
*
* @ return void
*/
public function testVirtualFieldsOrder () {
$this -> loadFixtures ( 'Post' , 'Author' );
$Post = ClassRegistry :: init ( 'Post' );
$Post -> virtualFields = array ( 'other_field' => '10 - Post.id' );
$result = $Post -> find ( 'list' , array ( 'order' => array ( 'Post.other_field' => 'ASC' )));
$expected = array (
'3' => 'Third Post' ,
'2' => 'Second Post' ,
'1' => 'First Post'
);
2011-12-13 04:35:31 +00:00
$this -> assertEquals ( $expected , $result );
2011-11-14 00:34:49 +00:00
$result = $Post -> find ( 'list' , array ( 'order' => array ( 'Post.other_field' => 'DESC' )));
$expected = array (
'1' => 'First Post' ,
'2' => 'Second Post' ,
'3' => 'Third Post'
);
2011-12-13 04:35:31 +00:00
$this -> assertEquals ( $expected , $result );
2011-11-14 00:34:49 +00:00
$Post -> Author -> virtualFields = array ( 'joined' => 'Post.id * Author.id' );
2012-10-29 01:16:50 +00:00
$result = $Post -> find ( 'all' , array (
'order' => array ( 'Post.id' => 'ASC' )
));
2012-03-11 01:57:18 +00:00
$result = Hash :: extract ( $result , '{n}.Author.joined' );
2011-11-14 00:34:49 +00:00
$expected = array ( 1 , 6 , 3 );
2011-12-13 04:35:31 +00:00
$this -> assertEquals ( $expected , $result );
2011-11-14 00:34:49 +00:00
$result = $Post -> find ( 'all' , array ( 'order' => array ( 'Author.joined' => 'ASC' )));
2012-03-11 01:57:18 +00:00
$result = Hash :: extract ( $result , '{n}.Author.joined' );
2011-11-14 00:34:49 +00:00
$expected = array ( 1 , 3 , 6 );
2011-12-13 04:35:31 +00:00
$this -> assertEquals ( $expected , $result );
2011-11-14 00:34:49 +00:00
$result = $Post -> find ( 'all' , array ( 'order' => array ( 'Author.joined' => 'DESC' )));
2012-03-11 01:57:18 +00:00
$result = Hash :: extract ( $result , '{n}.Author.joined' );
2011-11-14 00:34:49 +00:00
$expected = array ( 6 , 3 , 1 );
2011-12-13 04:35:31 +00:00
$this -> assertEquals ( $expected , $result );
2011-11-14 00:34:49 +00:00
}
2011-01-02 02:37:27 +00:00
/**
* testVirtualFieldsMysql ()
*
* Test correct fetching of virtual fields
* currently is not possible to do Relation . virtualField
*
2014-04-02 01:02:37 +00:00
* @ return void
2011-01-02 02:37:27 +00:00
*/
public function testVirtualFieldsMysql () {
2012-02-23 23:29:53 +00:00
$this -> skipIf ( ! ( $this -> db instanceof Mysql ), 'The rest of virtualFields test only compatible with Mysql.' );
2011-05-31 00:49:46 +00:00
2011-01-02 02:37:27 +00:00
$this -> loadFixtures ( 'Post' , 'Author' );
2010-06-05 03:37:29 +00:00
$Post = ClassRegistry :: init ( 'Post' );
2010-01-09 19:29:49 +00:00
2010-01-15 04:38:24 +00:00
$Post -> create ();
$Post -> virtualFields = array (
2010-11-27 04:16:34 +00:00
'low_title' => 'lower(Post.title)' ,
2010-01-15 04:38:24 +00:00
'unique_test_field' => 'COUNT(Post.id)'
);
2010-01-09 19:29:49 +00:00
2010-01-15 04:38:24 +00:00
$expectation = array (
'Post' => array (
2010-11-27 04:16:34 +00:00
'low_title' => 'first post' ,
'unique_test_field' => 1
2010-01-15 04:38:24 +00:00
)
);
$result = $Post -> find ( 'first' , array (
'fields' => array_keys ( $Post -> virtualFields ),
2010-11-27 04:16:34 +00:00
'group' => array ( 'low_title' )
2010-01-15 04:38:24 +00:00
));
2012-03-23 06:37:12 +00:00
$this -> assertEquals ( $expectation , $result );
2010-01-21 15:35:20 +00:00
2010-06-05 03:37:29 +00:00
$Author = ClassRegistry :: init ( 'Author' );
2010-01-21 15:35:20 +00:00
$Author -> virtualFields = array (
'full_name' => 'CONCAT(Author.user, " ", Author.id)'
);
$result = $Author -> find ( 'first' , array (
'conditions' => array ( 'Author.user' => 'mariano' ),
'fields' => array ( 'Author.password' , 'Author.full_name' ),
'recursive' => - 1
));
$this -> assertTrue ( isset ( $result [ 'Author' ][ 'full_name' ]));
$result = $Author -> find ( 'first' , array (
'conditions' => array ( 'Author.user' => 'mariano' ),
'fields' => array ( 'Author.full_name' , 'Author.password' ),
'recursive' => - 1
));
$this -> assertTrue ( isset ( $result [ 'Author' ][ 'full_name' ]));
2010-01-15 04:38:24 +00:00
}
2010-01-19 14:22:13 +00:00
2010-05-08 03:25:10 +00:00
/**
* test that virtual fields work when they don ' t contain functions .
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testVirtualFieldAsAString () {
2010-05-08 03:25:10 +00:00
$this -> loadFixtures ( 'Post' , 'Author' );
2010-06-05 03:37:29 +00:00
$Post = new Post ();
2010-05-08 03:25:10 +00:00
$Post -> virtualFields = array (
2011-12-19 13:18:28 +00:00
'writer' => 'Author.user'
2010-05-08 03:25:10 +00:00
);
$result = $Post -> find ( 'first' );
$this -> assertTrue ( isset ( $result [ 'Post' ][ 'writer' ]), 'virtual field not fetched %s' );
}
2010-01-19 14:22:13 +00:00
/**
* test that isVirtualField will accept both aliased and non aliased fieldnames
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testIsVirtualField () {
2010-01-19 14:22:13 +00:00
$this -> loadFixtures ( 'Post' );
2010-06-05 03:37:29 +00:00
$Post = ClassRegistry :: init ( 'Post' );
2010-01-19 14:22:13 +00:00
$Post -> virtualFields = array ( 'other_field' => 'COUNT(Post.id) + 1' );
$this -> assertTrue ( $Post -> isVirtualField ( 'other_field' ));
$this -> assertTrue ( $Post -> isVirtualField ( 'Post.other_field' ));
2011-10-04 02:41:31 +00:00
$this -> assertFalse ( $Post -> isVirtualField ( 'Comment.other_field' ), 'Other models should not match.' );
2010-01-19 14:22:13 +00:00
$this -> assertFalse ( $Post -> isVirtualField ( 'id' ));
$this -> assertFalse ( $Post -> isVirtualField ( 'Post.id' ));
$this -> assertFalse ( $Post -> isVirtualField ( array ()));
}
/**
* test that getting virtual fields works with and without model alias attached
*
* @ return void
*/
2011-05-30 20:02:32 +00:00
public function testGetVirtualField () {
2010-01-19 14:22:13 +00:00
$this -> loadFixtures ( 'Post' );
2010-06-05 03:37:29 +00:00
$Post = ClassRegistry :: init ( 'Post' );
2010-01-19 14:22:13 +00:00
$Post -> virtualFields = array ( 'other_field' => 'COUNT(Post.id) + 1' );
2011-11-16 00:07:56 +00:00
$this -> assertEquals ( $Post -> getVirtualField ( 'other_field' ), $Post -> virtualFields [ 'other_field' ]);
$this -> assertEquals ( $Post -> getVirtualField ( 'Post.other_field' ), $Post -> virtualFields [ 'other_field' ]);
2010-01-19 14:22:13 +00:00
}
2012-02-23 06:12:08 +00:00
2012-02-05 18:37:54 +00:00
/**
* test that checks for error when NOT condition passed in key and a 1 element array value
*
* @ return void
2012-02-23 06:12:08 +00:00
*/
2012-02-05 18:37:54 +00:00
public function testNotInArrayWithOneValue () {
$this -> loadFixtures ( 'Article' );
$Article = new Article ();
$Article -> recursive = - 1 ;
2012-02-23 06:12:08 +00:00
2012-02-05 18:37:54 +00:00
$result = $Article -> find (
'all' ,
array (
'conditions' => array (
'Article.id NOT' => array ( 1 )
)
)
);
$this -> assertTrue ( is_array ( $result ) && ! empty ( $result ));
2012-03-19 01:20:17 +00:00
}
2012-03-03 22:45:45 +00:00
2013-05-28 12:02:58 +00:00
/**
* test to assert that != in key together with a single element array will work
*
* @ return void
*/
public function testNotEqualsInArrayWithOneValue () {
$this -> loadFixtures ( 'Article' );
$Article = new Article ();
$Article -> recursive = - 1 ;
$result = $Article -> find (
'all' ,
array (
'conditions' => array (
'Article.id !=' => array ( 1 )
)
)
);
$this -> assertTrue ( is_array ( $result ) && ! empty ( $result ));
}
2012-03-03 22:45:45 +00:00
/**
* test custom find method
*
* @ return void
*/
public function testfindCustom () {
$this -> loadFixtures ( 'Article' );
$Article = new CustomArticle ();
$data = array ( 'user_id' => 3 , 'title' => 'Fourth Article' , 'body' => 'Article Body, unpublished' , 'published' => 'N' );
$Article -> create ( $data );
2012-05-15 14:57:42 +00:00
$Article -> save ( null , false );
2012-03-03 22:45:45 +00:00
$this -> assertEquals ( 4 , $Article -> id );
$result = $Article -> find ( 'published' );
$this -> assertEquals ( 3 , count ( $result ));
$result = $Article -> find ( 'unPublished' );
$this -> assertEquals ( 1 , count ( $result ));
2012-03-19 01:20:17 +00:00
}
2013-08-13 08:04:17 +00:00
/**
2013-08-13 10:59:30 +00:00
* test after find callback on related model
2015-09-22 12:21:04 +00:00
*
* @ return void
2013-08-13 10:59:30 +00:00
*/
2013-08-13 08:04:17 +00:00
public function testRelatedAfterFindCallback () {
2013-08-16 07:28:32 +00:00
$this -> loadFixtures ( 'Something' , 'SomethingElse' , 'JoinThing' );
$Something = new Something ();
2013-08-16 08:02:50 +00:00
2013-08-16 07:28:32 +00:00
$Something -> bindModel ( array (
'hasMany' => array (
'HasMany' => array (
'className' => 'JoinThing' ,
'foreignKey' => 'something_id'
2013-08-13 08:04:17 +00:00
)
),
2013-08-16 07:51:01 +00:00
'hasOne' => array (
'HasOne' => array (
2013-08-16 07:28:32 +00:00
'className' => 'JoinThing' ,
'foreignKey' => 'something_id'
2013-08-13 08:04:17 +00:00
)
2013-08-13 10:59:30 +00:00
)
2013-08-18 15:41:43 +00:00
));
2013-08-16 07:51:01 +00:00
2013-08-16 07:28:32 +00:00
$results = $Something -> find ( 'all' );
2013-08-16 07:51:01 +00:00
2013-08-13 08:04:17 +00:00
$expected = array (
array (
2013-08-16 07:28:32 +00:00
'Something' => array (
2013-08-13 08:04:17 +00:00
'id' => '1' ,
2013-08-16 07:28:32 +00:00
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31'
2013-08-13 08:04:17 +00:00
),
'HasOne' => array (
'id' => '1' ,
2013-08-16 07:28:32 +00:00
'something_id' => '1' ,
'something_else_id' => '2' ,
'doomed' => true ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
),
'HasMany' => array (
array (
'id' => '1' ,
'something_id' => '1' ,
'something_else_id' => '2' ,
'doomed' => true ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
),
'SomethingElse' => array (
array (
'id' => '2' ,
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind' ,
2013-08-16 07:28:32 +00:00
'JoinThing' => array (
'doomed' => true ,
'something_id' => '1' ,
'something_else_id' => '2' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
)
2013-08-13 08:04:17 +00:00
)
),
array (
2013-08-16 07:28:32 +00:00
'Something' => array (
2013-08-13 08:04:17 +00:00
'id' => '2' ,
2013-08-16 07:28:32 +00:00
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31'
2013-08-13 08:04:17 +00:00
),
'HasOne' => array (
'id' => '2' ,
2013-08-16 07:28:32 +00:00
'something_id' => '2' ,
'something_else_id' => '3' ,
'doomed' => false ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
),
'HasMany' => array (
array (
2013-08-16 07:28:32 +00:00
'id' => '2' ,
'something_id' => '2' ,
'something_else_id' => '3' ,
'doomed' => false ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
),
'SomethingElse' => array (
array (
'id' => '3' ,
'title' => 'Third Post' ,
'body' => 'Third Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind' ,
2013-08-16 07:28:32 +00:00
'JoinThing' => array (
'doomed' => false ,
'something_id' => '2' ,
'something_else_id' => '3' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
2013-08-13 08:04:17 +00:00
)
)
),
array (
2013-08-16 07:28:32 +00:00
'Something' => array (
'id' => '3' ,
'title' => 'Third Post' ,
'body' => 'Third Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31'
),
'HasOne' => array (
'id' => '3' ,
'something_id' => '3' ,
'something_else_id' => '1' ,
'doomed' => true ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
),
'HasMany' => array (
array (
2013-08-16 07:28:32 +00:00
'id' => '3' ,
'something_id' => '3' ,
'something_else_id' => '1' ,
'doomed' => true ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
),
'SomethingElse' => array (
array (
'id' => '1' ,
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind' ,
2013-08-16 07:28:32 +00:00
'JoinThing' => array (
'doomed' => true ,
'something_id' => '3' ,
'something_else_id' => '1' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
2013-08-13 08:04:17 +00:00
)
)
2013-08-13 07:29:14 +00:00
)
2013-08-13 08:04:17 +00:00
);
2013-08-18 15:41:43 +00:00
$this -> assertEquals ( $expected , $results , 'Model related with has* afterFind callback fails' );
2012-03-19 01:20:17 +00:00
2013-08-16 07:28:32 +00:00
$JoinThing = new JoinThing ();
$JoinThing -> unbindModel ( array (
2013-08-16 07:51:01 +00:00
'belongsTo' => array (
2013-08-16 07:28:32 +00:00
'Something'
)
2013-08-18 15:41:43 +00:00
));
2013-08-16 07:28:32 +00:00
$results = $JoinThing -> find ( 'all' );
2013-08-16 07:51:01 +00:00
2013-08-13 08:04:17 +00:00
$expected = array (
array (
2013-08-16 07:28:32 +00:00
'JoinThing' => array (
2013-08-13 08:04:17 +00:00
'id' => '1' ,
2013-08-16 07:28:32 +00:00
'something_id' => '1' ,
'something_else_id' => '2' ,
'doomed' => true ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
),
2013-08-16 07:28:32 +00:00
'SomethingElse' => array (
'id' => '2' ,
'title' => 'Second Post' ,
'body' => 'Second Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
)
),
array (
2013-08-16 07:28:32 +00:00
'JoinThing' => array (
2013-08-13 08:04:17 +00:00
'id' => '2' ,
2013-08-16 07:28:32 +00:00
'something_id' => '2' ,
'something_else_id' => '3' ,
'doomed' => false ,
'created' => '2007-03-18 10:41:23' ,
'updated' => '2007-03-18 10:43:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
),
2013-08-16 07:28:32 +00:00
'SomethingElse' => array (
'id' => '3' ,
'title' => 'Third Post' ,
'body' => 'Third Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
)
),
array (
'JoinThing' => array (
'id' => '3' ,
'something_id' => '3' ,
'something_else_id' => '1' ,
'doomed' => true ,
'created' => '2007-03-18 10:43:23' ,
'updated' => '2007-03-18 10:45:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-16 07:28:32 +00:00
),
'SomethingElse' => array (
'id' => '1' ,
'title' => 'First Post' ,
'body' => 'First Post Body' ,
'published' => 'Y' ,
'created' => '2007-03-18 10:39:23' ,
'updated' => '2007-03-18 10:41:31' ,
2013-08-18 15:41:43 +00:00
'afterFind' => 'Successfully added by AfterFind'
2013-08-13 08:04:17 +00:00
)
)
);
2013-08-18 15:41:43 +00:00
$this -> assertEquals ( $expected , $results , 'Model related with belongsTo afterFind callback fails' );
2013-08-13 08:04:17 +00:00
}
2016-10-09 11:43:27 +00:00
2016-10-09 15:05:35 +00:00
/**
* Pull out the username from a result set .
*
* @ param array $result The results .
* @ return string The username .
*/
2016-10-09 11:43:27 +00:00
public static function extractUserNameFromQueryResult ( array $result ) {
return isset ( $result [ 0 ][ 0 ]) ? $result [ 0 ][ 0 ][ 'user' ] : $result [ 0 ][ 'u' ][ 'user' ];
}
2016-10-09 15:05:35 +00:00
/**
* Test that query () doesn ' t override the 2 nd argument with a default .
*
* @ return void
*/
2016-10-09 11:43:27 +00:00
public function testQueryRespectsCacheQueriesAsSecondArgument () {
$model = new User ();
$model -> save ( array ( 'user' => 'Chuck' ));
$userTableName = $this -> db -> fullTableName ( 'users' );
$getUserNameFromDb = function ( $cacheArgument ) use ( $model , $userTableName ) {
$query = sprintf ( 'SELECT u.user FROM %s u WHERE id=%d' , $userTableName , $model -> id );
$users = $model -> query ( $query , $cacheArgument );
return ModelReadTest :: extractUserNameFromQueryResult ( $users );
};
$model -> cacheQueries = true ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( true ));
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( false ));
$model -> updateAll ( array ( 'User.user' => " 'Sylvester' " ), array ( 'User.id' => $model -> id ));
$model -> cacheQueries = false ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( true ));
$this -> assertSame ( 'Sylvester' , $getUserNameFromDb ( false ));
}
2016-10-09 15:05:35 +00:00
/**
* Test that query () doesn ' t override the cache param in the 3 nd argument
* with a default .
*
* @ return void
*/
2016-10-09 11:43:27 +00:00
public function testQueryRespectsCacheQueriesAsThirdArgument () {
$model = new User ();
$model -> save ( array ( 'user' => 'Chuck' ));
$userTableName = $this -> db -> fullTableName ( 'users' );
$getUserNameFromDb = function ( $cacheArgument ) use ( $model , $userTableName ) {
$query = sprintf ( 'SELECT u.user FROM %s u WHERE id=?' , $userTableName );
$users = $model -> query ( $query , array ( $model -> id ), $cacheArgument );
return ModelReadTest :: extractUserNameFromQueryResult ( $users );
};
$model -> cacheQueries = true ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( true ));
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( false ));
2016-10-09 15:05:35 +00:00
2016-10-09 11:43:27 +00:00
$model -> updateAll ( array ( 'User.user' => " 'Sylvester' " ), array ( 'User.id' => $model -> id ));
$model -> cacheQueries = false ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ( true ));
$this -> assertSame ( 'Sylvester' , $getUserNameFromDb ( false ));
}
2016-10-09 15:05:35 +00:00
/**
* Test that query () uses the cacheQueries property when there is one argument .
*
* @ return void
*/
2016-10-09 11:43:27 +00:00
public function testQueryTakesModelCacheQueriesValueAsDefaultForOneArgument () {
$model = new User ();
$model -> save ( array ( 'user' => 'Chuck' ));
$userTableName = $this -> db -> fullTableName ( 'users' );
$getUserNameFromDb = function () use ( $model , $userTableName ) {
$query = sprintf ( 'SELECT u.user FROM %s u WHERE id=%d' , $userTableName , $model -> id );
$users = $model -> query ( $query );
return ModelReadTest :: extractUserNameFromQueryResult ( $users );
};
$model -> cacheQueries = true ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ());
$model -> updateAll ( array ( 'User.user' => " 'Sylvester' " ), array ( 'User.id' => $model -> id ));
2016-10-09 15:05:35 +00:00
2016-10-09 11:43:27 +00:00
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ());
$model -> cacheQueries = false ;
$this -> assertSame ( 'Sylvester' , $getUserNameFromDb ());
}
2016-10-09 15:05:35 +00:00
/**
* Test that query () uses the cacheQueries property when there are two arguments .
*
* @ return void
*/
2016-10-09 11:43:27 +00:00
public function testQueryTakesModelCacheQueriesValueAsDefaultForTwoArguments () {
$model = new User ();
$model -> save ( array ( 'user' => 'Chuck' ));
$userTableName = $this -> db -> fullTableName ( 'users' );
$getUserNameFromDb = function () use ( $model , $userTableName ) {
$query = sprintf ( 'SELECT u.user FROM %s u WHERE id=?' , $userTableName );
$users = $model -> query ( $query , array ( $model -> id ));
return ModelReadTest :: extractUserNameFromQueryResult ( $users );
};
$model -> cacheQueries = true ;
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ());
2016-10-09 15:05:35 +00:00
2016-10-09 11:43:27 +00:00
$model -> updateAll ( array ( 'User.user' => " 'Sylvester' " ), array ( 'User.id' => $model -> id ));
$this -> assertSame ( 'Chuck' , $getUserNameFromDb ());
2016-10-09 15:05:35 +00:00
2016-10-09 11:43:27 +00:00
$model -> cacheQueries = false ;
$this -> assertSame ( 'Sylvester' , $getUserNameFromDb ());
}
2009-07-24 22:17:14 +00:00
}