mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing some tests to make them run on sqlite
This commit is contained in:
parent
2e9283abd9
commit
2e04c5260e
6 changed files with 36 additions and 22 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -361,6 +361,7 @@ class DboSource extends DataSource {
|
|||
} catch (PDOException $e) {
|
||||
$this->_results = null;
|
||||
$this->error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.');
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue