Skip to content

Commit

Permalink
Updating tests for schema. Making tests more reliable for schema read.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 3, 2009
1 parent e733c56 commit 236a679
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions cake/libs/model/cake_schema.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand Down
22 changes: 16 additions & 6 deletions cake/tests/cases/libs/model/cake_schema.test.php
Expand Up @@ -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()
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
);
Expand All @@ -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)
Expand All @@ -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();
}
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 236a679

Please sign in to comment.