Adding test that fails when using page + limit and offset + limit on a HABTM binding

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5108 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2007-05-15 18:19:56 +00:00
parent 3a9799c554
commit e4fb1372c5

View file

@ -1151,6 +1151,70 @@ class DboSourceTest extends UnitTestCase {
$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);
}
function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() {
$this->model = new TestModel4();
$this->model->loadInfo();
$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->db->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`\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);
$result = $this->db->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;
}
function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() {
$this->model = new TestModel4();
$this->model->loadInfo();
$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->db->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`\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);
$result = $this->db->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;
}
function _buildRelatedModels(&$model) {
foreach($model->__associations as $type) {