Merge pull request #12259 from seamuslee001/dev_core_163
[civicrm-core.git] / tests / phpunit / CRM / Utils / HtmlToTextTest.php
index 0e64445bc13dc9a52b5a09bf7e2c0338f749c610..982580d609aaadc46ed11ed91ab8598e749253be 100644 (file)
@@ -1,50 +1,68 @@
 <?php
 
-require_once 'CiviTest/CiviUnitTestCase.php';
-
 /**
  * Class CRM_Utils_HtmlToTextTest
+ * @group headless
  */
 class CRM_Utils_HtmlToTextTest extends CiviUnitTestCase {
-  protected $_testInput = array(
-    '<br/><p>' => '', // empty test
-    '
-<p>
-This is a paragraph with <b>Bold</b> and <i>italics</i>
-Also some <a href="http://www.example.com">hrefs</a> and a
-few <mailto:"info@example.org">mailto</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
-',
-    '
-<p>
-A <a href="{action.do_something}">token</a>
-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"
-      );
-    }
+  /**
+   * @return array
+   */
+  public function htmlToTextExamples() {
+    $cases = array(); // array(0 => string $html, 1 => string $text)
+
+    $cases[] = array(
+      '<br/><p>',
+      '',
+    );
+
+    $cases[] = array(
+      "\n<p>\n" .
+      "This is a paragraph with <b>Bold</b> and <i>italics</i>\n" .
+      "Also some <a href=\"http://www.example.com\">hrefs</a> and a\n" .
+      "few <mailto:\"info@example.org\">mailto</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(
+      "<p>\nA <a href=\"{action.do_something}\">token</a>\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"
+    );
   }
+
 }