3 commits - lib/ext tests/body_converter.php tests/bootstrap.php tests/.htaccess tests/phpunit.xml
Aleksander Machniak
machniak at kolabsys.com
Wed Sep 26 20:01:45 CEST 2012
lib/ext/html2text.php | 32 +++++++++++++++++---------------
tests/.htaccess | 2 ++
tests/body_converter.php | 30 ++++++++++++++++++++++++++++++
tests/bootstrap.php | 10 ++++++++++
tests/phpunit.xml | 9 +++++++++
5 files changed, 68 insertions(+), 15 deletions(-)
New commits:
commit 9940509079b22b15a67fd5f5361cce2ea74dbd8b
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Sep 26 20:01:25 2012 +0200
Added phpunit tests
diff --git a/tests/.htaccess b/tests/.htaccess
new file mode 100644
index 0000000..cb24fd7
--- /dev/null
+++ b/tests/.htaccess
@@ -0,0 +1,2 @@
+Order allow,deny
+Deny from all
diff --git a/tests/body_converter.php b/tests/body_converter.php
new file mode 100644
index 0000000..d93884b
--- /dev/null
+++ b/tests/body_converter.php
@@ -0,0 +1,30 @@
+<?php
+
+class body_converter extends PHPUnit_Framework_TestCase
+{
+ function setUp()
+ {
+ }
+
+
+ function data_html_to_text()
+ {
+ return array(
+ array('', ''),
+ array('<div></div>', ''),
+ array('<div>a</div>', 'a'),
+ array('<html><head><title>title</title></head></html>', ''),
+ );
+ }
+
+ /**
+ * @dataProvider data_html_to_text
+ */
+ function test_html_to_text($html, $text)
+ {
+ $converter = new kolab_sync_body_converter($html, Syncroton_Model_EmailBody::TYPE_HTML);
+ $output = $converter->convert(Syncroton_Model_EmailBody::TYPE_PLAINTEXT);
+
+ $this->assertEquals(trim($text), trim($output));
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..7aeb695
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,10 @@
+<?php
+
+if (php_sapi_name() != 'cli')
+ die("Not in shell mode (php-cli)");
+
+define('TESTS_DIR', dirname(__FILE__) . '/');
+
+require_once(TESTS_DIR . '/../lib/init.php');
+
+rcube::get_instance()->config->set('devel_mode', false);
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 0000000..337c0eb
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,9 @@
+<phpunit backupGlobals="false"
+ bootstrap="bootstrap.php"
+ colors="true">
+ <testsuites>
+ <testsuite name="All Tests">
+ <file>body_converter.php</file>
+ </testsuite>
+ </testsuites>
+</phpunit>
commit 528bdbb5b5de26ac6459e20c6fdc6872b12d0f8c
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Sep 26 20:00:33 2012 +0200
Fix unwanted <title> tag conversion (#1032)
diff --git a/lib/ext/html2text.php b/lib/ext/html2text.php
index 28c5ae0..dd413e0 100644
--- a/lib/ext/html2text.php
+++ b/lib/ext/html2text.php
@@ -145,6 +145,7 @@ class html2text
var $search = array(
"/\r/", // Non-legal carriage return
"/[\n\t]+/", // Newlines and tabs
+ '/<head[^>]*>.*?<\/head>/i', // <head>
'/<script[^>]*>.*?<\/script>/i', // <script>s -- which strip_tags supposedly has problems with
'/<style[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with
'/<p[^>]*>/i', // <P>
@@ -172,6 +173,7 @@ class html2text
var $replace = array(
'', // Non-legal carriage return
' ', // Newlines and tabs
+ '', // <head>
'', // <script>s -- which strip_tags supposedly has problems with
'', // <style>s -- which strip_tags supposedly has problems with
"\n\n", // <P>
commit d193d2d5bb7f5e2b044f29ea1a786ac531398c59
Author: Aleksander Machniak <alec at alec.pl>
Date: Wed Sep 26 19:56:02 2012 +0200
Update html2text class (from Roundcube Framework)
diff --git a/lib/ext/html2text.php b/lib/ext/html2text.php
index 9de2e96..28c5ae0 100644
--- a/lib/ext/html2text.php
+++ b/lib/ext/html2text.php
@@ -89,7 +89,7 @@
* out that extra spaces should be compressed--a problem addressed with
* Marcus Bointon's fixes but that I had not yet incorporated.
*
- * Thanks to Daniel Schledermann (http://www.typoconsult.dk/) for
+ * Thanks to Daniel Schledermann (http://www.typoconsult.dk/) for
* suggesting a valuable fix with <a> tag handling.
*
* Thanks to Wojciech Bajon (again!) for suggesting fixes and additions,
@@ -200,7 +200,7 @@ class html2text
var $ent_search = array(
'/&(nbsp|#160);/i', // Non-breaking space
'/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i',
- // Double quotes
+ // Double quotes
'/&(apos|rsquo|lsquo|#8216|#8217);/i', // Single quotes
'/>/i', // Greater-than
'/</i', // Less-than
@@ -437,11 +437,11 @@ class html2text
function set_base_url( $url = '' )
{
if ( empty($url) ) {
- if ( !empty($_SERVER['HTTP_HOST']) ) {
- $this->url = 'http://' . $_SERVER['HTTP_HOST'];
- } else {
- $this->url = '';
- }
+ if ( !empty($_SERVER['HTTP_HOST']) ) {
+ $this->url = 'http://' . $_SERVER['HTTP_HOST'];
+ } else {
+ $this->url = '';
+ }
} else {
// Strip any trailing slashes for consistency (relative
// URLs may already start with a slash like "/file.html")
@@ -515,7 +515,7 @@ class html2text
$text = preg_replace($this->ent_search, $this->ent_replace, $text);
// Replace known html entities
- $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
+ $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// Remove unknown/unhandled entities (this cannot be done in search-and-replace block)
$text = preg_replace('/&([a-zA-Z0-9]{2,6}|#[0-9]{2,4});/', '', $text);
@@ -535,7 +535,7 @@ class html2text
// for PHP versions >= 4.0.2. Default width is 75
// If width is 0 or less, don't wrap the text.
if ( $this->width > 0 ) {
- $text = wordwrap($text, $this->width);
+ $text = wordwrap($text, $this->width);
}
}
@@ -554,16 +554,16 @@ class html2text
*/
function _build_link_list( $link, $display )
{
- if (!$this->_do_links || empty($link)) {
- return $display;
- }
+ if (!$this->_do_links || empty($link)) {
+ return $display;
+ }
// Ignored link types
- if (preg_match('!^(javascript:|mailto:|#)!i', $link)) {
- return $display;
+ if (preg_match('!^(javascript:|mailto:|#)!i', $link)) {
+ return $display;
}
- if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) {
+ if (preg_match('!^([a-z][a-z0-9.+-]+:)!i', $link)) {
$url = $link;
}
else {
More information about the commits
mailing list