From 9b05f19338e209f05386e5b13fe0a704c94062bb Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 27 Aug 2012 08:45:13 +0200 Subject: Restructured tests --- tests/Framework/Shared.php | 161 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/Framework/Shared.php (limited to 'tests/Framework/Shared.php') 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 @@ +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"); + } +} -- cgit v1.2.3 From 528113069db7734cc6a85557291cc9f3c8d8bb91 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 29 Aug 2012 08:23:26 +0200 Subject: More tests --- tests/Framework/Shared.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/Framework/Shared.php') diff --git a/tests/Framework/Shared.php b/tests/Framework/Shared.php index d38fb03a3..99ef829da 100644 --- a/tests/Framework/Shared.php +++ b/tests/Framework/Shared.php @@ -158,4 +158,47 @@ class Framework_Shared extends PHPUnit_Framework_TestCase $this->assertEquals($input_str, $result_str, "Invalid array_keys_recursive() result"); } + + /** + * rcube_shared.inc: 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() + */ + 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 ' => array('test@test.tld', 'TEST'), + '"TEST\"" ' => 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()"); + } + + } + } -- cgit v1.2.3