From: Tim Otten Date: Tue, 13 Jan 2015 00:22:31 +0000 (-0800) Subject: INFRA-132 - CRM_Utils_HtmlToTextTest - Spacing errors X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eaa756bf53835ff354a049e623d918f9cf64b8fe;p=civicrm-core.git INFRA-132 - CRM_Utils_HtmlToTextTest - Spacing errors --- diff --git a/tests/phpunit/CRM/Utils/HtmlToTextTest.php b/tests/phpunit/CRM/Utils/HtmlToTextTest.php index 0e64445bc1..56d7714624 100644 --- a/tests/phpunit/CRM/Utils/HtmlToTextTest.php +++ b/tests/phpunit/CRM/Utils/HtmlToTextTest.php @@ -6,45 +6,60 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * Class CRM_Utils_HtmlToTextTest */ class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase { - protected $_testInput = array( - '

' => '', // empty test - ' -

-This is a paragraph with Bold and italics -Also some hrefs and a -few mailto tags. -This is also a really long long line' => ' -This is a paragraph with BOLD and _italics_ Also some hrefs [1] and a few -mailto tags. This is also a really long long line - -Links: ------- -[1] http://www.example.com -', - ' -

-A token -is not treated as a relative URL' => ' -A token [1] is not treated as a relative URL - -Links: ------- -[1] {action.do_something} -', - ); public function setUp() { parent::setUp(); } - public function testHtmlToText() { - foreach ($this->_testInput as $html => $text) { - $output = CRM_Utils_String::htmlToText($html); - $this->assertEquals( - trim($output), - trim($text), - "Text Output did not match for $html" - ); - } + public function htmlToTextExamples() { + $cases = array(); // array(0 => string $html, 1 => string $text) + + $cases[] = array( + '

', + '', + ); + + $cases[] = array( + "\n

\n" . + "This is a paragraph with Bold and italics\n" . + "Also some hrefs and a\n" . + "few mailto tags.\n" . + "This is also a really long long line\n" . + "\n", + "This is a paragraph with BOLD and _italics_ Also some hrefs [1] and a few\n" . + "mailto tags. This is also a really long long line\n" . + "\n" . + "Links:\n" . + "------\n" . + "[1] http://www.example.com\n" . + "", + ); + + $cases[] = array( + "

\nA token\nis not treated as a relative URL", + "A token [1] is not treated as a relative URL\n" . + "\n" . + "Links:\n" . + "------\n" . + "[1] {action.do_something}\n", + ); + + return $cases; + } + + /** + * @param string $html + * Example HTML input. + * @param string $text + * Expected text output. + * @dataProvider htmlToTextExamples + */ + public function testHtmlToText($html, $text) { + $output = CRM_Utils_String::htmlToText($html); + $this->assertEquals( + trim($output), + trim($text), + "Text Output did not match for $html" + ); } }