diff options
Diffstat (limited to 'tests/Framework')
-rw-r--r-- | tests/Framework/ImapGeneric.php | 23 | ||||
-rw-r--r-- | tests/Framework/Mime.php | 62 | ||||
-rw-r--r-- | tests/Framework/StringReplacer.php | 2 | ||||
-rw-r--r-- | tests/Framework/Utils.php | 65 | ||||
-rw-r--r-- | tests/Framework/VCard.php | 14 | ||||
-rw-r--r-- | tests/Framework/Washtml.php | 15 |
6 files changed, 180 insertions, 1 deletions
diff --git a/tests/Framework/ImapGeneric.php b/tests/Framework/ImapGeneric.php index 2f9b6d10f..af73158e5 100644 --- a/tests/Framework/ImapGeneric.php +++ b/tests/Framework/ImapGeneric.php @@ -35,4 +35,27 @@ class Framework_ImapGeneric extends PHPUnit_Framework_TestCase $this->assertSame(array(1, 2, 3), $result); $this->assertCount(3, $result); } + + /** + * Test for tokenizeResponse + */ + function test_tokenizeResponse() + { + $response = "test brack[et] {1}\r\na {0}\r\n (item1 item2)"; + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("test", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("brack[et]", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("a", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame("", $result); + + $result = rcube_imap_generic::tokenizeResponse($response, 1); + $this->assertSame(array('item1', 'item2'), $result); + } } diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php index 1f9a8c58f..4db1856be 100644 --- a/tests/Framework/Mime.php +++ b/tests/Framework/Mime.php @@ -39,6 +39,8 @@ class Framework_Mime extends PHPUnit_Framework_TestCase 19 => 'Test <"test test"@domain.tld>', 20 => '<"test test"@domain.tld>', 21 => '"test test"@domain.tld', + // invalid (#1489092) + 22 => '"John Doe @ SomeBusinessName" <MAILER-DAEMON>', ); $results = array( @@ -64,6 +66,8 @@ class Framework_Mime extends PHPUnit_Framework_TestCase 19 => array(1, 'Test', '"test test"@domain.tld'), 20 => array(1, '', '"test test"@domain.tld'), 21 => array(1, '', '"test test"@domain.tld'), + // invalid (#1489092) + 22 => array(1, 'John Doe @ SomeBusinessName', 'MAILER-DAEMON'), ); foreach ($headers as $idx => $header) { @@ -142,4 +146,62 @@ class Framework_Mime extends PHPUnit_Framework_TestCase $this->assertEquals($unfolded, rcube_mime::unfold_flowed($flowed), "Test correct unfolding of quoted lines"); } + + /** + * Test wordwrap() + */ + function test_wordwrap() + { + $samples = array( + array( + array("aaaa aaaa\n aaaa"), + "aaaa aaaa\n aaaa", + ), + array( + array("123456789 123456789 123456789 123", 29), + "123456789 123456789 123456789\n123", + ), + array( + array("123456789 3456789 123456789", 29), + "123456789 3456789 123456789", + ), + array( + array("123456789 123456789 123456789 123", 29), + "123456789 123456789 123456789\n 123", + ), + array( + array("abc", 1, "\n", true), + "a\nb\nc", + ), + array( + array("ąść", 1, "\n", true, 'UTF-8'), + "ą\nś\nć", + ), + array( + array(">abc\n>def", 2, "\n", true), + ">abc\n>def", + ), + array( + array("abc def", 3, "-"), + "abc-def", + ), + array( + array("----------------------------------------------------------------------------------------\nabc def123456789012345", 76), + "----------------------------------------------------------------------------------------\nabc def123456789012345", + ), + array( + array("-------\nabc def", 5), + "-------\nabc\ndef", + ), + array( + array("http://xx.xxx.xx.xxx:8080/addressbooks/roundcubexxxxx%40xxxxxxxxxxxxxxxxxxxxxxx.xx.xx/testing/", 70), + "http://xx.xxx.xx.xxx:8080/addressbooks/roundcubexxxxx%40xxxxxxxxxxxxxxxxxxxxxxx.xx.xx/testing/", + ), + ); + + foreach ($samples as $sample) { + $this->assertEquals($sample[1], call_user_func_array(array('rcube_mime', 'wordwrap'), $sample[0]), "Test text wrapping"); + } + } + } diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php index 95c59221b..dc7638734 100644 --- a/tests/Framework/StringReplacer.php +++ b/tests/Framework/StringReplacer.php @@ -37,6 +37,8 @@ class Framework_StringReplacer extends PHPUnit_Framework_TestCase array('http://link.com?(link)', '<a href="http://link.com?(link)">http://link.com?(link)</a>'), array('http://<test>', 'http://<test>'), array('http://', 'http://'), + array('1@1.com www.domain.tld', '<a href="mailto:1@1.com">1@1.com</a> <a href="http://www.domain.tld">www.domain.tld</a>'), + array(' www.domain.tld ', ' <a href="http://www.domain.tld">www.domain.tld</a> '), ); } diff --git a/tests/Framework/Utils.php b/tests/Framework/Utils.php index 7c1e92ac8..abfb7cb65 100644 --- a/tests/Framework/Utils.php +++ b/tests/Framework/Utils.php @@ -195,6 +195,23 @@ class Framework_Utils extends PHPUnit_Framework_TestCase } /** + * Check rcube_utils::explode_quoted_string() + */ + function test_explode_quoted_string() + { + $data = array( + '"a,b"' => array('"a,b"'), + '"a,b","c,d"' => array('"a,b"','"c,d"'), + '"a,\\"b",d' => array('"a,\\"b"', 'd'), + ); + + foreach ($data as $text => $res) { + $result = rcube_utils::explode_quoted_string(',', $text); + $this->assertSame($res, $result); + } + } + + /** * Check rcube_utils::explode_quoted_string() compat. with explode() */ function test_explode_quoted_string_compat() @@ -229,4 +246,52 @@ class Framework_Utils extends PHPUnit_Framework_TestCase } } + /** + * rcube:utils::file2class() + */ + function test_file2class() + { + $test = array( + array('', '', 'unknown'), + array('text', 'text', 'text'), + array('image/png', 'image.png', 'image png'), + ); + + foreach ($test as $v) { + $result = rcube_utils::file2class($v[0], $v[1]); + $this->assertSame($v[2], $result); + } + } + + /** + * rcube:utils::strtotime() + */ + function test_strtotime() + { + $test = array( + '1' => 1, + '' => 0, + ); + + foreach ($test as $datetime => $ts) { + $result = rcube_utils::strtotime($datetime); + $this->assertSame($ts, $result); + } + } + + /** + * rcube:utils::normalize _string() + */ + function test_normalize_string() + { + $test = array( + '' => '', + 'abc def' => 'abc def', + ); + + foreach ($test as $input => $output) { + $result = rcube_utils::normalize_string($input); + $this->assertSame($output, $result); + } + } } diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php index 15aa5d816..3353b5b13 100644 --- a/tests/Framework/VCard.php +++ b/tests/Framework/VCard.php @@ -65,6 +65,20 @@ class Framework_VCard extends PHPUnit_Framework_TestCase $this->assertEquals("prefix", $vcard['prefix'], "Decode backslash character"); } + /** + * Backslash parsing test (#1489085) + */ + function test_parse_five() + { + $vcard = "BEGIN:VCARD\nVERSION:3.0\nN:last\\\\\\a;fir\\nst\nURL:http\\://domain.tld\nEND:VCARD"; + $vcard = new rcube_vcard($vcard, null); + $vcard = $vcard->get_assoc(); + + $this->assertEquals("last\\a", $vcard['surname'], "Decode dummy backslash character"); + $this->assertEquals("fir\nst", $vcard['firstname'], "Decode backslash character"); + $this->assertEquals("http://domain.tld", $vcard['website:other'][0], "Decode dummy backslash character"); + } + function test_import() { $input = file_get_contents($this->_srcpath('apple.vcf')); diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php index cd443266f..cb7234314 100644 --- a/tests/Framework/Washtml.php +++ b/tests/Framework/Washtml.php @@ -47,7 +47,7 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase $html = "<!--[if gte mso 10]><p>p1</p><!--><p>p2</p>"; $washed = $washer->wash($html); - $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>p2</p>', $washed, "HTML conditional comments (#1489004)"); + $this->assertEquals('<!-- node type 8 --><!-- html ignored --><!-- body ignored --><p>p2</p>', $washed, "HTML conditional comments (#1489004)"); $html = "<!--TestCommentInvalid><p>test</p>"; $washed = $washer->wash($html); @@ -55,4 +55,17 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>test</p>', $washed, "HTML invalid comments (#1487759)"); } + /** + * Test fixing of invalid self-closing elements (#1489137) + */ + function test_self_closing() + { + $html = "<textarea>test"; + + $washer = new rcube_washtml; + $washed = $washer->wash($html); + + $this->assertRegExp('|<textarea>test</textarea>|', $washed, "Self-closing textarea (#1489137)"); + } + } |