3 defined('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION') ?
null : define('AK_ACTIVE_RECORD_PROTECT_GET_RECURSION', false);
4 defined('AK_TEST_DATABASE_ON') ?
null : define('AK_TEST_DATABASE_ON', true);
6 require_once(dirname(__FILE__
).'/../../../fixtures/config/config.php');
8 class AkDbAdapter_schema_TestCase
extends AkUnitTest
11 function test_should_return_available_tables_for_mysql()
13 $db =& AkDbAdapter
::getInstance();
14 if ($db->type() !== 'mysql') return;
15 $old_adodb_style = $db->connection
->MetaTables();
16 $new_implementation = $db->availableTables();
17 $this->assertEqual($old_adodb_style,$new_implementation);
20 function test_should_return_available_tables_for_postgre()
22 $db =& AkDbAdapter
::getInstance();
23 if ($db->type() !== 'postgre') return;
24 $old = $db->connection
->MetaTables();
25 $new = $db->availableTables();
27 $this->assertEqual($old,$new);
30 function test_should_return_column_details()
32 $this->installAndIncludeModels(array(
33 'AkTestUser'=>'id,user_name string(32),email string(150), visits int default 1, taken bool, created_at, updated_at, expires_on'
35 $db =& AkDbAdapter
::getInstance();
36 $old_adodb_style = $db->connection
->MetaColumns('ak_test_users');
37 $new_implementation = $db->getColumnDetails('ak_test_users');
38 $this->assertEqual($old_adodb_style,$new_implementation);
41 function _test_column_details_should_serve_activerecord_with_a_processed_array()
43 $this->installAndIncludeModels(array(
44 'AkTestUser'=>'id,user_name string(32),email string(150), visits int default 1, taken bool, created_at, updated_at, expires_on'
46 $db =& AkDbAdapter
::getInstance();
47 $processed_return = $db->getColumnDetails('ak_test_users');
48 $expected_return = $this->AkTestUser
->getColumns();
49 $this->assertEqual($processed_return,$expected_return);
52 function test_should_rename_columns_for_mysql()
54 $db =& AkDbAdapter
::getInstance();
55 if ($db->type() !== 'mysql') return;
57 $this->installAndIncludeModels(array(
58 'RenameColumn'=>"id,namen string(55),postcunt int not null default 0,help string default 'none'"
60 $table_name = 'rename_columns';
61 $this->_mysql_rename($db, $table_name,'namen','name');
62 $this->_mysql_rename($db, $table_name,'help','nohelp');
63 $this->_mysql_rename($db, $table_name,'postcunt','postcount');
65 $this->assertError($db->renameColumn($table_name,'not_found','not_here'));
68 function _mysql_rename($db, $table_name,$old_name,$new_name)
70 $old = $db->select("SHOW COLUMNS FROM $table_name LIKE '$old_name'");
72 $db->renameColumn($table_name,$old_name,$new_name);
74 $this->assertFalse($db->select("SHOW COLUMNS FROM $table_name LIKE '$old_name'"));
75 $new = $db->select("SHOW COLUMNS FROM $table_name LIKE '$new_name'");
76 unset($old[0],$old['Field'],$new[0],$new['Field']);
77 $this->assertEqual($old,$new);
81 function test_should_rename_columns_for_postgre()
83 $db =& AkDbAdapter
::getInstance();
84 if ($db->type() !== 'postgre') return;
86 $this->installAndIncludeModels(array(
87 'RenameColumn'=>"id,namen string(55),postcunt int not null default 0,help string default 'none'"
89 $table_name = 'rename_columns';
90 $db->renameColumn($table_name,'namen','name');
95 ak_test('AkDbAdapter_schema_TestCase',true);