From 2e04c5260ecb60410f4f36a2cfd14a1f40cf0b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Thu, 2 Dec 2010 00:19:43 -0430 Subject: [PATCH] Fixing some tests to make them run on sqlite --- cake/console/shells/schema.php | 2 +- cake/libs/model/cake_schema.php | 16 +++++++--------- cake/libs/model/datasources/dbo/dbo_sqlite.php | 15 +++++++++------ cake/libs/model/datasources/dbo_source.php | 1 + cake/tests/cases/console/shells/schema.test.php | 10 ++++++---- cake/tests/cases/libs/model/cake_schema.test.php | 14 ++++++++++++-- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/cake/console/shells/schema.php b/cake/console/shells/schema.php index dc863f6e5..157377482 100644 --- a/cake/console/shells/schema.php +++ b/cake/console/shells/schema.php @@ -299,7 +299,7 @@ class SchemaShell extends Shell { * * @access private */ - function __create(&$Schema, $table = null) { + function __create($Schema, $table = null) { $db = ConnectionManager::getDataSource($this->Schema->connection); $drop = $create = array(); diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 12e6f09c0..96de01439 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -94,11 +94,7 @@ class CakeSchema extends Object { } if (empty($options['path'])) { - if (is_dir(CONFIGS . 'schema')) { - $this->path = CONFIGS . 'schema'; - } else { - $this->path = CONFIGS . 'sql'; - } + $this->path = CONFIGS . 'schema'; } $options = array_merge(get_object_vars($this), $options); @@ -160,7 +156,7 @@ class CakeSchema extends Object { * @param array $options schema object properties * @return array Set of name and tables */ - public function &load($options = array()) { + public function load($options = array()) { if (is_string($options)) { $options = array('path' => $options); } @@ -182,8 +178,8 @@ class CakeSchema extends Object { $Schema = new $class($options); return $Schema; } - $false = false; - return $false; + + return false; } /** @@ -298,7 +294,9 @@ class CakeSchema extends Object { $systemTables = array( 'aros', 'acos', 'aros_acos', Configure::read('Session.table'), 'i18n' ); - + if (get_class($Object) === 'AppModel') { + continue; + } if (in_array($table, $systemTables)) { $tables[$Object->table] = $this->__columns($Object); $tables[$Object->table]['indexes'] = $db->index($Object); diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index e605380b8..33248048b 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -465,7 +465,10 @@ class DboSqlite extends DboSource { $table = $this->fullTableName($model); if ($table) { $indexes = $this->query('PRAGMA index_list(' . $table . ')'); - $tableInfo = $this->query('PRAGMA table_info(' . $table . ')'); + + if (is_bool($indexes)) { + return array(); + } foreach ($indexes as $i => $info) { $key = array_pop($info); $keyInfo = $this->query('PRAGMA index_info("' . $key['name'] . '")'); @@ -502,11 +505,11 @@ class DboSqlite extends DboSource { switch (strtolower($type)) { case 'schema': extract($data); - - foreach (array('columns', 'indexes') as $var) { - if (is_array(${$var})) { - ${$var} = "\t" . join(",\n\t", array_filter(${$var})); - } + if (is_array($columns)) { + $columns = "\t" . join(",\n\t", array_filter($columns)); + } + if (is_array($indexes)) { + $indexes = "\t" . join("\n\t", array_filter($indexes)); } return "CREATE TABLE {$table} (\n{$columns});\n{$indexes}"; break; diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 5183447bc..02adeb03e 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -361,6 +361,7 @@ class DboSource extends DataSource { } catch (PDOException $e) { $this->_results = null; $this->error = $e->getMessage(); + return false; } } diff --git a/cake/tests/cases/console/shells/schema.test.php b/cake/tests/cases/console/shells/schema.test.php index 611928e53..4f73c8b3d 100644 --- a/cake/tests/cases/console/shells/schema.test.php +++ b/cake/tests/cases/console/shells/schema.test.php @@ -253,7 +253,7 @@ class SchemaShellTest extends CakeTestCase { $this->file = new File(TMP . 'tests' . DS . 'dump_test.sql'); $contents = $this->file->read(); - $this->assertPattern('/CREATE TABLE `test_plugin_acos`/', $contents); + $this->assertPattern('/CREATE TABLE.*?test_plugin_acos/', $contents); $this->assertPattern('/id/', $contents); $this->assertPattern('/model/', $contents); @@ -366,8 +366,7 @@ class SchemaShellTest extends CakeTestCase { */ public function testCreateNoArgs() { $this->Shell->params = array( - 'connection' => 'test', - 'path' => APP . 'config' . DS . 'sql' + 'connection' => 'test' ); $this->Shell->args = array('i18n'); $this->Shell->startup(); @@ -375,6 +374,8 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->create(); $db = ConnectionManager::getDataSource('test'); + + $db->cacheSources = false; $sources = $db->listSources(); $this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources)); @@ -396,7 +397,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->params = array( 'connection' => 'test', 'name' => 'DbAcl', - 'path' => APP . 'config' . DS . 'schema' + 'path' => CONFIGS . 'schema' ); $this->Shell->args = array('DbAcl', 'acos'); $this->Shell->startup(); @@ -404,6 +405,7 @@ class SchemaShellTest extends CakeTestCase { $this->Shell->create(); $db = ConnectionManager::getDataSource('test'); + $db->cacheSources = false; $sources = $db->listSources(); $this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources), 'acos should be present.'); $this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources), 'aros should not be found.'); diff --git a/cake/tests/cases/libs/model/cake_schema.test.php b/cake/tests/cases/libs/model/cake_schema.test.php index 1fba09129..ff5c8ffdd 100644 --- a/cake/tests/cases/libs/model/cake_schema.test.php +++ b/cake/tests/cases/libs/model/cake_schema.test.php @@ -578,8 +578,18 @@ class CakeSchemaTest extends CakeTestCase { } $this->assertEqual( - $read['tables']['datatypes']['float_field'], - $this->Schema->tables['datatypes']['float_field'] + $read['tables']['datatypes']['float_field']['length'], + $this->Schema->tables['datatypes']['float_field']['length'] + ); + + $this->assertEqual( + $read['tables']['datatypes']['float_field']['type'], + $this->Schema->tables['datatypes']['float_field']['type'] + ); + + $this->assertEqual( + $read['tables']['datatypes']['float_field']['null'], + $this->Schema->tables['datatypes']['float_field']['null'] ); $db = ConnectionManager::getDataSource('test');