From 6dc665d25b31276b96310fef63c9e9c8dfc2893e Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Fri, 20 May 2016 15:03:08 +0200 Subject: [PATCH] [+]: added some more tests [+]: fixed tests for Windows --- tests/LinkTest.php | 37 ++++++++++++++++++++++++++++--------- tests/MailTest.php | 29 ++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/tests/LinkTest.php b/tests/LinkTest.php index 6160142..06b4e9d 100644 --- a/tests/LinkTest.php +++ b/tests/LinkTest.php @@ -11,13 +11,19 @@ */ class LinkTest extends \PHPUnit_Framework_TestCase { - const TEST_HTML = 'Link text'; + const TEST_HTML = ' + Link text +

+ Fritz Eierschale, fritz.eierschale@example.org + '; public function testDoLinksAfter() { $expected = << 'table')); $output = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", $expected), $output); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksInline() { $expected = << 'inline')); $output = $html2text->getText(); - self::assertEquals($expected, $output); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksBBCode() { $expected = << 'bbcode')); $output = $html2text->getText(); - self::assertEquals($output, $expected); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksNone() { $expected = << 'none')); $output = $html2text->getText(); - self::assertEquals($output, $expected); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksNextline() @@ -70,12 +82,14 @@ public function testDoLinksNextline() $expected = << 'nextline')); $output = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", $expected), $output); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksInHtmlTable() @@ -117,7 +131,7 @@ public function testDoLinksInHtmlTable() $html2text = new Html2Text($html, array('do_links' => 'table')); $output = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", $expected), $output); + self::assertEquals($this->normalizeString($expected), $output); } public function testDoLinksInHtml() @@ -149,7 +163,7 @@ public function testDoLinksInHtml() $html2text = new Html2Text($html); $output = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", $expected), $output); + self::assertEquals($this->normalizeString($expected), $output); } public function testBaseUrl() @@ -192,7 +206,7 @@ public function testIgnoredLinkTypes() $html2text = new Html2Text($html, array('do_links' => 'inline')); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", $expected), $html2text->getText()); + self::assertEquals($this->normalizeString($expected), $html2text->getText()); } public function testBaseUrlWithPlaceholder() @@ -235,4 +249,9 @@ public function testJavascriptSanitizing() self::assertEquals($expected, $html2text->getText()); } + + protected function normalizeString($string) + { + return str_replace(array("\r\n", "\r"), "\n", $string); + } } diff --git a/tests/MailTest.php b/tests/MailTest.php index 1d2ae16..b76c4ee 100644 --- a/tests/MailTest.php +++ b/tests/MailTest.php @@ -21,7 +21,7 @@ public function testHtmlToText1() $text = $html2text->getText(); - self::assertEquals(UTF8::file_get_contents(__DIR__ . '/test1Html.txt'), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test1Html.txt'), $text); } public function testHtmlToText2() @@ -32,7 +32,7 @@ public function testHtmlToText2() $text = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", UTF8::file_get_contents(__DIR__ . '/test2Html.txt')), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test2Html.txt'), $text); } public function testHtmlToText3() @@ -43,7 +43,7 @@ public function testHtmlToText3() $text = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", UTF8::file_get_contents(__DIR__ . '/test3Html.txt')), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test3Html.txt'), $text); } public function testHtmlToText4() @@ -54,7 +54,7 @@ public function testHtmlToText4() $text = $html2text->getText(); - self::assertEquals(UTF8::file_get_contents(__DIR__ . '/test4Html.txt'), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test4Html.txt'), $text); } public function testHtmlToText5() @@ -65,7 +65,7 @@ public function testHtmlToText5() $text = $html2text->getText(); - self::assertEquals(UTF8::file_get_contents(__DIR__ . '/test5Html.txt'), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test5Html.txt'), $text); } public function testHtmlToText6() @@ -76,7 +76,7 @@ public function testHtmlToText6() $text = $html2text->getText(); - self::assertEquals(UTF8::file_get_contents(__DIR__ . '/test6Html.txt'), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test6Html.txt'), $text); } public function testHtmlToText7() @@ -87,7 +87,7 @@ public function testHtmlToText7() $text = $html2text->getText(); - self::assertEquals(UTF8::file_get_contents(__DIR__ . '/test7Html.txt'), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test7Html.txt'), $text); } public function testHtmlToText8() @@ -98,7 +98,7 @@ public function testHtmlToText8() $text = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", UTF8::file_get_contents(__DIR__ . '/test8Html.txt')), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test8Html.txt'), $text); } public function testHtmlToText9() @@ -109,6 +109,17 @@ public function testHtmlToText9() $text = $html2text->getText(); - self::assertEquals(str_replace(array("\n", "\r\n", "\r"), "\n", UTF8::file_get_contents(__DIR__ . '/test9Html.txt')), $text); + self::assertEquals($this->file_get_contents(__DIR__ . '/test9Html.txt'), $text); + } + + protected function file_get_contents($filename) { + $string = UTF8::file_get_contents($filename); + + return $this->normalizeString($string); + } + + protected function normalizeString($string) + { + return str_replace(array("\r\n", "\r"), "\n", $string); } }