From 6614bc96ab28079dc179cffa07e63da288159399 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 15 May 2008 06:42:31 +0000 Subject: [PATCH] Adding tests for tinyint(1) -> boolean typecasting in DboMysql, closes #4568 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6885 3807eeeb-6ff5-0310-8944-8be069107fe0 --- .../model/datasources/dbo/dbo_mysql.test.php | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 4d3c2a2c5..f558e4f21 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -43,9 +43,14 @@ class DboMysqlTestDb extends DboMysql { var $simulated = array(); + var $testing = true; + function _execute($sql) { - $this->simulated[] = $sql; - return null; + if ($this->testing) { + $this->simulated[] = $sql; + return null; + } + return parent::_execute($sql); } function getLastQuery() { @@ -185,5 +190,36 @@ class DboMysqlTest extends CakeTestCase { $result = $this->db->value('00010010001'); $this->assertEqual($expected, $result); } + + function testTinyintCasting() { + $this->db->cacheSources = $this->db->testing = false; + $this->db->query('CREATE TABLE ' . $this->db->fullTableName('tinyint') . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));'); + + $this->model = new Model(array('name' => 'Tinyint', 'table' => $this->db->fullTableName('tinyint', false))); + $result = $this->model->schema(); + $this->assertEqual($result['bool']['type'], 'boolean'); + $this->assertEqual($result['small_int']['type'], 'integer'); + + $this->assertTrue($this->model->save(array('bool' => 5, 'small_int' => 5))); + $result = $this->model->find('first'); + $this->assertIdentical($result['Tinyint']['bool'], '1'); + $this->assertIdentical($result['Tinyint']['small_int'], '5'); + $this->model->deleteAll(true); + + $this->assertTrue($this->model->save(array('bool' => 0, 'small_int' => 100))); + $result = $this->model->find('first'); + $this->assertIdentical($result['Tinyint']['bool'], '0'); + $this->assertIdentical($result['Tinyint']['small_int'], '100'); + $this->model->deleteAll(true); + + $this->assertTrue($this->model->save(array('bool' => true, 'small_int' => 0))); + $result = $this->model->find('first'); + $this->assertIdentical($result['Tinyint']['bool'], '1'); + $this->assertIdentical($result['Tinyint']['small_int'], '0'); + $this->model->deleteAll(true); + + $this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint')); + } } + ?> \ No newline at end of file