r114504 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114503‎ | r114504 | r114505 >
Date:23:03, 26 March 2012
Author:awjrichards
Status:deferred
Tags:
Comment:
Followup r114497; Adding files that got missed in previous sync to git origin/master head
Modified paths:
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png (added) (history)
  • /branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php (added) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png
Cannot display: file marked as a binary type.
svn:mime-type = image/png
Property changes on: branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png
___________________________________________________________________
Added: svn:mime-type
11 + image/png
Index: branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php
@@ -0,0 +1,73 @@
 2+<?php
 3+
 4+/**
 5+ * @group MobileFrontend
 6+ */
 7+class HtmlFormatterTest extends MediaWikiTestCase {
 8+ /**
 9+ * @dataProvider getHtmlData
 10+ */
 11+ public function testTransform( $input, $expected, $callback = false ) {
 12+ $t = Title::newFromText( 'Mobile' );
 13+ $input = self::normalize( $input );
 14+ $formatter = new HtmlFormatter( HtmlFormatter::wrapHTML( $input ), $t, 'XHTML' );
 15+ if ( $callback ) {
 16+ $callback( $formatter );
 17+ }
 18+ $formatter->filterContent();
 19+ $html = $formatter->getText();
 20+ $this->assertEquals( self::normalize( $expected ), self::normalize( $html ) );
 21+ }
 22+
 23+ private static function normalize( $s ) {
 24+ return str_replace( "\n", '',
 25+ str_replace( "\r", '', $s ) // "yay" to Windows!
 26+ );
 27+ }
 28+
 29+ public function getHtmlData() {
 30+ $disableImages = function( HtmlFormatter $f ) {
 31+ $f->removeImages();
 32+ };
 33+ $removeTags = function( HtmlFormatter $f ) {
 34+ $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) );
 35+ $f->whitelistIds( 'jedi' );
 36+ };
 37+ $flattenSomeStuff = function( HtmlFormatter $f ) {
 38+ $f->flatten( array( 's', 'div' ) );
 39+ };
 40+ $flattenEverything = function( HtmlFormatter $f ) {
 41+ $f->flattenAllTags();
 42+ };
 43+ return array(
 44+ // remove images if asked
 45+ array(
 46+ '<img src="/foo/bar.jpg">Blah</img>',
 47+ 'Blah',
 48+ $disableImages,
 49+ ),
 50+ // basic tag removal
 51+ array(
 52+ '<table><tr><td>foo</td></tr></table><div class="foo">foo</div><span id="bar">bar</span>
 53+<strong class="foo" id="bar">foobar</strong><div class="notfoo">test</div><div class="baz"/>
 54+<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>',
 55+
 56+ '<div class="notfoo">test</div>
 57+<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>',
 58+ $removeTags,
 59+ ),
 60+ // don't flatten tags that start like chosen ones
 61+ array(
 62+ '<div><s>foo</s> <span>bar</span></div>',
 63+ 'foo <span>bar</span>',
 64+ $flattenSomeStuff,
 65+ ),
 66+ // total flattening
 67+ array(
 68+ '<div style="foo">bar<sup>2</sup></div>',
 69+ 'bar2',
 70+ $flattenEverything,
 71+ ),
 72+ );
 73+ }
 74+}
Property changes on: branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php
___________________________________________________________________
Added: svn:eol-style
175 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114497Syncing to head of origin/master at Change-Id: Ic5b2491485a93909ae2a4c944f714...awjrichards21:41, 26 March 2012

Status & tagging log