Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.77
diff -u -p -r1.77 filter.test
--- modules/filter/filter.test	28 Sep 2010 03:30:37 -0000	1.77
+++ modules/filter/filter.test	28 Sep 2010 19:57:50 -0000
@@ -835,6 +835,49 @@ class FilterUnitTestCase extends DrupalU
     if (!$success) {
       $this->verbose("\n" . $source . "\n<hr />\n" . $result);
     }
+
+    // Tests that the filter outputs valid XHTML. If the output is valid, it
+    // will not need to be corrected.
+    $tests = array();
+    $test1 = "<div>\nParagraph text\n\nMore text\n</div>";
+    $this->assertCorrectHTML(_filter_autop($test1));
+
+    $test2 = <<<EOT
+<img src="/logo.png" />
+
+<big class="fat">The quick brown fox <em>jumps over the lazy dog.
+
+The lazy dog</em> jumps over the quick brown </big>fox.
+
+<div id="some-id">
+  Quick lazy fox,
+
+  Jumps <span style="color:blue">over a lazy</span> fish.
+</div>
+The end.
+EOT;
+    $this->assertCorrectHTML(_filter_autop($test2));
+
+    // test3 is identical to test2, just with a <pre> tag inserted.
+    $test3 = <<<EOT
+<img src="/logo.png" />
+
+<pre>
+This is a pre tag!
+</pre>
+
+<big class="fat">The quick brown fox <em>jumps over the lazy dog.
+
+The lazy dog</em> jumps over the quick brown </big>fox.
+
+<div id="some-id">
+  Quick lazy fox,
+
+  Jumps <span style="color:blue">over a lazy</span> fish.
+</div>
+The end.
+EOT;
+    $this->assertCorrectHTML(_filter_autop($test3));
   }
 
   /**
@@ -1462,6 +1505,24 @@ www.example.com with a newline in commen
   }
 
   /**
+   * Asserts that a string consists of valid HTML.
+   *
+   * If $source is valid HTML, _filter_htmlcorrector() will return the same
+   * $source without modification.
+   *
+   * @param $source
+   *   String of HTML to test.
+   */
+  function assertCorrectHTML($source) {
+    $corrected = _filter_htmlcorrector($source);
+    if (!$this->assertIdentical($source, $corrected)) {
+      $this->verbose('Source:<pre>' . check_plain(var_export($source, TRUE)) . '</pre>'
+        . '<hr />' . 'Corrected:<pre>' . check_plain(var_export($corrected, TRUE)) . '</pre>'
+      );
+    }
+  }
+
+  /**
    * Tests URL filter on longer content.
    *
    * Filters based on regular expressions should also be tested with a more
