diff options
Diffstat (limited to 'tests/Framework')
-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/Framework/Utils.php | 32 |
4 files changed, 255 insertions, 0 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() |