2013-10-25 18:02:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group Parser
|
2019-02-01 20:48:33 +00:00
|
|
|
* @covers MWTidy
|
2013-10-25 18:02:11 +00:00
|
|
|
*/
|
2021-02-18 16:51:12 +00:00
|
|
|
class TidyTest extends \MediaWikiIntegrationTestCase {
|
2013-11-24 00:46:49 +00:00
|
|
|
|
2013-10-25 18:02:11 +00:00
|
|
|
/**
|
|
|
|
|
* @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 );
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 01:28:26 +00:00
|
|
|
public static function provideTestWrapping() {
|
2014-08-14 16:28:36 +00:00
|
|
|
$testMathML = <<<'MathML'
|
|
|
|
|
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
|
|
|
|
<mrow>
|
|
|
|
|
<mi>a</mi>
|
|
|
|
|
<mo>⁢</mo>
|
|
|
|
|
<msup>
|
|
|
|
|
<mi>x</mi>
|
|
|
|
|
<mn>2</mn>
|
|
|
|
|
</msup>
|
|
|
|
|
<mo>+</mo>
|
|
|
|
|
<mi>b</mi>
|
|
|
|
|
<mo>⁢ </mo>
|
|
|
|
|
<mi>x</mi>
|
|
|
|
|
<mo>+</mo>
|
|
|
|
|
<mi>c</mi>
|
|
|
|
|
</mrow>
|
|
|
|
|
</math>
|
|
|
|
|
MathML;
|
2021-02-18 15:51:57 +00:00
|
|
|
$testMathML = Sanitizer::normalizeCharReferences( $testMathML );
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2013-10-25 18:02:11 +00:00
|
|
|
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
|
|
|
|
|
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
|
|
|
|
|
'<mw:editsection> should survive tidy'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-10-25 18:02:11 +00:00
|
|
|
'<editsection page="foo" section="bar">foo</editsection>',
|
|
|
|
|
'<editsection page="foo" section="bar">foo</editsection>',
|
|
|
|
|
'<editsection> should survive tidy'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[ '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ],
|
2021-12-21 03:26:38 +00:00
|
|
|
[
|
|
|
|
|
'<meta property="mw:PageProp/toc" />',
|
|
|
|
|
'<meta property="mw:PageProp/toc" />',
|
|
|
|
|
'TOC_PLACEHOLDER should survive tidy',
|
|
|
|
|
],
|
2018-04-04 17:18:56 +00:00
|
|
|
[ "<link foo=\"bar\" />foo", '<link foo="bar"/>foo', '<link> should survive tidy' ],
|
|
|
|
|
[ "<meta foo=\"bar\" />foo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $testMathML, $testMathML, '<math> should survive tidy' ],
|
|
|
|
|
];
|
2013-10-25 18:02:11 +00:00
|
|
|
}
|
2013-11-19 18:03:54 +00:00
|
|
|
}
|