https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114504

Revision: 114504
Author:   awjrichards
Date:     2012-03-26 23:03:08 +0000 (Mon, 26 Mar 2012)
Log Message:
-----------
Followup r114497; Adding files that got missed in previous sync to git 
origin/master head

Added Paths:
-----------
    
branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png
    branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php

Added: 
branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png
===================================================================
(Binary files differ)


Property changes on: 
branches/wmf/1.19wmf1/extensions/MobileFrontend/stylesheets/images/logo-copyright-en.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Added: 
branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php
===================================================================
--- branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php 
                        (rev 0)
+++ branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php 
2012-03-26 23:03:08 UTC (rev 114504)
@@ -0,0 +1,73 @@
+<?php
+
+/**
+ * @group MobileFrontend
+ */
+class HtmlFormatterTest extends MediaWikiTestCase {
+       /**
+        * @dataProvider getHtmlData
+        */
+       public function testTransform( $input, $expected, $callback = false ) {
+               $t = Title::newFromText( 'Mobile' );
+               $input = self::normalize( $input );
+               $formatter = new HtmlFormatter( HtmlFormatter::wrapHTML( $input 
), $t, 'XHTML' );
+               if ( $callback ) {
+                       $callback( $formatter );
+               }
+               $formatter->filterContent();
+               $html = $formatter->getText();
+               $this->assertEquals( self::normalize( $expected ), 
self::normalize( $html ) );
+       }
+
+       private static function normalize( $s ) {
+               return str_replace( "\n", '',
+                       str_replace( "\r", '', $s ) // "yay" to Windows!
+               );
+       }
+
+       public function getHtmlData() {
+               $disableImages = function( HtmlFormatter $f ) {
+                       $f->removeImages();
+               };
+               $removeTags = function( HtmlFormatter $f ) {
+                       $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) 
);
+                       $f->whitelistIds( 'jedi' );
+               };
+               $flattenSomeStuff = function( HtmlFormatter $f ) {
+                       $f->flatten( array( 's', 'div' ) );
+               };
+               $flattenEverything = function( HtmlFormatter $f ) {
+                       $f->flattenAllTags();
+               };
+               return array(
+                       // remove images if asked
+                       array(
+                               '<img src="/foo/bar.jpg">Blah</img>',
+                               'Blah',
+                               $disableImages,
+                       ),
+                       // basic tag removal
+                       array(
+                               '<table><tr><td>foo</td></tr></table><div 
class="foo">foo</div><span id="bar">bar</span>
+<strong class="foo" id="bar">foobar</strong><div class="notfoo">test</div><div 
class="baz"/>
+<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>',
+
+                               '<div class="notfoo">test</div>
+<span class="baz">baz</span> <span class="foo" id="jedi">jedi</span>',
+                               $removeTags,
+                       ),
+                       // don't flatten tags that start like chosen ones
+                       array(
+                               '<div><s>foo</s> <span>bar</span></div>',
+                               'foo <span>bar</span>',
+                               $flattenSomeStuff,
+                       ),
+                       // total flattening 
+                       array(
+                               '<div style="foo">bar<sup>2</sup></div>',
+                               'bar2',
+                               $flattenEverything,
+                       ),
+               );
+       }
+}


Property changes on: 
branches/wmf/1.19wmf1/extensions/MobileFrontend/tests/HtmlFormatterTest.php
___________________________________________________________________
Added: svn:eol-style
   + native


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to