6 class HtmlFormatterTest
extends MediaWikiTestCase
{
8 * @dataProvider getHtmlData
9 * @covers HtmlFormatter::getText
11 public function testTransform( $input, $expected, $callback = false ) {
12 $input = self
::normalize( $input );
13 $formatter = new HtmlFormatter( HtmlFormatter
::wrapHTML( $input ) );
15 $callback( $formatter );
17 $formatter->filterContent();
18 $html = $formatter->getText();
19 $this->assertEquals( self
::normalize( $expected ), self
::normalize( $html ) );
22 private static function normalize( $s ) {
23 return str_replace( "\n", '',
24 str_replace( "\r", '', $s ) // "yay" to Windows!
28 public function getHtmlData() {
29 $removeImages = function( HtmlFormatter
$f ) {
32 $removeTags = function( HtmlFormatter
$f ) {
33 $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) );
35 $flattenSomeStuff = function( HtmlFormatter
$f ) {
36 $f->flatten( array( 's', 'div' ) );
38 $flattenEverything = function( HtmlFormatter
$f ) {
42 // remove images if asked
44 '<img src="/foo/bar.jpg" alt="Blah"/>',
50 '<table><tr><td>foo</td></tr></table><div class="foo">foo</div><div class="foo quux">foo</div><span id="bar">bar</span>
51 <strong class="foo" id="bar">foobar</strong><div class="notfoo">test</div><div class="baz"/>
52 <span class="baz">baz</span>',
54 '<div class="notfoo">test</div>
55 <span class="baz">baz</span>',
58 // don't flatten tags that start like chosen ones
60 '<div><s>foo</s> <span>bar</span></div>',
61 'foo <span>bar</span>',
66 '<div style="foo">bar<sup>2</sup></div>',
70 // UTF-8 preservation and security
72 '<span title="" \' &"><Тест!></span> &<&&&&',
73 '<span title="" \' &"><Тест!></span> &<&&&&',
75 // https://bugzilla.wikimedia.org/show_bug.cgi?id=53086
77 'Foo<sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup> <a href="/wiki/Bar" title="Bar" class="mw-redirect">Bar</a>',
78 'Foo<sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup> <a href="/wiki/Bar" title="Bar" class="mw-redirect">Bar</a>',