From 0c82e95c59ab7a5823c69fcbc4f1b2745b7b86f9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 27 Nov 2012 09:13:13 +0100 Subject: Apply rcube_shared.inc -> bootstrap.php change in tests --- tests/Framework/Bootstrap.php | 210 ++++++++++++++++++++++++++++++++++++++ tests/Framework/Shared.php | 232 ------------------------------------------ tests/Framework/Utils.php | 23 +++++ tests/phpunit.xml | 2 +- 4 files changed, 234 insertions(+), 233 deletions(-) create mode 100644 tests/Framework/Bootstrap.php delete mode 100644 tests/Framework/Shared.php (limited to 'tests') diff --git a/tests/Framework/Bootstrap.php b/tests/Framework/Bootstrap.php new file mode 100644 index 000000000..d18fd371b --- /dev/null +++ b/tests/Framework/Bootstrap.php @@ -0,0 +1,210 @@ +assertTrue($result, $title); + + $result = in_array_nocase($needle, null); + + $this->assertFalse($result, $title); + } + + /** + * 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"); + } + } + + /** + * 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"); + } + + } + + /** + * 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"); + } + + } + + /** + * 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"); + } + + } + + /** + * 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"); + } + + /** + * 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"); + } + + } + + /** + * 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 ' => 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()"); + } + + } + + /** + * 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/Shared.php b/tests/Framework/Shared.php deleted file mode 100644 index 0394cd025..000000000 --- a/tests/Framework/Shared.php +++ /dev/null @@ -1,232 +0,0 @@ -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"); - } - - /** - * 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()"); - } - - } - - /** - * rcube_shared.inc: 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 @@ -206,4 +206,27 @@ class Framework_Utils extends PHPUnit_Framework_TestCase $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 @@ -4,6 +4,7 @@ Framework/BaseReplacer.php + Framework/Bootstrap.php Framework/Browser.php Framework/Cache.php Framework/Charset.php @@ -20,7 +21,6 @@ Framework/ResultIndex.php Framework/ResultSet.php Framework/ResultThread.php - Framework/Shared.php Framework/Smtp.php Framework/Spellchecker.php Framework/StringReplacer.php -- cgit v1.2.3