Index: modules/simpletest/tests/mail.test
===================================================================
RCS file: modules/simpletest/tests/mail.test
diff -N modules/simpletest/tests/mail.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/mail.test	6 Nov 2008 21:23:18 -0000
@@ -0,0 +1,81 @@
+<?php
+// $Id:$
+
+/**
+ * @file
+ * Provides Simpletests for mail.inc.
+ */
+
+class MailIncTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name'  => t('Text HTML to Text Filter'),
+      'description'  => t('Test mail.inc function drupal_html_to_text() function.'),
+      'group' => t('Mail'),
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+
+    define('LF', "\n");
+
+    $this->html_to_text_cases = array(
+      '<a href = "http://drupal.org">Drupal.org</a>' => "Drupal.org [1]" . LF . LF . "[1] http://drupal.org" . LF,
+      '<em>Drupal</em>'                 => '/Drupal/' . LF,
+      '<i>Drupal</i>'                   => '/Drupal/' . LF,
+      '<strong>Drupal</strong>'         => '*Drupal*' . LF,
+      '<b>Drupal</b>'                   => '*Drupal*' . LF,
+      'Drupal<br>Drupal'                => 'Drupal' . LF . 'Drupal' . LF,
+      '<p>Drupal</p>'                   => 'Drupal' . LF . LF,  // why not LF . 'Drupal' . LF . LF?
+      // 'Drupal<p>Drupal'                 => 'Drupal' . LF . LF . 'Drupal', // this is what i expected...
+      '<blockquote>Drupal</blockquote>' => '>Drupal' . LF,
+      '<ul>Drupal</ul>'                 => 'Drupal' . LF . LF,
+      '<ul><li>Drupal<li>Drupal</ul>'   => ' * Drupal' . LF . ' * Drupal' . LF . LF,
+      '<ol>Drupal</ol>'                 => 'Drupal' . LF . LF,
+      '<ol><li>Drupal<li>Drupal</ol>'   => ' 1) Drupal' . LF . ' 2) Drupal' . LF . LF,
+      // '<li>Drupal</li>'              => 'Drupal' . LF, // gives "Notice: undefined offset: 0"
+      '<dl>Drupal</dl>'                 => 'Drupal' . LF . LF,
+      '<dt>Drupal</dt>'                 => 'Drupal' . LF,
+      '<dl><dt>Drupal</dl>'             => 'Drupal' . LF . LF,
+      '<dl><dt>Drupal<dd>Drupal</dl>'   => 'Drupal' . LF . '    Drupal' . LF . LF ,
+      '<h1>Drupal</h1>'                 => '======== DRUPAL ' . str_repeat("=", 62) . LF . LF,
+      '<h2>Drupal</h2>'                 => '-------- DRUPAL ' . str_repeat("-", 62). LF . LF,
+      '<h3>Drupal</h3>'                 => '.... Drupal' . LF . LF,
+      '<h4>Drupal</h4>'                 => '.. Drupal' . LF . LF ,
+      '<h5>Drupal</h5>'                 => 'Drupal' . LF . LF,
+      '<h6>Drupal</h6>'                 => 'Drupal' . LF . LF,
+      'Drupal<hr>'             => 'Drupal' . LF . str_repeat("-", 78) . LF,
+      'Drupal<hr>Drupal'       => 'Drupal' . LF . str_repeat("-", 78) . LF . 'Drupal' . LF,
+    );
+    parent::setUp();
+  }
+
+  /**
+   * testDrupalHtmlToText
+   *
+   * Ensure that no HTML characters pass the filter and that the
+   * function returns expected result.
+   */
+  function testDrupalHtmlToText() {
+
+    // we loop the testcases defined in setUp().
+    foreach (array($this->html_to_text_cases) as $test_case) {
+      foreach ($test_case as $html_string => $expected_text) {
+        $result = drupal_html_to_text($html_string);
+        $this->assertEqual($result,  $expected_text, 'drupal_html_to_text(' . htmlentities(substr($html_string, 0, 10)) . '...)' , t('Mail'));
+      }
+    }
+
+    // test a tagsoup.
+    $html_string = '<a href><i><b><script src=""><em><strong><ol><h1><h6><hr><p>';
+    $result = drupal_html_to_text($html_string);
+    $html_expression = "/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i";
+    $this->assertTrue(!preg_match($html_expression, $result), "Testing removal of HTML tags", t('mail'));
+  }
+}
\ No newline at end of file
