summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Framework/DB.php56
-rw-r--r--tests/Framework/DBMssql.php20
-rw-r--r--tests/Framework/DBMysql.php20
-rw-r--r--tests/Framework/DBPgsql.php20
-rw-r--r--tests/Framework/DBSqlite.php20
-rw-r--r--tests/Framework/DBSqlsrv.php20
-rw-r--r--tests/phpunit.xml5
7 files changed, 160 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);
+ }
}
diff --git a/tests/Framework/DBMssql.php b/tests/Framework/DBMssql.php
new file mode 100644
index 000000000..b88c95b28
--- /dev/null
+++ b/tests/Framework/DBMssql.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_db_mssql class
+ *
+ * @package Tests
+ */
+class Framework_DBMssql extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_db_mssql('test');
+
+ $this->assertInstanceOf('rcube_db_mssql', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/DBMysql.php b/tests/Framework/DBMysql.php
new file mode 100644
index 000000000..a3b8fda39
--- /dev/null
+++ b/tests/Framework/DBMysql.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_db_mysql class
+ *
+ * @package Tests
+ */
+class Framework_DBMysql extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_db_mysql('test');
+
+ $this->assertInstanceOf('rcube_db_mysql', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/DBPgsql.php b/tests/Framework/DBPgsql.php
new file mode 100644
index 000000000..67d1c4696
--- /dev/null
+++ b/tests/Framework/DBPgsql.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_db_pgsql class
+ *
+ * @package Tests
+ */
+class Framework_DBPgsql extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_db_pgsql('test');
+
+ $this->assertInstanceOf('rcube_db_pgsql', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/DBSqlite.php b/tests/Framework/DBSqlite.php
new file mode 100644
index 000000000..121bb7770
--- /dev/null
+++ b/tests/Framework/DBSqlite.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_db_sqlite class
+ *
+ * @package Tests
+ */
+class Framework_DBSqlite extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_db_sqlite('test');
+
+ $this->assertInstanceOf('rcube_db_sqlite', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/DBSqlsrv.php b/tests/Framework/DBSqlsrv.php
new file mode 100644
index 000000000..6272ef5d7
--- /dev/null
+++ b/tests/Framework/DBSqlsrv.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_db_sqlsrv class
+ *
+ * @package Tests
+ */
+class Framework_DBSqlsrv extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_db_sqlsrv('test');
+
+ $this->assertInstanceOf('rcube_db_sqlsrv', $object, "Class constructor");
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index c2874fd07..cee3434c1 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -13,6 +13,11 @@
<file>Framework/ContentFilter.php</file>
<file>Framework/Csv2vcard.php</file>
<file>Framework/DB.php</file>
+ <file>Framework/DBMssql.php</file>
+ <file>Framework/DBMysql.php</file>
+ <file>Framework/DBPgsql.php</file>
+ <file>Framework/DBSqlite.php</file>
+ <file>Framework/DBSqlsrv.php</file>
<file>Framework/Enriched.php</file>
<file>Framework/Html.php</file>
<file>Framework/Html2text.php</file>