Permalink
Browse files

Updating tests for schema. Making tests more reliable for schema read.

  • Loading branch information...
1 parent e733c56 commit 236a679b172f86f128c1cc95966332a7c5f50f64 @markstory markstory committed Oct 3, 2009
Showing with 22 additions and 9 deletions.
  1. +6 −3 cake/libs/model/cake_schema.php
  2. +16 −6 cake/tests/cases/libs/model/cake_schema.test.php
@@ -368,7 +368,7 @@ function write($object, $options = array()) {
$out .= $this->generateTable($table, $fields);
}
}
- $out .="}\n";
+ $out .= "}\n";
$File =& new File($path . DS . $file, true);
$header = '$Id';
@@ -430,7 +430,7 @@ function generateTable($table, $fields) {
*/
function compare($old, $new = null) {
if (empty($new)) {
- $new = $this;
+ $new =& $this;
}
if (is_array($new)) {
if (isset($new['tables'])) {
@@ -467,7 +467,7 @@ function compare($old, $new = null) {
foreach ($fields as $field => $value) {
if (isset($old[$table][$field])) {
$diff = array_diff_assoc($value, $old[$table][$field]);
- if (!empty($diff) && $field !== 'indexes') {
+ if (!empty($diff) && $field !== 'indexes' && $field !== 'tableParameters') {
$tables[$table]['change'][$field] = array_merge($old[$table][$field], $diff);
}
}
@@ -489,6 +489,9 @@ function compare($old, $new = null) {
$tables[$table]['add']['indexes'] = $diff['add'];
}
}
+ if (isset($old[$table]['tableParameters']) && isset($new[$table]['tableParameters'])) {
+
+ }
}
return $tables;
}
@@ -195,7 +195,7 @@ class TestAppSchema extends CakeSchema {
*/
var $datatypes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
- 'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
+ 'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array()
);
@@ -389,7 +389,9 @@ class CakeSchemaTest extends CakeTestCase {
* @var array
* @access public
*/
- var $fixtures = array('core.post', 'core.tag', 'core.posts_tag', 'core.comment', 'core.datatype');
+ var $fixtures = array(
+ 'core.post', 'core.tag', 'core.posts_tag', 'core.comment', 'core.datatype', 'core.auth_user'
+ );
/**
* setUp method
@@ -445,12 +447,12 @@ function testSchemaRead() {
$expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags');
$this->assertEqual(array_keys($read['tables']), $expected);
-
+
foreach ($read['tables'] as $table => $fields) {
$this->assertEqual(array_keys($fields), array_keys($this->Schema->tables[$table]));
}
- $this->assertIdentical(
+ $this->assertEqual(
$read['tables']['datatypes']['float_field'],
$this->Schema->tables['datatypes']['float_field']
);
@@ -468,7 +470,7 @@ function testSchemaRead() {
*
* @return void
**/
- function XXtestSchemaReadWithPlugins() {
+ function testSchemaReadWithPlugins() {
App::objects('model', null, false);
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
@@ -480,7 +482,11 @@ function XXtestSchemaReadWithPlugins() {
'name' => 'TestApp',
'models' => true
));
+ unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['posts']));
+ $this->assertTrue(isset($read['tables']['auth_users']));
+ $this->assertEqual(count($read['tables']), 2);
+
App::build();
}
@@ -538,13 +544,17 @@ function testSchemaComparison() {
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'title' => array('type' => 'string', 'null' => false, 'length' => 100)
),
- 'drop' => array('article_id' => array('type' => 'integer', 'null' => false)),
+ 'drop' => array(
+ 'article_id' => array('type' => 'integer', 'null' => false),
+ 'tableParameters' => array()
+ ),
'change' => array(
'comment' => array('type' => 'text', 'null' => false, 'default' => null)
)
),
'posts' => array(
'add' => array('summary' => array('type' => 'text', 'null' => 1)),
+ 'drop' => array('tableParameters' => array()),
'change' => array(
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),

0 comments on commit 236a679

Please sign in to comment.