mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing broken tests in dbo_mysql caused by changes in CakeSchema.
Adding tableParameter altering to DboMysql. Tests added.
This commit is contained in:
parent
7b0bc014cc
commit
d2bf31f69f
4 changed files with 62 additions and 21 deletions
|
@ -486,8 +486,10 @@ class CakeSchema extends Object {
|
|||
|
||||
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 @@ class CakeSchema extends Object {
|
|||
if (!is_array($new) || !is_array($old)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$change = array();
|
||||
|
||||
$change = array_diff_assoc($new, $old);
|
||||
return $change;
|
||||
}
|
||||
|
@ -632,7 +631,7 @@ class CakeSchema extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
return compact('add', 'drop');
|
||||
return array_filter(compact('add', 'drop'));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -326,6 +326,9 @@ class DboMysqlBase extends DboSource {
|
|||
* @todo Implement this method.
|
||||
**/
|
||||
function _alterTableParameters($table, $parameters) {
|
||||
if (isset($parameters['change'])) {
|
||||
return $this->buildTableParameters($parameters['change']);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
|
|
@ -538,12 +538,10 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
'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 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
'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 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
$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 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
)
|
||||
),
|
||||
'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 @@ class DboMysqlTest extends CakeTestCase {
|
|||
*
|
||||
* @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 @@ class DboMysqlTest extends CakeTestCase {
|
|||
*
|
||||
* @access public
|
||||
*/
|
||||
function tearDown() {
|
||||
function endTest() {
|
||||
unset($this->db);
|
||||
}
|
||||
|
||||
|
@ -568,7 +563,7 @@ class DboMysqlTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testAlterSchemaIndexes() {
|
||||
App::import('Core', 'CakeSchema');
|
||||
App::import('Model', 'CakeSchema');
|
||||
$this->db->cacheSources = $this->db->testing = false;
|
||||
|
||||
$schema1 =& new CakeSchema(array(
|
||||
|
@ -634,6 +629,56 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$this->db->query($this->db->dropSchema($schema1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue