Skip to content

Commit

Permalink
[+]: added some more tests
Browse files Browse the repository at this point in the history
[+]: fixed tests for Windows
  • Loading branch information
voku committed May 20, 2016
1 parent df13ed6 commit 6dc665d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
37 changes: 28 additions & 9 deletions tests/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
*/
class LinkTest extends \PHPUnit_Framework_TestCase
{
const TEST_HTML = '<a href="http://example.com">Link text</a>';
const TEST_HTML = '
<a href="http://example.com">Link text</a>
<br /><br />
<a href="mailto:fritz.eierschale@example.org">Fritz Eierschale, fritz.eierschale@example.org</a>
';

public function testDoLinksAfter()
{
$expected = <<<EOT
Link text [1]
Fritz Eierschale, fritz.eierschale@example.org
Links:
------
[1] http://example.com
Expand All @@ -26,56 +32,64 @@ public function testDoLinksAfter()
$html2text = new Html2Text(self::TEST_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 testDoLinksInline()
{
$expected = <<<EOT
Link text [http://example.com]
Fritz Eierschale, fritz.eierschale@example.org
EOT;

$html2text = new Html2Text(self::TEST_HTML, array('do_links' => 'inline'));
$output = $html2text->getText();

self::assertEquals($expected, $output);
self::assertEquals($this->normalizeString($expected), $output);
}

public function testDoLinksBBCode()
{
$expected = <<<EOT
[url=http://example.com]Link text[/url]
Fritz Eierschale, fritz.eierschale@example.org
EOT;

$html2text = new Html2Text(self::TEST_HTML, array('do_links' => 'bbcode'));
$output = $html2text->getText();

self::assertEquals($output, $expected);
self::assertEquals($this->normalizeString($expected), $output);
}

public function testDoLinksNone()
{
$expected = <<<EOT
Link text
Fritz Eierschale, fritz.eierschale@example.org
EOT;

$html2text = new Html2Text(self::TEST_HTML, array('do_links' => 'none'));
$output = $html2text->getText();

self::assertEquals($output, $expected);
self::assertEquals($this->normalizeString($expected), $output);
}

public function testDoLinksNextline()
{
$expected = <<<EOT
Link text
[http://example.com]
Fritz Eierschale, fritz.eierschale@example.org
EOT;

$html2text = new Html2Text(self::TEST_HTML, array('do_links' => '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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}
}
29 changes: 20 additions & 9 deletions tests/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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);
}
}

0 comments on commit 6dc665d

Please sign in to comment.