diff options
author | Hugues Hiegel <root@paranoid> | 2015-04-21 12:49:44 +0200 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2015-04-21 12:49:44 +0200 |
commit | 733f8e8d0ce6217d906d06dc4fb08e36d48ed794 (patch) | |
tree | cff28366ff63ea6596f8026e1698090bd0b9405c /tests/Framework | |
parent | ef2e7b3f9d264ec146d4dae257b1e295ab3b462a (diff) | |
parent | a4ba3df54834ee90fb2c9930669f1229dc80261a (diff) |
Conflicts:
composer.json-dist
config/defaults.inc.php
plugins
plugins/acl/acl.js
plugins/acl/acl.php
plugins/acl/skins/classic/templates/table.html
plugins/acl/skins/larry/templates/table.html
plugins/enigma/README
plugins/enigma/config.inc.php.dist
plugins/enigma/enigma.js
plugins/enigma/enigma.php
plugins/enigma/lib/enigma_driver.php
plugins/enigma/lib/enigma_driver_gnupg.php
plugins/enigma/lib/enigma_driver_phpssl.php
plugins/enigma/lib/enigma_engine.php
plugins/enigma/lib/enigma_error.php
plugins/enigma/lib/enigma_key.php
plugins/enigma/lib/enigma_signature.php
plugins/enigma/lib/enigma_subkey.php
plugins/enigma/lib/enigma_ui.php
plugins/enigma/lib/enigma_userid.php
plugins/enigma/localization/en_US.inc
plugins/enigma/localization/ja_JP.inc
plugins/enigma/localization/ru_RU.inc
plugins/enigma/skins/classic/enigma.css
plugins/enigma/skins/classic/templates/keys.html
plugins/help/config.inc.php.dist
plugins/help/help.php
plugins/help/localization/en_US.inc
plugins/jqueryui/jqueryui.php
plugins/managesieve/Changelog
plugins/managesieve/composer.json
plugins/managesieve/config.inc.php.dist
plugins/managesieve/lib/Roundcube/rcube_sieve.php
plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php
plugins/managesieve/lib/Roundcube/rcube_sieve_vacation.php
plugins/managesieve/localization/en_US.inc
plugins/managesieve/managesieve.js
plugins/managesieve/skins/classic/managesieve.css
plugins/managesieve/skins/larry/managesieve.css
plugins/password/README
plugins/password/config.inc.php.dist
plugins/password/drivers/ldap.php
plugins/password/drivers/poppassd.php
plugins/password/drivers/vpopmaild.php
plugins/vcard_attachments/vcardattach.js
plugins/zipdownload/zipdownload.php
Diffstat (limited to 'tests/Framework')
-rw-r--r-- | tests/Framework/DB.php | 108 | ||||
-rw-r--r-- | tests/Framework/Html2text.php | 5 | ||||
-rw-r--r-- | tests/Framework/Text2Html.php | 2 |
3 files changed, 103 insertions, 12 deletions
diff --git a/tests/Framework/DB.php b/tests/Framework/DB.php index 42020f47a..04897bb90 100644 --- a/tests/Framework/DB.php +++ b/tests/Framework/DB.php @@ -25,6 +25,8 @@ class Framework_DB extends PHPUnit_Framework_TestCase { $db = new rcube_db_test_wrapper('test'); $db->set_option('table_prefix', 'prefix_'); + $db->set_option('identifier_start', '`'); + $db->set_option('identifier_end', '`'); $script = implode("\n", array( "CREATE TABLE `xxx` (test int, INDEX xxx (test));", @@ -38,26 +40,88 @@ class Framework_DB extends PHPUnit_Framework_TestCase "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_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;", + 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 = ''; + $out = array(); foreach ($db->queries as $q) { - $out[] = $q[0]; + $out[] = $q; } $this->assertTrue($result, "Execute SQL script (result)"); $this->assertSame(implode("\n", $out), $output, "Execute SQL script (content)"); } + + /** + * Test query parsing and arguments quoting + */ + function test_query_parsing() + { + $db = new rcube_db_test_wrapper('test'); + $db->set_option('identifier_start', '`'); + $db->set_option('identifier_end', '`'); + + $db->query("SELECT ?", "test`test"); + $db->query("SELECT ?", "test?test"); + $db->query("SELECT ?", "test``test"); + $db->query("SELECT ?", "test??test"); + $db->query("SELECT `test` WHERE 'test``test'"); + $db->query("SELECT `test` WHERE 'test??test'"); + $db->query("SELECT `test` WHERE `test` = ?", "`te``st`"); + $db->query("SELECT `test` WHERE `test` = ?", "?test?"); + $db->query("SELECT `test` WHERE `test` = ?", "????"); + + $expected = implode("\n", array( + "SELECT 'test`test'", + "SELECT 'test?test'", + "SELECT 'test``test'", + "SELECT 'test??test'", + "SELECT `test` WHERE 'test`test'", + "SELECT `test` WHERE 'test?test'", + "SELECT `test` WHERE `test` = '`te``st`'", + "SELECT `test` WHERE `test` = '?test?'", + "SELECT `test` WHERE `test` = '????'", + )); + + $this->assertSame($expected, implode("\n", $db->queries), "Query parsing [1]"); + + $db->set_option('identifier_start', '"'); + $db->set_option('identifier_end', '"'); + $db->queries = array(); + + $db->query("SELECT ?", "test`test"); + $db->query("SELECT ?", "test?test"); + $db->query("SELECT ?", "test``test"); + $db->query("SELECT ?", "test??test"); + $db->query("SELECT `test` WHERE 'test``test'"); + $db->query("SELECT `test` WHERE 'test??test'"); + $db->query("SELECT `test` WHERE `test` = ?", "`te``st`"); + $db->query("SELECT `test` WHERE `test` = ?", "?test?"); + $db->query("SELECT `test` WHERE `test` = ?", "????"); + + $expected = implode("\n", array( + "SELECT 'test`test'", + "SELECT 'test?test'", + "SELECT 'test``test'", + "SELECT 'test??test'", + "SELECT \"test\" WHERE 'test`test'", + "SELECT \"test\" WHERE 'test?test'", + "SELECT \"test\" WHERE \"test\" = '`te``st`'", + "SELECT \"test\" WHERE \"test\" = '?test?'", + "SELECT \"test\" WHERE \"test\" = '????'", + )); + + $this->assertSame($expected, implode("\n", $db->queries), "Query parsing [2]"); + } } /** @@ -67,8 +131,30 @@ class rcube_db_test_wrapper extends rcube_db { public $queries = array(); - protected function _query($query, $offset, $numrows, $params) + protected function query_execute($query) + { + $this->queries[] = $query; + } + + public function db_connect($mode, $force = false) + { + $this->dbh = new rcube_db_test_dbh(); + } + + public function is_connected() + { + return true; + } + + protected function debug($data) + { + } +} + +class rcube_db_test_dbh +{ + public function quote($data, $type) { - $this->queries[] = array(trim($query), $offset, $numrows, $params); + return "'$data'"; } } diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php index 76b1f16cd..dee767057 100644 --- a/tests/Framework/Html2text.php +++ b/tests/Framework/Html2text.php @@ -46,6 +46,11 @@ class rc_html2text extends PHPUnit_Framework_TestCase 'in' => chr(0x002).chr(0x003), 'out' => chr(0x002).chr(0x003), ), + 7 => array( + 'title' => 'Remove spaces after <br>', + 'in' => 'test<br> test', + 'out' => "test\ntest", + ), ); } diff --git a/tests/Framework/Text2Html.php b/tests/Framework/Text2Html.php index 8d1325dee..771e14703 100644 --- a/tests/Framework/Text2Html.php +++ b/tests/Framework/Text2Html.php @@ -41,7 +41,7 @@ class Framework_Text2Html extends PHPUnit_Framework_TestCase $data[] = array(">aaaa \n>aaaa", "<blockquote>aaaa_<br>aaaa</blockquote>", $options); $data[] = array(">aaaa\n>aaaa", "<blockquote>aaaa<br>aaaa</blockquote>", $options); $data[] = array(">aaaa \n>bbbb\ncccc dddd", "<blockquote>aaaa_<br>bbbb</blockquote>cccc_dddd", $options); - $data[] = array("aaaa-bbbb/cccc", "aaaa-⁠bbbb/⁠cccc", $options); + $data[] = array("aaaa-bbbb/cccc", "aaaa\xEF\xBB\xBF-\xEF\xBB\xBFbbbb\xEF\xBB\xBF/cccc", $options); $options['flowed'] = true; |