summaryrefslogtreecommitdiff
path: root/tests/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Framework')
-rw-r--r--tests/Framework/Bootstrap.php8
-rw-r--r--tests/Framework/Charset.php18
-rw-r--r--tests/Framework/Csv2vcard.php1
-rw-r--r--tests/Framework/Enriched.php74
-rw-r--r--tests/Framework/Html2text.php78
-rw-r--r--tests/Framework/Mime.php22
-rw-r--r--tests/Framework/StringReplacer.php18
-rw-r--r--tests/Framework/VCard.php15
-rw-r--r--tests/Framework/Washtml.php58
9 files changed, 287 insertions, 5 deletions
diff --git a/tests/Framework/Bootstrap.php b/tests/Framework/Bootstrap.php
index d18fd371b..904be7e3b 100644
--- a/tests/Framework/Bootstrap.php
+++ b/tests/Framework/Bootstrap.php
@@ -207,4 +207,12 @@ class Framework_Bootstrap extends PHPUnit_Framework_TestCase
$this->assertFalse($result, "Invalid ASCII (UTF-8 character [2])");
}
+ /**
+ * bootstrap.php: version_parse()
+ */
+ function test_version_parse()
+ {
+ $this->assertEquals('0.9.0', version_parse('0.9-stable'));
+ $this->assertEquals('0.9.99', version_parse('0.9-git'));
+ }
}
diff --git a/tests/Framework/Charset.php b/tests/Framework/Charset.php
index 1fd1654dc..d3d3e88dd 100644
--- a/tests/Framework/Charset.php
+++ b/tests/Framework/Charset.php
@@ -159,4 +159,22 @@ class Framework_Charset extends PHPUnit_Framework_TestCase
$this->assertEquals($output, rcube_charset::detect($input, $fallback));
}
+ /**
+ * Data for test_detect()
+ */
+ function data_detect_with_lang()
+ {
+ return array(
+ array('Åã¥Ü¦WºÙ,¥D­n', 'zh_TW', 'BIG-5'),
+ );
+ }
+
+ /**
+ * @dataProvider data_detect_with_lang
+ */
+ function test_detect_with_lang($input, $lang, $output)
+ {
+ $this->assertEquals($output, rcube_charset::detect($input, $output, $lang));
+ }
+
}
diff --git a/tests/Framework/Csv2vcard.php b/tests/Framework/Csv2vcard.php
index 6fa3e163c..5d52efc58 100644
--- a/tests/Framework/Csv2vcard.php
+++ b/tests/Framework/Csv2vcard.php
@@ -31,6 +31,7 @@ class Framework_Csv2vcard extends PHPUnit_Framework_TestCase
$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/Enriched.php b/tests/Framework/Enriched.php
new file mode 100644
index 000000000..26bbc3b4e
--- /dev/null
+++ b/tests/Framework/Enriched.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Test class to test rcube_enriched class
+ *
+ * @package Tests
+ */
+class Framework_Enriched extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Class constructor
+ */
+ function test_class()
+ {
+ $object = new rcube_enriched();
+
+ $this->assertInstanceOf('rcube_enriched', $object, "Class constructor");
+ }
+
+ /**
+ * Test to_html()
+ */
+ function test_to_html()
+ {
+ $enriched = '<bold><italic>the-text</italic></bold>';
+ $expected = '<b><i>the-text</i></b>';
+ $result = rcube_enriched::to_html($enriched);
+
+ $this->assertSame($expected, $result);
+ }
+
+ /**
+ * Data for test_formatting()
+ */
+ function data_formatting()
+ {
+ return array(
+ array('<bold>', '<b>'),
+ array('</bold>', '</b>'),
+ array('<italic>', '<i>'),
+ array('</italic>', '</i>'),
+ array('<fixed>', '<tt>'),
+ array('</fixed>', '</tt>'),
+ array('<smaller>', '<font size=-1>'),
+ array('</smaller>', '</font>'),
+ array('<bigger>', '<font size=+1>'),
+ array('</bigger>', '</font>'),
+ array('<underline>', '<span style="text-decoration: underline">'),
+ array('</underline>', '</span>'),
+ array('<flushleft>', '<span style="text-align: left">'),
+ array('</flushleft>', '</span>'),
+ array('<flushright>', '<span style="text-align: right">'),
+ array('</flushright>', '</span>'),
+ array('<flushboth>', '<span style="text-align: justified">'),
+ array('</flushboth>', '</span>'),
+ array('<indent>', '<span style="padding-left: 20px">'),
+ array('</indent>', '</span>'),
+ array('<indentright>', '<span style="padding-right: 20px">'),
+ array('</indentright>', '</span>'),
+ );
+ }
+
+ /**
+ * Test formatting conversion
+ * @dataProvider data_formatting
+ */
+ function test_formatting($enriched, $expected)
+ {
+ $result = rcube_enriched::to_html($enriched);
+
+ $this->assertSame($expected, $result);
+ }
+}
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
new file mode 100644
index 000000000..3e0df48d9
--- /dev/null
+++ b/tests/Framework/Html2text.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * Test class to test rcube_html2text class
+ *
+ * @package Tests
+ */
+class rc_html2text extends PHPUnit_Framework_TestCase
+{
+
+ function data_html2text()
+ {
+ return array(
+ 0 => array(
+ 'title' => 'Test entry',
+ 'in' => '',
+ 'out' => '',
+ ),
+ 1 => array(
+ 'title' => 'Basic HTML entities',
+ 'in' => '&quot;&amp;',
+ 'out' => '"&',
+ ),
+ 2 => array(
+ 'title' => 'HTML entity string',
+ 'in' => '&amp;quot;',
+ 'out' => '&quot;',
+ ),
+ 3 => array(
+ 'title' => 'HTML entity in STRONG tag',
+ 'in' => '<strong>&#347;</strong>', // Å›
+ 'out' => 'Åš', // upper Å›
+ ),
+ 4 => array(
+ 'title' => 'STRONG tag to upper-case conversion',
+ 'in' => '<strong>Å›</strong>',
+ 'out' => 'Åš',
+ ),
+ 5 => array(
+ 'title' => 'STRONG inside B tag',
+ 'in' => '<b><strong>&#347;</strong></b>',
+ 'out' => 'Åš',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider data_html2text
+ */
+ function test_html2text($title, $in, $out)
+ {
+ $ht = new rcube_html2text(null, false, false);
+
+ $ht->set_html($in);
+ $res = $ht->get_text();
+
+ $this->assertEquals($out, $res, $title);
+ }
+
+ /**
+ *
+ */
+ function test_multiple_blockquotes()
+ {
+ $html = <<<EOF
+<br>Begin<br><blockquote>OUTER BEGIN<blockquote>INNER 1<br></blockquote><div><br></div><div>Par 1</div>
+<blockquote>INNER 2</blockquote><div><br></div><div>Par 2</div>
+<div><br></div><div>Par 3</div><div><br></div>
+<blockquote>INNER 3</blockquote>OUTER END</blockquote>
+EOF;
+ $ht = new rcube_html2text($html, false, false);
+ $res = $ht->get_text();
+
+ $this->assertContains('>> INNER 1', $res, 'Quote inner');
+ $this->assertContains('>> INNER 3', $res, 'Quote inner');
+ $this->assertContains('> OUTER END', $res, 'Quote outer');
+ }
+}
diff --git a/tests/Framework/Mime.php b/tests/Framework/Mime.php
index dcd55992a..1f9a8c58f 100644
--- a/tests/Framework/Mime.php
+++ b/tests/Framework/Mime.php
@@ -120,4 +120,26 @@ class Framework_Mime extends PHPUnit_Framework_TestCase
$this->assertEquals($item['out'], $res, "Header decoding for: " . $idx);
}
}
+
+ /**
+ * Test format=flowed unfolding
+ */
+ function test_format_flowed()
+ {
+ $raw = file_get_contents(TESTS_DIR . 'src/format-flowed-unfolded.txt');
+ $flowed = file_get_contents(TESTS_DIR . 'src/format-flowed.txt');
+
+ $this->assertEquals($flowed, rcube_mime::format_flowed($raw, 80), "Test correct folding and space-stuffing");
+ }
+
+ /**
+ * Test format=flowed unfolding
+ */
+ function test_unfold_flowed()
+ {
+ $flowed = file_get_contents(TESTS_DIR . 'src/format-flowed.txt');
+ $unfolded = file_get_contents(TESTS_DIR . 'src/format-flowed-unfolded.txt');
+
+ $this->assertEquals($unfolded, rcube_mime::unfold_flowed($flowed), "Test correct unfolding of quoted lines");
+ }
}
diff --git a/tests/Framework/StringReplacer.php b/tests/Framework/StringReplacer.php
index a76ba00ee..95c59221b 100644
--- a/tests/Framework/StringReplacer.php
+++ b/tests/Framework/StringReplacer.php
@@ -24,11 +24,19 @@ class Framework_StringReplacer extends PHPUnit_Framework_TestCase
function data_replace()
{
return array(
- array('http://domain.tld/path*path2', '<a href="http://domain.tld/path*path2" target="_blank">http://domain.tld/path*path2</a>'),
- array("Click this link:\nhttps://mail.xn--brderli-o2a.ch/rc/ EOF", "Click this link:\n<a href=\"https://mail.xn--brderli-o2a.ch/rc/\" target=\"_blank\">https://mail.xn--brderli-o2a.ch/rc/</a> EOF"),
- array('Start http://localhost/?foo End', 'Start <a href="http://localhost/?foo" target="_blank">http://localhost/?foo</a> End'),
- array('www.domain.tld', '<a href="http://www.domain.tld" target="_blank">www.domain.tld</a>'),
- array('WWW.DOMAIN.TLD', '<a href="http://WWW.DOMAIN.TLD" target="_blank">WWW.DOMAIN.TLD</a>'),
+ array('http://domain.tld/path*path2', '<a href="http://domain.tld/path*path2">http://domain.tld/path*path2</a>'),
+ array("Click this link:\nhttps://mail.xn--brderli-o2a.ch/rc/ EOF", "Click this link:\n<a href=\"https://mail.xn--brderli-o2a.ch/rc/\">https://mail.xn--brderli-o2a.ch/rc/</a> EOF"),
+ array('Start http://localhost/?foo End', 'Start <a href="http://localhost/?foo">http://localhost/?foo</a> End'),
+ array('www.domain.tld', '<a href="http://www.domain.tld">www.domain.tld</a>'),
+ array('WWW.DOMAIN.TLD', '<a href="http://WWW.DOMAIN.TLD">WWW.DOMAIN.TLD</a>'),
+ array('[http://link.com]', '[<a href="http://link.com">http://link.com</a>]'),
+ array('http://link.com?a[]=1', '<a href="http://link.com?a[]=1">http://link.com?a[]=1</a>'),
+ array('http://link.com?a[]', '<a href="http://link.com?a[]">http://link.com?a[]</a>'),
+ array('(http://link.com)', '(<a href="http://link.com">http://link.com</a>)'),
+ array('http://link.com?a(b)c', '<a href="http://link.com?a(b)c">http://link.com?a(b)c</a>'),
+ array('http://link.com?(link)', '<a href="http://link.com?(link)">http://link.com?(link)</a>'),
+ array('http://<test>', 'http://<test>'),
+ array('http://', 'http://'),
);
}
diff --git a/tests/Framework/VCard.php b/tests/Framework/VCard.php
index 79d297664..15aa5d816 100644
--- a/tests/Framework/VCard.php
+++ b/tests/Framework/VCard.php
@@ -50,6 +50,21 @@ class Framework_VCard extends PHPUnit_Framework_TestCase
$this->assertRegExp('/TEL;TYPE=CELL:\+987654321/', $vcf, "Return CELL instead of MOBILE (set)");
}
+ /**
+ * Backslash escaping test (#1488896)
+ */
+ function test_parse_four()
+ {
+ $vcard = "BEGIN:VCARD\nVERSION:3.0\nN:last\\;;first\\\\;middle\\\\\\;\\\\;prefix;\nFN:test\nEND:VCARD";
+ $vcard = new rcube_vcard($vcard, null);
+ $vcard = $vcard->get_assoc();
+
+ $this->assertEquals("last;", $vcard['surname'], "Decode backslash character");
+ $this->assertEquals("first\\", $vcard['firstname'], "Decode backslash character");
+ $this->assertEquals("middle\\;\\", $vcard['middlename'], "Decode backslash character");
+ $this->assertEquals("prefix", $vcard['prefix'], "Decode 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
new file mode 100644
index 000000000..cd443266f
--- /dev/null
+++ b/tests/Framework/Washtml.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Test class to test rcube_washtml class
+ *
+ * @package Tests
+ */
+class Framework_Washtml extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Test the elimination of some XSS vulnerabilities
+ */
+ function test_html_xss3()
+ {
+ // #1488850
+ $html = '<p><a href="data:text/html,&lt;script&gt;alert(document.cookie)&lt;/script&gt;">Firefox</a>'
+ .'<a href="vbscript:alert(document.cookie)">Internet Explorer</a></p>';
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertNotRegExp('/data:text/', $washed, "Remove data:text/html links");
+ $this->assertNotRegExp('/vbscript:/', $washed, "Remove vbscript: links");
+ }
+
+ /**
+ * Test fixing of invalid href (#1488940)
+ */
+ function test_href()
+ {
+ $html = "<p><a href=\"\nhttp://test.com\n\">Firefox</a>";
+
+ $washer = new rcube_washtml;
+ $washed = $washer->wash($html);
+
+ $this->assertRegExp('|href="http://test.com">|', $washed, "Link href with newlines (#1488940)");
+ }
+
+ /**
+ * Test handling HTML comments
+ */
+ function test_comments()
+ {
+ $washer = new rcube_washtml;
+
+ $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)");
+
+ $html = "<!--TestCommentInvalid><p>test</p>";
+ $washed = $washer->wash($html);
+
+ $this->assertEquals('<!-- html ignored --><!-- body ignored --><p>test</p>', $washed, "HTML invalid comments (#1487759)");
+ }
+
+}