diff options
Diffstat (limited to 'tests/Framework')
-rw-r--r-- | tests/Framework/Bootstrap.php (renamed from tests/Framework/Shared.php) | 42 | ||||
-rw-r--r-- | tests/Framework/Csv2vcard.php | 57 | ||||
-rw-r--r-- | tests/Framework/ImapGeneric.php | 18 | ||||
-rw-r--r-- | tests/Framework/Utils.php | 36 | ||||
-rw-r--r-- | tests/Framework/VCard.php | 17 |
5 files changed, 138 insertions, 32 deletions
diff --git a/tests/Framework/Shared.php b/tests/Framework/Bootstrap.php index 0394cd025..d18fd371b 100644 --- a/tests/Framework/Shared.php +++ b/tests/Framework/Bootstrap.php @@ -5,11 +5,11 @@ * * @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() { @@ -25,29 +25,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * 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() { @@ -75,7 +53,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: slashify() + * bootstrap.php: slashify() */ function test_slashify() { @@ -94,7 +72,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: unslashify() + * bootstrap.php: unslashify() */ function test_unslashify() { @@ -115,7 +93,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: get_offset_sec() + * bootstrap.php: get_offset_sec() */ function test_get_offset_sec() { @@ -138,7 +116,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: array_keys_recursive() + * bootstrap.php: array_keys_recursive() */ function test_array_keys_recursive() { @@ -160,7 +138,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: format_email() + * bootstrap.php: format_email() */ function test_format_email() { @@ -180,7 +158,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: format_email_recipient() + * bootstrap.php: format_email_recipient() */ function test_format_email_recipient() { @@ -202,7 +180,7 @@ class Framework_Shared extends PHPUnit_Framework_TestCase } /** - * rcube_shared.inc: is_ascii() + * bootstrap.php: is_ascii() */ function test_is_ascii() { diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php new file mode 100644 index 000000000..6fa3e163c --- /dev/null +++ b/tests/Framework/Csv2vcard.php @@ -0,0 +1,57 @@ +<?php + +/** + * Test class to test rcube_csv2vcard class + * + * @package Tests + */ +class Framework_Csv2vcard extends PHPUnit_Framework_TestCase +{ + + function test_import_generic() + { + $csv = new rcube_csv2vcard; + + // empty input + $csv->import(''); + $this->assertSame(array(), $csv->export()); + } + + function test_import_tb_plain() + { + $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/tb_plain.csv'); + $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/tb_plain.vcf'); + + $csv = new rcube_csv2vcard; + $csv->import($csv_text); + $result = $csv->export(); + $vcard = $result[0]->export(false); + + $this->assertCount(1, $result); + + $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text)); + $vcard = trim(str_replace("\r\n", "\n", $vcard)); + $this->assertEquals($vcf_text, $vcard); + } + + function test_import_email() + { + $csv_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/email.csv'); + $vcf_text = file_get_contents(TESTS_DIR . '/src/Csv2vcard/email.vcf'); + + $csv = new rcube_csv2vcard; + $csv->import($csv_text); + $result = $csv->export(); + + $this->assertCount(4, $result); + + $vcard = ''; + foreach ($result as $vcf) { + $vcard .= $vcf->export(false) . "\n"; + } + + $vcf_text = trim(str_replace("\r\n", "\n", $vcf_text)); + $vcard = trim(str_replace("\r\n", "\n", $vcard)); + $this->assertEquals($vcf_text, $vcard); + } +} diff --git a/tests/Framework/ImapGeneric.php b/tests/Framework/ImapGeneric.php index 0b2cc3d53..2f9b6d10f 100644 --- a/tests/Framework/ImapGeneric.php +++ b/tests/Framework/ImapGeneric.php @@ -17,4 +17,22 @@ class Framework_ImapGeneric extends PHPUnit_Framework_TestCase $this->assertInstanceOf('rcube_imap_generic', $object, "Class constructor"); } + + /** + * Test for uncompressMessageSet + */ + function test_uncompressMessageSet() + { + $result = rcube_imap_generic::uncompressMessageSet(null); + $this->assertSame(array(), $result); + $this->assertCount(0, $result); + + $result = rcube_imap_generic::uncompressMessageSet('1'); + $this->assertSame(array(1), $result); + $this->assertCount(1, $result); + + $result = rcube_imap_generic::uncompressMessageSet('1:3'); + $this->assertSame(array(1, 2, 3), $result); + $this->assertCount(3, $result); + } } diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index e58835956..7c1e92ac8 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -193,4 +193,40 @@ class Framework_Utils extends PHPUnit_Framework_TestCase $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/Framework/VCard.php b/tests/Framework/VCard.php index 56ca9d721..79d297664 100644 --- a/tests/Framework/VCard.php +++ b/tests/Framework/VCard.php @@ -33,6 +33,23 @@ class Framework_VCard extends PHPUnit_Framework_TestCase $this->assertEquals("roundcube@gmail.com", $vcard->email[0], "Use PREF e-mail as primary"); } + /** + * Make sure MOBILE phone is returned as CELL (as specified in standard) + */ + function test_parse_three() + { + $vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null); + + $vcf = $vcard->export(); + $this->assertRegExp('/TEL;CELL:\+987654321/', $vcf, "Return CELL instead of MOBILE (import)"); + + $vcard = new rcube_vcard(); + $vcard->set('phone', '+987654321', 'MOBILE'); + + $vcf = $vcard->export(); + $this->assertRegExp('/TEL;TYPE=CELL:\+987654321/', $vcf, "Return CELL instead of MOBILE (set)"); + } + function test_import() { $input = file_get_contents($this->_srcpath('apple.vcf')); |