From e4fb1372c5242b62b615e50e6629124aad912759 Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Tue, 15 May 2007 18:19:56 +0000 Subject: [PATCH] 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 --- .../model/datasources/dbo_source.test.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 09b8b8050..40cfb390a 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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) {