Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

4227 lines (3598 sloc) 150.339 kb
<?php
/**
* DboSourceTest file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
* @since CakePHP(tm) v 1.2.0.4206
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
App::import('Model', array('Model', 'DataSource', 'DboSource', 'DboMysql', 'App'));
require_once dirname(dirname(__FILE__)) . DS . 'models.php';
/**
* TestModel class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel'
* @access public
*/
var $name = 'TestModel';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* schema property
*
* @var array
* @access protected
*/
var $_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)
);
/**
* find method
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
* @access public
* @return void
*/
function find($conditions = null, $fields = null, $order = null, $recursive = null) {
return array($conditions, $fields);
}
/**
* findAll method
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
* @access public
* @return void
*/
function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
return $conditions;
}
}
/**
* TestModel2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel2 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel2'
* @access public
*/
var $name = 'TestModel2';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
}
/**
* TestModel4 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel3 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel3'
* @access public
*/
var $name = 'TestModel3';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
}
/**
* TestModel4 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel4 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel4'
* @access public
*/
var $name = 'TestModel4';
/**
* table property
*
* @var string 'test_model4'
* @access public
*/
var $table = 'test_model4';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'TestModel4Parent' => array(
'className' => 'TestModel4',
'foreignKey' => 'parent_id'
)
);
/**
* hasOne property
*
* @var array
* @access public
*/
var $hasOne = array(
'TestModel5' => array(
'className' => 'TestModel5',
'foreignKey' => 'test_model4_id'
)
);
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('TestModel7' => array(
'className' => 'TestModel7',
'joinTable' => 'test_model4_test_model7',
'foreignKey' => 'test_model4_id',
'associationForeignKey' => 'test_model7_id',
'with' => 'TestModel4TestModel7'
));
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* TestModel4TestModel7 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel4TestModel7 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel4TestModel7'
* @access public
*/
var $name = 'TestModel4TestModel7';
/**
* table property
*
* @var string 'test_model4_test_model7'
* @access public
*/
var $table = 'test_model4_test_model7';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* schema method
*
* @access public
* @return void
*/
function schema() {
if (!isset($this->_schema)) {
$this->_schema = array(
'test_model4_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
'test_model7_id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8')
);
}
return $this->_schema;
}
}
/**
* TestModel5 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel5 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel5'
* @access public
*/
var $name = 'TestModel5';
/**
* table property
*
* @var string 'test_model5'
* @access public
*/
var $table = 'test_model5';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('TestModel4' => array(
'className' => 'TestModel4',
'foreignKey' => 'test_model4_id'
));
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array('TestModel6' => array(
'className' => 'TestModel6',
'foreignKey' => 'test_model5_id'
));
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* TestModel6 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel6 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel6'
* @access public
*/
var $name = 'TestModel6';
/**
* table property
*
* @var string 'test_model6'
* @access public
*/
var $table = 'test_model6';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('TestModel5' => array(
'className' => 'TestModel5',
'foreignKey' => 'test_model5_id'
));
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* TestModel7 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel7 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel7'
* @access public
*/
var $name = 'TestModel7';
/**
* table property
*
* @var string 'test_model7'
* @access public
*/
var $table = 'test_model7';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* TestModel8 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel8 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel8'
* @access public
*/
var $name = 'TestModel8';
/**
* table property
*
* @var string 'test_model8'
* @access public
*/
var $table = 'test_model8';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* hasOne property
*
* @var array
* @access public
*/
var $hasOne = array(
'TestModel9' => array(
'className' => 'TestModel9',
'foreignKey' => 'test_model8_id',
'conditions' => 'TestModel9.name != \'mariano\''
)
);
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* TestModel9 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class TestModel9 extends CakeTestModel {
/**
* name property
*
* @var string 'TestModel9'
* @access public
*/
var $name = 'TestModel9';
/**
* table property
*
* @var string 'test_model9'
* @access public
*/
var $table = 'test_model9';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('TestModel8' => array(
'className' => 'TestModel8',
'foreignKey' => 'test_model8_id',
'conditions' => 'TestModel8.name != \'larry\''
));
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* Level class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Level extends CakeTestModel {
/**
* name property
*
* @var string 'Level'
* @access public
*/
var $name = 'Level';
/**
* table property
*
* @var string 'level'
* @access public
*/
var $table = 'level';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array(
'Group'=> array(
'className' => 'Group'
),
'User2' => array(
'className' => 'User2'
)
);
/**
* schema method
*
* @access public
* @return void
*/
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'),
);
}
return $this->_schema;
}
}
/**
* Group class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Group extends CakeTestModel {
/**
* name property
*
* @var string 'Group'
* @access public
*/
var $name = 'Group';
/**
* table property
*
* @var string 'group'
* @access public
*/
var $table = 'group';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('Level');
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array('Category2', 'User2');
/**
* schema method
*
* @access public
* @return void
*/
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'),
);
}
return $this->_schema;
}
}
/**
* User2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class User2 extends CakeTestModel {
/**
* name property
*
* @var string 'User2'
* @access public
*/
var $name = 'User2';
/**
* table property
*
* @var string 'user'
* @access public
*/
var $table = 'user';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'Group' => array(
'className' => 'Group'
),
'Level' => array(
'className' => 'Level'
)
);
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array(
'Article2' => array(
'className' => 'Article2'
),
);
/**
* schema method
*
* @access public
* @return void
*/
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'),
);
}
return $this->_schema;
}
}
/**
* Category2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Category2 extends CakeTestModel {
/**
* name property
*
* @var string 'Category2'
* @access public
*/
var $name = 'Category2';
/**
* table property
*
* @var string 'category'
* @access public
*/
var $table = 'category';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id'
),
'ParentCat' => array(
'className' => 'Category2',
'foreignKey' => 'parent_id'
)
);
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array(
'ChildCat' => array(
'className' => 'Category2',
'foreignKey' => 'parent_id'
),
'Article2' => array(
'className' => 'Article2',
'order'=>'Article2.published_date DESC',
'foreignKey' => 'category_id',
'limit'=>'3')
);
/**
* schema method
*
* @access public
* @return void
*/
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),
);
}
return $this->_schema;
}
}
/**
* Article2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Article2 extends CakeTestModel {
/**
* name property
*
* @var string 'Article2'
* @access public
*/
var $name = 'Article2';
/**
* table property
*
* @var string 'article'
* @access public
*/
var $table = 'article';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'Category2' => array('className' => 'Category2'),
'User2' => array('className' => 'User2')
);
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* CategoryFeatured2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class CategoryFeatured2 extends CakeTestModel {
/**
* name property
*
* @var string 'CategoryFeatured2'
* @access public
*/
var $name = 'CategoryFeatured2';
/**
* table property
*
* @var string 'category_featured'
* @access public
*/
var $table = 'category_featured';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* Featured2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Featured2 extends CakeTestModel {
/**
* name property
*
* @var string 'Featured2'
* @access public
*/
var $name = 'Featured2';
/**
* table property
*
* @var string 'featured2'
* @access public
*/
var $table = 'featured2';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'CategoryFeatured2' => array(
'className' => 'CategoryFeatured2'
)
);
/**
* schema method
*
* @access public
* @return void
*/
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')
);
}
return $this->_schema;
}
}
/**
* Comment2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class Comment2 extends CakeTestModel {
/**
* name property
*
* @var string 'Comment2'
* @access public
*/
var $name = 'Comment2';
/**
* table property
*
* @var string 'comment'
* @access public
*/
var $table = 'comment';
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('ArticleFeatured2', 'User2');
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* schema method
*
* @access public
* @return void
*/
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')
);
}
return $this->_schema;
}
}
/**
* ArticleFeatured2 class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class ArticleFeatured2 extends CakeTestModel {
/**
* name property
*
* @var string 'ArticleFeatured2'
* @access public
*/
var $name = 'ArticleFeatured2';
/**
* table property
*
* @var string 'article_featured'
* @access public
*/
var $table = 'article_featured';
/**
* useTable property
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array(
'CategoryFeatured2' => array('className' => 'CategoryFeatured2'),
'User2' => array('className' => 'User2')
);
/**
* hasOne property
*
* @var array
* @access public
*/
var $hasOne = array(
'Featured2' => array('className' => 'Featured2')
);
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array(
'Comment2' => array('className'=>'Comment2', 'dependent' => true)
);
/**
* schema method
*
* @access public
* @return void
*/
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)
);
}
return $this->_schema;
}
}
/**
* DboSourceTest class
*
* @package cake
* @subpackage cake.tests.cases.libs.model.datasources
*/
class DboSourceTest extends CakeTestCase {
/**
* debug property
*
* @var mixed null
* @access public
*/
var $debug = null;
/**
* autoFixtures property
*
* @var bool false
* @access public
*/
var $autoFixtures = false;
/**
* fixtures property
*
* @var array
* @access public
*/
var $fixtures = array(
'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment',
'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author'
);
/**
* startTest method
*
* @access public
* @return void
*/
function startTest() {
$this->__config = $this->db->config;
if (!class_exists('DboTest')) {
$db = ConnectionManager::getDataSource('test_suite');
$class = get_class($db);
eval("class DboTest extends $class {
var \$simulated = array();
/**
* execute method
*
* @param \$sql
* @access protected
* @return void
*/
function _execute(\$sql) {
\$this->simulated[] = \$sql;
return null;
}
/**
* getLastQuery method
*
* @access public
* @return void
*/
function getLastQuery() {
return \$this->simulated[count(\$this->simulated) - 1];
}
}");
}
$this->testDb =& new DboTest($this->__config);
$this->testDb->cacheSources = false;
$this->testDb->startQuote = '`';
$this->testDb->endQuote = '`';
Configure::write('debug', 1);
$this->debug = Configure::read('debug');
$this->Model =& new TestModel();
}
/**
* endTest method
*
* @access public
* @return void
*/
function endTest() {
unset($this->Model);
Configure::write('debug', $this->debug);
unset($this->debug);
}
/**
* testFieldDoubleEscaping method
*
* @access public
* @return void
*/
function testFieldDoubleEscaping() {
$config = array_merge($this->__config, array('driver' => 'test'));
$test =& ConnectionManager::create('quoteTest', $config);
$test->simulated = array();
$this->Model =& new Article2(array('alias' => '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 `' . $this->testDb->fullTableName('article', false) . '` 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 [' . $this->testDb->fullTableName('article', false) . '] AS [Article] WHERE 1 = 1');
ClassRegistry::removeObject('Article');
}
/**
* testGenerateAssociationQuerySelfJoin method
*
* @access public
* @return void
*/
function testGenerateAssociationQuerySelfJoin() {
$this->startTime = microtime(true);
$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();
$queryData = array();
foreach ($this->Model->Category2->__associations as $type) {
foreach ($this->Model->Category2->{$type} as $assoc => $assocData) {
$linkModel =& $this->Model->Category2->{$assoc};
$external = isset($assocData['external']);
if ($this->Model->Category2->alias == $linkModel->alias && $type != 'hasAndBelongsToMany' && $type != 'hasMany') {
$result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertTrue($result);
} else {
if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) {
$result = $this->testDb->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
$this->assertTrue($result);
}
}
}
}
$query = $this->testDb->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null);
$this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query);
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$_queryData = $queryData;
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$expected = array(
'fields' => array(
'`TestModel4`.`id`',
'`TestModel4`.`name`',
'`TestModel4`.`created`',
'`TestModel4`.`updated`',
'`TestModel4Parent`.`id`',
'`TestModel4Parent`.`name`',
'`TestModel4Parent`.`created`',
'`TestModel4Parent`.`updated`'
),
'joins' => array(
array(
'table' => '`test_model4`',
'alias' => 'TestModel4Parent',
'type' => 'LEFT',
'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`'
)
),
'limit' => array(),
'offset' => array(),
'conditions' => array(),
'order' => array(),
'group' => null
);
$this->assertEqual($queryData, $expected);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+1 = 1\s+$/', $result);
$params['assocData']['type'] = 'INNER';
$this->Model->belongsTo['TestModel4Parent']['type'] = 'INNER';
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$this->assertEqual($_queryData['joins'][0]['type'], 'INNER');
}
/**
* testGenerateInnerJoinAssociationQuery method
*
* @access public
* @return void
*/
function testGenerateInnerJoinAssociationQuery() {
$this->Model =& new TestModel9();
$test =& ConnectionManager::create('test2', $this->__config);
$this->Model->setDataSource('test2');
$this->Model->TestModel8 =& new TestModel8();
$this->Model->TestModel8->setDataSource('test2');
$this->testDb->read($this->Model, array('recursive' => 1));
$result = $this->testDb->getLastQuery();
$this->assertPattern('/`TestModel9` LEFT JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result);
$this->Model->belongsTo['TestModel8']['type'] = 'INNER';
$this->testDb->read($this->Model, array('recursive' => 1));
$result = $this->testDb->getLastQuery();
$this->assertPattern('/`TestModel9` INNER JOIN `' . $this->testDb->fullTableName('test_model8', false) . '`/', $result);
}
/**
* testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding method
*
* @access public
* @return void
*/
function testGenerateAssociationQuerySelfJoinWithConditionsInHasOneBinding() {
$this->Model =& new TestModel8();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasOne', 'model' => 'TestModel9');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$_queryData = $queryData;
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/FROM\s+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+`test_model9` AS `TestModel9`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
}
/**
* testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding method
*
* @access public
* @return void
*/
function testGenerateAssociationQuerySelfJoinWithConditionsInBelongsToBinding() {
$this->Model =& new TestModel9();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'belongsTo', 'model' => 'TestModel8');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/FROM\s+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+`test_model8` AS `TestModel8`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
}
/**
* testGenerateAssociationQuerySelfJoinWithConditions method
*
* @access public
* @return void
*/
function testGenerateAssociationQuerySelfJoinWithConditions() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
$queryData = array('conditions' => array('TestModel4Parent.name !=' => 'mariano'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?`TestModel4Parent`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
$this->Featured2 =& new Featured2();
$this->Featured2->schema();
$this->Featured2->bindModel(array(
'belongsTo' => array(
'ArticleFeatured2' => array(
'conditions' => 'ArticleFeatured2.published = \'Y\'',
'fields' => 'id, title, user_id, published'
)
)
));
$this->_buildRelatedModels($this->Featured2);
$binding = array('type' => 'belongsTo', 'model' => 'ArticleFeatured2');
$queryData = array('conditions' => array());
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Featured2, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->generateAssociationQuery($this->Featured2, $null, null, null, null, $queryData, false, $null);
$this->assertPattern(
'/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+'.
'`ArticleFeatured2`\.`id`, `ArticleFeatured2`\.`title`, `ArticleFeatured2`\.`user_id`, `ArticleFeatured2`\.`published`\s+' .
'FROM\s+`featured2` AS `Featured2`\s+LEFT JOIN\s+`article_featured` AS `ArticleFeatured2`' .
'\s+ON\s+\(`ArticleFeatured2`.`published` = \'Y\'\s+AND\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`\)' .
'\s+WHERE\s+1\s+=\s+1\s*$/',
$result
);
}
/**
* testGenerateAssociationQueryHasOne method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasOne() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasOne', 'model' => 'TestModel5');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
$expected = ' LEFT JOIN `test_model5` AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
$this->assertEqual(trim($result), trim($expected));
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
}
/**
* testGenerateAssociationQueryHasOneWithConditions method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasOneWithConditions() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasOne', 'model' => 'TestModel5');
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id`\s+=\s+`TestModel4`.`id`\)\s+WHERE/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?\s*`TestModel5`.`name`\s+!=\s+\'mariano\'\s*(?:\))?\s*$/', $result);
}
/**
* testGenerateAssociationQueryBelongsTo method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryBelongsTo() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type'=>'belongsTo', 'model'=>'TestModel4');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
$expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
$this->assertEqual(trim($result), trim($expected));
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
$this->assertPattern('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
}
/**
* testGenerateAssociationQueryBelongsToWithConditions method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryBelongsToWithConditions() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4');
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertTrue($result);
$result = $this->testDb->buildJoinStatement($queryData['joins'][0]);
$expected = ' LEFT JOIN `test_model4` AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
$this->assertEqual(trim($result), trim($expected));
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->assertPattern('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
$this->assertPattern('/\s+WHERE\s+`TestModel5`.`name` != \'mariano\'\s*$/', $result);
}
/**
* testGenerateAssociationQueryHasMany method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasMany() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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);
$this->assertPattern('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
}
/**
* testGenerateAssociationQueryHasManyWithLimit method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasManyWithLimit() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$this->Model->hasMany['TestModel6']['limit'] = 2;
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)\s*'.
'LIMIT \d*'.
'\s*$/', $result
);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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
);
}
/**
* testGenerateAssociationQueryHasManyWithConditions method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasManyWithConditions() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
}
/**
* testGenerateAssociationQueryHasManyWithOffsetAndLimit method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasManyWithOffsetAndLimit() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$__backup = $this->Model->hasMany['TestModel6'];
$this->Model->hasMany['TestModel6']['offset'] = 2;
$this->Model->hasMany['TestModel6']['limit'] = 5;
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$this->assertPattern('/\s+LIMIT 2,\s*5\s*$/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->Model->hasMany['TestModel6'] = $__backup;
}
/**
* testGenerateAssociationQueryHasManyWithPageAndLimit method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasManyWithPageAndLimit() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$__backup = $this->Model->hasMany['TestModel6'];
$this->Model->hasMany['TestModel6']['page'] = 2;
$this->Model->hasMany['TestModel6']['limit'] = 5;
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$this->assertPattern('/\s+LIMIT 5,\s*5\s*$/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->Model->hasMany['TestModel6'] = $__backup;
}
/**
* testGenerateAssociationQueryHasManyWithFields method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasManyWithFields() {
$this->Model =& new TestModel5();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`name`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`id`\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);
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`id`, `TestModel5`.`name`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`name`', '`TestModel5`.`created`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$this->assertPattern('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`id`\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);
$this->Model->hasMany['TestModel6']['fields'] = array('name');
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
$this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
unset($this->Model->hasMany['TestModel6']['fields']);
$this->Model->hasMany['TestModel6']['fields'] = array('id', 'name');
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
$this->assertPattern('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
unset($this->Model->hasMany['TestModel6']['fields']);
$this->Model->hasMany['TestModel6']['fields'] = array('test_model5_id', 'name');
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$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+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
unset($this->Model->hasMany['TestModel6']['fields']);
}
/**
* testGenerateAssociationQueryHasAndBelongsToMany method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasAndBelongsToMany() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
$queryData = array();
$resultSet = null;
$null = null;
$params =& $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`' . $this->testDb->fullTableName('test_model4_test_model7', false) . '`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+AND/', $result);
$this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)/', $result);
$this->assertPattern('/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
}
/**
* testGenerateAssociationQueryHasAndBelongsToManyWithConditions method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasAndBelongsToManyWithConditions() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7');
$queryData = array('conditions' => array('TestModel4.name !=' => 'mariano'));
$resultSet = null;
$null = null;
$params =& $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result);
$this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
}
/**
* testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$__backup = $this->Model->hasAndBelongsToMany['TestModel7'];
$this->Model->hasAndBelongsToMany['TestModel7']['offset'] = 2;
$this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5;
$binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+/', $result);
$this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`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);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->Model->hasAndBelongsToMany['TestModel7'] = $__backup;
}
/**
* testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit method
*
* @access public
* @return void
*/
function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() {
$this->Model =& new TestModel4();
$this->Model->schema();
$this->_buildRelatedModels($this->Model);
$__backup = $this->Model->hasAndBelongsToMany['TestModel7'];
$this->Model->hasAndBelongsToMany['TestModel7']['page'] = 2;
$this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5;
$binding = array('type'=>'hasAndBelongsToMany', 'model'=>'TestModel7');
$queryData = array();
$resultSet = null;
$null = null;
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->testDb->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result);
$this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`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);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
$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);
$this->Model->hasAndBelongsToMany['TestModel7'] = $__backup;
}
/**
* buildRelatedModels method
*
* @param mixed $model
* @access protected
* @return void
*/
function _buildRelatedModels(&$model) {
foreach ($model->__associations as $type) {
foreach ($model->{$type} as $assoc => $assocData) {
if (is_string($assocData)) {
$className = $assocData;
} elseif (isset($assocData['className'])) {
$className = $assocData['className'];
}
$model->$className =& new $className();
$model->$className->schema();
}
}
}
/**
* &_prepareAssociationQuery method
*
* @param mixed $model
* @param mixed $queryData
* @param mixed $binding
* @access public
* @return void
*/
function &_prepareAssociationQuery(&$model, &$queryData, $binding) {
$type = $binding['type'];
$assoc = $binding['model'];
$assocData = $model->{$type}[$assoc];
$className = $assocData['className'];
$linkModel =& $model->{$className};
$external = isset($assocData['external']);
$queryData = $this->testDb->__scrubQueryData($queryData);
$result = array_merge(array('linkModel' => &$linkModel), compact('type', 'assoc', 'assocData', 'external'));
return $result;
}
/**
* testSelectDistict method
*
* @access public
* @return void
*/
function testSelectDistict() {
$result = $this->testDb->fields($this->Model, 'Vendor', "DISTINCT Vendor.id, Vendor.name");
$expected = array('DISTINCT `Vendor`.`id`', '`Vendor`.`name`');
$this->assertEqual($result, $expected);
}
/**
* testStringConditionsParsing method
*
* @access public
* @return void
*/
function testStringConditionsParsing() {
$result = $this->testDb->conditions("ProjectBid.project_id = Project.id");
$expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id`";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("Candy.name LIKE 'a' AND HardCandy.name LIKE 'c'");
$expected = " WHERE `Candy`.`name` LIKE 'a' AND `HardCandy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("HardCandy.name LIKE 'a' AND Candy.name LIKE 'c'");
$expected = " WHERE `HardCandy`.`name` LIKE 'a' AND `Candy`.`name` LIKE 'c'";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("Post.title = '1.1'");
$expected = " WHERE `Post`.`title` = '1.1'";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("User.id != 0 AND User.user LIKE '%arr%'");
$expected = " WHERE `User`.`id` != 0 AND `User`.`user` LIKE '%arr%'";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("SUM(Post.comments_count) > 500");
$expected = " WHERE SUM(`Post`.`comments_count`) > 500";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("score BETWEEN 90.1 AND 95.7");
$expected = " WHERE score BETWEEN 90.1 AND 95.7";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions(array('score' => array(2=>1, 2, 10)));
$expected = " WHERE score IN (1, 2, 10)";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("Aro.rght = Aro.lft + 1.1");
$expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2');
$expected = ' WHERE `Sportstaette`.`sportstaette` LIKE "%ru%" AND `Sportstaette`.`sportstaettenart_id` = 2';
$this->assertPattern('/\s*WHERE\s+`Sportstaette`\.`sportstaette`\s+LIKE\s+"%ru%"\s+AND\s+`Sports/', $result);
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('Sportstaette.sportstaettenart_id = 2 AND Sportstaette.sportstaette LIKE "%ru%"');
$expected = ' WHERE `Sportstaette`.`sportstaettenart_id` = 2 AND `Sportstaette`.`sportstaette` LIKE "%ru%"';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('SUM(Post.comments_count) > 500 AND NOT Post.title IS NULL AND NOT Post.extended_title IS NULL');
$expected = ' WHERE SUM(`Post`.`comments_count`) > 500 AND NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('NOT Post.title IS NULL AND NOT Post.extended_title IS NULL AND SUM(Post.comments_count) > 500');
$expected = ' WHERE NOT `Post`.`title` IS NULL AND NOT `Post`.`extended_title` IS NULL AND SUM(`Post`.`comments_count`) > 500';
$this->assertEqual($result, $expected);
$result = $this->testDb->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');
$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';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('NOT Post.title_extended IS NULL AND NOT Post.title IS NULL AND Post.title_extended != Post.title');
$expected = ' WHERE NOT `Post`.`title_extended` IS NULL AND NOT `Post`.`title` IS NULL AND `Post`.`title_extended` != `Post`.`title`';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("Comment.id = 'a'");
$expected = " WHERE `Comment`.`id` = 'a'";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("lower(Article.title) LIKE 'a%'");
$expected = " WHERE lower(`Article`.`title`) LIKE 'a%'";
$this->assertEqual($result, $expected);
$result = $this->testDb->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->testDb->conditions('DATEDIFF(NOW(),Article.published) < 1 && Article.live=1');
$expected = " WHERE DATEDIFF(NOW(),`Article`.`published`) < 1 && `Article`.`live`=1";
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('file = "index.html"');
$expected = ' WHERE file = "index.html"';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions("file = 'index.html'");
$expected = " WHERE file = 'index.html'";
$this->assertEqual($result, $expected);
$letter = $letter = 'd.a';
$conditions = array('Company.name like ' => $letter . '%');
$result = $this->testDb->conditions($conditions);
$expected = " WHERE `Company`.`name` like 'd.a%'";
$this->assertEqual($result, $expected);
$conditions = array('Artist.name' => 'JUDY and MARY');
$result = $this->testDb->conditions($conditions);
$expected = " WHERE `Artist`.`name` = 'JUDY and MARY'";
$this->assertEqual($result, $expected);
$conditions = array('Artist.name' => 'JUDY AND MARY');
$result = $this->testDb->conditions($conditions);
$expected = " WHERE `Artist`.`name` = 'JUDY AND MARY'";
$this->assertEqual($result, $expected);
}
/**
* testQuotesInStringConditions method
*
* @access public
* @return void
*/
function testQuotesInStringConditions() {
$result = $this->testDb->conditions('Member.email = \'mariano@cricava.com\'');
$expected = ' WHERE `Member`.`email` = \'mariano@cricava.com\'';
$this->assertEqual($result, $expected);
$result = $this->testDb->conditions('Member.email = "mariano@cricava.com"');
$expected = ' WHERE `Member`.`email` = "mariano@cricava.com"';
$this->assertEqual($result, $expected);
$result = $this->testDb->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);
$result = $this->testDb->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);
}
/**
* testParenthesisInStringConditions method
*
* @access public
* @return void
*/
function testParenthesisInStringConditions() {
$result = $this->testDb->conditions('Member.name = \'(lu\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(lu\'$/', $result);
$result = $this->testDb->conditions('Member.name = \')lu\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\)lu\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'va(lu\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'va)lu\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\)lu\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'va(lu)\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'va(lu)e\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'va\(lu\)e\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'(mariano)\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'(mariano)iglesias\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\)iglesias\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'(mariano) iglesias\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano\) iglesias\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'(mariano word) iglesias\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano word\) iglesias\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'(mariano.iglesias)\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\)\'$/', $result);
$result = $this->testDb->conditions('Member.name = \'Mariano Iglesias (mariano.iglesias)\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'Mariano Iglesias \(mariano.iglesias\)\'$/', $result);
$result = $this->testDb->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->testDb->conditions('Member.name = \'(mariano.iglesias) CakePHP\'');
$this->assertPattern('/^\s+WHERE\s+`Member`.`name`\s+=\s+\'\(mariano.iglesias\) CakePHP\'$/', $result);
}
/**