wiki.techinc.nl/tests/phpunit/unit/includes/parser/TidyTest.php
C. Scott Ananian aeb2f33cc7 Deprecate a few more tidy-related methods
Hard-deprecate ParserOptions::getTidy(), since it always returns true
and is rarely used.  Code search:
https://codesearch.wmflabs.org/search/?q=getTidy%5C%28&i=nope&files=&repos=

Soft deprecate most methods of MWTidy; folks should use MWTidy::tidy()
as the entry point here.  Code search:
https://codesearch.wmflabs.org/search/?q=MWTidy&i=nope&files=&repos=

Bug: T198214
Change-Id: I3584181070da7ed4888beaaf04e083114aca1eab
2020-05-01 21:08:54 +00:00

61 lines
1.6 KiB
PHP

<?php
/**
* @group Parser
* @covers MWTidy
*/
class TidyTest extends \MediaWikiUnitTestCase {
protected function setUp() : void {
parent::setUp();
}
/**
* @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 static 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 [
[
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
'<mw:editsection> should survive tidy'
],
[
'<editsection page="foo" section="bar">foo</editsection>',
'<editsection page="foo" section="bar">foo</editsection>',
'<editsection> should survive tidy'
],
[ '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ],
[ "<link foo=\"bar\" />foo", '<link foo="bar"/>foo', '<link> should survive tidy' ],
[ "<meta foo=\"bar\" />foo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ],
[ $testMathML, $testMathML, '<math> should survive tidy' ],
];
}
}