aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/parser/TidyTest.php
blob: c9cbb67dc303fe7d5404ffd6ffcf4d51a09d27cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

namespace MediaWiki\Tests\Parser;

use MediaWiki\Parser\MWTidy;
use MediaWiki\Parser\Sanitizer;

/**
 * @group Parser
 * @covers \MediaWiki\Parser\MWTidy
 */
class TidyTest extends \MediaWikiIntegrationTestCase {

	/**
	 * @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;
		$testMathML = Sanitizer::normalizeCharReferences( $testMathML );
		return [
			[
				'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
				'<mw:editsection page="foo" section="bar">foo</mw:editsection>',
				'<mw:editsection> should survive tidy'
			],
			[
				'<meta property="mw:PageProp/toc" />',
				'<meta property="mw:PageProp/toc" />',
				'TOC_PLACEHOLDER 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' ],
		];
	}
}