Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2530134
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tests/Framework/Shared.php b/tests/Framework/Bootstrap.php
similarity index 84%
rename from tests/Framework/Shared.php
rename to tests/Framework/Bootstrap.php
index 0394cd025..d18fd371b 100644
--- a/tests/Framework/Shared.php
+++ b/tests/Framework/Bootstrap.php
@@ -1,232 +1,210 @@
<?php
/**
* Test class to test rcube_shared functions
*
* @package Tests
*/
-class Framework_Shared extends PHPUnit_Framework_TestCase
+class Framework_Bootstrap extends PHPUnit_Framework_TestCase
{
/**
- * rcube_shared.inc: in_array_nocase()
+ * bootstrap.php: 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()
+ * bootstrap.php: 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()
+ * bootstrap.php: 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()
+ * bootstrap.php: 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()
+ * bootstrap.php: 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()
+ * bootstrap.php: 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");
}
/**
- * rcube_shared.inc: format_email()
+ * bootstrap.php: format_email()
*/
function test_format_email()
{
$data = array(
'' => '',
'test' => 'test',
'test@test.tld' => 'test@test.tld',
'test@[127.0.0.1]' => 'test@[127.0.0.1]',
'TEST@TEST.TLD' => 'TEST@test.tld',
);
foreach ($data as $value => $expected) {
$result = format_email($value);
$this->assertEquals($expected, $result, "Invalid format_email() result for $value");
}
}
/**
- * rcube_shared.inc: format_email_recipient()
+ * bootstrap.php: format_email_recipient()
*/
function test_format_email_recipient()
{
$data = array(
'' => array(''),
'test' => array('test'),
'test@test.tld' => array('test@test.tld'),
'test@[127.0.0.1]' => array('test@[127.0.0.1]'),
'TEST@TEST.TLD' => array('TEST@TEST.TLD'),
'TEST <test@test.tld>' => array('test@test.tld', 'TEST'),
'"TEST\"" <test@test.tld>' => array('test@test.tld', 'TEST"'),
);
foreach ($data as $expected => $value) {
$result = format_email_recipient($value[0], $value[1]);
$this->assertEquals($expected, $result, "Invalid format_email_recipient()");
}
}
/**
- * rcube_shared.inc: is_ascii()
+ * bootstrap.php: is_ascii()
*/
function test_is_ascii()
{
$result = is_ascii("0123456789");
$this->assertTrue($result, "Valid ASCII (numbers)");
$result = is_ascii("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
$this->assertTrue($result, "Valid ASCII (letters)");
$result = is_ascii(" !\"#\$%&'()*+,-./:;<=>?@[\\^_`{|}~");
$this->assertTrue($result, "Valid ASCII (special characters)");
$result = is_ascii("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
."\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F");
$this->assertTrue($result, "Valid ASCII (control characters)");
$result = is_ascii("\n", false);
$this->assertFalse($result, "Valid ASCII (control characters)");
$result = is_ascii("ż");
$this->assertFalse($result, "Invalid ASCII (UTF-8 character)");
$result = is_ascii("ż", false);
$this->assertFalse($result, "Invalid ASCII (UTF-8 character [2])");
}
}
diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php
index ec61c5d4b..7c1e92ac8 100644
--- a/tests/Framework/Utils.php
+++ b/tests/Framework/Utils.php
@@ -1,209 +1,232 @@
<?php
/**
* Test class to test rcube_utils class
*
* @package Tests
*/
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);
}
/**
* Valid IP addresses for test_valid_ip()
*/
function data_valid_ip()
{
return array(
array('0.0.0.0'),
array('123.123.123.123'),
array('::'),
array('::1'),
array('::1.2.3.4'),
array('2001:2d12:c4fe:5afe::1'),
);
}
/**
* Valid IP addresses for test_invalid_ip()
*/
function data_invalid_ip()
{
return array(
array(''),
array(0),
array('123.123.123.1234'),
array('1.1.1.1.1'),
array('::1.2.3.260'),
array('::1.0'),
array('2001::c4fe:5afe::1'),
);
}
/**
* @dataProvider data_valid_ip
*/
function test_valid_ip($ip)
{
$this->assertTrue(rcube_utils::check_ip($ip));
}
/**
* @dataProvider data_invalid_ip
*/
function test_invalid_ip($ip)
{
$this->assertFalse(rcube_utils::check_ip($ip));
}
/**
* Data for test_rep_specialchars_output()
*/
function data_rep_specialchars_output()
{
return array(
array('', '', 'abc', 'abc'),
array('', '', '?', '?'),
array('', '', '"', '"'),
array('', '', '<', '<'),
array('', '', '>', '>'),
array('', '', '&', '&'),
array('', '', '&', '&amp;'),
array('', '', '<a>', '<a>'),
array('', 'remove', '<a>', ''),
);
}
/**
* Test for rep_specialchars_output
* @dataProvider data_rep_specialchars_output
*/
function test_rep_specialchars_output($type, $mode, $str, $res)
{
$result = rcube_utils::rep_specialchars_output(
$str, $type ? $type : 'html', $mode ? $mode : 'strict');
$this->assertEquals($result, $res);
}
/**
* 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('xss3') )", 'rcmbody');
$this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks");
$mod = rcube_utils::mod_css_styles("background:\\0075\\0072\\006c( javascript:alert('xss') )", 'rcmbody');
$this->assertEquals("/* evil! */", $mod, "Don't allow encoding quirks (2)");
}
/**
* Check rcube_utils::explode_quoted_string() compat. with explode()
*/
function test_explode_quoted_string_compat()
{
$data = array('', 'a,b,c', 'a', ',', ',a');
foreach ($data as $text) {
$result = rcube_utils::explode_quoted_string(',', $text);
$this->assertSame(explode(',', $text), $result);
}
}
+
+ /**
+ * rcube_utils::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");
+ }
+ }
+
}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 2e52b7795..36ab6d714 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -1,38 +1,38 @@
<phpunit backupGlobals="false"
bootstrap="bootstrap.php"
colors="true">
<testsuites>
<testsuite name="All Tests">
<file>Framework/BaseReplacer.php</file>
+ <file>Framework/Bootstrap.php</file>
<file>Framework/Browser.php</file>
<file>Framework/Cache.php</file>
<file>Framework/Charset.php</file>
<file>Framework/ContentFilter.php</file>
<file>Framework/Csv2vcard.php</file>
<file>Framework/Html.php</file>
<file>Framework/Imap.php</file>
<file>Framework/ImapGeneric.php</file>
<file>Framework/Image.php</file>
<file>Framework/MessageHeader.php</file>
<file>Framework/MessagePart.php</file>
<file>Framework/Mime.php</file>
<file>Framework/Rcube.php</file>
<file>Framework/ResultIndex.php</file>
<file>Framework/ResultSet.php</file>
<file>Framework/ResultThread.php</file>
- <file>Framework/Shared.php</file>
<file>Framework/Smtp.php</file>
<file>Framework/Spellchecker.php</file>
<file>Framework/StringReplacer.php</file>
<file>Framework/User.php</file>
<file>Framework/Utils.php</file>
<file>Framework/VCard.php</file>
<file>HtmlToText.php</file>
<file>MailFunc.php</file>
</testsuite>
<testsuite name="Managesieve Tests">
<file>./../plugins/managesieve/tests/Parser.php</file>
<file>./../plugins/managesieve/tests/Tokenizer.php</file>
</testsuite>
</testsuites>
</phpunit>
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Feb 3, 6:46 AM (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
427098
Default Alt Text
(17 KB)
Attached To
Mode
R3 roundcubemail
Attached
Detach File
Event Timeline
Log In to Comment