r111679 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111678‎ | r111679 | r111680 >
Date:20:49, 16 February 2012
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
Basic tests for HTML transformations
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFrontend.php (modified) (history)
  • /trunk/extensions/MobileFrontend/tests/MobileFormatterTest.php (added) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/tests/MobileFormatterTest.php
@@ -0,0 +1,48 @@
 2+<?php
 3+
 4+/**
 5+ * @group MobileFrontend
 6+ */
 7+class MobileFormatterTest extends MediaWikiTestCase {
 8+ /**
 9+ * @dataProvider getXhtmlData
 10+ */
 11+ public function testXhtmlTransform( $input, $expected, $callback = false ) {
 12+ $t = Title::newFromText( 'Mobile' );
 13+ $mf = new MobileFormatter( "<div id='content'>$input</div>", $t, 'XHTML' );
 14+ if ( $callback ) {
 15+ $callback( $mf );
 16+ }
 17+ $mf->filterContent();
 18+ $html = $mf->getText( 'content' );
 19+ $html = preg_replace( '/^<div.*?>|<\\/div>$/', '', $html ); // Forgive me father for I have sinned
 20+ $this->assertEquals( str_replace( "\n", '', $expected ), str_replace( "\n", '', $html ) );
 21+ }
 22+
 23+ public function getXhtmlData() {
 24+ $disableImages = function( MobileFormatter $mf ) {
 25+ $mf->removeImages();
 26+ };
 27+ return array(
 28+ // down with infoboxes
 29+ array(
 30+ '<div class="infobox">Insanity!</div>',
 31+ '',
 32+ ),
 33+ // remove magnifying glass
 34+ array(
 35+ '<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="https://www.mediawiki.org/wiki/File:Foo.jpg" class="image">
 36+<img alt="" src="/foo.jpg" width="220" height="165" class="thumbimage"/></a><div class="thumbcaption">
 37+<div class="magnify"><a href="https://www.mediawiki.org/wiki/File:Foo.jpg" class="internal" title="Enlarge"></div>
 38+Foobar!</div></div></div>',
 39+ '<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="https://www.mediawiki.org/wiki/File:Foo.jpg" class="image"><img alt="" src="/foo.jpg" width="220" height="165" class="thumbimage"></img></a><div class="thumbcaption">Foobar!</div></div></div>',
 40+ ),
 41+ // remove images if asked
 42+ array(
 43+ '<img src="/foo/bar.jpg">Blah</img>',
 44+ 'Blah',
 45+ $disableImages,
 46+ ),
 47+ );
 48+ }
 49+}
\ No newline at end of file
Property changes on: trunk/extensions/MobileFrontend/tests/MobileFormatterTest.php
___________________________________________________________________
Added: svn:eol-style
150 + native
Index: trunk/extensions/MobileFrontend/MobileFrontend.php
@@ -124,7 +124,9 @@
125125 * @return bool
126126 */
127127 function efExtMobileFrontendUnitTests( &$files ) {
128 - $files[] = dirname( __FILE__ ) . '/tests/MobileFrontendTest.php';
129 - $files[] = dirname( __FILE__ ) . '/tests/DeviceDetectionTest.php';
 128+ $dir = dirname( __FILE__ ) . '/tests';
 129+ $files[] = "$dir/MobileFrontendTest.php";
 130+ $files[] = "$dir/DeviceDetectionTest.php";
 131+ $files[] = "$dir/MobileFormatterTest.php";
130132 return true;
131133 }

Sign-offs

UserFlagDate
Nikerabbitinspected06:50, 17 February 2012

Comments

#Comment by Preilly (talk | contribs)   12:54, 17 February 2012

Do we really need this comment: // Forgive me father for I have sinned?

Status & tagging log