Page MenuHomePhorge

No OneTemporary

Size
22 KB
Referenced Files
None
Subscribers
None
diff --git a/tests/MailDecode.php b/tests/Framework/Mime.php
similarity index 97%
rename from tests/MailDecode.php
rename to tests/Framework/Mime.php
index 7969603dd..dcd55992a 100644
--- a/tests/MailDecode.php
+++ b/tests/Framework/Mime.php
@@ -1,123 +1,123 @@
<?php
/**
- * Test class to test messages decoding functions
+ * Test class to test rcube_mime class
*
* @package Tests
*/
-class MailDecode extends PHPUnit_Framework_TestCase
+class Framework_Mime extends PHPUnit_Framework_TestCase
{
/**
* Test decoding of single e-mail address strings
* Uses rcube_mime::decode_address_list()
*/
function test_decode_single_address()
{
$headers = array(
0 => 'test@domain.tld',
1 => '<test@domain.tld>',
2 => 'Test <test@domain.tld>',
3 => 'Test Test <test@domain.tld>',
4 => 'Test Test<test@domain.tld>',
5 => '"Test Test" <test@domain.tld>',
6 => '"Test Test"<test@domain.tld>',
7 => '"Test \\" Test" <test@domain.tld>',
8 => '"Test<Test" <test@domain.tld>',
9 => '=?ISO-8859-1?B?VGVzdAo=?= <test@domain.tld>',
10 => '=?ISO-8859-1?B?VGVzdAo=?=<test@domain.tld>', // #1487068
// comments in address (#1487673)
11 => 'Test (comment) <test@domain.tld>',
12 => '"Test" (comment) <test@domain.tld>',
13 => '"Test (comment)" (comment) <test@domain.tld>',
14 => '(comment) <test@domain.tld>',
15 => 'Test <test@(comment)domain.tld>',
16 => 'Test Test ((comment)) <test@domain.tld>',
17 => 'test@domain.tld (comment)',
18 => '"Test,Test" <test@domain.tld>',
// 1487939
19 => 'Test <"test test"@domain.tld>',
20 => '<"test test"@domain.tld>',
21 => '"test test"@domain.tld',
);
$results = array(
0 => array(1, '', 'test@domain.tld'),
1 => array(1, '', 'test@domain.tld'),
2 => array(1, 'Test', 'test@domain.tld'),
3 => array(1, 'Test Test', 'test@domain.tld'),
4 => array(1, 'Test Test', 'test@domain.tld'),
5 => array(1, 'Test Test', 'test@domain.tld'),
6 => array(1, 'Test Test', 'test@domain.tld'),
7 => array(1, 'Test " Test', 'test@domain.tld'),
8 => array(1, 'Test<Test', 'test@domain.tld'),
9 => array(1, 'Test', 'test@domain.tld'),
10 => array(1, 'Test', 'test@domain.tld'),
11 => array(1, 'Test', 'test@domain.tld'),
12 => array(1, 'Test', 'test@domain.tld'),
13 => array(1, 'Test (comment)', 'test@domain.tld'),
14 => array(1, '', 'test@domain.tld'),
15 => array(1, 'Test', 'test@domain.tld'),
16 => array(1, 'Test Test', 'test@domain.tld'),
17 => array(1, '', 'test@domain.tld'),
18 => array(1, 'Test,Test', 'test@domain.tld'),
19 => array(1, 'Test', '"test test"@domain.tld'),
20 => array(1, '', '"test test"@domain.tld'),
21 => array(1, '', '"test test"@domain.tld'),
);
foreach ($headers as $idx => $header) {
$res = rcube_mime::decode_address_list($header);
$this->assertEquals($results[$idx][0], count($res), "Rows number in result for header: " . $header);
$this->assertEquals($results[$idx][1], $res[1]['name'], "Name part decoding for header: " . $header);
$this->assertEquals($results[$idx][2], $res[1]['mailto'], "Email part decoding for header: " . $header);
}
}
/**
* Test decoding of header values
* Uses rcube_mime::decode_mime_string()
*/
function test_header_decode_qp()
{
$test = array(
// #1488232: invalid character "?"
'quoted-printable (1)' => array(
'in' => '=?utf-8?Q?Certifica=C3=A7=C3=A3??=',
'out' => 'Certifica=C3=A7=C3=A3?',
),
'quoted-printable (2)' => array(
'in' => '=?utf-8?Q?Certifica=?= =?utf-8?Q?C3=A7=C3=A3?=',
'out' => 'Certifica=C3=A7=C3=A3',
),
'quoted-printable (3)' => array(
'in' => '=?utf-8?Q??= =?utf-8?Q??=',
'out' => '',
),
'quoted-printable (4)' => array(
'in' => '=?utf-8?Q??= a =?utf-8?Q??=',
'out' => ' a ',
),
'quoted-printable (5)' => array(
'in' => '=?utf-8?Q?a?= =?utf-8?Q?b?=',
'out' => 'ab',
),
'quoted-printable (6)' => array(
'in' => '=?utf-8?Q? ?= =?utf-8?Q?a?=',
'out' => ' a',
),
'quoted-printable (7)' => array(
'in' => '=?utf-8?Q?___?= =?utf-8?Q?a?=',
'out' => ' a',
),
);
foreach ($test as $idx => $item) {
$res = rcube_mime::decode_mime_string($item['in'], 'UTF-8');
$res = quoted_printable_encode($res);
$this->assertEquals($item['out'], $res, "Header decoding for: " . $idx);
}
}
}
diff --git a/tests/Framework/Shared.php b/tests/Framework/Shared.php
new file mode 100644
index 000000000..d38fb03a3
--- /dev/null
+++ b/tests/Framework/Shared.php
@@ -0,0 +1,161 @@
+<?php
+
+/**
+ * Test class to test rcube_shared functions
+ *
+ * @package Tests
+ */
+class Framework_Shared extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * rcube_shared.inc: in_array_nocase()
+ */
+ function test_in_array_nocase()
+ {
+ $haystack = array('Test');
+ $needle = 'test';
+ $result = in_array_nocase($needle, $haystack);
+
+ $this->assertTrue($result, $title);
+
+ $result = in_array_nocase($needle, null);
+
+ $this->assertFalse($result, $title);
+ }
+
+ /**
+ * rcube_shared.inc: get_boolean()
+ */
+ function test_get_boolean()
+ {
+ $input = array(
+ false, 'false', '0', 'no', 'off', 'nein', 'FALSE', '', null,
+ );
+
+ foreach ($input as $idx => $value) {
+ $this->assertFalse(get_boolean($value), "Invalid result for $idx test item");
+ }
+
+ $input = array(
+ true, 'true', '1', 1, 'yes', 'anything', 1000,
+ );
+
+ foreach ($input as $idx => $value) {
+ $this->assertTrue(get_boolean($value), "Invalid result for $idx test item");
+ }
+ }
+
+ /**
+ * rcube_shared.inc: parse_bytes()
+ */
+ function test_parse_bytes()
+ {
+ $data = array(
+ '1' => 1,
+ '1024' => 1024,
+ '2k' => 2 * 1024,
+ '2 k' => 2 * 1024,
+ '2kb' => 2 * 1024,
+ '2kB' => 2 * 1024,
+ '2m' => 2 * 1048576,
+ '2 m' => 2 * 1048576,
+ '2mb' => 2 * 1048576,
+ '2mB' => 2 * 1048576,
+ '2g' => 2 * 1024 * 1048576,
+ '2 g' => 2 * 1024 * 1048576,
+ '2gb' => 2 * 1024 * 1048576,
+ '2gB' => 2 * 1024 * 1048576,
+ );
+
+ foreach ($data as $value => $expected) {
+ $result = parse_bytes($value);
+ $this->assertEquals($expected, $result, "Invalid parse_bytes() result for $value");
+ }
+ }
+
+ /**
+ * rcube_shared.inc: slashify()
+ */
+ function test_slashify()
+ {
+ $data = array(
+ 'test' => 'test/',
+ 'test/' => 'test/',
+ '' => '/',
+ "\\" => "\\/",
+ );
+
+ foreach ($data as $value => $expected) {
+ $result = slashify($value);
+ $this->assertEquals($expected, $result, "Invalid slashify() result for $value");
+ }
+
+ }
+
+ /**
+ * rcube_shared.inc: unslashify()
+ */
+ function test_unslashify()
+ {
+ $data = array(
+ 'test' => 'test',
+ 'test/' => 'test',
+ '/' => '',
+ "\\/" => "\\",
+ 'test/test' => 'test/test',
+ 'test//' => 'test',
+ );
+
+ foreach ($data as $value => $expected) {
+ $result = unslashify($value);
+ $this->assertEquals($expected, $result, "Invalid unslashify() result for $value");
+ }
+
+ }
+
+ /**
+ * rcube_shared.inc: get_offset_sec()
+ */
+ function test_get_offset_sec()
+ {
+ $data = array(
+ '1s' => 1,
+ '1m' => 1 * 60,
+ '1h' => 1 * 60 * 60,
+ '1d' => 1 * 60 * 60 * 24,
+ '1w' => 1 * 60 * 60 * 24 * 7,
+ '1y' => (int) '1y',
+ 100 => 100,
+ '100' => 100,
+ );
+
+ foreach ($data as $value => $expected) {
+ $result = get_offset_sec($value);
+ $this->assertEquals($expected, $result, "Invalid get_offset_sec() result for $value");
+ }
+
+ }
+
+ /**
+ * rcube_shared.inc: array_keys_recursive()
+ */
+ function test_array_keys_recursive()
+ {
+ $input = array(
+ 'one' => array(
+ 'two' => array(
+ 'three' => array(),
+ 'four' => 'something',
+ ),
+ ),
+ 'five' => 'test',
+ );
+
+ $result = array_keys_recursive($input);
+ $input_str = 'one,two,three,four,five';
+ $result_str = implode(',', $result);
+
+ $this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result");
+ }
+}
diff --git a/tests/Utils.php b/tests/Framework/Utils.php
similarity index 69%
rename from tests/Utils.php
rename to tests/Framework/Utils.php
index ad0aa1dde..b6cc5d577 100644
--- a/tests/Utils.php
+++ b/tests/Framework/Utils.php
@@ -1,85 +1,119 @@
<?php
/**
* Test class to test rcube_utils class
*
* @package Tests
*/
-class Utils extends PHPUnit_Framework_TestCase
+class Framework_Utils extends PHPUnit_Framework_TestCase
{
/**
* Valid email addresses for test_valid_email()
*/
function data_valid_email()
{
return array(
array('email@domain.com', 'Valid email'),
array('firstname.lastname@domain.com', 'Email contains dot in the address field'),
array('email@subdomain.domain.com', 'Email contains dot with subdomain'),
array('firstname+lastname@domain.com', 'Plus sign is considered valid character'),
array('email@[123.123.123.123]', 'Square bracket around IP address'),
array('email@[IPv6:::1]', 'Square bracket around IPv6 address (1)'),
array('email@[IPv6:::1.2.3.4]', 'Square bracket around IPv6 address (2)'),
array('email@[IPv6:2001:2d12:c4fe:5afe::1]', 'Square bracket around IPv6 address (3)'),
array('"email"@domain.com', 'Quotes around email is considered valid'),
array('1234567890@domain.com', 'Digits in address are valid'),
array('email@domain-one.com', 'Dash in domain name is valid'),
array('_______@domain.com', 'Underscore in the address field is valid'),
array('email@domain.name', '.name is valid Top Level Domain name'),
array('email@domain.co.jp', 'Dot in Top Level Domain name also considered valid (use co.jp as example here)'),
array('firstname-lastname@domain.com', 'Dash in address field is valid'),
);
}
/**
* Invalid email addresses for test_invalid_email()
*/
function data_invalid_email()
{
return array(
array('plainaddress', 'Missing @ sign and domain'),
array('#@%^%#$@#$@#.com', 'Garbage'),
array('@domain.com', 'Missing username'),
array('Joe Smith <email@domain.com>', 'Encoded html within email is invalid'),
array('email.domain.com', 'Missing @'),
array('email@domain@domain.com', 'Two @ sign'),
array('.email@domain.com', 'Leading dot in address is not allowed'),
array('email.@domain.com', 'Trailing dot in address is not allowed'),
array('email..email@domain.com', 'Multiple dots'),
array('あいうえお@domain.com', 'Unicode char as address'),
array('email@domain.com (Joe Smith)', 'Text followed email is not allowed'),
array('email@domain', 'Missing top level domain (.com/.net/.org/etc)'),
array('email@-domain.com', 'Leading dash in front of domain is invalid'),
// array('email@domain.web', '.web is not a valid top level domain'),
array('email@123.123.123.123', 'IP address without brackets'),
array('email@2001:2d12:c4fe:5afe::1', 'IPv6 address without brackets'),
array('email@IPv6:2001:2d12:c4fe:5afe::1', 'IPv6 address without brackets (2)'),
array('email@[111.222.333.44444]', 'Invalid IP format'),
array('email@[111.222.255.257]', 'Invalid IP format (2)'),
array('email@[.222.255.257]', 'Invalid IP format (3)'),
array('email@[::1]', 'Invalid IPv6 format (1)'),
array('email@[IPv6:2001:23x2:1]', 'Invalid IPv6 format (2)'),
array('email@[IPv6:1111:2222:33333::4444:5555]', 'Invalid IPv6 format (3)'),
array('email@[IPv6:1111::3333::4444:5555]', 'Invalid IPv6 format (4)'),
array('email@domain..com', 'Multiple dot in the domain portion is invalid'),
);
}
/**
* @dataProvider data_valid_email
*/
function test_valid_email($email, $title)
{
$this->assertTrue(rcube_utils::check_email($email, false), $title);
}
/**
* @dataProvider data_invalid_email
*/
function test_invalid_email($email, $title)
{
$this->assertFalse(rcube_utils::check_email($email, false), $title);
}
+ /**
+ * rcube_utils::mod_css_styles()
+ */
+ function test_mod_css_styles()
+ {
+ $css = file_get_contents(TESTS_DIR . 'src/valid.css');
+ $mod = rcube_utils::mod_css_styles($css, 'rcmbody');
+
+ $this->assertRegExp('/#rcmbody\s+\{/', $mod, "Replace body style definition");
+ $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");
+ }
+
+ /**
+ * rcube_utils::mod_css_styles()
+ */
+ function test_mod_css_styles_xss()
+ {
+ $mod = rcube_utils::mod_css_styles("body.main2cols { background-image: url('../images/leftcol.png'); }", 'rcmbody');
+ $this->assertEquals("/* evil! */", $mod, "No url() values allowed");
+
+ $mod = rcube_utils::mod_css_styles("@import url('http://localhost/somestuff/css/master.css');", 'rcmbody');
+ $this->assertEquals("/* evil! */", $mod, "No import statements");
+
+ $mod = rcube_utils::mod_css_styles("left:expression(document.body.offsetWidth-20)", 'rcmbody');
+ $this->assertEquals("/* evil! */", $mod, "No expression properties");
+
+ $mod = rcube_utils::mod_css_styles("left:exp/* */ression( alert(&#039;xss3&#039;) )", 'rcmbody');
+ $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks");
+
+ $mod = rcube_utils::mod_css_styles("background:\\0075\\0072\\006c( javascript:alert(&#039;xss&#039;) )", 'rcmbody');
+ $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks (2)");
+ }
}
diff --git a/tests/VCards.php b/tests/Framework/VCard.php
similarity index 94%
rename from tests/VCards.php
rename to tests/Framework/VCard.php
index e61dca934..a830c2cbc 100644
--- a/tests/VCards.php
+++ b/tests/Framework/VCard.php
@@ -1,59 +1,59 @@
<?php
/**
* Unit tests for class rcube_vcard
*
* @package Tests
*/
-class VCards extends PHPUnit_Framework_TestCase
+class Framework_VCard extends PHPUnit_Framework_TestCase
{
function _srcpath($fn)
{
- return realpath(dirname(__FILE__) . '/src/' . $fn);
+ return realpath(dirname(__FILE__) . '/../src/' . $fn);
}
function test_parse_one()
{
$vcard = new rcube_vcard(file_get_contents($this->_srcpath('apple.vcf')));
$this->assertTrue($vcard->business, "Identify as business record");
$this->assertEquals("Apple Computer AG", $vcard->displayname, "FN => displayname");
$this->assertEquals("", $vcard->firstname, "No person name set");
}
function test_parse_two()
{
$vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null);
$this->assertFalse($vcard->business, "Identify as private record");
$this->assertEquals("John Doë", $vcard->displayname, "Decode according to charset attribute");
$this->assertEquals("roundcube.net", $vcard->organization, "Test organization field");
$this->assertCount(2, $vcard->email, "List two e-mail addresses");
$this->assertEquals("roundcube@gmail.com", $vcard->email[0], "Use PREF e-mail as primary");
}
function test_import()
{
$input = file_get_contents($this->_srcpath('apple.vcf'));
$input .= file_get_contents($this->_srcpath('johndoe.vcf'));
$vcards = rcube_vcard::import($input);
$this->assertCount(2, $vcards, "Detected 2 vcards");
$this->assertEquals("Apple Computer AG", $vcards[0]->displayname, "FN => displayname");
$this->assertEquals("John Doë", $vcards[1]->displayname, "Displayname with correct charset");
// http://trac.roundcube.net/ticket/1485542
$vcards2 = rcube_vcard::import(file_get_contents($this->_srcpath('thebat.vcf')));
$this->assertEquals("Iksiñski", $vcards2[0]->surname, "Detect charset in encoded values");
}
function test_encodings()
{
$input = file_get_contents($this->_srcpath('utf-16_sample.vcf'));
$vcards = rcube_vcard::import($input);
$this->assertEquals("Ǽgean ĽdaMonté", $vcards[0]->displayname, "Decoded from UTF-16");
}
}
diff --git a/tests/ModCss.php b/tests/ModCss.php
deleted file mode 100644
index 38cf84c9d..000000000
--- a/tests/ModCss.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-/**
- * Test class to test rcmail_mod_css_styles and XSS vulnerabilites
- *
- * @package Tests
- */
-class ModCss extends PHPUnit_Framework_TestCase
-{
-
- function test_modcss()
- {
- $css = file_get_contents(TESTS_DIR . 'src/valid.css');
- $mod = rcmail_mod_css_styles($css, 'rcmbody');
-
- $this->assertRegExp('/#rcmbody\s+\{/', $mod, "Replace body style definition");
- $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");
- }
-
- function test_xss()
- {
- $mod = rcmail_mod_css_styles("body.main2cols { background-image: url('../images/leftcol.png'); }", 'rcmbody');
- $this->assertEquals("/* evil! */", $mod, "No url() values allowed");
-
- $mod = rcmail_mod_css_styles("@import url('http://localhost/somestuff/css/master.css');", 'rcmbody');
- $this->assertEquals("/* evil! */", $mod, "No import statements");
-
- $mod = rcmail_mod_css_styles("left:expression(document.body.offsetWidth-20)", 'rcmbody');
- $this->assertEquals("/* evil! */", $mod, "No expression properties");
-
- $mod = rcmail_mod_css_styles("left:exp/* */ression( alert(&#039;xss3&#039;) )", 'rcmbody');
- $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks");
-
- $mod = rcmail_mod_css_styles("background:\\0075\\0072\\006c( javascript:alert(&#039;xss&#039;) )", 'rcmbody');
- $this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks (2)");
- }
-}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index b32112592..a9e25610c 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,33 +1,35 @@
<?php
/*
+-----------------------------------------------------------------------+
| tests/bootstrap.php |
| |
| This file is part of the Roundcube Webmail client |
| Copyright (C) 2009-2012, The Roundcube Dev Team |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Environment initialization script for unit tests |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
if (php_sapi_name() != 'cli')
die("Not in shell mode (php-cli)");
if (!defined('INSTALL_PATH')) define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
define('TESTS_DIR', dirname(__FILE__) . '/');
if (@is_dir(TESTS_DIR . 'config')) {
define('RCMAIL_CONFIG_DIR', TESTS_DIR . 'config');
}
require_once(INSTALL_PATH . 'program/include/iniset.php');
+
+rcmail::get_instance()->config->set('devel_mode', false);
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index d6212f458..1bde91be1 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -1,15 +1,14 @@
<phpunit backupGlobals="false"
bootstrap="bootstrap.php"
colors="true">
<testsuites>
<testsuite name="All Tests">
+ <file>Framework/Mime.php</file>
+ <file>Framework/Shared.php</file>
+ <file>Framework/Utils.php</file>
+ <file>Framework/VCard.php</file>
<file>HtmlToText.php</file>
- <file>MailDecode.php</file>
<file>MailFunc.php</file>
- <file>ModCss.php</file>
- <file>Shared.php</file>
- <file>Utils.php</file>
- <file>VCards.php</file>
</testsuite>
</testsuites>
</phpunit>

File Metadata

Mime Type
text/x-diff
Expires
Wed, Feb 4, 9:11 AM (9 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
427629
Default Alt Text
(22 KB)

Event Timeline