diff options
author | Aleksander Machniak <alec@alec.pl> | 2014-04-29 13:50:59 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2014-04-29 13:50:59 +0200 |
commit | ecef4cc91989005802e7432b985e3ed791097ef9 (patch) | |
tree | 102cf31f6b5d24f16b2a029906f1fceb67be035c /tests/Framework/DB.php | |
parent | 3ce4f0a83939a26c74ec990ae66af6a03ea216d6 (diff) |
Add some unit tests for DB classes
Diffstat (limited to 'tests/Framework/DB.php')
-rw-r--r-- | tests/Framework/DB.php | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/Framework/DB.php b/tests/Framework/DB.php index b7a063841..42020f47a 100644 --- a/tests/Framework/DB.php +++ b/tests/Framework/DB.php @@ -9,7 +9,7 @@ class Framework_DB extends PHPUnit_Framework_TestCase { /** - * Class constructor + * Class constructor test */ function test_class() { @@ -17,4 +17,58 @@ class Framework_DB extends PHPUnit_Framework_TestCase $this->assertInstanceOf('rcube_db', $object, "Class constructor"); } + + /** + * Test script execution and table_prefix replacements + */ + function test_exec_script() + { + $db = new rcube_db_test_wrapper('test'); + $db->set_option('table_prefix', 'prefix_'); + + $script = implode("\n", array( + "CREATE TABLE `xxx` (test int, INDEX xxx (test));", + "-- test comment", + "ALTER TABLE `xxx` CHANGE test test int;", + "TRUNCATE xxx;", + "DROP TABLE `vvv`;", + "CREATE TABLE `i` (test int CONSTRAINT `iii` + FOREIGN KEY (`test`) REFERENCES `xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE);", + "INSERT INTO xxx test = 1;", + "SELECT test FROM xxx;", + )); + $output = implode("\n", array( + "CREATE TABLE `prefix_xxx` (test int, INDEX prefix_xxx (test));", + "ALTER TABLE `prefix_xxx` CHANGE test test int;", + "TRUNCATE prefix_xxx;", + "DROP TABLE `prefix_vvv`;", + "CREATE TABLE `prefix_i` (test int CONSTRAINT `prefix_iii` + FOREIGN KEY (`test`) REFERENCES `prefix_xxx`(`test`) ON DELETE CASCADE ON UPDATE CASCADE);", + "INSERT INTO prefix_xxx test = 1;", + "SELECT test FROM prefix_xxx;", + )); + + $result = $db->exec_script($script); + $out = ''; + + foreach ($db->queries as $q) { + $out[] = $q[0]; + } + + $this->assertTrue($result, "Execute SQL script (result)"); + $this->assertSame(implode("\n", $out), $output, "Execute SQL script (content)"); + } +} + +/** + * rcube_db wrapper to test some protected methods + */ +class rcube_db_test_wrapper extends rcube_db +{ + public $queries = array(); + + protected function _query($query, $offset, $numrows, $params) + { + $this->queries[] = array(trim($query), $offset, $numrows, $params); + } } |