Run some parser tests with tidy.
authorC. Scott Ananian <cscott@cscott.net>
Sun, 18 May 2014 07:17:25 +0000 (00:17 -0700)
committerC. Scott Ananian <cscott@cscott.net>
Sun, 3 Aug 2014 21:45:54 +0000 (17:45 -0400)
Note that the old parser tests helper function `tidy()` never actually did
anything, since $wgUseTidy was forced to `false` in the parser test setup.
Remove this unused code, and replace it with our new tidy support.

Allows new parser test sections: 'html+tidy' denotes "tidied" HTML (open
tags closed and other fixups to original wikitext markup) which should be
applicable to any parser.  'html/php+tidy' is output specific to the PHP
parser with tidy turned on.  The Parsoid backend will use the 'html/parsoid'
section if present, but if it is not present it will fallback to first the
'html+tidy' section, and if that is missing the 'html' section.

Note that 'tidy' has a large number of open bugs (see
https://bugzilla.wikimedia.org/show_bug.cgi?id=2542 ) and so in some cases
we deliberately do *not* use 'html+tidy' or 'html/php+tidy' clauses, in
order to avoid documenting broken output.  In these cases, there is no
broken HTML in the PHP parser output, and so (in theory) the 'html' and
'html+tidy' sections would be identical (that is, if tidy didn't have
bugs).

Change-Id: Iba45f38774b221522dc3b6ae2d1312fb79f8f41f

tests/TestsAutoLoader.php
tests/parser/parserTest.inc
tests/parser/parserTests.txt
tests/phpunit/includes/parser/NewParserTest.php
tests/testHelpers.inc

index b56890b..664e7f5 100644 (file)
@@ -35,6 +35,7 @@ $wgAutoloadClasses += array(
        'TestRecorder' => "$testDir/testHelpers.inc",
        'ITestRecorder' => "$testDir/testHelpers.inc",
        'DjVuSupport' => "$testDir/testHelpers.inc",
+       'TidySupport' => "$testDir/testHelpers.inc",
 
        # tests/phpunit
        'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiTestCase.php",
index e76b9df..a2a3867 100644 (file)
@@ -69,6 +69,11 @@ class ParserTest {
         */
        private $djVuSupport;
 
+       /**
+        * @var TidySupport
+        */
+       private $tidySupport;
+
        private $maxFuzzTestLength = 300;
        private $fuzzSeed = 0;
        private $memoryLimit = 50;
@@ -137,6 +142,10 @@ class ParserTest {
                $this->runParsoid = isset( $options['run-parsoid'] );
 
                $this->djVuSupport = new DjVuSupport();
+               $this->tidySupport = new TidySupport();
+               if ( !$this->tidySupport->isEnabled() ) {
+                       echo "Warning: tidy is not installed, skipping some tests\n";
+               }
 
                $this->hooks = array();
                $this->functionHooks = array();
@@ -611,6 +620,13 @@ class ParserTest {
                        $output = $parser->parse( $input, $title, $options, true, true, 1337 );
                        $output->setTOCEnabled( !isset( $opts['notoc'] ) );
                        $out = $output->getText();
+                       if ( isset( $opts['tidy'] ) ) {
+                               if ( !$this->tidySupport->isEnabled() ) {
+                                       return $this->showSkipped();
+                               }
+                               $out = MWTidy::tidy( $out );
+                               $out = preg_replace( '/\s+$/', '', $out);
+                       }
 
                        if ( isset( $opts['showtitle'] ) ) {
                                if ( $output->getTitleText() ) {
@@ -621,20 +637,18 @@ class ParserTest {
                        }
 
                        if ( isset( $opts['ill'] ) ) {
-                               $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
+                               $out = implode( ' ', $output->getLanguageLinks() );
                        } elseif ( isset( $opts['cat'] ) ) {
                                $outputPage = $context->getOutput();
                                $outputPage->addCategoryLinks( $output->getCategories() );
                                $cats = $outputPage->getCategoryLinks();
 
                                if ( isset( $cats['normal'] ) ) {
-                                       $out = $this->tidy( implode( ' ', $cats['normal'] ) );
+                                       $out = implode( ' ', $cats['normal'] );
                                } else {
                                        $out = '';
                                }
                        }
-
-                       $result = $this->tidy( $result );
                }
 
                $this->teardownGlobals();
@@ -770,6 +784,8 @@ class ParserTest {
         * @param string $config
         */
        private function setupGlobals( $opts = '', $config = '' ) {
+               global $IP;
+
                # Find out values for some special options.
                $lang =
                        self::getOptionValue( 'language', $opts, 'en' );
@@ -832,7 +848,6 @@ class ParserTest {
                        'wgLocaltimezone' => 'UTC',
                        'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
                        'wgThumbLimits' => array( self::getOptionValue( 'thumbsize', $opts, 180 ) ),
-                       'wgUseTidy' => false,
                        'wgDefaultLanguageVariant' => $variant,
                        'wgVariantArticlePath' => false,
                        'wgGroupPermissions' => array( '*' => array(
@@ -848,13 +863,22 @@ class ParserTest {
                        'wgLinkHolderBatchSize' => $linkHolderBatchSize,
                        'wgExperimentalHtmlIds' => false,
                        'wgExternalLinkTarget' => false,
-                       'wgAlwaysUseTidy' => false,
                        'wgHtml5' => true,
                        'wgWellFormedXml' => true,
                        'wgAllowMicrodataAttributes' => true,
                        'wgAdaptiveMessageCache' => true,
                        'wgDisableLangConversion' => false,
                        'wgDisableTitleConversion' => false,
+                       // Tidy options.
+                       // We always set 'wgUseTidy' to false when parsing, but certain
+                       // test-running modes still use tidy if available, so ensure
+                       // that the tidy-related options are all set to their defaults.
+                       'wgUseTidy' => false,
+                       'wgAlwaysUseTidy' => false,
+                       'wgDebugTidy' => false,
+                       'wgTidyConf' => $IP . '/includes/tidy.conf',
+                       'wgTidyOpts' => '',
+                       'wgTidyInternal' => $this->tidySupport->isInternal(),
                );
 
                if ( $config ) {
@@ -1564,23 +1588,6 @@ class ParserTest {
                return true;
        }
 
-       /**
-        * Run the "tidy" command on text if the $wgUseTidy
-        * global is true
-        *
-        * @param string $text The text to tidy
-        * @return string
-        */
-       private function tidy( $text ) {
-               global $wgUseTidy;
-
-               if ( $wgUseTidy ) {
-                       $text = MWTidy::tidy( $text );
-               }
-
-               return $text;
-       }
-
        private function wellFormed( $text ) {
                $html =
                        Sanitizer::hackDocType() .
index 62e160b..3a315e1 100644 (file)
@@ -46,6 +46,12 @@ Main Page
 blah blah
 !! endarticle
 
+!!article
+Foo
+!!text
+FOO
+!!endarticle
+
 !!article
 Template:Foo
 !!text
@@ -401,6 +407,13 @@ http://fr.wikipedia.org/wiki/🍺
 </p>
 !! end
 
+# Note that the html+tidy output removes the spaces after the <li>,
+# which is a bug (http://sourceforge.net/p/tidy/bugs/945/, etc).
+# This is an issue for all tests with lists.  We intentionally do
+# *not* add html+tidy clauses for these, as we don't want to
+# document/test the broken behavior.  (Parsoid matches the non-tidy
+# output in these cases.)
+
 !! test
 Simple list
 !! wikitext
@@ -757,7 +770,7 @@ Italics and bold: 5-quote opening sequence: (5,2+3)
 parsoid=wt2wt,html2wt
 !! wikitext
 '''''foo'''''
-!! html/*
+!! html
 <p><b><i>foo</i></b>
 </p>
 !! end
@@ -1037,7 +1050,16 @@ parsoid=wt2html,wt2wt
 !''a!!''b
 |''a||''b
 |}
-!! html
+!! html/php+tidy
+<table>
+<tr>
+<th><i>a</i></th>
+<th><i>b</i></th>
+<td><i>a</i></td>
+<td><i>b</i></td>
+</tr>
+</table>
+!! html/parsoid
 <table>
 <tbody><tr><th><i>a</i></th><th><i>b</i></th>
 <td><i>a</i></td><td><i>b</i></td></tr>
@@ -1179,6 +1201,7 @@ Ruby markup (W3C-style)
 </p>
 !! end
 
+# There is a tidy bug here: http://sourceforge.net/p/tidy/bugs/946/
 !! test
 Non-word characters don't terminate tag names (bug 17663, 40670, 52022)
 !! wikitext
@@ -1539,6 +1562,10 @@ b
 a <div>foo</div>
 <p>b
 </p>
+!! html+tidy
+<p>a</p>
+<div>foo</div>
+<p>b</p>
 !! end
 
 !! test
@@ -1551,6 +1578,12 @@ b
 a <blockquote>foo</blockquote>
 <p>b
 </p>
+!! html+tidy
+<p>a</p>
+<blockquote>
+<p>foo</p>
+</blockquote>
+<p>b</p>
 !! end
 
 !! test
@@ -1563,6 +1596,11 @@ b <div>foo</div>
 a <div>foo</div>
 b <div>foo</div>
 
+!! html+tidy
+<p>a</p>
+<div>foo</div>
+<p>b</p>
+<div>foo</div>
 !! end
 
 !! test
@@ -1575,6 +1613,15 @@ b <blockquote>foo</blockquote>
 a <blockquote>foo</blockquote>
 b <blockquote>foo</blockquote>
 
+!! html+tidy
+<p>a</p>
+<blockquote>
+<p>foo</p>
+</blockquote>
+<p>b</p>
+<blockquote>
+<p>foo</p>
+</blockquote>
 !! end
 
 !! test
@@ -1593,6 +1640,13 @@ d e
 </p>
 x <div>foo</div> z
 
+!! html+tidy
+<div>foo</div>
+<p>a</p>
+<p>b c d e</p>
+<p>x</p>
+<div>foo</div>
+<p>z</p>
 !! end
 
 !! test
@@ -1623,9 +1677,20 @@ b
 </p>
 <div>e</div>
 
+!! html+tidy
+<p><br /></p>
+<p>a</p>
+<p>b</p>
+<div>a</div>
+<p>b</p>
+<div>b</div>
+<p>d</p>
+<p><br /></p>
+<div>e</div>
 !! end
 
 ## PHP parser emits output which is broken
+## XXX The parsoid output doesn't match the tidy output.
 !! test
 Unclosed HTML p-tags should be handled properly
 !! wikitext
@@ -1633,6 +1698,11 @@ Unclosed HTML p-tags should be handled properly
 a
 
 b
+!! html/php+tidy
+<div>
+<p>foo&lt;/div&gt;</p>
+<p>a</p>
+b</div>
 !! html/parsoid
 <div data-parsoid='{"stx":"html"}'><p data-parsoid='{"stx":"html", "autoInsertedEnd":true}'>foo</p></div>
 <p>a</p>
@@ -1784,6 +1854,10 @@ Bug 15491: <ins>/<del> in blockquote (2)
 <blockquote>Foo <del>bar</del> <ins>baz</ins> quux
 </blockquote>
 
+!! html+tidy
+<blockquote>
+<p>Foo</p>
+<del>bar</del> <ins>baz</ins> quux</blockquote>
 !! end
 
 !! test
@@ -1909,6 +1983,12 @@ foo
 </pre></div>
 <pre></pre>
 
+!! html+tidy
+<p>a</p>
+<div>
+<pre>
+foo
+</pre></div>
 !! end
 
 !! test
  a
  | b
  | c
-!! html/parsoid
+!! html/php
 <pre>a
 | b
-| c</pre>
+| c
+</pre>
 !!end
 
 !!test
@@ -2506,6 +2587,12 @@ c
 a
  | b
  | c
+!! html/php
+<p>a
+</p>
+<pre>| b
+| c
+</pre>
 !! html/parsoid
 <p>a</p>
 <pre>
@@ -2526,7 +2613,19 @@ a
  c <blockquote> foo </blockquote>
 <pre><span> foo </span>
 </pre>
-!!end
+!! html+tidy
+<p>a</p>
+<p>foo</p>
+<p>b</p>
+<div>foo</div>
+<p>c</p>
+<blockquote>
+<p>foo</p>
+</blockquote>
+<pre>
+<span> foo </span>
+</pre>
+!! end
 
 !!test
 3b. Indent-Pre and block tags (multi-line html)
@@ -2538,6 +2637,12 @@ a
 </pre>
  b <div> foo </div>
 
+!! html+tidy
+<pre>
+a <span>foo</span>
+</pre>
+<p>b</p>
+<div>foo</div>
 !!end
 
 !!test
@@ -2619,6 +2724,18 @@ File:foobar.jpg
                </div></li>
 </ul>
 
+!! html+tidy
+<p>a</p>
+<ul class="gallery mw-gallery-traditional">
+<li class="gallerybox" style="width: 155px">
+<div style="width: 155px">
+<div class="thumb" style="width: 150px;">
+<div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" /></a></div>
+</div>
+<div class="gallerytext"></div>
+</div>
+</li>
+</ul>
 !!end
 
 !! test
@@ -3390,6 +3507,9 @@ Definition Lists: Nesting: Test 4
 ## The Parsoid team believes the following three test exposes a
 ## bug in the PHP parser.  (Parsoid team thinks the PHP parser is
 ## wrong to close the <dl> after the <dt> containing the <ul>.)
+## It also exposes a "misfeature" in tidy, which doesn't like
+## <dl> tags with a single <dt> child; it converts the <dt> into
+## a <dd> in that case.  (Parsoid leaves the <dt> alone!)
 !! test
 Definition Lists: Mixed Lists: Test 1
 !! wikitext
@@ -3401,6 +3521,22 @@ Definition Lists: Mixed Lists: Test 1
 <li> bar</li></ul></dt></dl>
 <dl><dt> baz</dt></dl></dd></dl>
 
+!! html/php+tidy
+<dl>
+<dd>
+<dl>
+<dd>
+<ul>
+<li>foo</li>
+<li>bar</li>
+</ul>
+</dd>
+</dl>
+<dl>
+<dt>baz</dt>
+</dl>
+</dd>
+</dl>
 !! html/parsoid
 <dl>
 <dd><dl>
@@ -3528,6 +3664,7 @@ Definition Lists: Mixed Lists: Test 10
 # rules regarding dd/dt on the next two tests.  Parsoid is more
 # consistent, and recognizes the shared nesting and keeps the
 # still-open tags around until the nesting is complete.
+# (And tidy again converts <dt> to <dd> before 'bar'.)
 
 !! test
 Definition Lists: Mixed Lists: Test 11
@@ -3540,6 +3677,43 @@ Definition Lists: Mixed Lists: Test 11
 <dl><dt>boo&#160;</dt>
 <dd>baz</dd></dl></li></ol></li></ul></li></ol></li></ul>
 
+!! html/php+tidy
+<ul>
+<li>
+<ol>
+<li>
+<ul>
+<li>
+<ol>
+<li>
+<dl>
+<dt>foo&#160;</dt>
+<dd>
+<ul>
+<li>
+<dl>
+<dd>
+<dl>
+<dt>bar</dt>
+</dl>
+</dd>
+</dl>
+</li>
+</ul>
+</dd>
+</dl>
+<dl>
+<dt>boo&#160;</dt>
+<dd>baz</dd>
+</dl>
+</li>
+</ol>
+</li>
+</ul>
+</li>
+</ol>
+</li>
+</ul>
 !! html/parsoid
 <ul>
 <li>
@@ -3571,6 +3745,7 @@ Definition Lists: Mixed Lists: Test 11
 !! end
 
 
+# Another case where tidy converts a <dt> to a <dd> (but Parsoid doesn't).
 !! test
 Definition Lists: Weird Ones: Test 1
 !! wikitext
@@ -3579,6 +3754,39 @@ Definition Lists: Weird Ones: Test 1
 <ul><li><ol><li><dl><dt> foo&#160;</dt>
 <dd><ul><li><dl><dd><dl><dd><dl><dt><dl><dt> bar (who uses this?)</dt></dl></dd></dl></dd></dl></dd></dl></li></ul></dd></dl></li></ol></li></ul>
 
+!! html/php+tidy
+<ul>
+<li>
+<ol>
+<li>
+<dl>
+<dt>foo&#160;</dt>
+<dd>
+<ul>
+<li>
+<dl>
+<dd>
+<dl>
+<dd>
+<dl>
+<dd>
+<dl>
+<dt>bar (who uses this?)</dt>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+</li>
+</ul>
+</dd>
+</dl>
+</li>
+</ol>
+</li>
+</ul>
 !! html/parsoid
 <ul>
 <li>
@@ -3789,6 +3997,11 @@ External links: with no contents
 [[wikipedia:Foo|Bar]]
 
 [[wikipedia:Foo|<span>Bar</span>]]
+!! html/php
+<p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/wiki/Foo">[1]</a>
+</p><p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo">Bar</a>
+</p><p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo"><span>Bar</span></a>
+</p>
 !! html/parsoid
 <p><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo"></a></p>
 <p><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo">Bar</a></p>
@@ -4374,6 +4587,8 @@ External link containing double-single-quotes with no space separating the url f
 !! html/php
 <p><a rel="nofollow" class="external text" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de <a href="/index.php?title=Museo_Picasso_(Par%C3%ADs)&amp;action=edit&amp;redlink=1" class="new" title="Museo Picasso (París) (page does not exist)">Museo Picasso</a>.</a>
 </p>
+!! html/php+tidy
+<p><a rel="nofollow" class="external text" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de</a> <a href="/index.php?title=Museo_Picasso_(Par%C3%ADs)&amp;action=edit&amp;redlink=1" class="new" title="Museo Picasso (París) (page does not exist)">Museo Picasso</a>.</p>
 !! html/parsoid
 <p><a rel="mw:ExtLink" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a rel="mw:WikiLink" href="./Museo_Picasso_(París)">Museo Picasso</a><span>.</span></p>
 !! end
@@ -4906,6 +5121,13 @@ Accept "!!" in table data
 {|
 | Foo!! ||
 |}
+!! html
+<table>
+<tr>
+<td> Foo!! </td>
+<td>
+</td></tr></table>
+
 !! html/parsoid
 <table data-parsoid='{}'>
 <tbody data-parsoid='{}'><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'> Foo!! </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'></td></tr>
@@ -5286,6 +5508,14 @@ Table-cell after a comment-only-empty-line
 <!--c1-->
 <!--c2-->| b
 |}
+!! html
+<table>
+<tr>
+<td>a
+</td>
+<td> b
+</td></tr></table>
+
 !! html/parsoid
 <table>
 <tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'>a</td>
@@ -5312,9 +5542,14 @@ Wikitext table with html-syntax row
 <td>foo</td></tr></tbody></table>
 !! end
 
+## Note that Parsoid output differs from PHP and PHP+tidy here.
+## The lack of <tr> tags in the PHP output is arguably a bug in the
+## PHP parser, which tidy then compounds by fostering the content
+## entirely out of the table.  Parsoid recognizes the table context
+## and generates <tr> and <td> wrappers as needed.  Hopefully nobody
+## depends on PHP's treatment of broken table markup!
 !! test
 Implicit <td> after a |-
-(PHP parser relies on Tidy to add the missing <td> tags)
 !! options
 parsoid=wt2html,wt2wt
 !! wikitext
@@ -5322,15 +5557,23 @@ parsoid=wt2html,wt2wt
 |-
 a
 |}
-!! html
+!! html/php
+<table>
+
+a
+</table>
+
+!! html/php+tidy
+<p>a</p>
+!! html/parsoid
 <table>
 <tr><td>a</td></tr>
 </table>
 !! end
 
+# Again, Parsoid adds implicit <td>s here, PHP and Tidy strip the b out.
 !! test
-Pres should be recognized in an explicit <td> context, but not in an implicit <td> context
-(PHP parser relies on Tidy to add the missing <td> tags)
+<pre> tags should be recognized in an explicit <td> context, but not in an implicit <td> context
 !! options
 parsoid=wt2html,wt2wt
 !! wikitext
@@ -5341,7 +5584,28 @@ parsoid=wt2html,wt2wt
 |-
  b
 |}
-!! html
+!! html/php
+<table>
+
+<tr>
+<td>
+<pre>a
+</pre>
+</td></tr>
+ b
+</table>
+
+!! html/php+tidy
+<p>b</p>
+<table>
+<tr>
+<td>
+<pre>
+a
+</pre></td>
+</tr>
+</table>
+!! html/parsoid
 <table>
 <tbody>
 <tr><td><pre>a</pre></td></tr>
@@ -5350,9 +5614,9 @@ parsoid=wt2html,wt2wt
 </table>
 !! end
 
+# PHP + Tidy strips the list out of the table; Parsoid wraps it.
 !! test
 Lists should be recognized in an implicit <td> context
-(PHP parser relies on Tidy to add the missing <td> tags)
 !! options
 parsoid=wt2html,wt2wt
 !! wikitext
@@ -5360,7 +5624,17 @@ parsoid=wt2html,wt2wt
 |-
 *a
 |}
-!! html
+!! html/php
+<table>
+
+<ul><li>a</li></ul>
+</table>
+
+!! html/php+tidy
+<ul>
+<li>a</li>
+</ul>
+!! html/parsoid
 <table>
 <tr>
 <td><ul>
@@ -5433,15 +5707,26 @@ parsoid=wt2html,wt2wt
 ! foo || bar
 <!-- foo -->  || baz || quux
 |}
+!! html/php
+<table>
+<tr>
+<th> foo </th>
+<th> bar
+</th>
+<td> baz </td>
+<td> quux
+</td></tr></table>
+
 !! html/parsoid
 <table>
-<tbody>
-<tr><th>foo </th><th>bar  </th>
-<td>baz </td>
-<td>quux</td></tr></tbody></table>
+<tbody><tr><th> foo </th><th> bar
+<!-- foo -->  </th><td> baz </td><td> quux</td></tr>
+</tbody></table>
 !! end
 
 
+# PHP throws away the (semi-broken) "foo" class here; Parsoid
+# preserves it.
 !!test
 Parsoid: Recover better from broken table attributes
 !!options
@@ -5451,6 +5736,14 @@ parsoid=wt2html
 | class="bar" |
 foo
 |}
+!!html/php+tidy
+<table>
+<tr>
+<td class="bar">
+<p>foo</p>
+</td>
+</tr>
+</table>
 !!html/parsoid
 <table class="foo">
 <tr>
@@ -6028,6 +6321,8 @@ title=[[Bug462]]
 !! html/php
 <p><strong class="selflink">Bu&#103;462</strong> <strong class="selflink">Bug462</strong>
 </p>
+!! html/php+tidy
+<p><strong class="selflink">Bug462</strong> <strong class="selflink">Bug462</strong></p>
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./Bug462">Bug462</a> <a rel="mw:WikiLink" href="./Bug462">Bug462</a></p>
 !! end
@@ -6161,6 +6456,9 @@ Purely hash wikilink
 title=[[User:test/123]]
 !! wikitext
 [[#a|b]]
+!! html/php
+<p><a href="#a">b</a>
+</p>
 !! html/parsoid
 <p data-parsoid='{}'><a rel="mw:WikiLink" href="../User:Test/123#a" data-parsoid='{"stx":"piped","a":{"href":"../User:Test/123#a"},"sa":{"href":"#a"}}'>b</a></p>
 !! end
@@ -6269,8 +6567,8 @@ Parsoid-centric test: Whitespace in ext- and wiki-links should be preserved
 
 [http://wp.org   ''foo'']
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">  bar</a>
-</p><p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">  <i>bar</i></a>
+<p><a href="/wiki/Foo" title="Foo">  bar</a>
+</p><p><a href="/wiki/Foo" title="Foo">  <i>bar</i></a>
 </p><p><a rel="nofollow" class="external text" href="http://wp.org">foo</a>
 </p><p><a rel="nofollow" class="external text" href="http://wp.org"><i>foo</i></a>
 </p>
@@ -6290,6 +6588,9 @@ parsoid
 Link with angle bracket after anchor
 !! wikitext
 [[Foo#<bar>]]
+!! html/php
+<p><a href="/wiki/Foo#.3Cbar.3E" title="Foo">Foo#&lt;bar&gt;</a>
+</p>
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./Foo#%3Cbar%3E" data-parsoid='{"stx":"simple","a":{"href":"./Foo#%3Cbar%3E"},"sa":{"href":"Foo#&lt;bar>"}}'>Foo#&lt;bar></a></p>
 !! end
@@ -6325,6 +6626,11 @@ Interwiki link encoding conversion (bug 1636)
 <ul><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li>
 <li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li></ul>
 
+!! html+tidy
+<ul>
+<li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a></li>
+<li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a></li>
+</ul>
 !! end
 
 !! test
@@ -6803,6 +7109,9 @@ Broken br tag sanitization
 !! end
 
 # TODO: Fix html2html mode (bug 51055)!
+# This </br> handling was added as part of bug 50831; but it
+# differs from how PHP+tidy handles this.  We should investigate
+# this.
 !! test
 Parsoid: Broken br tag recognition
 !! options
@@ -6811,6 +7120,9 @@ parsoid=wt2html
 </br>
 
 <br/ >
+!! html/php+tidy
+<p>&lt;/br&gt;</p>
+<p><br /></p>
 !! html/parsoid
 <p><br></p>
 <p><br/></p>
@@ -6938,6 +7250,9 @@ Horizontal ruler -- Supports content following dashes on same line
 !! html
 <hr /> Foo
 
+!! html+tidy
+<hr />
+<p>Foo</p>
 !! end
 
 ###
@@ -7189,6 +7504,12 @@ Multiple list tags generated by templates
 </li>
 </li>
 
+!! html+tidy
+<ul>
+<li>a</li>
+<li>b</li>
+<li>c</li>
+</ul>
 !!end
 
 !!test
@@ -7230,7 +7551,7 @@ Replacing whitespace with tabs still doesn't break the list (gerrit 78327)
 
 !!test
 Test the li-hack
-(Cannot test this with PHP parser since it relies on Tidy for the hack)
+(The PHP parser relies on Tidy for the hack)
 !!options
 parsoid=wt2html,wt2wt
 !! wikitext
@@ -7243,19 +7564,15 @@ parsoid=wt2html,wt2wt
 <li><li>not a li-hack
 </li>
 </ul>
-!! html
+!! html+tidy
 <ul>
-<li> foo</li>
+<li>foo</li>
 <li>li-hack</li>
-<li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<li>templated li-hack"}}}}]}'>templated li-hack</li>
-<li> <!--foo--> </li>
-<li> li-hack with preceding comments</li>
+<li>templated li-hack</li>
+<li>unsupported li-hack with preceding comments</li>
 </ul>
-
 <ul>
-<li></li>
-<li>not a li-hack
-</li>
+<li>not a li-hack</li>
 </ul>
 !!end
 
@@ -7305,47 +7622,60 @@ parsoid
 
 !! test
 Unbalanced closing block tags break a list
-(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up)
+(php parser relies on Tidy to fix up)
 !! wikitext
 <div>
 *a</div><div>
 *b</div>
-!! html/parsoid
+!! html+tidy
 <div>
 <ul>
-<li>a
-</li>
-</ul></div><div>
+<li>a</li>
+</ul>
+</div>
+<div>
 <ul>
-<li>b
-</li>
-</ul></div>
+<li>b</li>
+</ul>
+</div>
 !! end
 
+# Parsoid fails this test, but it might be tricky to support properly.
+# See bug 68395.
 !! test
 Unbalanced closing non-block tags don't break a list
-(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up)
+(php parser relies on Tidy to fix up)
 !! wikitext
 <span>
 *a</span><span>
 *b</span>
+!! html/php+tidy
+<ul>
+<li><span>a</span></li>
+<li><span>b</span></li>
+</ul>
 !! html/parsoid
-<p><span></span>
-</p>
+<span>
 <ul>
 <li>a<span></span>
 </li>
 <li>b
 </li>
 </ul>
+</span>
 !! end
 
 !! test
 Unclosed formatting tags that straddle lists are closed and reopened
-(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up)
+(php parser relies on Tidy to fix up)
 !! wikitext
 # <s> a
 # b </s>
+!! html/php+tidy
+<ol>
+<li><s>a</s></li>
+<li><s>b</s></li>
+</ol>
 !! html/parsoid
 <ol>
 <li> <s> a </s>
@@ -7355,23 +7685,31 @@ Unclosed formatting tags that straddle lists are closed and reopened
 </ol>
 !! end
 
+# Parsoid fails this test, but it might be tricky to support properly.
+# See bug 68395.
 !!test
 List embedded in a non-block tag
-(Ugly Parsoid output -- worth fixing; Disabled for PHP parser since it relies on Tidy)
+(Ugly Parsoid output -- worth fixing; PHP parser relies on Tidy)
 !! wikitext
 <small>
 * foo
 </small>
+!! html/php+tidy
+<ul>
+<li><small>foo</small></li>
+</ul>
 !! html/parsoid
-<p><small></small></p>
 <small>
 <ul>
 <li> foo</li>
 </ul>
 </small>
-<p><small></small></p>
 !!end
 
+# This is a bug in the PHP parser + tidy combination.
+# (The </tr> tag gets parsed as text and html-escaped by PHP,
+# and then fostered out of the table by tidy.)
+# We believe the Parsoid output to be correct.
 !! test
 Table with missing opening <tr> tag
 !! options
@@ -7381,6 +7719,13 @@ parsoid=wt2html,wt2wt
 <td>foo</td>
 </tr>
 </table>
+!! html/php+tidy
+<p>&lt;/tr&gt;</p>
+<table>
+<tr>
+<td>foo</td>
+</tr>
+</table>
 !! html/parsoid
 <table>
 <tr>
@@ -7837,9 +8182,11 @@ Magic Word: {{PAGENAME}} with metacharacters
 title=[['foo & bar = baz']]
 !! wikitext
 ''{{PAGENAME}}''
-!! html
+!! html/php
 <p><i>&#39;foo &#38; bar &#61; baz&#39;</i>
 </p>
+!! html+tidy
+<p><i>'foo &amp; bar = baz'</i></p>
 !! end
 
 !! test
@@ -7848,9 +8195,11 @@ Magic Word: {{PAGENAME}} with metacharacters (bug 26781)
 title=[[*RFC 1234 http://example.com/]]
 !! wikitext
 {{PAGENAME}}
-!! html
+!! html/php
 <p>&#42;RFC&#32;1234 http&#58;//example.com/
 </p>
+!! html+tidy
+<p>*RFC 1234 http://example.com/</p>
 !! end
 
 !! test
@@ -7870,9 +8219,11 @@ Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781)
 title=[[*RFC 1234 http://example.com/]]
 !! wikitext
 {{PAGENAMEE}}
-!! html
+!! html/php
 <p>&#42;RFC_1234_http&#58;//example.com/
 </p>
+!! html+tidy
+<p>*RFC_1234_http://example.com/</p>
 !! end
 
 !! test
@@ -8376,9 +8727,16 @@ Template with thumb image (with link in description)
 !! wikitext
 {{paramtest|
   param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}}
-!! html
+!! html/php
 This is a test template with parameter <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Noimage.png" class="new" title="File:Noimage.png">File:Noimage.png</a>  <div class="thumbcaption"><a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">link</a> <a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">caption</a></div></div></div>
 
+!! html+tidy
+<p>This is a test template with parameter</p>
+<div class="thumb tright">
+<div class="thumbinner" style="width:182px;"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Noimage.png" class="new" title="File:Noimage.png">File:Noimage.png</a>
+<div class="thumbcaption"><a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">link</a> <a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">caption</a></div>
+</div>
+</div>
 !! end
 
 !! article
@@ -8580,8 +8938,8 @@ Template with targets containing wikilinks
 
 {{{{echo|[[foo}}]]}}
 !! html
-<p>{{<a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">foo</a>}}
-</p><p>{{<a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">foo</a>}}
+<p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
+</p><p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
 </p><p>{{[[foo}}]]
 </p>
 !! end
@@ -9071,6 +9429,11 @@ Templates: 2. Inside a block tag
 <div>Foo</div>
 <blockquote>Foo</blockquote>
 
+!! html+tidy
+<div>Foo</div>
+<blockquote>
+<p>Foo</p>
+</blockquote>
 !!end
 
 !!test
@@ -9108,7 +9471,11 @@ Templates: P-wrapping: 1c. Templates on consecutive lines
 </p>
 bar <div>baz</div>
 
-!!end
+!! html+tidy
+<p>Foo</p>
+<p>bar</p>
+<div>baz</div>
+!! end
 
 !!test
 Templates: P-wrapping: 1d. Template preceded by comment-only line
@@ -9164,7 +9531,7 @@ Templates: Links: 1. Simple example
 !! wikitext
 {{echo|[[Foo|bar]]}}
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">bar</a>
+<p><a href="/wiki/Foo" title="Foo">bar</a>
 </p>
 !!end
 
@@ -9173,7 +9540,7 @@ Templates: Links: 2. Generation of link href
 !! wikitext
 [[{{echo|Foo}}|bar]]
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">bar</a>
+<p><a href="/wiki/Foo" title="Foo">bar</a>
 </p>
 !!end
 
@@ -9192,7 +9559,7 @@ Templates: Links: 3. Generation of part of a link href
 
 [[:Foo{{echo|bar}}|bar]]
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">bar</a>
+<p><a href="/wiki/Foo" title="Foo">bar</a>
 </p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">Foobar</a>
 </p><p><a href="/index.php?title=Foobarbaz&amp;action=edit&amp;redlink=1" class="new" title="Foobarbaz (page does not exist)">Foobarbaz</a>
 </p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">bar</a>
@@ -9215,7 +9582,7 @@ Templates: Links: 5. Generation of link text
 !! wikitext
 [[Foo|{{echo|bar}}]]
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">bar</a>
+<p><a href="/wiki/Foo" title="Foo">bar</a>
 </p>
 !!end
 
@@ -9224,7 +9591,7 @@ Templates: Links: 5. Nested templates (only outermost template should be marked)
 !! wikitext
 {{echo|[[{{echo|Foo}}|bar]]}}
 !! html
-<p><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">bar</a>
+<p><a href="/wiki/Foo" title="Foo">bar</a>
 </p>
 !!end
 
@@ -9406,7 +9773,14 @@ Templates: Wiki Tables: 1a. Fostering of entire template content
 a
 <tr><td></td></tr></table>
 
-!!end
+!! html+tidy
+<p>a</p>
+<table>
+<tr>
+<td></td>
+</tr>
+</table>
+!! end
 
 !!test
 Templates: Wiki Tables: 1b. Fostering of entire template content
@@ -9424,7 +9798,16 @@ foo
 </div>
 <tr><td></td></tr></table>
 
-!!end
+!! html+tidy
+<div>
+<p>foo</p>
+</div>
+<table>
+<tr>
+<td></td>
+</tr>
+</table>
+!! end
 
 !!test
 Templates: Wiki Tables: 2. Fostering of partial template content
@@ -9439,7 +9822,15 @@ a
 <div>b</div>
 <tr><td></td></tr></table>
 
-!!end
+!! html+tidy
+<p>a</p>
+<div>b</div>
+<table>
+<tr>
+<td></td>
+</tr>
+</table>
+!! end
 
 !!test
 Templates: Wiki Tables: 3. td-content via multiple templates
@@ -9545,7 +9936,11 @@ a<div>b{{echo|c</div>d}}e
 !! html
 a<div>bc</div>de
 
-!!end
+!! html+tidy
+<p>a</p>
+<div>bc</div>
+<p>de</p>
+!! end
 
 !!test
 Templates: Ugly templates: 1. Navbox template parses badly leading to table misnesting
@@ -10535,6 +10930,7 @@ Image with multiple attributes from the same template
 <figure class="mw-default-size mw-halign-right" typeof="mw:Image mw:Placeholder"><a href="File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" height="220" width="1941"></a><figcaption>Caption text</figcaption></figure>
 !! end
 
+# Parsoid's output here is broken (incorrect p-wrapping); see bug 64901.
 !! test
 Image with link tails
 !! options
@@ -10549,6 +10945,19 @@ thumbsize=220
 123<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>456
 123<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div></div></div></div>456
 
+!! html/php+tidy
+<p>123<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>456</p>
+<p>123</p>
+<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>
+<p>456 123</p>
+<div class="thumb tright">
+<div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>
+<div class="thumbcaption">
+<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"><img src="/skins/common/images/magnify-clip.png" width="15" height="11" alt="" /></a></div>
+</div>
+</div>
+</div>
+<p>456</p>
 !! html/parsoid
 <p>123<span class="mw-default-size" typeof="mw:Image"><a href="File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" height="220" width="1941"></a></span>456</p>
 123<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" height="220" width="1941"></a></figure>456
@@ -12761,6 +13170,8 @@ I always thought &eacute; was a cute letter.
 !! html
 <p>I always thought &#233; was a cute letter.
 </p>
+!! html+tidy
+<p>I always thought é was a cute letter.</p>
 !! end
 
 !! test
@@ -12822,6 +13233,7 @@ Ensure that HTML adoption agency algorithm is properly implemented.
 !! end
 
 # This was bug 41545 in the PHP parser.
+# Note that tidy doesn't handle this correctly.
 !! test
 Nesting of <kbd>
 !! wikitext
@@ -12834,6 +13246,8 @@ Nesting of <kbd>
 # The following cases were bug 51081 in the PHP parser.
 # Note that there are some other nestable tags (b, i, etc) which are
 # not covered; see bug 51081 for discussion.
+
+# Note that tidy doesn't handle this correctly.
 !! test
 Nesting of <em>
 !! wikitext
@@ -12843,6 +13257,7 @@ Nesting of <em>
 </p>
 !! end
 
+# Note that tidy doesn't handle this correctly.
 !! test
 Nesting of <strong>
 !! wikitext
@@ -12856,11 +13271,11 @@ Nesting of <strong>
 Nesting of <q>
 !! wikitext
 <q>X<q>Y</q>Z</q>
-!! html
-<p><q>X<q>Y</q>Z</q>
-</p>
+!! html+tidy
+<p><q>X<q>Y</q>Z</q></p>
 !! end
 
+# Note that tidy doesn't handle this correctly.
 !! test
 Nesting of <ruby>
 !! wikitext
@@ -12870,6 +13285,7 @@ Nesting of <ruby>
 </p>
 !! end
 
+# Note that tidy doesn't handle this correctly.
 !! test
 Nesting of <bdo>
 !! wikitext
@@ -12911,6 +13327,8 @@ fixme: doBlockLevels won't wrap this in a paragraph because it contains a div
 !! html
 <a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link&lt;div style="display:none"&gt;" onmouseover="alert(document.cookie)" onfoo="&lt;/div&gt;</a>
 
+!! html+tidy
+<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link&lt;div style="display:none"&gt;" onmouseover="alert(document.cookie)" onfoo="&lt;/div&gt;</a></p>
 !! end
 
 !! test
@@ -14056,6 +14474,17 @@ http://<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></div>
 </div>
 
 
+!! html+tidy
+<h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+<p>http://</p>
+<div id="toc" class="toc">
+<div id="toctitle">
+<h2>Contents</h2>
+</div>
+<ul>
+<li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
+</ul>
+</div>
 !! end
 
 !! test
@@ -14069,6 +14498,13 @@ Fuzz testing: Parser14-table
 <tr><td></td></tr>
 </table>
 
+!! html+tidy
+<h2><span class="mw-headline" id="a">a</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: a">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+<table style="__TOC__">
+<tr>
+<td></td>
+</tr>
+</table>
 !! end
 
 # Known to produce bogus xml (extra </td>)
@@ -14090,6 +14526,15 @@ noxml
 </tr>
 </table>
 
+!! html+tidy
+<table>
+<tr>
+<th>https://</th>
+<th></th>
+<th></th>
+<th></th>
+</tr>
+</table>
 !! end
 
 !! test
@@ -14177,7 +14622,6 @@ Fuzz testing: Parser25 (bug 6055)
 
 !!test
 Fuzz testing: URL adjacent extension (with space, clean)
-!! options
 !! wikitext
 http://example.com <nowiki>junk</nowiki>
 !! html
@@ -14187,7 +14631,6 @@ http://example.com <nowiki>junk</nowiki>
 
 !!test
 Fuzz testing: URL adjacent extension (no space, dirty; nowiki)
-!! options
 !! wikitext
 http://example.com<nowiki>junk</nowiki>
 !! html
@@ -14197,12 +14640,16 @@ http://example.com<nowiki>junk</nowiki>
 
 !!test
 Fuzz testing: URL adjacent extension (no space, dirty; pre)
-!! options
 !! wikitext
 http://example.com<pre>junk</pre>
 !! html
 <a rel="nofollow" class="external free" href="http://example.com">http://example.com</a><pre>junk</pre>
 
+!! html+tidy
+<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></p>
+<pre>
+junk
+</pre>
 !!end
 
 !!test
@@ -15595,6 +16042,8 @@ parsoid=wt2html,wt2wt,html2html
 !! html/php
 <p>&#x4a;&#x61;&#x76;&#x61;&#x53;&#x63;&#114;&#x69;&#112;&#x74;
 </p>
+!! html/php+tidy
+<p>JavaScript</p>
 !! html/parsoid
 <p><span typeof="mw:Entity">J</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">v</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">S</span><span typeof="mw:Entity">c</span><span typeof="mw:Entity">r</span><span typeof="mw:Entity">i</span><span typeof="mw:Entity">p</span><span typeof="mw:Entity">t</span></p>
 !! end
@@ -15619,6 +16068,8 @@ parsoid=wt2html,wt2wt,html2html
 !! html/php
 <p>&#xee;&#xee;
 </p>
+!! html/php+tidy
+<p>îî</p>
 !! html/parsoid
 <p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
 !! end
@@ -15640,6 +16091,8 @@ ISBN  978-0-1234-56&#x20;789
 !! html
 <p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a>&#x20;789
 </p>
+!! html+tidy
+<p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a> 789</p>
 !! end
 
 !! test
@@ -15711,6 +16164,8 @@ RFC   983&#x20;987
 !! html
 <p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc983">RFC 983</a>&#x20;987
 </p>
+!! html+tidy
+<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc983">RFC 983</a> 987</p>
 !! end
 
 !! test
@@ -16928,6 +17383,10 @@ Line two</blockquote>
 <blockquote>Line one
 Line two</blockquote>
 
+!! html+tidy
+<blockquote>
+<p>Line one Line two</p>
+</blockquote>
 !! end
 
 !! test
@@ -16943,6 +17402,10 @@ Line two</blockquote>
 </p>
 Line two</blockquote>
 
+!! html+tidy
+<blockquote>
+<p>Line one</p>
+Line two</blockquote>
 !! end
 
 !! test
@@ -16958,6 +17421,11 @@ Line two
 </p>
 </blockquote>
 
+!! html+tidy
+<blockquote>
+<p>Line one</p>
+<p>Line two</p>
+</blockquote>
 !! end
 
 !! test
@@ -16975,6 +17443,11 @@ Line two
 </p>
 </blockquote>
 
+!! html+tidy
+<blockquote>
+<p>Line one</p>
+<p>Line two</p>
+</blockquote>
 !! end
 
 !! test
@@ -17735,6 +18208,20 @@ __TOC__
 
 <h2><span class="mw-headline" id="Quote"><blockquote>Quote</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 
+!! html+tidy
+<div id="toc" class="toc">
+<div id="toctitle">
+<h2>Contents</h2>
+</div>
+<ul>
+<li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
+</ul>
+</div>
+<h2><span class="mw-headline" id="Quote"></span></h2>
+<blockquote>
+<p><span class="mw-headline" id="Quote">Quote</span></p>
+</blockquote>
+<p><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></p>
 !! end
 
 !! test
@@ -17777,6 +18264,22 @@ __TOC__
 <h2><span class="mw-headline" id="Foo_Bar"><i>Foo</i> <b>Bar</b></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 <h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i> <blockquote>Bar</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 
+!! html+tidy
+<div id="toc" class="toc">
+<div id="toctitle">
+<h2>Contents</h2>
+</div>
+<ul>
+<li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
+<li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
+</ul>
+</div>
+<h2><span class="mw-headline" id="Foo_Bar"><i>Foo</i> <b>Bar</b></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+<h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i></span></h2>
+<blockquote>
+<p><span class="mw-headline" id="Foo_Bar_2">Bar</span></p>
+</blockquote>
+<p><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></p>
 !! end
 
 !! test
@@ -17959,7 +18462,7 @@ nowiki inside link inside heading (bug 18295)
 !! wikitext
 ==[[foo|x<nowiki>y</nowiki>z]]==
 !! html
-<h2><span class="mw-headline" id="xyz"><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">xyz</a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: xyz">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+<h2><span class="mw-headline" id="xyz"><a href="/wiki/Foo" title="Foo">xyz</a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: xyz">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 
 !! end
 
@@ -20159,6 +20662,13 @@ Indented block & table
  {|
  |foo
  |}
+!! html/php
+ <div>foo</div>
+<table>
+<tr>
+<td>foo
+</td></tr></table>
+
 !! html/parsoid
  <div data-parsoid='{"stx":"html"}'>foo</div>
  <table><tbody>
@@ -20173,6 +20683,13 @@ Indent and comment before table row
  <!--hi-->|-
  | there
 |}
+!! html/php
+<table>
+
+<tr>
+<td> there
+</td></tr></table>
+
 !! html/parsoid
 <table data-parsoid='{}'>
  <!--hi--><tbody data-parsoid='{}'><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>
index 0499f88..750ada8 100644 (file)
@@ -36,6 +36,10 @@ class NewParserTest extends MediaWikiTestCase {
         * @var DjVuSupport
         */
        private $djVuSupport;
+       /**
+        * @var TidySupport
+        */
+       private $tidySupport;
 
        protected $file = false;
 
@@ -95,8 +99,6 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgUseImageResize'] = true;
                $tmpGlobals['wgAllowExternalImages'] = true;
                $tmpGlobals['wgRawHtml'] = false;
-               $tmpGlobals['wgUseTidy'] = false;
-               $tmpGlobals['wgAlwaysUseTidy'] = false;
                $tmpGlobals['wgWellFormedXml'] = true;
                $tmpGlobals['wgAllowMicrodataAttributes'] = true;
                $tmpGlobals['wgExperimentalHtmlIds'] = false;
@@ -153,8 +155,19 @@ class NewParserTest extends MediaWikiTestCase {
                # see https://gerrit.wikimedia.org/r/111390
                $tmpGlobals['wgExtraInterlanguageLinkPrefixes'] = array( 'mul' );
 
-               //DjVu support
+               // DjVu support
                $this->djVuSupport = new DjVuSupport();
+               // Tidy support
+               $this->tidySupport = new TidySupport();
+               // We always set 'wgUseTidy' to false when parsing, but certain
+               // test-running modes still use tidy if available, so ensure
+               // that the tidy-related options are all set to their defaults.
+               $tmpGlobals['wgUseTidy'] = false;
+               $tmpGlobals['wgAlwaysUseTidy'] = false;
+               $tmpGlobals['wgDebugTidy'] = false;
+               $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy.conf';
+               $tmpGlobals['wgTidyOpts'] = '';
+               $tmpGlobals['wgTidyInternal'] = $this->tidySupport->isInternal();
 
                $this->setMwGlobals( $tmpGlobals );
 
@@ -735,6 +748,14 @@ class NewParserTest extends MediaWikiTestCase {
                        $output = $parser->parse( $input, $title, $options, true, true, 1337 );
                        $output->setTOCEnabled( !isset( $opts['notoc'] ) );
                        $out = $output->getText();
+                       if ( isset( $opts['tidy'] ) ) {
+                               if ( !$this->tidySupport->isEnabled() ) {
+                                       $this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
+                               } else {
+                                       $out = MWTidy::tidy( $out );
+                                       $out = preg_replace( '/\s+$/', '', $out);
+                               }
+                       }
 
                        if ( isset( $opts['showtitle'] ) ) {
                                if ( $output->getTitleText() ) {
@@ -745,21 +766,19 @@ class NewParserTest extends MediaWikiTestCase {
                        }
 
                        if ( isset( $opts['ill'] ) ) {
-                               $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
+                               $out = implode( ' ', $output->getLanguageLinks() );
                        } elseif ( isset( $opts['cat'] ) ) {
                                $outputPage = $context->getOutput();
                                $outputPage->addCategoryLinks( $output->getCategories() );
                                $cats = $outputPage->getCategoryLinks();
 
                                if ( isset( $cats['normal'] ) ) {
-                                       $out = $this->tidy( implode( ' ', $cats['normal'] ) );
+                                       $out = implode( ' ', $cats['normal'] );
                                } else {
                                        $out = '';
                                }
                        }
                        $parser->mPreprocessor = null;
-
-                       $result = $this->tidy( $result );
                }
 
                $this->teardownGlobals();
@@ -963,23 +982,6 @@ class NewParserTest extends MediaWikiTestCase {
 
        //Various "cleanup" functions
 
-       /**
-        * Run the "tidy" command on text if the $wgUseTidy
-        * global is true
-        *
-        * @param string $text The text to tidy
-        * @return string
-        */
-       protected function tidy( $text ) {
-               global $wgUseTidy;
-
-               if ( $wgUseTidy ) {
-                       $text = MWTidy::tidy( $text );
-               }
-
-               return $text;
-       }
-
        /**
         * Remove last character if it is a newline
         * @param string $s
index 717c5f3..ea4d3c5 100644 (file)
@@ -364,6 +364,10 @@ class TestFileIterator implements Iterator {
        private $sectionData = array();
        private $lineNum;
        private $eof;
+       # Create a fake parser tests which never run anything unless
+       # asked to do so. This will avoid running hooks for a disabled test
+       private $delayedParserTest;
+       private $nextSubTest = 0;
 
        function __construct( $file, $parserTest ) {
                $this->file = $file;
@@ -374,6 +378,7 @@ class TestFileIterator implements Iterator {
                }
 
                $this->parserTest = $parserTest;
+               $this->delayedParserTest = new DelayedParserTest();
 
                $this->lineNum = $this->index = 0;
        }
@@ -412,12 +417,71 @@ class TestFileIterator implements Iterator {
                return $this->eof != true;
        }
 
+       function setupCurrentTest() {
+               // "input" and "result" are old section names allowed
+               // for backwards-compatibility.
+               $input = $this->checkSection( array( 'wikitext', 'input' ), false );
+               $result = $this->checkSection( array( 'html/php', 'html/*', 'html', 'result' ), false );
+               // some tests have "with tidy" and "without tidy" variants
+               $tidy = $this->checkSection( array( 'html/php+tidy', 'html+tidy'), false );
+               if ( $tidy != false ) {
+                       if ( $this->nextSubTest == 0 ) {
+                               if ( $result != false ) {
+                                       $this->nextSubTest = 1; // rerun non-tidy variant later
+                               }
+                               $result = $tidy;
+                       } else {
+                               $this->nextSubTest = 0; // go on to next test after this
+                               $tidy = false;
+                       }
+               }
+
+               if ( !isset( $this->sectionData['options'] ) ) {
+                       $this->sectionData['options'] = '';
+               }
+
+               if ( !isset( $this->sectionData['config'] ) ) {
+                       $this->sectionData['config'] = '';
+               }
+
+               $isDisabled = preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] ) && !$this->parserTest->runDisabled;
+               $isParsoidOnly = preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] ) && $result == 'html' && !$this->parserTest->runParsoid;
+               $isFiltered = !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] );
+               if ( $input == false || $result == false || $isDisabled || $isParsoidOnly || $isFiltered ) {
+                       # disabled test
+                       return false;
+               }
+
+               # We are really going to run the test, run pending hooks and hooks function
+               wfDebug( __METHOD__ . " unleashing delayed test for: {$this->sectionData['test']}" );
+               $hooksResult = $this->delayedParserTest->unleash( $this->parserTest );
+               if ( !$hooksResult ) {
+                       # Some hook reported an issue. Abort.
+                       throw new MWException( "Problem running hook" );
+               }
+
+               $this->test = array(
+                       'test' => ParserTest::chomp( $this->sectionData['test'] ),
+                       'input' => ParserTest::chomp( $this->sectionData[$input] ),
+                       'result' => ParserTest::chomp( $this->sectionData[$result] ),
+                       'options' => ParserTest::chomp( $this->sectionData['options'] ),
+                       'config' => ParserTest::chomp( $this->sectionData['config'] ),
+               );
+               if ( $tidy != false ) {
+                       $this->test['options'] .= " tidy";
+               }
+               return true;
+       }
+
        function readNextTest() {
-               $this->clearSection();
+               # Run additional subtests of previous test
+               while ( $this->nextSubTest > 0 )
+                       if ( $this->setupCurrentTest() )
+                               return true;
 
-               # Create a fake parser tests which never run anything unless
-               # asked to do so. This will avoid running hooks for a disabled test
-               $delayedParserTest = new DelayedParserTest();
+               $this->clearSection();
+               # Reset hooks for the delayed test object
+               $this->delayedParserTest->reset();
 
                while ( false !== ( $line = fgets( $this->fh ) ) ) {
                        $this->lineNum++;
@@ -446,7 +510,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       $delayedParserTest->requireHook( $line );
+                                                       $this->delayedParserTest->requireHook( $line );
                                                }
                                        }
 
@@ -462,7 +526,7 @@ class TestFileIterator implements Iterator {
                                                $line = trim( $line );
 
                                                if ( $line ) {
-                                                       $delayedParserTest->requireFunctionHook( $line );
+                                                       $this->delayedParserTest->requireFunctionHook( $line );
                                                }
                                        }
 
@@ -489,52 +553,14 @@ class TestFileIterator implements Iterator {
 
                                if ( $this->section == 'end' ) {
                                        $this->checkSection( 'test' );
-                                       // "input" and "result" are old section names allowed
-                                       // for backwards-compatibility.
-                                       $input = $this->checkSection( array( 'wikitext', 'input' ), false );
-                                       $result = $this->checkSection( array( 'html/php', 'html/*', 'html', 'result' ), false );
-
-                                       if ( !isset( $this->sectionData['options'] ) ) {
-                                               $this->sectionData['options'] = '';
-                                       }
-
-                                       if ( !isset( $this->sectionData['config'] ) ) {
-                                               $this->sectionData['config'] = '';
-                                       }
-
-                                       if ( $input == false || $result == false ||
-                                               ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] )
-                                                       && !$this->parserTest->runDisabled )
-                                               || ( preg_match( '/\\bparsoid\\b/i', $this->sectionData['options'] )
-                                                       && $result != 'html/php' && !$this->parserTest->runParsoid )
-                                               || !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] ) )
-                                       ) {
-                                               # disabled test
-                                               $this->clearSection();
-
-                                               # Forget any pending hooks call since test is disabled
-                                               $delayedParserTest->reset();
-
-                                               continue;
-                                       }
-
-                                       # We are really going to run the test, run pending hooks and hooks function
-                                       wfDebug( __METHOD__ . " unleashing delayed test for: {$this->sectionData['test']}" );
-                                       $hooksResult = $delayedParserTest->unleash( $this->parserTest );
-                                       if ( !$hooksResult ) {
-                                               # Some hook reported an issue. Abort.
-                                               return false;
-                                       }
-
-                                       $this->test = array(
-                                               'test' => ParserTest::chomp( $this->sectionData['test'] ),
-                                               'input' => ParserTest::chomp( $this->sectionData[$input] ),
-                                               'result' => ParserTest::chomp( $this->sectionData[$result] ),
-                                               'options' => ParserTest::chomp( $this->sectionData['options'] ),
-                                               'config' => ParserTest::chomp( $this->sectionData['config'] ),
-                                       );
-
-                                       return true;
+                                       do {
+                                               if ( $this->setupCurrentTest() )
+                                                       return true;
+                                       } while ( $this->nextSubTest > 0 );
+                                       # go on to next test (since this was disabled)
+                                       $this->clearSection();
+                                       $this->delayedParserTest->reset();
+                                       continue;
                                }
 
                                if ( isset( $this->sectionData[$this->section] ) ) {
@@ -732,7 +758,7 @@ class DjVuSupport {
        }
 
        /**
-        * Returns if the DjVu tools are usable
+        * Returns true if the DjVu tools are usable
         *
         * @return bool
         */
@@ -745,3 +771,43 @@ class DjVuSupport {
                        && is_executable( $wgDjvuTxt );
        }
 }
+
+/**
+ * Initialize and detect the tidy support
+ */
+class TidySupport {
+       private $internalTidy;
+       private $externalTidy;
+
+       /**
+        * Determine if there is a usable tidy.
+        */
+       public function __construct() {
+               global $wgTidyBin;
+
+               $this->internalTidy = extension_loaded( 'tidy' ) &&
+                       class_exists( 'tidy' );
+
+               $this->externalTidy = is_executable( $wgTidyBin ) ||
+                       Installer::locateExecutableInDefaultPaths( array( $wgTidyBin ) )
+                       !== false;
+       }
+
+       /**
+        * Returns true if we should use internal tidy.
+        *
+        * @return bool
+        */
+       public function isInternal() {
+               return $this->internalTidy;
+       }
+
+       /**
+        * Returns true if tidy is usable
+        *
+        * @return bool
+        */
+       public function isEnabled() {
+               return $this->internalTidy || $this->externalTidy;
+       }
+}