summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Framework/Browser.php203
-rw-r--r--tests/Framework/Mime.php4
-rw-r--r--tests/Framework/StringReplacer.php16
-rw-r--r--tests/Framework/Utils.php32
-rw-r--r--tests/MailFunc.php88
-rw-r--r--tests/phpunit.xml1
-rw-r--r--tests/src/media.css22
7 files changed, 363 insertions, 3 deletions
diff --git a/tests/Framework/Browser.php b/tests/Framework/Browser.php
index c3860d8a3..832d4bf14 100644
--- a/tests/Framework/Browser.php
+++ b/tests/Framework/Browser.php
@@ -17,4 +17,207 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('rcube_browser', $object, "Class constructor");
}
+
+ /**
+ * @dataProvider browsers
+ */
+ function test_browser($useragent, $opera, $chrome, $ie, $ns, $ns4, $khtml, $safari, $mz)
+ {
+
+ $object = $this->getBrowser($useragent);
+
+ $this->assertEquals($opera, $object->opera, 'Check for Opera failed');
+ $this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed');
+ $this->assertEquals($ie, $object->ie, 'Check for IE failed');
+ $this->assertEquals($ns, $object->ns, 'Check for NS failed');
+ $this->assertEquals($ns4, $object->ns4, 'Check for NS4 failed');
+ $this->assertEquals($khtml, $object->khtml, 'Check for khtml failed');
+ $this->assertEquals($safari, $object->safari, 'Check for Safari failed');
+ $this->assertEquals($mz, $object->mz, 'Check for MZ failed');
+ }
+
+ /**
+ * @dataProvider os
+ */
+ function test_os($useragent, $windows, $linux, $unix, $mac)
+ {
+ $object = $this->getBrowser($useragent);
+
+ $this->assertEquals($windows, $object->win, 'Check Result of Windows');
+ $this->assertEquals($linux, $object->linux, 'Check Result of Linux');
+ $this->assertEquals($mac, $object->mac, 'Check Result of Mac');
+ $this->assertEquals($unix, $object->unix, 'Check Result of Unix');
+
+ }
+
+ /**
+ * @dataProvider versions
+ */
+ function test_version($useragent, $version)
+ {
+ $object = $this->getBrowser($useragent);
+ $this->assertEquals($version, $object->ver);
+ }
+
+ /**
+ * @dataProvider dom
+ */
+ function test_dom($useragent, $dom)
+ {
+ $object = $this->getBrowser($useragent);
+ $this->assertEquals($dom, $object->dom);
+
+ }
+
+ /**
+ * @dataProvider pngalpha
+ */
+ function test_pngalpha($useragent, $pngalpha)
+ {
+ $object = $this->getBrowser($useragent);
+ $this->assertEquals($pngalpha, $object->pngalpha);
+ }
+
+ /**
+ * @dataProvider imgdata
+ */
+ function test_imgdata($useragent, $imgdata)
+ {
+ $object = $this->getBrowser($useragent);
+ $this->assertEquals($imgdata, $object->imgdata);
+ }
+
+ function versions()
+ {
+ return $this->extractDataSet(array('version'));
+ }
+
+ function pngalpha()
+ {
+ return $this->extractDataSet(array('canPNGALPHA'));
+ }
+
+ function imgdata()
+ {
+ return $this->extractDataSet(array('canIMGDATA'));
+ }
+
+ private function extractDataSet($keys)
+ {
+ $keys = array_merge(array('useragent'), $keys);
+
+ $browser = $this->useragents();
+
+ $extracted = array();
+
+ foreach ($browser as $label => $data) {
+ foreach($keys as $key) {
+ $extracted[$data['useragent']][] = $data[$key];
+ }
+
+ }
+
+ return $extracted;
+ }
+
+ function lang()
+ {
+ return $this->extractDataSet(array('lang'));
+ }
+
+ function dom()
+ {
+ return $this->extractDataSet(array('hasDOM'));
+ }
+
+ function browsers()
+ {
+ return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isNS4','isKHTML','isSafari','isMZ'));
+ }
+
+ function useragents()
+ {
+ return array(
+ 'WIN: Mozilla Firefox ' => array(
+ 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
+ 'version' => '1.8', //Version
+ 'isWin' => true, //isWindows
+ 'isLinux' => false,
+ 'isMac' => false, //isMac
+ 'isUnix' => false, //isUnix
+ 'isOpera' => false, //isOpera
+ 'isChrome' => false, //isChrome
+ 'isIE' => false, //isIE
+ 'isNS' => false, //isNS
+ 'isNS4' => false, //isNS4
+ 'isKHTML' => false, //isKHTML
+ 'isSafari' => false, //isSafari
+ 'isMZ' => true, //isMZ
+ 'lang' => 'en-US', //lang
+ 'hasDOM' => true, //hasDOM
+ 'canPNGALPHA' => true, //canPNGALPHA
+ 'canIMGDATA' => true, //canIMGDATA
+ ),
+ 'LINUX: Bon Echo ' => array(
+ 'useragent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20070222 BonEcho/2.0.0.1',
+ 'version' => '1.8', //Version
+ 'isWin' => false, //isWindows
+ 'isLinux' => true,
+ 'isMac' => false, //isMac
+ 'isUnix' => false, //isUnix
+ 'isOpera' => false, //isOpera
+ 'isChrome' => false, //isChrome
+ 'isIE' => false, //isIE
+ 'isNS' => false, //isNS
+ 'isNS4' => false, //isNS4
+ 'isKHTML' => false, //isKHTML
+ 'isSafari' => false, //isSafari
+ 'isMZ' => true, //isMZ
+ 'lang' => 'en-US', //lang
+ 'hasDOM' => true, //hasDOM
+ 'canPNGALPHA' => true, //canPNGALPHA
+ 'canIMGDATA' => true, //canIMGDATA
+ ),
+
+ 'Chrome Mac' => array(
+ 'useragent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.461.0 Safari/534.3',
+ 'version' => '5', //Version
+ 'isWin' => false, //isWindows
+ 'isLinux' => false,
+ 'isMac' => true, //isMac
+ 'isUnix' => false, //isUnix
+ 'isOpera' => false, //isOpera
+ 'isChrome' => true, //isChrome
+ 'isIE' => false, //isIE
+ 'isNS' => false, //isNS
+ 'isNS4' => false, //isNS4
+ 'isKHTML' => true, //isKHTML
+ 'isSafari' => false, //isSafari
+ 'isMZ' => false, //isMZ
+ 'lang' => 'en-US', //lang
+ 'hasDOM' => false, //hasDOM
+ 'canPNGALPHA' => false, //canPNGALPHA
+ 'canIMGDATA' => true, //canIMGDATA
+ ),
+ );
+ }
+
+ function os()
+ {
+ return $this->extractDataSet(array('isWin','isLinux','isUnix','isMac'));
+ }
+
+ /**
+ * @param string $useragent
+ * @return rcube_browser
+ */
+ private function getBrowser($useragent)
+ {
+ /** @var $object rcube_browser */
+ $_SERVER['HTTP_USER_AGENT'] = $useragent;
+
+ $object = new rcube_browser();
+
+ return $object;
+ }
}
diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php
index 4db1856be..1450b4f90 100644
--- a/tests/Framework/Mime.php
+++ b/tests/Framework/Mime.php
@@ -197,6 +197,10 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
array("http://xx.xxx.xx.xxx:8080/addressbooks/roundcubexxxxx%40xxxxxxxxxxxxxxxxxxxxxxx.xx.xx/testing/", 70),
"http://xx.xxx.xx.xxx:8080/addressbooks/roundcubexxxxx%40xxxxxxxxxxxxxxxxxxxxxxx.xx.xx/testing/",
),
+ array(
+ array("this-is-just-some-blabla-to-make-this-more-than-seventy-five-characters-in-a-row -- this line should be wrapped", 20, "\n"),
+ "this-is-just-some-blabla-to-make-this-more-than-seventy-five-characters-in-a-row\n-- this line should\nbe wrapped",
+ ),
);
foreach ($samples as $sample) {
diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php
index e23fb9b17..0fa7fae34 100644
--- a/tests/Framework/StringReplacer.php
+++ b/tests/Framework/StringReplacer.php
@@ -56,4 +56,20 @@ class Framework_StringReplacer extends PHPUnit_Framework_TestCase
$this->assertEquals($output, $result);
}
+
+ function test_linkrefs()
+ {
+ $input = "This is a sample message [1] to test the new linkref [ref0] replacement feature of [Roundcube].\n";
+ $input.= "\n";
+ $input.= "[1] http://en.wikipedia.org/wiki/Email\n";
+ $input.= "[ref0] www.link-ref.com\n";
+
+ $replacer = new rcube_string_replacer;
+ $result = $replacer->replace($input);
+ $result = $replacer->resolve($result);
+
+ $this->assertContains('[<a href="http://en.wikipedia.org/wiki/Email">1</a>] to', $result, "Numeric linkref replacements");
+ $this->assertContains('[<a href="http://www.link-ref.com">ref0</a>] repl', $result, "Alphanum linkref replacements");
+ $this->assertContains('of [Roundcube].', $result, "Don't touch strings wihtout an index entry");
+ }
}
diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php
index 3f7f48c3a..1f1e57b0e 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -171,6 +171,12 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
$this->assertRegExp('/#rcmbody h1\s\{/', $mod, "Prefix tag styles (single)");
$this->assertRegExp('/#rcmbody h1, #rcmbody h2, #rcmbody h3, #rcmbody textarea\s+\{/', $mod, "Prefix tag styles (multiple)");
$this->assertRegExp('/#rcmbody \.noscript\s+\{/', $mod, "Prefix class styles");
+
+ $css = file_get_contents(TESTS_DIR . 'src/media.css');
+ $mod = rcube_utils::mod_css_styles($css, 'rcmbody');
+
+ $this->assertContains('#rcmbody table[class=w600]', $mod, 'Replace styles nested in @media block');
+ $this->assertContains('#rcmbody {width:600px', $mod, 'Replace body selector nested in @media block');
}
/**
@@ -288,6 +294,32 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
}
/**
+ * rcube:utils::anytodatetime()
+ */
+ function test_anytodatetime()
+ {
+ $test = array(
+ '2013-04-22' => '2013-04-22',
+ '2013/04/22' => '2013-04-22',
+ '2013.04.22' => '2013-04-22',
+ '22-04-2013' => '2013-04-22',
+ '22/04/2013' => '2013-04-22',
+ '22.04.2013' => '2013-04-22',
+ '04/22/2013' => '2013-04-22',
+ '22.4.2013' => '2013-04-22',
+ '20130422' => '2013-04-22',
+ '1900-10-10' => '1900-10-10',
+ '01-01-1900' => '1900-01-01',
+ '01/30/1960' => '1960-01-30'
+ );
+
+ foreach ($test as $datetime => $ts) {
+ $result = rcube_utils::anytodatetime($datetime);
+ $this->assertSame($ts, $result ? $result->format('Y-m-d') : '', "Error parsing date: $datetime");
+ }
+ }
+
+ /**
* rcube:utils::normalize _string()
*/
function test_normalize_string()
diff --git a/tests/MailFunc.php b/tests/MailFunc.php
index 319075abd..ab0074ef2 100644
--- a/tests/MailFunc.php
+++ b/tests/MailFunc.php
@@ -17,8 +17,6 @@ class MailFunc extends PHPUnit_Framework_TestCase
$RCMAIL->storage_init(false);
require_once INSTALL_PATH . 'program/steps/mail/func.inc';
-
- $GLOBALS['EMAIL_ADDRESS_PATTERN'] = $EMAIL_ADDRESS_PATTERN;
}
/**
@@ -147,7 +145,7 @@ class MailFunc extends PHPUnit_Framework_TestCase
// render HTML in normal mode
$html = rcmail_html4inline(rcmail_print_body($part, array('safe' => false)), 'foo');
- $mailto = '<a href="mailto:me@me.com?subject=this is the subject&amp;body=this is the body"'
+ $mailto = '<a href="mailto:me@me.com"'
.' onclick="return rcmail.command(\'compose\',\'me@me.com?subject=this is the subject&amp;body=this is the body\',this)" rel="noreferrer">e-mail</a>';
$this->assertRegExp('|'.preg_quote($mailto, '|').'|', $html, "Extended mailto links");
@@ -183,4 +181,88 @@ class MailFunc extends PHPUnit_Framework_TestCase
$this->assertRegExp('|src="cid:theCID"|', $html, "URI base resolving exception [1]");
$this->assertRegExp('|src="http://other\.domain\.tld/img3\.gif"|', $html, "URI base resolving exception [2]");
}
+
+ /**
+ * Test identities selection using Return-Path header
+ */
+ function test_rcmail_identity_select()
+ {
+ $identities = array(
+ array(
+ 'name' => 'Test',
+ 'email_ascii' => 'addr@domain.tld',
+ 'ident' => 'Test <addr@domain.tld>',
+ ),
+ array(
+ 'name' => 'Test',
+ 'email_ascii' => 'thing@domain.tld',
+ 'ident' => 'Test <thing@domain.tld>',
+ ),
+ array(
+ 'name' => 'Test',
+ 'email_ascii' => 'other@domain.tld',
+ 'ident' => 'Test <other@domain.tld>',
+ ),
+ );
+
+ $message = new stdClass;
+ $message->headers = new rcube_message_header;
+ $message->headers->set('Return-Path', '<some_thing@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+
+ $this->assertSame($identities[0], $res);
+
+ $message->headers->set('Return-Path', '<thing@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+
+ $this->assertSame($identities[1], $res);
+ }
+
+ /**
+ * Test identities selection (#1489378)
+ */
+ function test_rcmail_identity_select2()
+ {
+ $identities = array(
+ array(
+ 'name' => 'Test 1',
+ 'email_ascii' => 'addr1@domain.tld',
+ 'ident' => 'Test 1 <addr1@domain.tld>',
+ ),
+ array(
+ 'name' => 'Test 2',
+ 'email_ascii' => 'addr2@domain.tld',
+ 'ident' => 'Test 2 <addr2@domain.tld>',
+ ),
+ array(
+ 'name' => 'Test 3',
+ 'email_ascii' => 'addr3@domain.tld',
+ 'ident' => 'Test 3 <addr3@domain.tld>',
+ ),
+ array(
+ 'name' => 'Test 4',
+ 'email_ascii' => 'addr2@domain.tld',
+ 'ident' => 'Test 4 <addr2@domain.tld>',
+ ),
+ );
+
+ $message = new stdClass;
+ $message->headers = new rcube_message_header;
+
+ $message->headers->set('From', '<addr2@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+ $this->assertSame($identities[1], $res);
+
+ $message->headers->set('From', 'Test 2 <addr2@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+ $this->assertSame($identities[1], $res);
+
+ $message->headers->set('From', 'Other <addr2@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+ $this->assertSame($identities[1], $res);
+
+ $message->headers->set('From', 'Test 4 <addr2@domain.tld>');
+ $res = rcmail_identity_select($message, $identities);
+ $this->assertSame($identities[3], $res);
+ }
}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index da0f899a9..a5942c433 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -46,6 +46,7 @@
<file>./../plugins/help/tests/Help.php</file>
<file>./../plugins/hide_blockquote/tests/HideBlockquote.php</file>
<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/managesieve/tests/Managesieve.php</file>
<file>./../plugins/managesieve/tests/Parser.php</file>
diff --git a/tests/src/media.css b/tests/src/media.css
new file mode 100644
index 000000000..24eacc8a1
--- /dev/null
+++ b/tests/src/media.css
@@ -0,0 +1,22 @@
+.ReadMsgBody{width: 100%;}
+.ExternalClass{width: 100%;}
+div, p, a, li, td { -webkit-text-size-adjust:none; }
+@media (max-width: 450px){
+ table[class=w600], td[class=w600], table[class=w540], td[class=w540], img[class=w600]{ width:100% !important; }
+ table[class=w30], td[class=w30]{ width:20px !important; }
+ .pict img {max-width:260px; height:auto !important;}
+}
+@media (min-width: 450px) and (max-width: 600px){
+ table[class=w600], td[class=w600], table[class=w540], td[class=w540], img[class=w600]{ width:100% !important; }
+ table[class=w30], td[class=w30]{ width:20px !important; }
+ .pict img {max-width:410px; height:auto !important;}
+}
+@media (min-width:600px){
+ body {width:600px !important; margin:auto !important;}
+ .pict img {max-width:540px !important; height:auto !important;}
+}
+h1{ font-weight:bold; font-size:14px;color:#3c3c3c ;margin:0px; }
+h2{ color:#8DB048 ; font-size:14px; font-weight:bold; margin-top:20px; border-bottom:1px solid #d6d6d6; padding-bottom:4px; }
+h3{ color:#7e7e7e ; font-size:14px; font-weight:bold; margin:20px 0px 0px 0px; border-bottom:1px solid #d6d6d6; padding-bottom:0px 0px 4px 0px; }
+h4{ color:#8DB048 ; font-size:12px; font-weight:bold; margin:0px; padding:0px; }
+a:visited{cursor:pointer; color:#8DB048; text-decoration:none; border:none;}