mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
3a9799c554
commit
e4fb1372c5
1 changed files with 64 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue