wiki.techinc.nl/tests/phpunit/includes/parser/TidyTest.php
physikerwelt 6a68fad159 Protect MathML from Tidy
MediaWiki installations that use the setting
$wgUseTidy = true; are unable to output
MathML since the well defined MathML elements
are filtered out by Tidy. This was reported as
  http://sourceforge.net/p/tidy/patches/84/ .

This change hides MathML blocks from
Tidy.

Bug: 66516
Change-Id: Ib48b91238c3eddd6a86b62f6ce57801d7058f0d8
2014-08-22 12:21:06 -04:00

64 lines
1.7 KiB
PHP

<?php
/**
* @group Parser
*/
class TidyTest extends MediaWikiTestCase {
protected function setUp() {
parent::setUp();
$check = MWTidy::tidy( '' );
if ( strpos( $check, '<!--' ) !== false ) {
$this->markTestSkipped( 'Tidy not found' );
}
}
/**
* @dataProvider provideTestWrapping
*/
public function testTidyWrapping( $expected, $text, $msg = '' ) {
$text = MWTidy::tidy( $text );
// We don't care about where Tidy wants to stick is <p>s
$text = trim( preg_replace( '#</?p>#', '', $text ) );
// Windows, we love you!
$text = str_replace( "\r", '', $text );
$this->assertEquals( $expected, $text, $msg );
}
public function provideTestWrapping() {
$testMathML = <<<'MathML'
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>a</mi>
<mo>&InvisibleTimes;</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>b</mi>
<mo>&InvisibleTimes; </mo>
<mi>x</mi>
<mo>+</mo>
<mi>c</mi>
</mrow>
</math>
MathML;
return array(
array(
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
'<mw:editsection> should survive tidy'
),
array(
'<editsection page="foo" section="bar">foo</editsection>',
'<editsection page="foo" section="bar">foo</editsection>',
'<editsection> should survive tidy'
),
array( '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ),
array( "<link foo=\"bar\" />\nfoo", '<link foo="bar"/>foo', '<link> should survive tidy' ),
array( "<meta foo=\"bar\" />\nfoo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ),
array( $testMathML , $testMathML, '<math> should survive tidy' ),
);
}
}