From 7a380cc0de9cddd37c40993dd09f2c64c16ba9bf Mon Sep 17 00:00:00 2001 From: "mariano.iglesias" Date: Tue, 15 May 2007 18:47:02 +0000 Subject: [PATCH] Adding tests for 'page' and 'offset' with hasMany bindings git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5109 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../model/datasources/dbo_source.test.php | 62 +++++++++++++++++++ 1 file changed, 62 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 40cfb390a..4106107fe 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -983,6 +983,68 @@ class DboSourceTest extends UnitTestCase { $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); } + + function testGenerateAssociationQueryHasManyWithOffsetAndLimit() { + $this->model = new TestModel5(); + $this->model->loadInfo(); + $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->db->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+IN\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + $this->assertPattern('/\s+LIMIT 2,\s*5\s*$/', $result); + + $result = $this->db->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; + } + + function testGenerateAssociationQueryHasManyWithPageAndLimit() { + $this->model = new TestModel5(); + $this->model->loadInfo(); + $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->db->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+IN\s+\({\$__cakeID__\$}\)(?:\))?/', $result); + $this->assertPattern('/\s+LIMIT 5,\s*5\s*$/', $result); + + $result = $this->db->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; + } function testGenerateAssociationQueryHasManyWithFields() { $this->model = new TestModel5();