summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Framework/Browser.php19
-rw-r--r--tests/Framework/CacheShared.php20
-rw-r--r--tests/Framework/Contacts.php20
-rw-r--r--tests/Framework/DB.php74
-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.php48
-rw-r--r--tests/Framework/Html2text.php33
-rw-r--r--tests/Framework/ImapCache.php20
-rw-r--r--tests/Framework/LdapGeneric.php20
-rw-r--r--tests/Framework/Mime.php5
-rw-r--r--tests/Framework/ResultIndex.php47
-rw-r--r--tests/Framework/ResultThread.php2
-rw-r--r--tests/Framework/SpellcheckAtd.php21
-rw-r--r--tests/Framework/SpellcheckEnchant.php21
-rw-r--r--tests/Framework/SpellcheckGoogie.php21
-rw-r--r--tests/Framework/SpellcheckPspell.php21
-rw-r--r--tests/Framework/StringReplacer.php4
-rw-r--r--tests/Framework/Text2Html.php94
-rw-r--r--tests/Framework/Utils.php36
-rw-r--r--tests/Framework/Washtml.php59
-rw-r--r--tests/Selenium/Login.php6
-rw-r--r--tests/Selenium/README.md49
-rw-r--r--tests/Selenium/bootstrap.php61
-rw-r--r--tests/Selenium/data/mysql.sql1
-rw-r--r--tests/phpunit.xml16
29 files changed, 808 insertions, 10 deletions
diff --git a/tests/Framework/Browser.php b/tests/Framework/Browser.php
index a042572a8..6afd2144c 100644
--- a/tests/Framework/Browser.php
+++ b/tests/Framework/Browser.php
@@ -210,6 +210,25 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => false, //canIMGDATA
),
+
+ 'Opera 15' => array(
+ 'useragent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36 OPR/15.0.1147.24',
+ 'version' => '15.0', //Version
+ 'isWin' => true, //isWindows
+ 'isLinux' => false,
+ 'isMac' => false, //isMac
+ 'isUnix' => false, //isUnix
+ 'isOpera' => true, //isOpera
+ 'isChrome' => false, //isChrome
+ 'isIE' => false, //isIE
+ 'isNS' => false, //isNS
+ 'isSafari' => false, //isSafari
+ 'isMZ' => false, //isMZ
+ 'lang' => '', //lang
+ 'hasDOM' => true, //hasDOM
+ 'canPNGALPHA' => true, //canPNGALPHA
+ 'canIMGDATA' => true, //canIMGDATA
+ ),
);
}
diff --git a/tests/Framework/CacheShared.php b/tests/Framework/CacheShared.php
new file mode 100644
index 000000000..9ddcafc7f
--- /dev/null
+++ b/tests/Framework/CacheShared.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_cache_shared class
+ *
+ * @package Tests
+ */
+class Framework_CacheShared extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_cache_shared('db');
+
+ $this->assertInstanceOf('rcube_cache_shared', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/Contacts.php b/tests/Framework/Contacts.php
new file mode 100644
index 000000000..0167ea366
--- /dev/null
+++ b/tests/Framework/Contacts.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_contacts class
+ *
+ * @package Tests
+ */
+class Framework_Contacts extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_contacts(null, null);
+
+ $this->assertInstanceOf('rcube_contacts', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/DB.php b/tests/Framework/DB.php
new file mode 100644
index 000000000..42020f47a
--- /dev/null
+++ b/tests/Framework/DB.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Test class to test rcube_db class
+ *
+ * @package Tests
+ */
+class Framework_DB extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor test
+ */
+ function test_class()
+ {
+ $object = new rcube_db('test');
+
+ $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 60284deef..259d73e1a 100644
--- a/tests/Framework/Html.php
+++ b/tests/Framework/Html.php
@@ -19,6 +19,54 @@ class Framework_Html extends PHPUnit_Framework_TestCase
}
/**
+ * Data for test_attrib_string()
+ */
+ function data_attrib_string()
+ {
+ return array(
+ array(
+ array(), null, '',
+ ),
+ array(
+ array('test' => 'test'), null, ' test="test"',
+ ),
+ array(
+ array('test' => 'test'), array('test'), ' test="test"',
+ ),
+ array(
+ array('test' => 'test'), array('other'), '',
+ ),
+ array(
+ array('checked' => true), null, ' checked="checked"',
+ ),
+ array(
+ array('checked' => ''), null, '',
+ ),
+ array(
+ array('onclick' => ''), null, '',
+ ),
+ array(
+ array('size' => 5), null, ' size="5"',
+ ),
+ array(
+ array('size' => 'test'), null, '',
+ ),
+ array(
+ array('data-test' => 'test'), null, ' data-test="test"',
+ ),
+ );
+ }
+
+ /**
+ * Test for attrib_string()
+ * @dataProvider data_attrib_string
+ */
+ function test_attrib_string($arg1, $arg2, $result)
+ {
+ $this->assertEquals(html::attrib_string($arg1, $arg2), $result);
+ }
+
+ /**
* Data for test_quote()
*/
function data_quote()
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
index 3e0df48d9..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),
+ ),
);
}
@@ -75,4 +80,32 @@ EOF;
$this->assertContains('>> INNER 3', $res, 'Quote inner');
$this->assertContains('> OUTER END', $res, 'Quote outer');
}
+
+ function test_broken_blockquotes()
+ {
+ // no end tag
+ $html = <<<EOF
+Begin<br>
+<blockquote>QUOTED TEXT
+<blockquote>
+NO END TAG FOUND
+EOF;
+ $ht = new rcube_html2text($html, false, false);
+ $res = $ht->get_text();
+
+ $this->assertContains('QUOTED TEXT NO END TAG FOUND', $res, 'No quoating on invalid html');
+
+ // with some (nested) end tags
+ $html = <<<EOF
+Begin<br>
+<blockquote>QUOTED TEXT
+<blockquote>INNER 1</blockquote>
+<blockquote>INNER 2</blockquote>
+NO END TAG FOUND
+EOF;
+ $ht = new rcube_html2text($html, false, false);
+ $res = $ht->get_text();
+
+ $this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html');
+ }
}
diff --git a/tests/Framework/ImapCache.php b/tests/Framework/ImapCache.php
new file mode 100644
index 000000000..83612c549
--- /dev/null
+++ b/tests/Framework/ImapCache.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_imap_cache class
+ *
+ * @package Tests
+ */
+class Framework_ImapCache extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_imap_cache(null, null, null, null);
+
+ $this->assertInstanceOf('rcube_imap_cache', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/LdapGeneric.php b/tests/Framework/LdapGeneric.php
new file mode 100644
index 000000000..8cb1a2ce5
--- /dev/null
+++ b/tests/Framework/LdapGeneric.php
@@ -0,0 +1,20 @@
+<?php
+
+/**
+ * Test class to test rcube_ldap_generic class
+ *
+ * @package Tests
+ */
+class Framework_LdapGeneric extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_ldap_generic(array());
+
+ $this->assertInstanceOf('rcube_ldap_generic', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php
index 1450b4f90..d47eba896 100644
--- a/tests/Framework/Mime.php
+++ b/tests/Framework/Mime.php
@@ -41,6 +41,9 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
21 => '"test test"@domain.tld',
// invalid (#1489092)
22 => '"John Doe @ SomeBusinessName" <MAILER-DAEMON>',
+ 23 => '=?UTF-8?B?IlRlc3QsVGVzdCI=?= <test@domain.tld>',
+ // invalid, but we do our best to parse correctly
+ 24 => '"email@test.com" <>',
);
$results = array(
@@ -68,6 +71,8 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
21 => array(1, '', '"test test"@domain.tld'),
// invalid (#1489092)
22 => array(1, 'John Doe @ SomeBusinessName', 'MAILER-DAEMON'),
+ 23 => array(1, 'Test,Test', 'test@domain.tld'),
+ 24 => array(1, '', 'email@test.com'),
);
foreach ($headers as $idx => $header) {
diff --git a/tests/Framework/ResultIndex.php b/tests/Framework/ResultIndex.php
index efbba6da7..da1cc628f 100644
--- a/tests/Framework/ResultIndex.php
+++ b/tests/Framework/ResultIndex.php
@@ -17,4 +17,51 @@ class Framework_ResultIndex extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('rcube_result_index', $object, "Class constructor");
}
+
+ /**
+ * thread parser test
+ */
+ function test_parse()
+ {
+ $text = "* SORT 2001 2002 2035 2036 2037 2038 2044 2046 2043 2045 2226 2225 2224 2223";
+ $object = new rcube_result_index('INBOX', $text);
+
+ $this->assertSame(false, $object->is_empty(), "Object is empty");
+ $this->assertSame(false, $object->is_error(), "Object is error");
+ $this->assertSame(2226, $object->max(), "Max message UID");
+ $this->assertSame(2001, $object->min(), "Min message UID");
+ $this->assertSame(14, $object->count_messages(), "Messages count");
+ $this->assertSame(14, $object->count(), "Messages count");
+ $this->assertSame(1, $object->exists(2002, true), "Message exists");
+ $this->assertSame(true, $object->exists(2002), "Message exists (bool)");
+ $this->assertSame(2001, $object->get_element('FIRST'), "Get first element");
+ $this->assertSame(2223, $object->get_element('LAST'), "Get last element");
+ $this->assertSame(2035, (int) $object->get_element(2), "Get specified element");
+ $this->assertSame("2001:2002,2035:2038,2043:2046,2223:2226", $object->get_compressed(), "Get compressed index");
+ $this->assertSame('INBOX', $object->get_parameters('MAILBOX'), "Get parameter");
+
+ $clone = clone $object;
+ $clone->filter(array(2035, 2002));
+
+ $this->assertSame(2, $clone->count(), "Messages count (filtered)");
+ $this->assertSame(2002, $clone->get_element('FIRST'), "Get first element (filtered)");
+
+ $clone = clone $object;
+ $clone->revert();
+
+ $this->assertSame(14, $clone->count(), "Messages count (reverted)");
+ $this->assertSame(12, $clone->exists(2002, true), "Message exists (reverted)");
+ $this->assertSame(true, $clone->exists(2002), "Message exists (bool) (reverted)");
+ $this->assertSame(2223, $clone->get_element('FIRST'), "Get first element (reverted)");
+ $this->assertSame(2001, $clone->get_element('LAST'), "Get last element (reverted)");
+ $this->assertSame(2225, (int) $clone->get_element(2), "Get specified element (reverted)");
+
+ $clone = clone $object;
+ $clone->slice(2, 3);
+
+ $this->assertSame(3, $clone->count(), "Messages count (sliced)");
+ $this->assertSame(2035, $clone->get_element('FIRST'), "Get first element (sliced)");
+ $this->assertSame(2037, $clone->get_element('LAST'), "Get last element (sliced)");
+ }
+
}
diff --git a/tests/Framework/ResultThread.php b/tests/Framework/ResultThread.php
index 8f5c5092f..55fca4c6a 100644
--- a/tests/Framework/ResultThread.php
+++ b/tests/Framework/ResultThread.php
@@ -55,7 +55,5 @@ class Framework_ResultThread extends PHPUnit_Framework_TestCase
$object->filter(array(784));
$this->assertSame(118, $object->count_messages(), "Messages filter");
$this->assertSame(1, $object->count(), "Messages filter (count)");
-
-//echo $object->get_compressed();
}
}
diff --git a/tests/Framework/SpellcheckAtd.php b/tests/Framework/SpellcheckAtd.php
new file mode 100644
index 000000000..cc828240f
--- /dev/null
+++ b/tests/Framework/SpellcheckAtd.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Test class to test rcube_spellcheck_atd class
+ *
+ * @package Tests
+ */
+class Framework_SpellcheckAtd extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_spellcheck_atd(null, 'en');
+
+ $this->assertInstanceOf('rcube_spellcheck_atd', $object, "Class constructor");
+ $this->assertInstanceOf('rcube_spellcheck_engine', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/SpellcheckEnchant.php b/tests/Framework/SpellcheckEnchant.php
new file mode 100644
index 000000000..85393e76c
--- /dev/null
+++ b/tests/Framework/SpellcheckEnchant.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Test class to test rcube_spellcheck_enchant class
+ *
+ * @package Tests
+ */
+class Framework_SpellcheckEnchant extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_spellcheck_enchant(null, 'en');
+
+ $this->assertInstanceOf('rcube_spellcheck_enchant', $object, "Class constructor");
+ $this->assertInstanceOf('rcube_spellcheck_engine', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/SpellcheckGoogie.php b/tests/Framework/SpellcheckGoogie.php
new file mode 100644
index 000000000..dc7d70dcc
--- /dev/null
+++ b/tests/Framework/SpellcheckGoogie.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Test class to test rcube_spellcheck_googie class
+ *
+ * @package Tests
+ */
+class Framework_SpellcheckGoogie extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_spellcheck_googie(null, 'en');
+
+ $this->assertInstanceOf('rcube_spellcheck_googie', $object, "Class constructor");
+ $this->assertInstanceOf('rcube_spellcheck_engine', $object, "Class constructor");
+ }
+}
diff --git a/tests/Framework/SpellcheckPspell.php b/tests/Framework/SpellcheckPspell.php
new file mode 100644
index 000000000..bd622b206
--- /dev/null
+++ b/tests/Framework/SpellcheckPspell.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Test class to test rcube_spellcheck_pspell class
+ *
+ * @package Tests
+ */
+class Framework_SpellcheckPspell extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_spellcheck_pspell(null, 'en');
+
+ $this->assertInstanceOf('rcube_spellcheck_pspell', $object, "Class constructor");
+ $this->assertInstanceOf('rcube_spellcheck_engine', $object, "Class constructor");
+ }
+}
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 1f1e57b0e..560a8bde7 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -320,13 +320,19 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
}
/**
- * rcube:utils::normalize _string()
+ * rcube:utils::normalize_string()
*/
function test_normalize_string()
{
$test = array(
- '' => '',
+ '' => '',
'abc def' => 'abc def',
+ 'ÇçäâàåæéêëèïîìÅÉöôòüûùÿøØáíóúñÑÁÂÀãÃÊËÈÍÎÏÓÔõÕÚÛÙýÝ' => 'ccaaaaaeeeeiiiaeooouuuyooaiounnaaaaaeeeiiioooouuuyy',
+ 'ąáâäćçčéęëěíîłľĺńňóôöŕřśšşťţůúűüźžżýĄŚŻŹĆ' => 'aaaaccceeeeiilllnnooorrsssttuuuuzzzyaszzc',
+ 'ß' => 'ss',
+ 'ae' => 'a',
+ 'oe' => 'o',
+ 'ue' => 'u',
);
foreach ($test as $input => $output) {
@@ -334,4 +340,30 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
$this->assertSame($output, $result);
}
}
+
+ /**
+ * rcube:utils::is_absolute_path()
+ */
+ function test_is_absolute_path()
+ {
+ if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
+ $test = array(
+ '' => false,
+ "C:\\" => true,
+ 'some/path' => false,
+ );
+ }
+ else {
+ $test = array(
+ '' => false,
+ '/path' => true,
+ 'some/path' => false,
+ );
+ }
+
+ foreach ($test as $input => $output) {
+ $result = rcube_utils::is_absolute_path($input);
+ $this->assertSame($output, $result);
+ }
+ }
}
diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php
index 7485d4383..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)");
}
/**
@@ -124,4 +134,53 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase
}
}
+ /**
+ * Test color style handling (#1489697)
+ */
+ function test_color_style()
+ {
+ $html = "<p style=\"font-size: 10px; color: rgb(241, 245, 218)\">a</p>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|color: rgb\(241, 245, 218\)|', $washed, "Color style (#1489697)");
+ $this->assertRegExp('|font-size: 10px|', $washed, "Font-size style");
+ }
+
+ /**
+ * Test handling of unicode chars in style (#1489777)
+ */
+ function test_style_unicode()
+ {
+ $html = "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
+ <body><span style='font-family:\"新細明體\",\"serif\";color:red'>test</span></body></html>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|style=\'font-family: "新細明體","serif"; color: red\'|', $washed, "Unicode chars in style attribute - quoted (#1489697)");
+
+ $html = "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
+ <body><span style='font-family:新細明體;color:red'>test</span></body></html>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $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");
+ }
}
diff --git a/tests/Selenium/Login.php b/tests/Selenium/Login.php
index a3f0ab6b4..65b082851 100644
--- a/tests/Selenium/Login.php
+++ b/tests/Selenium/Login.php
@@ -2,6 +2,12 @@
class Selenium_Login extends Selenium_Test
{
+ protected function setUp()
+ {
+ bootstrap::init_db();
+ parent::setUp();
+ }
+
public function testLogin()
{
// first test, we're already on the login page
diff --git a/tests/Selenium/README.md b/tests/Selenium/README.md
new file mode 100644
index 000000000..5610fae71
--- /dev/null
+++ b/tests/Selenium/README.md
@@ -0,0 +1,49 @@
+Running Selenium Tests
+======================
+
+In order to run the Selenium-based web tests, some configuration for the
+Roundcube test instance need to be created. Along with the default config for a
+given Roundcube instance, you should provide a config specifically for running
+tests. To do so, create a config file named `config-test.inc.php` in the
+regular Roundcube config dir. That should provide specific `db_dsnw` and
+`default_host` values for testing purposes as well as the credentials of a
+valid IMAP user account used for running the tests with.
+
+Add these config options used by the Selenium tests:
+
+```php
+ // Unit tests settings
+ $config['tests_username'] = 'roundcube.test@example.org';
+ $config['tests_password'] = '<test-account-password>';
+ $config['tests_url'] = 'http://localhost/roundcube/index-test.php';
+```
+
+The `tests_url` should point to Roundcube's index-test.php file accessible by
+the Selenium web browser.
+
+WARNING
+-------
+Please note that the configured IMAP account as well as the Roundcube database
+configred in `db_dsnw` will be wiped and filled with test data in every test
+run. Under no circumstances you should use credentials of a production database
+or email account!
+
+
+Run the tests
+-------------
+
+First you need to start a Selenium server. We recommend to use the
+[Selenium Standalone Server][selenium-server] but the tests will also run on a
+Selenium Grid. The tests are based in [PHPUnit_Selenium][phpunit] which can be
+installed through [PEAR][pear-phpunit].
+
+To start the test suite call `phpunit` from the Selenium directory:
+
+```
+ cd <roundcube-dir>/tests/Selenium
+ phpunit
+```
+
+[phpunit]: http://phpunit.de/manual/4.0/en/selenium.html
+[pear-phpunit]: http://pear.phpunit.de/
+[selenium-server]: http://docs.seleniumhq.org/download/
diff --git a/tests/Selenium/bootstrap.php b/tests/Selenium/bootstrap.php
index e8b186a1e..ed9c2eb32 100644
--- a/tests/Selenium/bootstrap.php
+++ b/tests/Selenium/bootstrap.php
@@ -5,7 +5,7 @@
| tests/Selenium/bootstrap.php |
| |
| This file is part of the Roundcube Webmail client |
- | Copyright (C) 2009-2013, The Roundcube Dev Team |
+ | Copyright (C) 2009-2014, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
@@ -38,7 +38,7 @@ if (set_include_path($include_path) === false) {
die("Fatal error: ini_set/set_include_path does not work.");
}
-$rcmail = rcube::get_instance('test');
+$rcmail = rcmail::get_instance('test');
define('TESTS_URL', $rcmail->config->get('tests_url'));
define('TESTS_BROWSER', $rcmail->config->get('tests_browser', 'firefox'));
@@ -48,7 +48,56 @@ define('TESTS_SLEEP', $rcmail->config->get('tests_sleep', 5));
PHPUnit_Extensions_Selenium2TestCase::shareSession(true);
-// @TODO: remove user record from DB before running tests
+
+/**
+ * satisfy PHPUnit
+ */
+class bootstrap
+{
+ /**
+ * Wipe and re-initialize (mysql) database
+ */
+ public static function init_db()
+ {
+ $rcmail = rcmail::get_instance();
+
+ // drop all existing tables first
+ $db = $rcmail->get_dbh();
+ $db->query("SET FOREIGN_KEY_CHECKS=0");
+ $sql_res = $db->query("SHOW TABLES");
+ while ($sql_arr = $db->fetch_array($sql_res)) {
+ $table = reset($sql_arr);
+ $db->query("DROP TABLE $table");
+ }
+
+ // init database with schema
+ $dsn = parse_url($rcmail->config->get('db_dsnw'));
+ $db_name = trim($dsn['path'], '/');
+
+ if ($dsn['scheme'] == 'mysql' || $dsn['scheme'] == 'mysqli') {
+ system(sprintf('cat %s %s | mysql -h %s -u %s --password=%s %s',
+ realpath(INSTALL_PATH . '/SQL/mysql.initial.sql'),
+ realpath(TESTS_DIR . '/Selenium/data/mysql.sql'),
+ escapeshellarg($dsn['host']),
+ escapeshellarg($dsn['user']),
+ escapeshellarg($dsn['pass']),
+ escapeshellarg($db_name)
+ ));
+ }
+ }
+
+ /**
+ * Wipe the configured IMAP account and fill with test data
+ */
+ public static function init_imap()
+ {
+ if (!TESTS_USER)
+ return false;
+
+ // TBD.
+ }
+}
+
// @TODO: make sure mailbox has some content (always the same) or is empty
// @TODO: plugins: enable all?
@@ -59,12 +108,12 @@ class Selenium_Test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
-// $this->rc = rcube::get_instance();
$this->setBrowser(TESTS_BROWSER);
// Set root to our index.html, for better performance
// See https://github.com/sebastianbergmann/phpunit-selenium/issues/217
- $this->setBrowserUrl(TESTS_URL . '/tests/Selenium');
+ $baseurl = preg_replace('!/index(-.+)?\.php^!', '', TESTS_URL);
+ $this->setBrowserUrl($baseurl . '/tests/Selenium');
}
protected function login()
@@ -87,7 +136,7 @@ class Selenium_Test extends PHPUnit_Extensions_Selenium2TestCase
protected function go($task = 'mail', $action = null)
{
- $this->url(TESTS_URL . '/?_task=' . $task);
+ $this->url(TESTS_URL . '?_task=' . $task);
// wait for interface load (initial ajax requests, etc.)
sleep(TESTS_SLEEP);
diff --git a/tests/Selenium/data/mysql.sql b/tests/Selenium/data/mysql.sql
new file mode 100644
index 000000000..fe6741a02
--- /dev/null
+++ b/tests/Selenium/data/mysql.sql
@@ -0,0 +1 @@
+-- empty \ No newline at end of file
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index a5942c433..f3df53521 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -7,15 +7,25 @@
<file>Framework/Bootstrap.php</file>
<file>Framework/Browser.php</file>
<file>Framework/Cache.php</file>
+ <file>Framework/CacheShared.php</file>
<file>Framework/Charset.php</file>
+ <file>Framework/Contacts.php</file>
<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>
<file>Framework/Imap.php</file>
+ <file>Framework/ImapCache.php</file>
<file>Framework/ImapGeneric.php</file>
<file>Framework/Image.php</file>
+ <file>Framework/LdapGeneric.php</file>
<file>Framework/MessageHeader.php</file>
<file>Framework/MessagePart.php</file>
<file>Framework/Mime.php</file>
@@ -24,8 +34,13 @@
<file>Framework/ResultSet.php</file>
<file>Framework/ResultThread.php</file>
<file>Framework/Smtp.php</file>
+ <file>Framework/SpellcheckAtd.php</file>
+ <file>Framework/SpellcheckEnchant.php</file>
+ <file>Framework/SpellcheckGoogie.php</file>
+ <file>Framework/SpellcheckPspell.php</file>
<file>Framework/Spellchecker.php</file>
<file>Framework/StringReplacer.php</file>
+ <file>Framework/Text2Html.php</file>
<file>Framework/User.php</file>
<file>Framework/Utils.php</file>
<file>Framework/VCard.php</file>
@@ -48,6 +63,7 @@
<file>./../plugins/http_authentication/tests/HttpAuthentication.php</file>
<file>./../plugins/identity_select/tests/IdentitySelect.php</file>
<file>./../plugins/jqueryui/tests/Jqueryui.php</file>
+ <file>./../plugins/legacy_browser/tests/LegacyBrowser.php</file>
<file>./../plugins/managesieve/tests/Managesieve.php</file>
<file>./../plugins/managesieve/tests/Parser.php</file>
<file>./../plugins/managesieve/tests/Tokenizer.php</file>