Permalink
Browse files

Fixing broken tests in dbo_mysql caused by changes in CakeSchema.

Adding tableParameter altering to DboMysql.
Tests added.
  • Loading branch information...
1 parent 7b0bc01 commit d2bf31f69f32007c0edd5f6c1bda378c9b9d0819 @markstory markstory committed Oct 5, 2009
@@ -486,8 +486,10 @@ function compare($old, $new = null) {
if (isset($old[$table]['indexes']) && isset($new[$table]['indexes'])) {
$diff = $this->_compareIndexes($new[$table]['indexes'], $old[$table]['indexes']);
- if ($diff) {
+ if ($diff && isset($diff['drop'])) {
$tables[$table]['drop']['indexes'] = $diff['drop'];
+ }
+ if ($diff && isset($diff['add'])) {
$tables[$table]['add']['indexes'] = $diff['add'];
}
}
@@ -577,9 +579,6 @@ function _compareTableParameters($new, $old) {
if (!is_array($new) || !is_array($old)) {
return false;
}
-
- $change = array();
-
$change = array_diff_assoc($new, $old);
return $change;
}
@@ -632,7 +631,7 @@ function _compareIndexes($new, $old) {
}
}
}
- return compact('add', 'drop');
+ return array_filter(compact('add', 'drop'));
}
}
?>
@@ -326,6 +326,9 @@ function dropSchema($schema, $table = null) {
* @todo Implement this method.
**/
function _alterTableParameters($table, $parameters) {
+ if (isset($parameters['change'])) {
+ return $this->buildTableParameters($parameters['change']);
+ }
return array();
}
@@ -538,12 +538,10 @@ function testSchemaComparison() {
'add' => array(
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
- 'indexes' => array(),
),
'drop' => array(
'article_id' => array('type' => 'integer', 'null' => false),
'tableParameters' => array(),
- 'indexes' => array(),
),
'change' => array(
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
@@ -552,11 +550,9 @@ function testSchemaComparison() {
'posts' => array(
'add' => array(
'summary' => array('type' => 'text', 'null' => 1),
- 'indexes' => array(),
),
'drop' => array(
'tableParameters' => array(),
- 'indexes' => array(),
),
'change' => array(
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
@@ -633,7 +629,6 @@ function testTableParametersAndIndexComparison() {
$compare = $this->Schema->compare($old, $new);
$expected = array(
'posts' => array(
- 'drop' => array('indexes' => array()),
'add' => array(
'indexes' => array('author_id' => array('column' => 'author_id')),
),
@@ -646,7 +641,6 @@ function testTableParametersAndIndexComparison() {
)
),
'comments' => array(
- 'add' => array('indexes' => array()),
'drop' => array(
'indexes' => array('post_id' => array('column' => 'post_id')),
),
@@ -1,26 +1,21 @@
<?php
-/* SVN FILE: $Id$ */
-
/**
* DboMysqlTest file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
@@ -190,7 +185,7 @@ function skip() {
*
* @access public
*/
- function setUp() {
+ function startTest() {
$db = ConnectionManager::getDataSource('test_suite');
$this->db = new DboMysqlTestDb($db->config);
$this->model = new MysqlTestModel();
@@ -201,7 +196,7 @@ function setUp() {
*
* @access public
*/
- function tearDown() {
+ function endTest() {
unset($this->db);
}
@@ -568,7 +563,7 @@ function testColumn() {
* @return void
*/
function testAlterSchemaIndexes() {
- App::import('Core', 'CakeSchema');
+ App::import('Model', 'CakeSchema');
$this->db->cacheSources = $this->db->testing = false;
$schema1 =& new CakeSchema(array(
@@ -635,6 +630,56 @@ function testAlterSchemaIndexes() {
}
/**
+ * test altering the table settings with schema.
+ *
+ * @return void
+ **/
+ function testAlteringTableParameters() {
+ App::import('Model', 'CakeSchema');
+ $this->db->cacheSources = $this->db->testing = false;
+
+ $schema1 =& new CakeSchema(array(
+ 'name' => 'AlterTest1',
+ 'connection' => 'test_suite',
+ 'altertest' => array(
+ 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
+ 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
+ 'tableParameters' => array(
+ 'charset' => 'latin1',
+ 'collate' => 'latin1_general_ci',
+ 'engine' => 'MyISAM'
+ )
+ )
+ ));
+ $this->db->query($this->db->createSchema($schema1));
+ $schema2 =& new CakeSchema(array(
+ 'name' => 'AlterTest1',
+ 'connection' => 'test_suite',
+ 'altertest' => array(
+ 'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
+ 'name' => array('type' => 'string', 'null' => false, 'length' => 50),
+ 'tableParameters' => array(
+ 'charset' => 'utf8',
+ 'collate' => 'utf8_general_ci',
+ 'engine' => 'InnoDB'
+ )
+ )
+ ));
+ $result = $this->db->alterSchema($schema2->compare($schema1));
+ $this->assertPattern('/DEFAULT CHARSET=utf8/', $result);
+ $this->assertPattern('/ENGINE=InnoDB/', $result);
+ $this->assertPattern('/COLLATE=utf8_general_ci/', $result);
+
+ $this->db->query($result);
+ $result = $this->db->listDetailedSources('altertest');
+ $this->assertEqual($result['Collation'], 'utf8_general_ci');
+ $this->assertEqual($result['Engine'], 'InnoDB');
+ $this->assertEqual($result['charset'], 'utf8');
+
+ $this->db->query($this->db->dropSchema($schema1));
+ }
+
+/**
* testReadTableParameters method
*
* @access public

0 comments on commit d2bf31f

Please sign in to comment.