1 mail.test BackdropHtmlToTextTestCase::testTags()

Test all supported tags of backdrop_html_to_text().

File

core/modules/simpletest/tests/mail.test, line 132
Test the Backdrop mailing system.

Class

BackdropHtmlToTextTestCase
Unit tests for backdrop_html_to_text().

Code

function testTags() {
  global $base_path, $base_url;
  $tests = array(
    // @todo Trailing linefeeds should be trimmed.
    '<a href = "https://backdropcms.org">BackdropCMS.org</a>' => "BackdropCMS.org [1]\n\n[1] https://backdropcms.org\n",
    // @todo Footer URLs should be absolute.
    "<a href = \"$base_path\">Homepage</a>" => "Homepage [1]\n\n[1] $base_url/\n",
    '<address>Backdrop</address>' => "Backdrop\n",
    // @todo The <address> tag is currently not supported.
    '<address>Backdrop</address><address>Backdrop</address>' => "BackdropBackdrop\n",
    '<b>Backdrop</b>' => "*Backdrop*\n",
    // @todo There should be a space between the '>' and the text.
    '<blockquote>Backdrop</blockquote>' => ">Backdrop\n",
    '<blockquote>Backdrop</blockquote><blockquote>Backdrop</blockquote>' => ">Backdrop\n>Backdrop\n",
    '<br />Backdrop<br />Backdrop<br /><br />Backdrop' => "Backdrop\nBackdrop\nBackdrop\n",
    '<br/>Backdrop<br/>Backdrop<br/><br/>Backdrop' => "Backdrop\nBackdrop\nBackdrop\n",
    // @todo There should be two line breaks before the paragraph.
    '<br/>Backdrop<br/>Backdrop<br/><br/>Backdrop<p>Backdrop</p>' => "Backdrop\nBackdrop\nBackdrop\nBackdrop\n\n",
    '<div>Backdrop</div>' => "Backdrop\n",
    // @todo The <div> tag is currently not supported.
    '<div>Backdrop</div><div>Backdrop</div>' => "BackdropBackdrop\n",
    '<em>Backdrop</em>' => "/Backdrop/\n",
    '<h1>Backdrop</h1>' => "======== BACKDROP ============================================================\n\n",
    '<h1>Backdrop</h1><p>Backdrop</p>' => "======== BACKDROP ============================================================\n\nBackdrop\n\n",
    '<h2>Backdrop</h2>' => "-------- BACKDROP ------------------------------------------------------------\n\n",
    '<h2>Backdrop</h2><p>Backdrop</p>' => "-------- BACKDROP ------------------------------------------------------------\n\nBackdrop\n\n",
    '<h3>Backdrop</h3>' => ".... Backdrop\n\n",
    '<h3>Backdrop</h3><p>Backdrop</p>' => ".... Backdrop\n\nBackdrop\n\n",
    '<h4>Backdrop</h4>' => ".. Backdrop\n\n",
    '<h4>Backdrop</h4><p>Backdrop</p>' => ".. Backdrop\n\nBackdrop\n\n",
    '<h5>Backdrop</h5>' => "Backdrop\n\n",
    '<h5>Backdrop</h5><p>Backdrop</p>' => "Backdrop\n\nBackdrop\n\n",
    '<h6>Backdrop</h6>' => "Backdrop\n\n",
    '<h6>Backdrop</h6><p>Backdrop</p>' => "Backdrop\n\nBackdrop\n\n",
    '<hr />Backdrop<hr />' => "------------------------------------------------------------------------------\nBackdrop\n------------------------------------------------------------------------------\n",
    '<hr/>Backdrop<hr/>' => "------------------------------------------------------------------------------\nBackdrop\n------------------------------------------------------------------------------\n",
    '<hr/>Backdrop<hr/><p>Backdrop</p>' => "------------------------------------------------------------------------------\nBackdrop\n------------------------------------------------------------------------------\nBackdrop\n\n",
    '<i>Backdrop</i>' => "/Backdrop/\n",
    '<p>Backdrop</p>' => "Backdrop\n\n",
    '<p>Backdrop</p><p>Backdrop</p>' => "Backdrop\n\nBackdrop\n\n",
    '<strong>Backdrop</strong>' => "*Backdrop*\n",
    // @todo Tables are currently not supported.
    '<table><tr><td>Backdrop</td><td>Backdrop</td></tr><tr><td>Backdrop</td><td>Backdrop</td></tr></table>' => "BackdropBackdropBackdropBackdrop\n",
    '<table><tr><td>Backdrop</td></tr></table><p>Backdrop</p>' => "Backdrop\nBackdrop\n\n",
    // @todo The <u> tag is currently not supported.
    '<u>Backdrop</u>' => "Backdrop\n",
    '<ul><li>Backdrop</li></ul>' => " * Backdrop\n\n",
    '<ul><li>Backdrop <em>Backdrop</em> Backdrop</li></ul>' => " * Backdrop /Backdrop/ Backdrop\n\n",
    // @todo Lines containing nothing but spaces should be trimmed.
    '<ul><li>Backdrop</li><li><ol><li>Backdrop</li><li>Backdrop</li></ol></li></ul>' => " * Backdrop\n *  1) Backdrop\n    2) Backdrop\n   \n\n",
    '<ul><li>Backdrop</li><li><ol><li>Backdrop</li></ol></li><li>Backdrop</li></ul>' => " * Backdrop\n *  1) Backdrop\n   \n * Backdrop\n\n",
    '<ul><li>Backdrop</li><li>Backdrop</li></ul>' => " * Backdrop\n * Backdrop\n\n",
    '<ul><li>Backdrop</li></ul><p>Backdrop</p>' => " * Backdrop\n\nBackdrop\n\n",
    '<ol><li>Backdrop</li></ol>' => " 1) Backdrop\n\n",
    '<ol><li>Backdrop</li><li><ul><li>Backdrop</li><li>Backdrop</li></ul></li></ol>' => " 1) Backdrop\n 2)  * Backdrop\n     * Backdrop\n    \n\n",
    '<ol><li>Backdrop</li><li>Backdrop</li></ol>' => " 1) Backdrop\n 2) Backdrop\n\n",
    '<ol>Backdrop</ol>' => "Backdrop\n\n",
    '<ol><li>Backdrop</li></ol><p>Backdrop</p>' => " 1) Backdrop\n\nBackdrop\n\n",
    '<dl><dt>Backdrop</dt></dl>' => "Backdrop\n\n",
    '<dl><dt>Backdrop</dt><dd>Backdrop</dd></dl>' => "Backdrop\n    Backdrop\n\n",
    '<dl><dt>Backdrop</dt><dd>Backdrop</dd><dt>Backdrop</dt><dd>Backdrop</dd></dl>' => "Backdrop\n    Backdrop\nBackdrop\n    Backdrop\n\n",
    '<dl><dt>Backdrop</dt><dd>Backdrop</dd></dl><p>Backdrop</p>' => "Backdrop\n    Backdrop\n\nBackdrop\n\n",
    '<dl><dt>Backdrop<dd>Backdrop</dl>' => "Backdrop\n    Backdrop\n\n",
    '<dl><dt>Backdrop</dt></dl><p>Backdrop</p>' => "Backdrop\n\nBackdrop\n\n",
    // @todo Again, lines containing only spaces should be trimmed.
    '<ul><li>Backdrop</li><li><dl><dt>Backdrop</dt><dd>Backdrop</dd><dt>Backdrop</dt><dd>Backdrop</dd></dl></li><li>Backdrop</li></ul>' => " * Backdrop\n * Backdrop\n       Backdrop\n   Backdrop\n       Backdrop\n   \n * Backdrop\n\n",
    // Tests malformed HTML tags.
    '<br>Backdrop<br>Backdrop' => "Backdrop\nBackdrop\n",
    '<hr>Backdrop<hr>Backdrop' => "------------------------------------------------------------------------------\nBackdrop\n------------------------------------------------------------------------------\nBackdrop\n",
    '<ol><li>Backdrop<li>Backdrop</ol>' => " 1) Backdrop\n 2) Backdrop\n\n",
    '<ul><li>Backdrop <em>Backdrop</em> Backdrop</ul></ul>' => " * Backdrop /Backdrop/ Backdrop\n\n",
    '<ul><li>Backdrop<li>Backdrop</ol>' => " * Backdrop\n * Backdrop\n\n",
    '<ul><li>Backdrop<li>Backdrop</ul>' => " * Backdrop\n * Backdrop\n\n",
    '<ul>Backdrop</ul>' => "Backdrop\n\n",
    'Backdrop</ul></ol></dl><li>Backdrop' => "Backdrop\n * Backdrop\n",
    '<dl>Backdrop</dl>' => "Backdrop\n\n",
    '<dl>Backdrop</dl><p>Backdrop</p>' => "Backdrop\n\nBackdrop\n\n",
    '<dt>Backdrop</dt>' => "Backdrop\n",
    // Tests some unsupported HTML tags.
    '<html>Backdrop</html>' => "Backdrop\n",
    // @todo Perhaps the contents of <script> tags should be dropped.
    '<script type="text/javascript">Backdrop</script>' => "Backdrop\n",
    // A couple of tests for Unicode characters.
    '<q>I <em>will</em> be back…</q>' => "I /will/ be back…\n",
    'FrançAIS is ÜBER-åwesome' => "FrançAIS is ÜBER-åwesome\n",
  );

  foreach ($tests as $html => $text) {
    $this->assertHtmlToText($html, $text, 'Supported tags');
  }
}