From 14f74d141ab5580688bfd46d2f74c026e43ed967 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 1 Apr 2015 06:11:44 +0200 Subject: Update to MediaWiki 1.24.2 --- tests/phpunit/includes/HtmlFormatterTest.php | 127 +++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/phpunit/includes/HtmlFormatterTest.php (limited to 'tests/phpunit/includes/HtmlFormatterTest.php') diff --git a/tests/phpunit/includes/HtmlFormatterTest.php b/tests/phpunit/includes/HtmlFormatterTest.php new file mode 100644 index 00000000..9dbfa452 --- /dev/null +++ b/tests/phpunit/includes/HtmlFormatterTest.php @@ -0,0 +1,127 @@ +filterContent(); + $html = $formatter->getText(); + $removed = array(); + foreach ( $removedElements as $removedElement ) { + $removed[] = self::normalize( $formatter->getText( $removedElement ) ); + } + $expectedRemoved = array_map( 'self::normalize', $expectedRemoved ); + + $this->assertValidHtmlSnippet( $html ); + $this->assertEquals( self::normalize( $expectedText ), self::normalize( $html ) ); + $this->assertEquals( asort( $expectedRemoved ), asort( $removed ) ); + } + + private static function normalize( $s ) { + return str_replace( "\n", '', + str_replace( "\r", '', $s ) // "yay" to Windows! + ); + } + + public function getHtmlData() { + $removeImages = function ( HtmlFormatter $f ) { + $f->setRemoveMedia(); + }; + $removeTags = function ( HtmlFormatter $f ) { + $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) ); + }; + $flattenSomeStuff = function ( HtmlFormatter $f ) { + $f->flatten( array( 's', 'div' ) ); + }; + $flattenEverything = function ( HtmlFormatter $f ) { + $f->flattenAllTags(); + }; + return array( + // remove images if asked + array( + 'Blah', + '', + array( 'Blah' ), + $removeImages, + ), + // basic tag removal + array( + // @codingStandardsIgnoreStart Ignore long line warnings. + '
foo
foo
foo
bar +foobar
test
+baz', + // @codingStandardsIgnoreEnd + '
test
+baz', + array( + '
foo
', + '
foo
', + '
foo
', + 'bar', + 'foobar', + '
', + ), + $removeTags, + ), + // don't flatten tags that start like chosen ones + array( + '
foo bar
', + 'foo bar', + array(), + $flattenSomeStuff, + ), + // total flattening + array( + '
bar2
', + 'bar2', + array(), + $flattenEverything, + ), + // UTF-8 preservation and security + array( + '<Тест!> &<&&&&', + '<Тест!> &<&&&&', + array(), + $removeTags, // Have some rules to trigger a DOM parse + ), + // https://bugzilla.wikimedia.org/show_bug.cgi?id=53086 + array( + 'Foo[1]' + . ' Bar', + 'Foo[1]' + . ' Bar', + ), + ); + } + + public function testQuickProcessing() { + $f = new MockHtmlFormatter( 'foo' ); + $f->filterContent(); + $this->assertFalse( $f->hasDoc, 'HtmlFormatter should not needlessly parse HTML' ); + } +} + +class MockHtmlFormatter extends HtmlFormatter { + public $hasDoc = false; + + public function getDoc() { + $this->hasDoc = true; + return parent::getDoc(); + } +} -- cgit v1.2.3-54-g00ecf