2007-02-03 22:20:13 +00:00
< ? php
/* SVN FILE: $Id$ */
/**
* Short description for file .
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP ( tm ) Tests < https :// trac . cakephp . org / wiki / Developement / TestSuite >
2008-01-01 22:18:17 +00:00
* Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* 1785 E . Sahara Avenue , Suite 490 - 204
* Las Vegas , Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice .
*
* @ filesource
2008-01-01 22:18:17 +00:00
* @ copyright Copyright 2005 - 2008 , Cake Software Foundation , Inc .
2007-02-03 22:20:13 +00:00
* @ link https :// trac . cakephp . org / wiki / Developement / TestSuite CakePHP ( tm ) Tests
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
* @ since CakePHP ( tm ) v 1.2 . 0.4206
* @ version $Revision $
* @ modifiedby $LastChangedBy $
* @ lastmodified $Date $
* @ license http :// www . opensource . org / licenses / opengroup . php The Open Group Test Suite License
*/
2007-07-08 01:17:57 +00:00
if ( ! defined ( 'CAKEPHP_UNIT_TEST_EXECUTION' )) {
define ( 'CAKEPHP_UNIT_TEST_EXECUTION' , 1 );
}
uses ( 'model' . DS . 'model' , 'model' . DS . 'datasources' . DS . 'datasource' ,
'model' . DS . 'datasources' . DS . 'dbo_source' , 'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_mysql' );
2007-02-03 22:20:13 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel extends CakeTestModel {
2007-02-03 22:20:13 +00:00
var $name = 'TestModel' ;
var $useTable = false ;
function find ( $conditions = null , $fields = null , $order = null , $recursive = null ) {
return $conditions ;
}
2007-03-22 00:26:42 +00:00
function findAll ( $conditions = null , $fields = null , $order = null , $recursive = null ) {
return $conditions ;
}
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'client_id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '11' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'login' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'passwd' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '255' ),
'addr_1' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '255' ),
'addr_2' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '25' ),
'zip_code' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'city' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'country' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'phone' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'fax' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'url' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '255' ),
'email' => array ( 'type' => 'string' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'comments' => array ( 'type' => 'text' , 'null' => '1' , 'default' => '' , 'length' => '155' ),
'last_login' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
}
return $this -> _schema ;
2007-02-03 22:20:13 +00:00
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel2 extends CakeTestModel {
2007-02-03 22:20:13 +00:00
var $name = 'TestModel2' ;
var $useTable = false ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel3 extends CakeTestModel {
2007-02-03 22:20:13 +00:00
2007-03-16 23:35:25 +00:00
var $name = 'TestModel3' ;
var $useTable = false ;
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel4 extends CakeTestModel {
2007-03-16 23:35:25 +00:00
var $name = 'TestModel4' ;
var $table = 'test_model4' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
var $belongsTo = array (
'TestModel4Parent' => array (
'className' => 'TestModel4' ,
'foreignKey' => 'parent_id'
)
);
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
var $hasOne = array (
'TestModel5' => array (
'className' => 'TestModel5' ,
'foreignKey' => 'test_model4_id'
)
);
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
var $hasAndBelongsToMany = array ( 'TestModel7' => array (
'className' => 'TestModel7' ,
'joinTable' => 'test_model4_test_model7' ,
'foreignKey' => 'test_model4_id' ,
'associationForeignKey' => 'test_model7_id'
));
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-03-16 23:35:25 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-16 23:35:25 +00:00
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel5 extends CakeTestModel {
2007-03-16 23:35:25 +00:00
var $name = 'TestModel5' ;
var $table = 'test_model5' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
var $belongsTo = array ( 'TestModel4' => array (
'className' => 'TestModel4' ,
'foreignKey' => 'test_model4_id'
));
var $hasMany = array ( 'TestModel6' => array (
'className' => 'TestModel6' ,
'foreignKey' => 'test_model5_id'
));
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'test_model4_id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-03-16 23:35:25 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-16 23:35:25 +00:00
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel6 extends CakeTestModel {
2007-03-16 23:35:25 +00:00
var $name = 'TestModel6' ;
var $table = 'test_model6' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
var $belongsTo = array ( 'TestModel5' => array (
'className' => 'TestModel5' ,
'foreignKey' => 'test_model5_id'
));
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'test_model5_id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-03-16 23:35:25 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-16 23:35:25 +00:00
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel7 extends CakeTestModel {
2007-03-16 23:35:25 +00:00
var $name = 'TestModel7' ;
var $table = 'test_model7' ;
2007-02-03 22:20:13 +00:00
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-03-16 23:35:25 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-16 23:35:25 +00:00
}
2007-02-03 22:20:13 +00:00
}
2007-04-07 19:30:27 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel8 extends CakeTestModel {
2007-04-07 19:30:27 +00:00
var $name = 'TestModel8' ;
var $table = 'test_model8' ;
var $useTable = false ;
var $hasOne = array (
'TestModel9' => array (
'className' => 'TestModel9' ,
2008-03-11 02:44:33 +00:00
'foreignKey' => 'test_model8_id' ,
2007-04-07 19:30:27 +00:00
'conditions' => 'TestModel9.name != \'mariano\''
)
);
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'test_model9_id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-04-07 19:30:27 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-04-07 19:30:27 +00:00
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-10-27 20:33:52 +00:00
class TestModel9 extends CakeTestModel {
2007-04-07 19:30:27 +00:00
var $name = 'TestModel9' ;
var $table = 'test_model9' ;
var $useTable = false ;
var $belongsTo = array ( 'TestModel8' => array (
'className' => 'TestModel8' ,
'foreignKey' => 'test_model8_id' ,
'conditions' => 'TestModel8.name != \'larry\''
));
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '8' ),
'test_model8_id' => array ( 'type' => 'integer' , 'null' => '' , 'default' => '' , 'length' => '11' ),
'name' => array ( 'type' => 'string' , 'null' => '' , 'default' => '' , 'length' => '255' ),
'created' => array ( 'type' => 'date' , 'null' => '1' , 'default' => '' , 'length' => '' ),
'updated' => array ( 'type' => 'datetime' , 'null' => '1' , 'default' => '' , 'length' => null )
);
2007-04-07 19:30:27 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-04-07 19:30:27 +00:00
}
}
2007-03-26 17:16:43 +00:00
2007-10-27 20:33:52 +00:00
class Level extends CakeTestModel {
2007-03-26 17:16:43 +00:00
var $name = 'Level' ;
var $table = 'level' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-26 17:16:43 +00:00
var $hasMany = array (
'Group' => array (
'className' => 'Group'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
'className' => 'User2'
2007-03-26 17:16:43 +00:00
)
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' ),
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
}
2007-10-27 20:33:52 +00:00
class Group extends CakeTestModel {
2007-03-26 17:16:43 +00:00
var $name = 'Group' ;
var $table = 'group' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-10-27 20:33:52 +00:00
var $belongsTo = array ( 'Level' );
2007-04-04 19:55:57 +00:00
2007-10-27 20:33:52 +00:00
var $hasMany = array ( 'Category2' , 'User2' );
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'level_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' ),
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
2007-03-26 17:16:43 +00:00
}
2007-10-27 20:33:52 +00:00
class User2 extends CakeTestModel {
2007-03-27 01:34:59 +00:00
var $name = 'User2' ;
2007-03-26 17:16:43 +00:00
var $table = 'user' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-26 17:16:43 +00:00
var $belongsTo = array (
'Group' => array (
'className' => 'Group'
),
'Level' => array (
'className' => 'Level'
)
);
2007-04-04 19:55:57 +00:00
2007-03-26 17:16:43 +00:00
var $hasMany = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
'className' => 'Article2'
2007-03-26 17:16:43 +00:00
),
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'group_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'level_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' ),
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
}
2007-10-27 20:33:52 +00:00
class Category2 extends CakeTestModel {
2007-03-27 01:34:59 +00:00
var $name = 'Category2' ;
2007-03-26 17:16:43 +00:00
var $table = 'category' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-03-26 17:16:43 +00:00
var $belongsTo = array (
'Group' => array (
'className' => 'Group' ,
'foreignKey' => 'group_id'
),
'ParentCat' => array (
2007-03-27 01:34:59 +00:00
'className' => 'Category2' ,
2007-03-26 17:16:43 +00:00
'foreignKey' => 'parent_id'
)
);
2007-04-04 19:55:57 +00:00
2007-03-26 17:16:43 +00:00
var $hasMany = array (
'ChildCat' => array (
2007-03-27 01:34:59 +00:00
'className' => 'Category2' ,
2007-03-26 17:16:43 +00:00
'foreignKey' => 'parent_id'
),
2007-03-27 01:34:59 +00:00
'Article2' => array (
'className' => 'Article2' ,
'order' => 'Article2.published_date DESC' ,
2007-03-26 17:16:43 +00:00
'foreignKey' => 'category_id' ,
'limit' => '3' )
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'group_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'parent_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => '255' ),
'icon' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => '255' ),
'description' => array ( 'type' => 'text' , 'null' => false , 'default' => '' , 'length' => null ),
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
}
2007-10-27 20:33:52 +00:00
class Article2 extends CakeTestModel {
2007-03-27 01:34:59 +00:00
var $name = 'Article2' ;
2007-03-26 17:16:43 +00:00
var $table = 'article' ;
var $useTable = false ;
2007-03-27 01:34:59 +00:00
var $belongsTo = array (
'Category2' => array (
'className' => 'Category2'
),
'User2' => array (
'className' => 'User2'
)
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'category_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'user_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'rate_count' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'rate_sum' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'viewed' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'version' => array ( 'type' => 'string' , 'null' => true , 'default' => '' , 'length' => '45' ),
'title' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => '200' ),
'intro' => array ( 'text' => 'string' , 'null' => true , 'default' => '' , 'length' => null ),
'comments' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '4' ),
'body' => array ( 'text' => 'string' , 'null' => true , 'default' => '' , 'length' => null ),
'isdraft' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '0' , 'length' => '1' ),
'allow_comments' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '1' , 'length' => '1' ),
'moderate_comments' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '1' , 'length' => '1' ),
'published' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '0' , 'length' => '1' ),
'multipage' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '0' , 'length' => '1' ),
'published_date' => array ( 'type' => 'datetime' , 'null' => true , 'default' => '' , 'length' => null ),
'created' => array ( 'type' => 'datetime' , 'null' => false , 'default' => '0000-00-00 00:00:00' , 'length' => null ),
'modified' => array ( 'type' => 'datetime' , 'null' => false , 'default' => '0000-00-00 00:00:00' , 'length' => null )
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
}
2007-10-27 20:33:52 +00:00
class CategoryFeatured2 extends CakeTestModel {
2007-04-01 23:09:56 +00:00
var $name = 'CategoryFeatured2' ;
var $table = 'category_featured' ;
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'parent_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '' , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => '255' ),
'icon' => array ( 'type' => 'string' , 'null' => false , 'default' => '' , 'length' => '255' ),
'description' => array ( 'text' => 'string' , 'null' => false , 'default' => '' , 'length' => null )
);
2007-04-01 23:09:56 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-04-01 23:09:56 +00:00
}
}
2007-03-26 17:16:43 +00:00
2007-10-27 20:33:52 +00:00
class Featured2 extends CakeTestModel {
2007-04-01 23:09:56 +00:00
var $name = 'Featured2' ;
var $table = 'featured2' ;
2007-03-26 17:16:43 +00:00
var $useTable = false ;
var $belongsTo = array (
2007-04-01 23:09:56 +00:00
'CategoryFeatured2' => array (
'className' => 'CategoryFeatured2'
2007-03-26 17:16:43 +00:00
)
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'article_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'category_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' )
);
2007-03-26 17:16:43 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-03-26 17:16:43 +00:00
}
}
2007-10-27 20:33:52 +00:00
class Comment2 extends CakeTestModel {
2007-04-01 23:09:56 +00:00
var $name = 'Comment2' ;
var $table = 'comment' ;
var $belongsTo = array ( 'ArticleFeatured2' , 'User2' );
var $useTable = false ;
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'article_featured_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'user_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'name' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' )
);
2007-04-01 23:09:56 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-04-01 23:09:56 +00:00
}
}
2007-10-27 20:33:52 +00:00
class ArticleFeatured2 extends CakeTestModel {
2007-04-01 23:09:56 +00:00
var $name = 'ArticleFeatured2' ;
var $table = 'article_featured' ;
var $useTable = false ;
var $belongsTo = array (
'CategoryFeatured2' => array (
'className' => 'CategoryFeatured2'
),
'User2' => array (
'className' => 'User2'
)
);
var $hasOne = array (
'Featured2' => array ( 'className' => 'Featured2' )
);
var $hasMany = array (
'Comment2' => array ( 'className' => 'Comment2' , 'dependent' => true )
);
2007-04-04 19:55:57 +00:00
2007-10-28 04:18:18 +00:00
function schema () {
if ( ! isset ( $this -> _schema )) {
$this -> _schema = array (
'id' => array ( 'type' => 'integer' , 'null' => false , 'default' => null , 'length' => '10' ),
'category_featured_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'user_id' => array ( 'type' => 'integer' , 'null' => false , 'default' => '0' , 'length' => '10' ),
'title' => array ( 'type' => 'string' , 'null' => true , 'default' => null , 'length' => '20' ),
'body' => array ( 'text' => 'string' , 'null' => true , 'default' => '' , 'length' => null ),
'published' => array ( 'type' => 'boolean' , 'null' => false , 'default' => '0' , 'length' => '1' ),
'published_date' => array ( 'type' => 'datetime' , 'null' => true , 'default' => '' , 'length' => null ),
'created' => array ( 'type' => 'datetime' , 'null' => false , 'default' => '0000-00-00 00:00:00' , 'length' => null ),
'modified' => array ( 'type' => 'datetime' , 'null' => false , 'default' => '0000-00-00 00:00:00' , 'length' => null )
);
2007-04-01 23:09:56 +00:00
}
2007-10-28 04:18:18 +00:00
return $this -> _schema ;
2007-04-01 23:09:56 +00:00
}
}
2007-02-03 22:20:13 +00:00
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
class DboTest extends DboMysql {
var $simulated = array ();
function _execute ( $sql ) {
$this -> simulated [] = $sql ;
return null ;
}
function getLastQuery () {
return $this -> simulated [ count ( $this -> simulated ) - 1 ];
}
}
/**
* Short description for class .
*
* @ package cake . tests
* @ subpackage cake . tests . cases . libs . model . datasources
*/
2007-11-09 05:13:12 +00:00
class DboSourceTest extends CakeTestCase {
2007-11-12 17:31:37 +00:00
var $debug = null ;
2007-02-03 22:20:13 +00:00
function setUp () {
2007-11-09 05:13:12 +00:00
$this -> _initDb ();
2007-07-08 01:17:57 +00:00
config ( 'database' );
2007-02-03 22:20:13 +00:00
$config = new DATABASE_CONFIG ();
2007-10-27 20:33:52 +00:00
if ( isset ( $config -> test )) {
2008-03-16 05:44:20 +00:00
$this -> __config = $config -> test ;
2007-10-27 20:33:52 +00:00
} else {
2008-03-16 05:44:20 +00:00
$this -> __config = $config -> default ;
2007-10-27 20:33:52 +00:00
}
2007-11-12 17:31:37 +00:00
$this -> debug = Configure :: read ( 'debug' );
Configure :: write ( 'debug' , 1 );
2008-03-16 05:44:20 +00:00
$this -> db =& new DboTest ( $this -> __config );
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel ();
$db =& ConnectionManager :: getDataSource ( $this -> Model -> useDbConfig );
2007-02-03 22:20:13 +00:00
}
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
function tearDown () {
2007-11-09 05:13:12 +00:00
unset ( $this -> Model );
2007-03-16 23:35:25 +00:00
unset ( $this -> db );
2007-11-12 17:31:37 +00:00
Configure :: write ( 'debug' , $this -> debug );
unset ( $this -> debug );
2007-03-16 23:35:25 +00:00
}
2007-04-04 19:55:57 +00:00
2008-02-21 15:36:13 +00:00
function testCreateSpeed () {
$model = new TestModel ();
$data = array ( 'client_id' => 3 , 'name' => 'Nate' , 'login' => 'nate' );
$model -> set ( $data );
$start = microtime ( true );
for ( $i = 0 ; $i < 1000 ; $i ++ ) {
$this -> db -> create ( $model , array_keys ( $data ), array_values ( $data ));
}
$time = microtime ( true ) - $start ;
}
2008-02-24 15:28:17 +00:00
function testFieldDoubleEscaping () {
2008-03-16 05:44:20 +00:00
$config = array_merge ( $this -> __config , array ( 'driver' => 'test' ));
$test =& ConnectionManager :: create ( 'quoteTest' , $config );
2008-02-24 15:28:17 +00:00
$this -> Model = new Article2 ( array ( 'name' => 'Article' , 'ds' => 'quoteTest' ));
$this -> Model -> setDataSource ( 'quoteTest' );
$this -> assertEqual ( $this -> Model -> escapeField (), '`Article`.`id`' );
$result = $test -> fields ( $this -> Model , null , $this -> Model -> escapeField ());
$this -> assertEqual ( $result , array ( '`Article`.`id`' ));
$result = $test -> read ( $this -> Model , array (
'fields' => $this -> Model -> escapeField (),
'conditions' => null ,
'recursive' => - 1
));
$this -> assertEqual ( trim ( $test -> simulated [ 0 ]), 'SELECT `Article`.`id` FROM `article` AS `Article` WHERE 1 = 1' );
$test -> startQuote = '[' ;
$test -> endQuote = ']' ;
$this -> assertEqual ( $this -> Model -> escapeField (), '[Article].[id]' );
$result = $test -> fields ( $this -> Model , null , $this -> Model -> escapeField ());
$this -> assertEqual ( $result , array ( '[Article].[id]' ));
$result = $test -> read ( $this -> Model , array (
'fields' => $this -> Model -> escapeField (),
'conditions' => null ,
'recursive' => - 1
));
$this -> assertEqual ( trim ( $test -> simulated [ 1 ]), 'SELECT [Article].[id] FROM [article] AS [Article] WHERE 1 = 1' );
}
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQuerySelfJoin () {
2008-02-21 15:36:13 +00:00
$this -> startTime = microtime ( true );
2007-11-09 05:13:12 +00:00
$this -> Model = new Article2 ();
$this -> _buildRelatedModels ( $this -> Model );
$this -> _buildRelatedModels ( $this -> Model -> Category2 );
$this -> Model -> Category2 -> ChildCat = new Category2 ();
$this -> Model -> Category2 -> ParentCat = new Category2 ();
2007-03-26 17:16:43 +00:00
$queryData = array ();
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
foreach ( $this -> Model -> Category2 -> __associations as $type ) {
foreach ( $this -> Model -> Category2 -> { $type } as $assoc => $assocData ) {
$linkModel =& $this -> Model -> Category2 -> { $assoc };
2007-03-26 17:16:43 +00:00
$external = isset ( $assocData [ 'external' ]);
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
if ( $this -> Model -> Category2 -> alias == $linkModel -> alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany' ) {
2008-03-11 02:44:33 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model -> Category2 , $linkModel , $type , $assoc , $assocData , $queryData , $external , $null );
2007-03-26 17:16:43 +00:00
$this -> assertTrue ( $result );
} else {
2007-11-09 05:13:12 +00:00
if ( $this -> Model -> Category2 -> useDbConfig == $linkModel -> useDbConfig ) {
$result = $this -> db -> generateAssociationQuery ( $this -> Model -> Category2 , $linkModel , $type , $assoc , $assocData , $queryData , $external , $null );
2007-03-26 17:16:43 +00:00
$this -> assertTrue ( $result );
}
}
}
}
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$query = $this -> db -> generateAssociationQuery ( $this -> Model -> Category2 , $null , null , null , null , $queryData , false , $null );
2008-03-11 02:44:33 +00:00
$this -> assertPattern ( '/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/' , $query );
2007-04-05 00:47:17 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'TestModel4Parent' );
2007-03-16 23:35:25 +00:00
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-04 19:55:57 +00:00
2008-03-11 02:44:33 +00:00
$_queryData = $queryData ;
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-03-20 17:38:53 +00:00
2008-03-11 02:44:33 +00:00
$expected = array (
2008-02-24 15:28:17 +00:00
'fields' => array (
2007-04-05 04:47:01 +00:00
'`TestModel4`.`id`' ,
'`TestModel4`.`name`' ,
'`TestModel4`.`created`' ,
'`TestModel4`.`updated`' ,
'`TestModel4Parent`.`id`' ,
'`TestModel4Parent`.`name`' ,
'`TestModel4Parent`.`created`' ,
2007-04-05 03:40:08 +00:00
'`TestModel4Parent`.`updated`'
2007-04-05 04:47:01 +00:00
),
2008-02-24 15:28:17 +00:00
'joins' => array (
array (
2007-04-05 04:47:01 +00:00
'table' => '`test_model4`' ,
'alias' => 'TestModel4Parent' ,
'type' => 'LEFT' ,
2008-03-11 02:44:33 +00:00
'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`'
2007-04-05 03:40:08 +00:00
)
2007-04-05 04:47:01 +00:00
),
2008-02-24 15:28:17 +00:00
'limit' => array (),
'offset' => array (),
'conditions' => array (),
'order' => array ()
2008-03-11 02:44:33 +00:00
);
$this -> assertEqual ( $queryData , $expected );
2007-03-26 17:16:43 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/' , $result );
2007-04-04 22:14:45 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+1 = 1\s+$/' , $result );
2008-03-09 08:47:42 +00:00
$params [ 'assocData' ][ 'type' ] = 'INNER' ;
$this -> Model -> belongsTo [ 'TestModel4Parent' ][ 'type' ] = 'INNER' ;
2008-03-11 02:44:33 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $_queryData , $params [ 'external' ], $resultSet );
2008-03-09 08:47:42 +00:00
$this -> assertTrue ( $result );
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $_queryData [ 'joins' ][ 0 ][ 'type' ], 'INNER' );
2008-03-09 08:47:42 +00:00
}
function testGenerateInnerJoinAssociationQuery () {
$this -> Model =& new TestModel9 ();
2008-03-16 05:44:20 +00:00
$test =& ConnectionManager :: create ( 'test2' , $this -> __config );
2008-03-09 08:47:42 +00:00
$this -> Model -> setDataSource ( 'test2' );
$this -> Model -> TestModel8 =& new TestModel8 ();
$this -> Model -> TestModel8 -> setDataSource ( 'test2' );
$this -> db -> read ( $this -> Model , array ( 'recursive' => 1 ));
$result = $this -> db -> getLastQuery ();
$this -> assertPattern ( '/`TestModel9` LEFT JOIN `test_model8`/' , $result );
$this -> Model -> belongsTo [ 'TestModel8' ][ 'type' ] = 'INNER' ;
$this -> db -> read ( $this -> Model , array ( 'recursive' => 1 ));
$result = $this -> db -> getLastQuery ();
$this -> assertPattern ( '/`TestModel9` INNER JOIN `test_model8`/' , $result );
2008-03-16 05:44:20 +00:00
2007-03-16 23:35:25 +00:00
}
2007-04-09 04:00:04 +00:00
2007-04-07 19:51:20 +00:00
function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel8 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-04-09 04:00:04 +00:00
2007-04-07 19:30:27 +00:00
$binding = array ( 'type' => 'hasOne' , 'model' => 'TestModel9' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2008-03-11 02:44:33 +00:00
$_queryData = $queryData ;
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-07 19:30:27 +00:00
$this -> assertTrue ( $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-07 19:51:20 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`, `TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`\s+/' , $result );
2007-04-07 19:30:27 +00:00
$this -> assertPattern ( '/FROM\s+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+`test_model9` AS `TestModel9`/' , $result );
2008-03-11 02:44:33 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/' , $result );
2007-04-07 19:30:27 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-07 19:51:20 +00:00
}
2007-04-09 04:00:04 +00:00
2007-04-07 19:51:20 +00:00
function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel9 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-04-09 04:00:04 +00:00
2007-04-07 19:30:27 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'TestModel8' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2008-03-11 02:44:33 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-07 19:30:27 +00:00
$this -> assertTrue ( $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-07 19:51:20 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`, `TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`\s+/' , $result );
2007-04-07 19:30:27 +00:00
$this -> assertPattern ( '/FROM\s+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+`test_model8` AS `TestModel8`/' , $result );
2008-03-11 02:44:33 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/' , $result );
2007-04-07 19:30:27 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQuerySelfJoinWithConditions () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'TestModel4Parent' );
2007-03-16 23:35:25 +00:00
$queryData = array ( 'conditions' => array ( 'TestModel4Parent.name' => '!= mariano' ));
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2008-03-11 02:44:33 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model4` AS `TestModel4Parent`/' , $result );
2007-04-04 22:14:45 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/' , $result );
2007-04-09 04:00:04 +00:00
2007-04-01 23:09:56 +00:00
$this -> Featured2 = new Featured2 ();
2007-10-28 04:18:18 +00:00
$this -> Featured2 -> schema ();
2007-04-04 19:55:57 +00:00
2007-04-01 23:09:56 +00:00
$this -> Featured2 -> bindModel ( array (
'belongsTo' => array (
'ArticleFeatured2' => array (
'conditions' => 'ArticleFeatured2.published = \'Y\'' ,
'fields' => 'id, title, user_id, published'
)
)
));
2007-04-04 19:55:57 +00:00
2007-04-01 23:09:56 +00:00
$this -> _buildRelatedModels ( $this -> Featured2 );
2007-04-05 00:47:17 +00:00
2007-04-01 23:09:56 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'ArticleFeatured2' );
$queryData = array ( 'conditions' => array ());
$resultSet = null ;
$null = null ;
2007-04-04 19:55:57 +00:00
2007-04-01 23:09:56 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Featured2 , $queryData , $binding );
2007-04-05 00:47:17 +00:00
2008-03-11 02:44:33 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Featured2 , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-01 23:09:56 +00:00
$this -> assertTrue ( $result );
2007-04-04 19:55:57 +00:00
2007-04-01 23:09:56 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Featured2 , $null , null , null , null , $queryData , false , $null );
2007-04-04 19:55:57 +00:00
2007-04-01 23:09:56 +00:00
$this -> assertPattern (
2007-04-05 00:05:57 +00:00
'/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+' .
'`ArticleFeatured2`\.`id`, `ArticleFeatured2`\.`title`, `ArticleFeatured2`\.`user_id`, `ArticleFeatured2`\.`published`\s+' .
2007-04-01 23:09:56 +00:00
'FROM\s+`featured2` AS `Featured2`\s+LEFT JOIN\s+`article_featured` AS `ArticleFeatured2`' .
2008-03-11 02:44:33 +00:00
'\s+ON\s+\(`ArticleFeatured2`.`published` = \'Y\'\s+AND\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`\)' .
2007-04-05 00:47:17 +00:00
'\s+WHERE\s+1\s+=\s+1\s*$/' ,
2008-03-11 02:44:33 +00:00
$result
);
2007-03-16 23:35:25 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasOne () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'hasOne' , 'model' => 'TestModel5' );
2007-03-16 23:35:25 +00:00
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-03-20 17:38:53 +00:00
$result = $this -> db -> buildJoinStatement ( $queryData [ 'joins' ][ 0 ]);
2007-04-04 22:14:45 +00:00
$expected = ' LEFT JOIN `test_model5` AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)' ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( trim ( $result ), trim ( $expected ));
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/' , $result );
2007-04-04 22:14:45 +00:00
$this -> assertPattern ( '/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasOneWithConditions () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'hasOne' , 'model' => 'TestModel5' );
2007-03-16 23:35:25 +00:00
$queryData = array ( 'conditions' => array ( 'TestModel5.name' => '!= mariano' ));
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 04:00:04 +00:00
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+`test_model5` AS `TestModel5`/' , $result );
2007-04-07 19:51:20 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryBelongsTo () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'TestModel4' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-03-20 17:38:53 +00:00
$result = $this -> db -> buildJoinStatement ( $queryData [ 'joins' ][ 0 ]);
2007-04-04 22:14:45 +00:00
$expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)' ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( trim ( $result ), trim ( $expected ));
2007-04-05 00:47:17 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/' , $result );
2007-04-04 22:14:45 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryBelongsToWithConditions () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'belongsTo' , 'model' => 'TestModel4' );
2007-03-16 23:35:25 +00:00
$queryData = array ( 'conditions' => array ( 'TestModel5.name' => '!= mariano' ));
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-16 23:35:25 +00:00
$this -> assertTrue ( $result );
2007-03-20 17:38:53 +00:00
$result = $this -> db -> buildJoinStatement ( $queryData [ 'joins' ][ 0 ]);
2007-04-04 22:14:45 +00:00
$expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)' ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( trim ( $result ), trim ( $expected ));
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+`test_model4` AS `TestModel4`/' , $result );
2007-04-04 22:14:45 +00:00
$this -> assertPattern ( '/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/' , $result );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/\s+WHERE\s+`TestModel5`.`name` != \'mariano\'\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasMany () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
2007-03-16 23:35:25 +00:00
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE/' , $result );
2007-04-09 04:00:04 +00:00
$this -> assertPattern ( '/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)/' , $result );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-04-29 04:18:41 +00:00
2007-04-11 21:22:26 +00:00
function testGenerateAssociationQueryHasManyWithLimit () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-04-29 04:18:41 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'limit' ] = 2 ;
2007-04-29 04:18:41 +00:00
2007-04-11 21:22:26 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-11 21:22:26 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-11 21:22:26 +00:00
$this -> assertPattern ( '/^SELECT\s+' .
'`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+' .
'FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+' .
'`TestModel6`.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)\s*' .
'LIMIT \d*' .
'\s*$/' , $result );
2007-04-29 04:18:41 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-11 21:22:26 +00:00
$this -> assertPattern ( '/^SELECT\s+' .
'`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+' .
'FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+' .
'(?:\()?\s*1 = 1\s*(?:\))?' .
'\s*$/' , $result );
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasManyWithConditions () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
2007-03-16 23:35:25 +00:00
$queryData = array ( 'conditions' => array ( 'TestModel5.name' => '!= mariano' ));
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
2007-04-09 04:00:04 +00:00
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-06-23 05:56:36 +00:00
2007-05-15 18:47:02 +00:00
function testGenerateAssociationQueryHasManyWithOffsetAndLimit () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$__backup = $this -> Model -> hasMany [ 'TestModel6' ];
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'offset' ] = 2 ;
$this -> Model -> hasMany [ 'TestModel6' ][ 'limit' ] = 5 ;
2007-05-15 18:47:02 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-05-15 18:47:02 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-05-15 18:47:02 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
$this -> assertPattern ( '/\s+LIMIT 2,\s*5\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-05-15 18:47:02 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ] = $__backup ;
2007-05-15 18:47:02 +00:00
}
2007-06-23 05:56:36 +00:00
2007-05-15 18:47:02 +00:00
function testGenerateAssociationQueryHasManyWithPageAndLimit () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$__backup = $this -> Model -> hasMany [ 'TestModel6' ];
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'page' ] = 2 ;
$this -> Model -> hasMany [ 'TestModel6' ][ 'limit' ] = 5 ;
2007-05-15 18:47:02 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-05-15 18:47:02 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-05-15 18:47:02 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
$this -> assertPattern ( '/\s+LIMIT 5,\s*5\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-05-15 18:47:02 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ] = $__backup ;
2007-05-15 18:47:02 +00:00
}
2007-04-09 21:30:55 +00:00
2007-04-09 19:12:59 +00:00
function testGenerateAssociationQueryHasManyWithFields () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel5 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-04-09 21:30:55 +00:00
2007-04-09 19:12:59 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`name`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:12:59 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 21:30:55 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`id`\s+/' , $result );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-04-09 19:12:59 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`id`, `TestModel5`.`name`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:12:59 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-04-09 19:12:59 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`name`' , '`TestModel5`.`created`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:12:59 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 21:30:55 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`id`\s+/' , $result );
2007-04-09 19:12:59 +00:00
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ] = array ( 'name' );
2007-04-09 21:30:55 +00:00
2007-04-09 19:21:42 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`id`' , '`TestModel5`.`name`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:21:42 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 21:30:55 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/' , $result );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
unset ( $this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ]);
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ] = array ( 'id' , 'name' );
2007-04-09 21:30:55 +00:00
2007-04-09 19:21:42 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`id`' , '`TestModel5`.`name`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:21:42 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 21:30:55 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/' , $result );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
unset ( $this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ]);
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ] = array ( 'test_model5_id' , 'name' );
2007-04-09 21:30:55 +00:00
2007-04-09 19:21:42 +00:00
$binding = array ( 'type' => 'hasMany' , 'model' => 'TestModel6' );
$queryData = array ( 'fields' => array ( '`TestModel5`.`id`' , '`TestModel5`.`name`' ));
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-09 19:21:42 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel6`\.`test_model5_id`, `TestModel6`\.`name`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+IN\s+\({\$__cakeID__\$}\)(?:\))?/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-04-09 19:21:42 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model5` AS `TestModel5`\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-04-09 21:30:55 +00:00
2007-11-09 05:13:12 +00:00
unset ( $this -> Model -> hasMany [ 'TestModel6' ][ 'fields' ]);
2007-04-09 19:12:59 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasAndBelongsToMany () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-03-20 17:38:53 +00:00
$binding = array ( 'type' => 'hasAndBelongsToMany' , 'model' => 'TestModel7' );
2007-03-16 23:35:25 +00:00
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`test_model4_test_model7`/' , $result );
$this -> assertPattern ( '/\s+ON\s+(?:\()?`test_model4_test_model7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}(?:\))?/' , $result );
$this -> assertPattern ( '/\s+AND\s+(?:\()?`test_model4_test_model7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`(?:\))?/' , $result );
$this -> assertPattern ( '/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/' , $result );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE/' , $result );
$this -> assertPattern ( '/\s+WHERE\s+(?:\()?1 = 1(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
function testGenerateAssociationQueryHasAndBelongsToManyWithConditions () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
$binding = array ( 'type' => 'hasAndBelongsToMany' , 'model' => 'TestModel7' );
$queryData = array ( 'conditions' => array ( 'TestModel4.name' => '!= mariano' ));
$resultSet = null ;
$null = null ;
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`test_model4_test_model7`+/' , $result );
2007-03-22 00:26:42 +00:00
$this -> assertPattern ( '/\s+ON\s+(?:\()?`test_model4_test_model7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}(?:\))?/' , $result );
$this -> assertPattern ( '/\s+AND\s+(?:\()?`test_model4_test_model7`\.`test_model7_id`\s+=\s+`TestModel7`.`id`(?:\))?\s+WHERE\s+/' , $result );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?`TestModel4`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/' , $result );
2007-03-16 23:35:25 +00:00
}
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$__backup = $this -> Model -> hasAndBelongsToMany [ 'TestModel7' ];
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ][ 'offset' ] = 2 ;
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ][ 'limit' ] = 5 ;
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
$binding = array ( 'type' => 'hasAndBelongsToMany' , 'model' => 'TestModel7' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-05-15 18:19:56 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`test_model4_test_model7`+/' , $result );
$this -> assertPattern ( '/\s+ON\s+(?:\()?`test_model4_test_model7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}(?:\))?/' , $result );
$this -> assertPattern ( '/\s+AND\s+(?:\()?`test_model4_test_model7`\.`test_model7_id`\s+=\s+`TestModel7`.`id`(?:\))?\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 2,\s*5\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-05-15 18:19:56 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ] = $__backup ;
2007-05-15 18:19:56 +00:00
}
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit () {
2007-11-09 05:13:12 +00:00
$this -> Model = new TestModel4 ();
$this -> Model -> schema ();
$this -> _buildRelatedModels ( $this -> Model );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$__backup = $this -> Model -> hasAndBelongsToMany [ 'TestModel7' ];
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ][ 'page' ] = 2 ;
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ][ 'limit' ] = 5 ;
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
$binding = array ( 'type' => 'hasAndBelongsToMany' , 'model' => 'TestModel7' );
$queryData = array ();
$resultSet = null ;
$null = null ;
2007-11-09 05:13:12 +00:00
$params = & $this -> _prepareAssociationQuery ( $this -> Model , $queryData , $binding );
2007-05-15 18:19:56 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $params [ 'linkModel' ], $params [ 'type' ], $params [ 'assoc' ], $params [ 'assocData' ], $queryData , $params [ 'external' ], $resultSet );
2007-06-23 05:56:36 +00:00
2007-05-15 18:19:56 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`test_model4_test_model7`+/' , $result );
$this -> assertPattern ( '/\s+ON\s+(?:\()?`test_model4_test_model7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}(?:\))?/' , $result );
$this -> assertPattern ( '/\s+AND\s+(?:\()?`test_model4_test_model7`\.`test_model7_id`\s+=\s+`TestModel7`.`id`(?:\))?\s+WHERE\s+/' , $result );
$this -> assertPattern ( '/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 5,\s*5\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> generateAssociationQuery ( $this -> Model , $null , null , null , null , $queryData , false , $null );
2007-05-15 18:19:56 +00:00
$this -> assertPattern ( '/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/' , $result );
$this -> assertPattern ( '/\s+FROM\s+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/' , $result );
2007-06-23 05:56:36 +00:00
2007-11-09 05:13:12 +00:00
$this -> Model -> hasAndBelongsToMany [ 'TestModel7' ] = $__backup ;
2007-05-15 18:19:56 +00:00
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function _buildRelatedModels ( & $model ) {
2007-06-20 06:15:35 +00:00
foreach ( $model -> __associations as $type ) {
foreach ( $model -> { $type } as $assoc => $assocData ) {
2007-03-16 23:35:25 +00:00
if ( is_string ( $assocData )) {
$className = $assocData ;
2007-06-20 06:15:35 +00:00
} elseif ( isset ( $assocData [ 'className' ])) {
2007-03-16 23:35:25 +00:00
$className = $assocData [ 'className' ];
}
$model -> $className = new $className ();
2007-10-28 04:18:18 +00:00
$model -> $className -> schema ();
2007-03-16 23:35:25 +00:00
}
}
}
2007-03-20 17:38:53 +00:00
2007-03-16 23:35:25 +00:00
function & _prepareAssociationQuery ( & $model , & $queryData , $binding ) {
$type = $binding [ 'type' ];
$assoc = $binding [ 'model' ];
$assocData = $model -> { $type }[ $assoc ];
$className = $assocData [ 'className' ];
2007-04-04 19:55:57 +00:00
2007-03-16 23:35:25 +00:00
$linkModel =& $model -> { $className };
$external = isset ( $assocData [ 'external' ]);
2008-03-11 02:44:33 +00:00
$queryData = $this -> db -> __scrubQueryData ( $queryData );
2007-04-05 00:47:17 +00:00
2008-03-11 02:44:33 +00:00
$result = array_merge ( array ( 'linkModel' => & $linkModel ), compact ( 'type' , 'assoc' , 'assocData' , 'external' ));
2007-03-16 23:35:25 +00:00
return $result ;
}
2007-02-03 22:20:13 +00:00
2008-02-24 03:15:37 +00:00
function testSelectDistict () {
$result = $this -> db -> fields ( $this -> Model , 'Vendor' , " DISTINCT Vendor.id, Vendor.name " );
$expected = array ( 'DISTINCT `Vendor`.`id`' , '`Vendor`.`name`' );
$this -> assertEqual ( $result , $expected );
}
2007-02-03 22:20:13 +00:00
function testStringConditionsParsing () {
2007-06-12 15:13:53 +00:00
$result = $this -> db -> conditions ( " ProjectBid.project_id = Project.id " );
$expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id` " ;
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " Candy.name LIKE 'a' AND HardCandy.name LIKE 'c' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c' " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " HardCandy.name LIKE 'a' AND Candy.name LIKE 'c' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c' " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " Post.title = '1.1' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `Post`.`title` = '1.1' " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-03-20 17:38:53 +00:00
$result = $this -> db -> conditions ( " User.id != 0 AND User.user LIKE '%arr%' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `User`.`id` != 0 AND `User`.`user` LIKE '%arr%' " ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " SUM(Post.comments_count) > 500 " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE SUM(`Post`.`comments_count`) > 500 " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " (Post.created < ' " . date ( 'Y-m-d H:i:s' ) . " ') GROUP BY YEAR(Post.created), MONTH(Post.created) " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE (`Post`.`created` < ' " . date ( 'Y-m-d H:i:s' ) . " ') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`) " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " score BETWEEN 90.1 AND 95.7 " );
$expected = " WHERE score BETWEEN 90.1 AND 95.7 " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " Aro.rght = Aro.lft + 1.1 " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1 " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( " (Post.created < ' " . date ( 'Y-m-d H:i:s' ) . " ') GROUP BY YEAR(Post.created), MONTH(Post.created) " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE (`Post`.`created` < ' " . date ( 'Y-m-d H:i:s' ) . " ') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`) " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2' );
2007-04-06 11:15:45 +00:00
$expected = ' WHERE `Sportstaette`.`sportstaette` LIKE "%ru%" AND `Sportstaette`.`sportstaettenart_id` = 2' ;
2007-03-27 01:34:59 +00:00
$this -> assertPattern ( '/\s*WHERE\s+`Sportstaette`\.`sportstaette`\s+LIKE\s+"%ru%"\s+AND\s+`Sports/' , $result );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'Sportstaette.sportstaettenart_id = 2 AND Sportstaette.sportstaette LIKE "%ru%"' );
2007-04-06 11:15:45 +00:00
$expected = ' WHERE `Sportstaette`.`sportstaettenart_id` = 2 AND `Sportstaette`.`sportstaette` LIKE "%ru%"' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL' );
2007-04-06 11:15:45 +00:00
$expected = ' WHERE SUM(`Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500' );
2007-04-06 11:15:45 +00:00
$expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM(`Post`.`comments_count`) > 500' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'NOT Post.extended_title IS NULL AND NOT Post.title IS NULL AND Post.title != "" AND SPOON(SUM(Post.comments_count) + 1.1) > 500' );
2007-04-06 11:15:45 +00:00
$expected = ' WHERE NOT `Post`.`extended_title` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title` != "" AND SPOON(SUM(`Post`.`comments_count`) + 1.1) > 500' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( 'NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title' );
2007-02-04 17:56:17 +00:00
$expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`' ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-08 22:16:35 +00:00
$result = $this -> db -> conditions ( " Comment.id = 'a' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE `Comment`.`id` = 'a' " ;
2007-02-08 22:16:35 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-21 05:30:08 +00:00
$result = $this -> db -> conditions ( " lower(Article.title) LIKE 'a%' " );
2007-04-06 11:15:45 +00:00
$expected = " WHERE lower(`Article`.`title`) LIKE 'a%' " ;
2007-03-21 05:30:08 +00:00
$this -> assertEqual ( $result , $expected );
2007-04-04 19:55:57 +00:00
2007-04-06 11:15:45 +00:00
$result = $this -> db -> conditions ( '((MATCH(Video.title) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(Video.description) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(Video.tags) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))' );
$expected = ' WHERE ((MATCH(`Video`.`title`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 2) + (MATCH(`Video`.`description`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 0.4) + (MATCH(`Video`.`tags`) AGAINST(\'My Search*\' IN BOOLEAN MODE) * 1.5))' ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( 'DATEDIFF(NOW(),Article.published) < 1 && Article.live=1' );
$expected = " WHERE DATEDIFF(NOW(),`Article`.`published`) < 1 && `Article`.`live`=1 " ;
2007-03-31 20:49:26 +00:00
$this -> assertEqual ( $result , $expected );
2007-08-04 17:26:23 +00:00
$result = $this -> db -> conditions ( 'file = "index.html"' );
$expected = ' WHERE file = "index.html"' ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( " file = 'index.html' " );
$expected = " WHERE file = 'index.html' " ;
$this -> assertEqual ( $result , $expected );
2007-08-29 01:18:48 +00:00
$letter = $letter = 'd.a' ;
$conditions = array ( 'Company.name' => 'like ' . $letter . '%' );
$result = $this -> db -> conditions ( $conditions );
$expected = " WHERE `Company`.`name` like 'd.a%' " ;
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
}
2007-04-07 06:29:46 +00:00
2007-04-07 04:56:17 +00:00
function testQuotesInStringConditions () {
$result = $this -> db -> conditions ( 'Member.email = \'mariano@cricava.com\'' );
$expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\'' ;
$this -> assertEqual ( $result , $expected );
2007-04-07 06:29:46 +00:00
2007-04-07 04:56:17 +00:00
$result = $this -> db -> conditions ( 'Member.email = "mariano@cricava.com"' );
$expected = ' WHERE `Member`.`email` = "mariano@cricava.com"' ;
$this -> assertEqual ( $result , $expected );
2007-04-07 06:29:46 +00:00
2007-04-07 04:56:17 +00:00
$result = $this -> db -> conditions ( 'Member.email = \'mariano@cricava.com\' AND Member.user LIKE \'mariano.iglesias%\'' );
$expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\' AND `Member`.`user` LIKE \'mariano.iglesias%\'' ;
$this -> assertEqual ( $result , $expected );
2007-04-07 06:29:46 +00:00
2007-04-07 04:56:17 +00:00
$result = $this -> db -> conditions ( 'Member.email = "mariano@cricava.com" AND Member.user LIKE "mariano.iglesias%"' );
$expected = ' WHERE `Member`.`email` = "mariano@cricava.com" AND `Member`.`user` LIKE "mariano.iglesias%"' ;
$this -> assertEqual ( $result , $expected );
}
2007-02-03 22:20:13 +00:00
2007-04-29 04:18:41 +00:00
function testParenthesisInStringConditions () {
2007-04-29 04:24:47 +00:00
$result = $this -> db -> conditions ( 'Member.name = \'(lu\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \')lu\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'va(lu\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'va)lu\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'va(lu)\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'va(lu)e\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano)\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano)iglesias\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano) iglesias\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano word) iglesias\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano.iglesias)\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/' , $result );
2007-04-29 04:18:41 +00:00
$result = $this -> db -> conditions ( 'Member.name = \'Mariano Iglesias (mariano.iglesias)\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/' , $result );
2007-04-29 04:24:47 +00:00
$result = $this -> db -> conditions ( 'Member.name = \'Mariano Iglesias (mariano.iglesias) CakePHP\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/' , $result );
$result = $this -> db -> conditions ( 'Member.name = \'(mariano.iglesias) CakePHP\'' );
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/' , $result );
2007-04-29 04:18:41 +00:00
}
function testParenthesisInArrayConditions () {
$result = $this -> db -> conditions ( array ( 'Member.name' => '(lu' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => ')lu' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'va(lu' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'va)lu' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'va(lu)' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'va(lu)e' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano)' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano)iglesias' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano) iglesias' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano word) iglesias' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano.iglesias)' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'Mariano Iglesias (mariano.iglesias)' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => 'Mariano Iglesias (mariano.iglesias) CakePHP' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\) CakePHP\'$/' , $result );
$result = $this -> db -> conditions ( array ( 'Member.name' => '(mariano.iglesias) CakePHP' ));
$this -> assertPattern ( '/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/' , $result );
}
2007-02-03 22:20:13 +00:00
function testArrayConditionsParsing () {
$result = $this -> db -> conditions ( array ( 'Candy.name' => 'LIKE a' , 'HardCandy.name' => 'LIKE c' ));
2007-03-20 17:38:53 +00:00
$this -> assertPattern ( " /^ \ s+WHERE \ s+`Candy`.`name` LIKE \ s+'a' \ s+AND \ s+`HardCandy`.`name` \ s+LIKE \ s+'c'/ " , $result );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( array ( 'HardCandy.name' => 'LIKE a' , 'Candy.name' => 'LIKE c' ));
2007-03-20 17:38:53 +00:00
$expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c' " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'HardCandy.name' => 'LIKE a%' , 'Candy.name' => 'LIKE %c%' ));
$expected = " WHERE `HardCandy`.`name` LIKE 'a%' AND `Candy`.`name` LIKE '%c%' " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'HardCandy.name' => 'LIKE to be or%' , 'Candy.name' => 'LIKE %not to be%' ));
$expected = " WHERE `HardCandy`.`name` LIKE 'to be or%' AND `Candy`.`name` LIKE '%not to be%' " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( array ( 'score' => 'BETWEEN 90.1 AND 95.7' ));
2007-03-20 17:38:53 +00:00
$expected = " WHERE `score` BETWEEN '90.1' AND '95.7' " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( array ( 'Post.title' => 1.1 ));
2007-03-20 17:38:53 +00:00
$expected = " WHERE `Post`.`title` = 1.1 " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
$result = $this -> db -> conditions ( array ( 'SUM(Post.comments_count)' => '> 500' ));
2007-03-20 17:38:53 +00:00
$expected = " WHERE SUM(`Post`.`comments_count`) > 500 " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'MAX(Post.rating)' => '> 50' ));
$expected = " WHERE MAX(`Post`.`rating`) > 50 " ;
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-08 22:16:35 +00:00
$result = $this -> db -> conditions ( array ( 'title' => 'LIKE %hello' ));
2007-03-20 17:38:53 +00:00
$expected = " WHERE `title` LIKE '%hello' " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'Post.name' => '= mad(g)ik' ));
$expected = " WHERE `Post`.`name` = 'mad(g)ik' " ;
2007-02-08 22:16:35 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-20 17:38:53 +00:00
$result = $this -> db -> conditions ( array ( 'score' => array ( 1 , 2 , 10 )));
$expected = " WHERE `score` IN (1, 2, 10) " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'score' => '!= 20' ));
$expected = " WHERE `score` != 20 " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'score' => '> 20' ));
$expected = " WHERE `score` > 20 " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'or' => array ( 'score' => 'BETWEEN 4 AND 5' , 'rating' => '> 20' ) ));
2007-06-09 20:32:14 +00:00
$expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`rating` > 20)) " ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( $result , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$result = $this -> db -> conditions ( array ( 'or' => array ( 'score' => 'BETWEEN 4 AND 5' , array ( 'score' => '> 20' )) ));
2007-06-09 20:32:14 +00:00
$expected = " WHERE ((`score` BETWEEN '4' AND '5') OR (`score` > 20)) " ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'and' => array ( 'score' => 'BETWEEN 4 AND 5' , array ( 'score' => '> 20' )) ));
2007-06-09 20:32:14 +00:00
$expected = " WHERE ((`score` BETWEEN '4' AND '5') AND (`score` > 20)) " ;
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-22 00:26:42 +00:00
$result = $this -> db -> conditions ( array ( 'published' => 1 , 'or' => array ( 'score' => '< 2' , array ( 'score' => '> 20' )) ));
2007-06-09 20:32:14 +00:00
$expected = " WHERE `published` = 1 AND ((`score` < 2) OR (`score` > 20)) " ;
2007-02-08 22:16:35 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-22 00:59:28 +00:00
$result = $this -> db -> conditions ( array ( array ( 'Project.removed' => false )));
$this -> assertPattern ( '/^\s*WHERE\s+`Project`.`removed`\s+=\s+0\s*$/' , $result );
$result = $this -> db -> conditions ( array ( array ( 'Project.removed' => true )));
$this -> assertPattern ( '/^\s*WHERE\s+`Project`.`removed`\s+=\s+1\s*$/' , $result );
$result = $this -> db -> conditions ( array ( array ( 'Project.removed' => null )));
$this -> assertPattern ( '/^\s*WHERE\s+`Project`.`removed`\s+IS\s+NULL\s*$/' , $result );
2007-03-28 00:53:37 +00:00
$result = $this -> db -> conditions ( array ( '(Usergroup.permissions) & 4' => 4 ));
$this -> assertPattern ( '/^\s*WHERE\s+\(`Usergroup`\.`permissions`\)\s+& 4\s+=\s+4\s*$/' , $result );
2007-03-29 01:45:13 +00:00
2007-04-06 11:15:45 +00:00
$result = $this -> db -> conditions ( array ( '((Usergroup.permissions) & 4)' => 4 ));
$this -> assertPattern ( '/^\s*WHERE\s+\(\(`Usergroup`\.`permissions`\)\s+& 4\)\s+=\s+4\s*$/' , $result );
$result = $this -> db -> conditions ( array ( 'Post.modified' => '>= DATE_SUB(NOW(), INTERVAL 7 DAY)' ));
2008-03-20 16:40:45 +00:00
$expected = " WHERE `Post`.`modified` >= 'DATE_SUB(NOW(), INTERVAL 7 DAY)' " ;
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> conditions ( array ( 'Post.modified >= DATE_SUB(NOW(), INTERVAL 7 DAY)' ));
$expected = " WHERE `Post`.`modified` >= DATE_SUB(NOW(), INTERVAL 7 DAY) " ;
2007-04-06 11:15:45 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-29 01:45:13 +00:00
$result = $this -> db -> conditions ( array (
'NOT' => array ( 'Course.id' => null , 'Course.vet' => 'N' , 'level_of_education_id' => array ( 912 , 999 )),
'Enrollment.yearcompleted' => '> 0' )
);
2007-06-09 20:32:14 +00:00
$this -> assertPattern ( '/^\s*WHERE\s+NOT\s+\(\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\s*\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+0\s*$/' , $result );
2007-04-17 05:17:06 +00:00
$result = $this -> db -> conditions ( array ( 'id' => '<> 8' ));
$this -> assertPattern ( '/^\s*WHERE\s+`id`\s+<>\s+8\s*$/' , $result );
2007-04-29 05:37:39 +00:00
$result = $this -> db -> conditions ( array ( 'TestModel.field' => '= gribe$@()lu' ));
$expected = " WHERE `TestModel`.`field` = 'gribe $ @()lu' " ;
$this -> assertEqual ( $result , $expected );
2007-06-09 20:32:14 +00:00
$conditions [ 'NOT' ] = array ( 'Listing.expiration' => " BETWEEN 1 AND 100 " );
$conditions [ 0 ][ 'OR' ] = array (
" Listing.title " => " LIKE %term% " ,
" Listing.description " => " LIKE %term% "
);
$conditions [ 1 ][ 'OR' ] = array (
" Listing.title " => " LIKE %term_2% " ,
" Listing.description " => " LIKE %term_2% "
);
$result = $this -> db -> conditions ( $conditions );
$expected = " WHERE NOT ((`Listing`.`expiration` BETWEEN '1' AND '100')) AND ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%')) " ;
$this -> assertEqual ( $result , $expected );
2007-10-17 06:13:37 +00:00
$result = $this -> db -> conditions ( array ( 'MD5(CONCAT(Reg.email,Reg.id))' => 'blah' ));
$expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) = 'blah' " ;
$this -> assertEqual ( $result , $expected );
Fixes #2902, DB_ACL::allow allowing all when $actions is not an array.
Fixes #2988, AclComponent check() does not inherit permissions.
Fixes #3022, Inconsistent table alias quoting crashes Acl node lookup with PostgreSQL.
Fixes #3129, Console ACL Shell ACO View Broken
Fixes #3176, Problems with ACL support on Microsoft SQL Server.
Closes #3311 as invalid, DboSourceTest::testArrayConditionsParsing tests added
Fixes #3312, DB_ACL::check() fail returning right permission
Fixes #3344, Model->field adds incorrect condition under certain circumstances.
Fixes #3400, Cookie Component: When reading a non-existing key it throws a notice.
Fixes #3407, Since [5768] CookieComponent throws warning when used in beforeFilter().
Closes #3401, Added form test to ensure $Form->fields array is what the security component requires.
Updated AclComponentTest
Merged changes in app/ to cake/console/libs/templates/skel
Fixed generated link to Run More Test after running Group > All tests
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5776 3807eeeb-6ff5-0310-8944-8be069107fe0
2007-10-17 12:51:17 +00:00
$conditions = array ( 'id' => array ( 2 , 5 , 6 , 9 , 12 , 45 , 78 , 43 , 76 ));
$result = $this -> db -> conditions ( $conditions );
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76) " ;
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
}
2007-06-20 07:51:52 +00:00
function testMixedConditionsParsing () {
2007-05-14 01:52:59 +00:00
$conditions [] = 'User.first_name = \'Firstname\'' ;
$conditions [] = array ( 'User.last_name' => 'Lastname' );
$result = $this -> db -> conditions ( $conditions );
$expected = " WHERE `User`.`first_name` = 'Firstname' AND `User`.`last_name` = 'Lastname' " ;
$this -> assertEqual ( $result , $expected );
2007-07-08 01:17:57 +00:00
2007-06-25 14:48:20 +00:00
$conditions = array (
'Thread.project_id' => 5 ,
'Thread.buyer_id' => 14 ,
'1=1 GROUP BY Thread.project_id'
);
$result = $this -> db -> conditions ( $conditions );
$this -> assertPattern ( '/^\s*WHERE\s+`Thread`.`project_id`\s*=\s*5\s+AND\s+`Thread`.`buyer_id`\s*=\s*14\s+AND\s+1\s*=\s*1\s+GROUP BY `Thread`.`project_id`$/' , $result );
2007-05-14 01:52:59 +00:00
}
2007-07-29 12:21:41 +00:00
2007-12-02 23:39:43 +00:00
function testConditionsOptionalArguments () {
$result = $this -> db -> conditions ( array ( 'Member.name' => 'Mariano' ), true , false );
$this -> assertPattern ( '/^\s*`Member`.`name`\s*=\s*\'Mariano\'\s*$/' , $result );
$result = $this -> db -> conditions ( array (), true , false );
$this -> assertPattern ( '/^\s*1\s*=\s*1\s*$/' , $result );
}
2007-02-03 22:20:13 +00:00
function testFieldParsing () {
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Vendor' , " Vendor.id, COUNT(Model.vendor_id) AS `Vendor`.`count` " );
2007-04-30 13:27:41 +00:00
$expected = array ( '`Vendor`.`id`' , 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`' );
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Vendor' , " `Vendor`.`id`, COUNT(`Model`.`vendor_id`) AS `Vendor`.`count` " );
2007-04-30 13:27:41 +00:00
$expected = array ( '`Vendor`.`id`' , 'COUNT(`Model`.`vendor_id`) AS `Vendor`.`count`' );
2007-04-30 13:24:13 +00:00
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Post' , " CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name, Node.created " );
2007-02-03 22:20:13 +00:00
$expected = array ( " CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name " , " `Node`.`created` " );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'round( (3.55441 * fooField), 3 ) AS test' );
2007-03-21 05:24:03 +00:00
$this -> assertEqual ( $result , array ( 'round( (3.55441 * fooField), 3 ) AS test' ));
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating' );
2007-03-21 05:24:03 +00:00
$this -> assertEqual ( $result , array ( 'ROUND(`Rating`.`rate_total` / `Rating`.`rate_count`,2) AS rating' ));
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'ROUND(Rating.rate_total / Rating.rate_count,2) AS rating' );
2007-03-21 05:24:03 +00:00
$this -> assertEqual ( $result , array ( 'ROUND(Rating.rate_total / Rating.rate_count,2) AS rating' ));
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Post' , " Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name " );
2007-02-03 22:20:13 +00:00
$expected = array ( " `Node`.`created` " , " CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name " );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Post' , " 2.2,COUNT(*), SUM(Something.else) as sum, Node.created, CONCAT(REPEAT(' ', COUNT(Parent.name) - 1), Node.name) AS name,Post.title,Post.1,1.1 " );
2007-02-03 22:20:13 +00:00
$expected = array (
'2.2' , 'COUNT(*)' , 'SUM(`Something`.`else`) as sum' , '`Node`.`created`' ,
" CONCAT(REPEAT(' ', COUNT(`Parent`.`name`) - 1), Node.name) AS name " , '`Post`.`title`' , '`Post`.`1`' , '1.1'
);
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-03-20 17:38:53 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Post' );
2007-03-20 17:38:53 +00:00
$expected = array (
'`Post`.`id`' , '`Post`.`client_id`' , '`Post`.`name`' , '`Post`.`login`' ,
'`Post`.`passwd`' , '`Post`.`addr_1`' , '`Post`.`addr_2`' , '`Post`.`zip_code`' ,
'`Post`.`city`' , '`Post`.`country`' , '`Post`.`phone`' , '`Post`.`fax`' ,
'`Post`.`url`' , '`Post`.`email`' , '`Post`.`comments`' , '`Post`.`last_login`' ,
'`Post`.`created`' , '`Post`.`updated`'
);
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , 'Other' );
2007-03-20 17:38:53 +00:00
$expected = array (
'`Other`.`id`' , '`Other`.`client_id`' , '`Other`.`name`' , '`Other`.`login`' ,
'`Other`.`passwd`' , '`Other`.`addr_1`' , '`Other`.`addr_2`' , '`Other`.`zip_code`' ,
'`Other`.`city`' , '`Other`.`country`' , '`Other`.`phone`' , '`Other`.`fax`' ,
'`Other`.`url`' , '`Other`.`email`' , '`Other`.`comments`' , '`Other`.`last_login`' ,
'`Other`.`created`' , '`Other`.`updated`'
);
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , array (), false );
2007-03-20 17:38:53 +00:00
$expected = array ( 'id' , 'client_id' , 'name' , 'login' , 'passwd' , 'addr_1' , 'addr_2' , 'zip_code' , 'city' , 'country' , 'phone' , 'fax' , 'url' , 'email' , 'comments' , 'last_login' , 'created' , 'updated' );
$this -> assertEqual ( $result , $expected );
2007-03-27 01:34:59 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'COUNT(*)' );
2007-03-27 01:34:59 +00:00
$expected = array ( 'COUNT(*)' );
$this -> assertEqual ( $result , $expected );
2007-07-08 01:17:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'SUM(Thread.unread_buyer) AS ' . $this -> db -> name ( 'sum_unread_buyer' ));
2007-06-25 14:48:20 +00:00
$expected = array ( 'SUM(`Thread`.`unread_buyer`) AS `sum_unread_buyer`' );
$this -> assertEqual ( $result , $expected );
2007-07-08 02:29:37 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'name, count(*)' );
2007-07-08 02:29:37 +00:00
$expected = array ( '`TestModel`.`name`' , 'count(*)' );
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'count(*), name' );
2007-07-08 02:29:37 +00:00
$expected = array ( 'count(*)' , '`TestModel`.`name`' );
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , 'field1, field2, field3, count(*), name' );
2007-07-08 02:29:37 +00:00
$expected = array ( '`TestModel`.`field1`' , '`TestModel`.`field2`' , '`TestModel`.`field3`' , 'count(*)' , '`TestModel`.`name`' );
$this -> assertEqual ( $result , $expected );
2007-07-29 12:21:41 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> fields ( $this -> Model , null , array ( 'dayofyear(now())' ));
2007-07-29 12:21:41 +00:00
$expected = array ( 'dayofyear(now())' );
$this -> assertEqual ( $result , $expected );
2008-02-21 15:36:13 +00:00
$result = $this -> db -> fields ( $this -> Model , null , array ( 'MAX(Model.field) As Max' ));
$expected = array ( 'MAX(`Model`.`field`) As Max' );
$this -> assertEqual ( $result , $expected );
2008-03-09 22:15:08 +00:00
$result = $this -> db -> fields ( $this -> Model , null , array ( 'Model.field AS AnotherName' ));
$expected = array ( '`Model`.`field` AS `AnotherName`' );
$this -> assertEqual ( $result , $expected );
$result = $this -> db -> fields ( $this -> Model , null , array ( 'field AS AnotherName' ));
$expected = array ( '`TestModel`.`field` AS `AnotherName`' );
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
}
2007-03-20 17:38:53 +00:00
function testMergeAssociations () {
$data = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array (
2008-02-24 15:28:17 +00:00
'Topic' => array (
2008-02-21 15:36:13 +00:00
array ( 'id' => '1' , 'topic' => 'Topic' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' )
2007-03-20 17:38:53 +00:00
)
);
$expected = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
'Topic' => array (
'id' => '1' , 'topic' => 'Topic' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Topic' , 'hasOne' );
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
)
);
$merge = array (
2008-02-21 15:36:13 +00:00
'User2' => array (
array ( 'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' )
2007-03-20 17:38:53 +00:00
)
);
$expected = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
);
2007-03-27 01:34:59 +00:00
$this -> db -> __mergeAssociation ( $data , $merge , 'User2' , 'belongsTo' );
2007-03-20 17:38:53 +00:00
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
)
);
2008-02-21 15:36:13 +00:00
$merge = array ( array ( 'Comment' => false ));
2007-03-20 17:38:53 +00:00
$expected = array (
2007-03-27 01:34:59 +00:00
'Article2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array ()
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Comment' , 'hasMany' );
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = 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'
)
);
$merge = array (
2008-02-24 15:28:17 +00:00
array (
2007-03-20 17:38:53 +00:00
'Comment' => array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
),
array (
'Comment' => array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array (
'Article' => array (
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array (
array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Comment' , 'hasMany' );
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = 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'
)
);
$merge = array (
2008-02-24 15:28:17 +00:00
array (
2007-03-20 17:38:53 +00:00
'Comment' => array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
),
array (
'Comment' => array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = array (
'Article' => array (
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array (
array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ,
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
),
array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ,
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
)
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Comment' , 'hasMany' );
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = 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'
)
);
$merge = array (
2008-02-24 15:28:17 +00:00
array (
2007-03-20 17:38:53 +00:00
'Comment' => array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array (
array ( 'id' => 1 , 'tag' => 'Tag 1' ),
array ( 'id' => 2 , 'tag' => 'Tag 2' )
)
),
array (
'Comment' => array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array ()
)
);
$expected = array (
'Article' => array (
'id' => '1' , 'user_id' => '1' , 'title' => 'First Article' , 'body' => 'First Article Body' , 'published' => 'Y' , 'created' => '2007-03-18 10:39:23' , 'updated' => '2007-03-18 10:41:31'
),
'Comment' => array (
array (
'id' => '1' , 'comment' => 'Comment 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ,
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array (
array ( 'id' => 1 , 'tag' => 'Tag 1' ),
array ( 'id' => 2 , 'tag' => 'Tag 2' )
)
),
array (
'id' => '2' , 'comment' => 'Comment 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31' ,
2007-03-27 01:34:59 +00:00
'User2' => array (
2007-03-20 17:38:53 +00:00
'id' => '1' , 'user' => 'mariano' , 'password' => '5f4dcc3b5aa765d61d8327deb882cf99' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
'Tag' => array ()
)
)
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Comment' , 'hasMany' );
$this -> assertEqual ( $data , $expected );
2007-04-04 19:55:57 +00:00
2007-03-20 17:38:53 +00:00
$data = 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'
)
);
$merge = array (
2008-02-24 15:28:17 +00:00
array (
2007-03-20 17:38:53 +00:00
'Tag' => array (
'id' => '1' , 'tag' => 'Tag 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
),
array (
'Tag' => array (
'id' => '2' , 'tag' => 'Tag 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
),
array (
'Tag' => array (
'id' => '3' , 'tag' => 'Tag 3' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
);
$expected = 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'
),
'Tag' => array (
array (
'id' => '1' , 'tag' => 'Tag 1' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
array (
'id' => '2' , 'tag' => 'Tag 2' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
),
array (
'id' => '3' , 'tag' => 'Tag 3' , 'created' => '2007-03-17 01:16:23' , 'updated' => '2007-03-17 01:18:31'
)
)
);
$this -> db -> __mergeAssociation ( $data , $merge , 'Tag' , 'hasAndBelongsToMany' );
$this -> assertEqual ( $data , $expected );
}
2007-02-03 22:20:13 +00:00
function testMagicMethodQuerying () {
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findByFieldName' , array ( 'value' ), $this -> Model );
2007-02-03 22:20:13 +00:00
$expected = array ( 'TestModel.field_name' => '= value' );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findAllByFieldName' , array ( 'value' ), $this -> Model );
2007-03-22 00:26:42 +00:00
$expected = array ( 'TestModel.field_name' => '= value' );
$this -> assertEqual ( $result , $expected );
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findAllById' , array ( 'a' ), $this -> Model );
2007-04-07 06:42:08 +00:00
$expected = array ( 'TestModel.id' => '= a' );
2007-02-08 22:16:35 +00:00
$this -> assertEqual ( $result , $expected );
2007-04-09 04:00:04 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findByFieldName' , array ( array ( 'value1' , 'value2' , 'value3' )), $this -> Model );
2007-02-03 22:20:13 +00:00
$expected = array ( 'TestModel.field_name' => array ( 'value1' , 'value2' , 'value3' ));
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findByFieldName' , array ( null ), $this -> Model );
2007-02-03 22:20:13 +00:00
$expected = array ( 'TestModel.field_name' => null );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-02-03 22:20:13 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findByFieldName' , array ( '= a' ), $this -> Model );
2007-02-03 22:20:13 +00:00
$expected = array ( 'TestModel.field_name' => '= = a' );
2007-02-04 09:06:44 +00:00
$this -> assertEqual ( $result , $expected );
2007-04-04 19:55:57 +00:00
2007-11-09 05:13:12 +00:00
$result = $this -> db -> query ( 'findByFieldName' , array (), $this -> Model );
2007-04-03 05:43:31 +00:00
$expected = false ;
$this -> assertEqual ( $result , $expected );
2007-04-04 19:55:57 +00:00
2007-02-03 22:20:13 +00:00
}
2007-02-08 22:16:35 +00:00
function testOrderParsing () {
$result = $this -> db -> order ( " ADDTIME(Event.time_begin, '-06:00:00') ASC " );
$expected = " ORDER BY ADDTIME(`Event`.`time_begin`, '-06:00:00') ASC " ;
$this -> assertEqual ( $result , $expected );
2007-03-22 00:26:42 +00:00
$result = $this -> db -> order ( " title, id " );
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/' , $result );
$result = $this -> db -> order ( " title desc, id desc " );
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/' , $result );
$result = $this -> db -> order ( array ( " title desc, id desc " ));
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+desc,\s+`id`\s+desc\s*$/' , $result );
$result = $this -> db -> order ( array ( " title " , " id " ));
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/' , $result );
$result = $this -> db -> order ( array ( array ( 'title' ), array ( 'id' )));
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+ASC,\s+`id`\s+ASC\s*$/' , $result );
$result = $this -> db -> order ( array ( " Post.title " => 'asc' , " Post.id " => 'desc' ));
$this -> assertPattern ( '/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/' , $result );
$result = $this -> db -> order ( array ( array ( " Post.title " => 'asc' , " Post.id " => 'desc' )));
$this -> assertPattern ( '/^\s*ORDER BY\s+`Post`.`title`\s+asc,\s+`Post`.`id`\s+desc\s*$/' , $result );
$result = $this -> db -> order ( array ( " title " ));
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+ASC\s*$/' , $result );
$result = $this -> db -> order ( array ( array ( " title " )));
$this -> assertPattern ( '/^\s*ORDER BY\s+`title`\s+ASC\s*$/' , $result );
2007-08-29 01:02:21 +00:00
$result = $this -> db -> order ( " Dealer.id = 7 desc, Dealer.id = 3 desc, Dealer.title asc " );
$expected = " ORDER BY Dealer`.`id` = 7 desc, Dealer`.`id` = 3 desc, `Dealer`.`title` asc " ;
$this -> assertEqual ( $result , $expected );
2007-10-07 14:13:59 +00:00
$result = $this -> db -> order ( array ( " Page.name " => " ='test' DESC " ));
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+`Page` \ .`name` \ s*='test' \ s+DESC \ s* $ / " , $result );
$result = $this -> db -> order ( " Page.name = 'view' DESC " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+`Page` \ .`name` \ s*= \ s*'view' \ s+DESC \ s* $ / " , $result );
2007-12-02 23:39:43 +00:00
2007-11-17 03:57:15 +00:00
$result = $this -> db -> order ( " (Post.views) " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+ \ (`Post` \ .`views` \ ) \ s+ASC \ s* $ / " , $result );
$result = $this -> db -> order ( " (Post.views)*Post.views " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+ \ (`Post` \ .`views` \ ) \ *`Post` \ .`views` \ s+ASC \ s* $ / " , $result );
$result = $this -> db -> order ( " (Post.views) * Post.views " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+ \ (`Post` \ .`views` \ ) \ * `Post` \ .`views` \ s+ASC \ s* $ / " , $result );
$result = $this -> db -> order ( " (Model.field1 + Model.field2) * Model.field3 " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+ \ (`Model` \ .`field1` \ + `Model` \ .`field2` \ ) \ * `Model` \ .`field3` \ s+ASC \ s* $ / " , $result );
2007-12-02 23:39:43 +00:00
2007-11-17 03:57:15 +00:00
$result = $this -> db -> order ( " Model.name+0 ASC " );
$this -> assertPattern ( " /^ \ s*ORDER BY \ s+`Model` \ .`name` \ +0 \ s+ASC \ s* $ / " , $result );
2007-02-08 22:16:35 +00:00
}
2008-03-11 02:44:33 +00:00
function testCalculations () {
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'count' );
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'COUNT(*) AS `count`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'count' , array ( 'id' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'COUNT(`id`) AS `count`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'count' , array ( 'id' , 'id_count' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'COUNT(`id`) AS `id_count`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'count' , array ( 'Model.id' , 'id_count' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'COUNT(`Model`.`id`) AS `id_count`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'max' , array ( 'id' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'MAX(`id`) AS `id`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'max' , array ( 'Model.id' , 'id' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'MAX(`Model`.`id`) AS `id`' );
2008-03-13 03:11:29 +00:00
$result = $this -> db -> calculate ( $this -> Model , 'max' , array ( '`Model`.`id`' , 'id' ));
2008-03-11 02:44:33 +00:00
$this -> assertEqual ( $result , 'MAX(`Model`.`id`) AS `id`' );
}
2008-03-16 05:44:20 +00:00
2007-02-03 22:20:13 +00:00
}
2007-11-17 03:57:15 +00:00
2007-02-03 22:20:13 +00:00
?>