summaryrefslogtreecommitdiff
path: root/tests/Framework/Html2text.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-02-05 20:18:51 +0100
committerAleksander Machniak <alec@alec.pl>2014-02-05 20:18:51 +0100
commitb37954110d2184279a7f400d8750996a27b8f666 (patch)
tree0a0b3d1ecd72c157b4d229cb4ecd9ed928198b32 /tests/Framework/Html2text.php
parente445e0acb558b2c4805cef3ed13c84139962a5b3 (diff)
Bring back unit tests (they should be removed when creating a package)
Diffstat (limited to 'tests/Framework/Html2text.php')
-rw-r--r--tests/Framework/Html2text.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/Framework/Html2text.php b/tests/Framework/Html2text.php
new file mode 100644
index 000000000..2c7759f7d
--- /dev/null
+++ b/tests/Framework/Html2text.php
@@ -0,0 +1,106 @@
+<?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');
+ }
+
+ function test_broken_blockquotes()
+ {
+ // no end tag
+ $html = <<<EOF
+Begin<br>
+<blockquote>QUOTED TEXT
+<blockquote>
+NO END TAG FOUND
+EOF;
+ $ht = new rcube_html2text($html, false, false);
+ $res = $ht->get_text();
+
+ $this->assertContains('QUOTED TEXT NO END TAG FOUND', $res, 'No quoating on invalid html');
+
+ // with some (nested) end tags
+ $html = <<<EOF
+Begin<br>
+<blockquote>QUOTED TEXT
+<blockquote>INNER 1</blockquote>
+<blockquote>INNER 2</blockquote>
+NO END TAG FOUND
+EOF;
+ $ht = new rcube_html2text($html, false, false);
+ $res = $ht->get_text();
+
+ $this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html');
+ }
+}