898ef2d1635c256894068b532eb6e8a5ea8359b3
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / TidyTest.php
1 <?php
2
3 /**
4 * @group Parser
5 * @covers MWTidy
6 */
7 class TidyTest extends MediaWikiTestCase {
8
9 protected function setUp() {
10 parent::setUp();
11 if ( !MWTidy::isEnabled() ) {
12 $this->markTestSkipped( 'Tidy not found' );
13 }
14 }
15
16 /**
17 * @dataProvider provideTestWrapping
18 */
19 public function testTidyWrapping( $expected, $text, $msg = '' ) {
20 $text = MWTidy::tidy( $text );
21 // We don't care about where Tidy wants to stick is <p>s
22 $text = trim( preg_replace( '#</?p>#', '', $text ) );
23 // Windows, we love you!
24 $text = str_replace( "\r", '', $text );
25 $this->assertEquals( $expected, $text, $msg );
26 }
27
28 public static function provideTestWrapping() {
29 $testMathML = <<<'MathML'
30 <math xmlns="http://www.w3.org/1998/Math/MathML">
31 <mrow>
32 <mi>a</mi>
33 <mo>&InvisibleTimes;</mo>
34 <msup>
35 <mi>x</mi>
36 <mn>2</mn>
37 </msup>
38 <mo>+</mo>
39 <mi>b</mi>
40 <mo>&InvisibleTimes; </mo>
41 <mi>x</mi>
42 <mo>+</mo>
43 <mi>c</mi>
44 </mrow>
45 </math>
46 MathML;
47 return [
48 [
49 '<mw:editsection page="foo" section="bar">foo</mw:editsection>',
50 '<mw:editsection page="foo" section="bar">foo</mw:editsection>',
51 '<mw:editsection> should survive tidy'
52 ],
53 [
54 '<editsection page="foo" section="bar">foo</editsection>',
55 '<editsection page="foo" section="bar">foo</editsection>',
56 '<editsection> should survive tidy'
57 ],
58 [ '<mw:toc>foo</mw:toc>', '<mw:toc>foo</mw:toc>', '<mw:toc> should survive tidy' ],
59 [ "<link foo=\"bar\" />foo", '<link foo="bar"/>foo', '<link> should survive tidy' ],
60 [ "<meta foo=\"bar\" />foo", '<meta foo="bar"/>foo', '<meta> should survive tidy' ],
61 [ $testMathML, $testMathML, '<math> should survive tidy' ],
62 ];
63 }
64 }