diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Framework/Browser.php | 203 | ||||
-rw-r--r-- | tests/Framework/Mime.php | 4 | ||||
-rw-r--r-- | tests/Framework/StringReplacer.php | 16 | ||||
-rw-r--r-- | tests/MailFunc.php | 40 | ||||
-rw-r--r-- | tests/phpunit.xml | 1 |
5 files changed, 261 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/MailFunc.php b/tests/MailFunc.php index 319075abd..08cbd4ed0 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&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&body=this is the body\',this)" rel="noreferrer">e-mail</a>'; $this->assertRegExp('|'.preg_quote($mailto, '|').'|', $html, "Extended mailto links"); @@ -183,4 +181,40 @@ 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); + } } 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> |