summaryrefslogtreecommitdiff
path: root/tests/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Framework')
-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/Framework/Html.php9
-rw-r--r--tests/Framework/Html2text.php5
-rw-r--r--tests/Framework/StringReplacer.php4
-rw-r--r--tests/Framework/Text2Html.php94
-rw-r--r--tests/Framework/Utils.php8
-rw-r--r--tests/Framework/Washtml.php24
12 files changed, 289 insertions, 11 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/Framework/Html.php b/tests/Framework/Html.php
index d9466e601..259d73e1a 100644
--- a/tests/Framework/Html.php
+++ b/tests/Framework/Html.php
@@ -54,15 +54,6 @@ class Framework_Html extends PHPUnit_Framework_TestCase
array(
array('data-test' => 'test'), null, ' data-test="test"',
),
- array(
- array('data-test' => 'test'), array('other'), '',
- ),
- array(
- array('data-test' => 'test'), array('data-test'), ' data-test="test"',
- ),
- array(
- array('data-test' => 'test'), array('data-*'), ' data-test="test"',
- ),
);
}
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
index 2c7759f7d..76b1f16cd 100644
--- a/tests/Framework/Html2text.php
+++ b/tests/Framework/Html2text.php
@@ -41,6 +41,11 @@ class rc_html2text extends PHPUnit_Framework_TestCase
'in' => '<b><strong>&#347;</strong></b>',
'out' => 'Ś',
),
+ 6 => array(
+ 'title' => 'Don\'t remove non-printable chars',
+ 'in' => chr(0x002).chr(0x003),
+ 'out' => chr(0x002).chr(0x003),
+ ),
);
}
diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php
index 0fa7fae34..7d9600a78 100644
--- a/tests/Framework/StringReplacer.php
+++ b/tests/Framework/StringReplacer.php
@@ -42,6 +42,10 @@ class Framework_StringReplacer extends PHPUnit_Framework_TestCase
array('1@1.com www.domain.tld', '<a href="mailto:1@1.com">1@1.com</a> <a href="http://www.domain.tld">www.domain.tld</a>'),
array(' www.domain.tld ', ' <a href="http://www.domain.tld">www.domain.tld</a> '),
array(' www.domain.tld/#!download|856p1|2 ', ' <a href="http://www.domain.tld/#!download|856p1|2">www.domain.tld/#!download|856p1|2</a> '),
+ // #1489898: allow some unicode characters
+ array('https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62',
+ '<a href="https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62">https://www.google.com/maps/place/New+York,+État+de+New+York/@40.7056308,-73.9780035,11z/data=!3m1!4b1!4m2!3m1!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62</a>'
+ ),
);
}
diff --git a/tests/Framework/Text2Html.php b/tests/Framework/Text2Html.php
new file mode 100644
index 000000000..8d1325dee
--- /dev/null
+++ b/tests/Framework/Text2Html.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * Test class to test rcube_text2html class
+ *
+ * @package Tests
+ */
+class Framework_Text2Html extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Data for test_text2html()
+ */
+ function data_text2html()
+ {
+ $options = array(
+ 'begin' => '',
+ 'end' => '',
+ 'break' => '<br>',
+ 'links' => false,
+ 'flowed' => false,
+ 'wrap' => false,
+ 'space' => '_', // replace UTF-8 non-breaking space for simpler testing
+ );
+
+ $data[] = array(" aaaa", "_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa__aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa___aaaa", $options);
+ $data[] = array("aaaa\taaaa", "aaaa____aaaa", $options);
+ $data[] = array("aaaa\naaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>_aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>__aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>___aaaa", $options);
+ $data[] = array("\taaaa", "____aaaa", $options);
+ $data[] = array("\naaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>_aaaa", $options);
+ $data[] = array("\n aaaa", "<br>__aaaa", $options);
+ $data[] = array("\n aaaa", "<br>___aaaa", $options);
+ $data[] = array("aaaa\n\nbbbb", "aaaa<br><br>bbbb", $options);
+ $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-&#8288;bbbb/&#8288;cccc", $options);
+
+ $options['flowed'] = true;
+
+ $data[] = array(" aaaa", "aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa_aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa__aaaa", $options);
+ $data[] = array("aaaa aaaa", "aaaa___aaaa", $options);
+ $data[] = array("aaaa\taaaa", "aaaa____aaaa", $options);
+ $data[] = array("aaaa\naaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>_aaaa", $options);
+ $data[] = array("aaaa\n aaaa", "aaaa<br>__aaaa", $options);
+ $data[] = array("\taaaa", "____aaaa", $options);
+ $data[] = array("\naaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>aaaa", $options);
+ $data[] = array("\n aaaa", "<br>_aaaa", $options);
+ $data[] = array("\n aaaa", "<br>__aaaa", $options);
+ $data[] = array("aaaa\n\nbbbb", "aaaa<br><br>bbbb", $options);
+ $data[] = array(">aaaa \n>aaaa", "<blockquote>aaaa aaaa</blockquote>", $options);
+ $data[] = array(">aaaa\n>aaaa", "<blockquote>aaaa<br>aaaa</blockquote>", $options);
+ $data[] = array(">aaaa \n>bbbb\ncccc dddd", "<blockquote>aaaa bbbb</blockquote>cccc_dddd", $options);
+ $data[] = array(chr(0x002).chr(0x003), chr(0x002).chr(0x003), $options);
+
+ $options['flowed'] = false;
+ $options['wrap'] = true;
+
+ $data[] = array(">>aaaa bbbb\n>>\n>>>\n>cccc\n\ndddd eeee",
+ "<blockquote><blockquote>aaaa bbbb<br><br><blockquote><br></blockquote></blockquote>cccc</blockquote><br>dddd eeee", $options);
+ $data[] = array("\n>>aaaa\n\ndddd",
+ "<br><blockquote><blockquote>aaaa</blockquote></blockquote><br>dddd", $options);
+ $data[] = array("aaaa\n>bbbb\n>cccc\n\ndddd\n>>test",
+ "aaaa<blockquote>bbbb<br>cccc</blockquote><br>dddd<blockquote><blockquote>test</blockquote></blockquote>", $options);
+
+ return $data;
+ }
+
+ /**
+ * Test text to html conversion
+ *
+ * @dataProvider data_text2html
+ */
+ function test_text2html($input, $output, $options)
+ {
+ $t2h = new rcube_text2html($input, false, $options);
+
+ $html = $t2h->get_html();
+
+ $this->assertEquals($output, $html);
+ }
+}
diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php
index 082aaea3b..560a8bde7 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -325,8 +325,14 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
function test_normalize_string()
{
$test = array(
- '' => '',
+ '' => '',
'abc def' => 'abc def',
+ 'ÇçäâàåæéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ' => 'ccaaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy',
+ 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżýĄŚŻŹĆ' => 'aaaaccceeeeiilllnnooorrsssttuuuuzzzyaszzc',
+ 'ß' => 'ss',
+ 'ae' => 'a',
+ 'oe' => 'o',
+ 'ue' => 'u',
);
foreach ($test as $input => $output) {
diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php
index ab1ada05f..f041504d7 100644
--- a/tests/Framework/Washtml.php
+++ b/tests/Framework/Washtml.php
@@ -53,6 +53,16 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
$washed = $washer->wash($html);
$this->assertEquals('<!-- html ignored --><!-- body ignored --><p>test</p>', $washed, "HTML invalid comments (#1487759)");
+
+ $html = "<p>para1</p><!-- comment --><p>para2</p>";
+ $washed = $washer->wash($html);
+
+ $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>para1</p><!-- node type 8 --><p>para2</p>', $washed, "HTML comments - simple comment");
+
+ $html = "<p>para1</p><!-- <hr> comment --><p>para2</p>";
+ $washed = $washer->wash($html);
+
+ $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>para1</p><!-- node type 8 --><p>para2</p>', $washed, "HTML comments - tags inside (#1489904)");
}
/**
@@ -159,4 +169,18 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
$this->assertRegExp('|style="font-family: 新細明體; color: red"|', $washed, "Unicode chars in style attribute (#1489697)");
}
+
+ /**
+ * Test style item fixes
+ */
+ function test_style_wash()
+ {
+ $html = "<p style=\"line-height: 1; height: 10\">a</p>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|line-height: 1;|', $washed, "Untouched line-height (#1489917)");
+ $this->assertRegExp('|; height: 10px|', $washed, "Fixed height units");
+ }
}