From 0723ce4e94565abf1b97b9033fff10240c59e2d6 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Thu, 12 May 2011 01:34:07 +0000 Subject: [PATCH] Continue implementation QUnit/TestSwarm integration (bug 28915) -- For now static html files. I have considered using load.php calls, and tried an in-wiki SpecialPage. However in order for versioned testing to work in TestSwarm it must be possible to do a checkout of a revision, alias or put it in a web-acccesible directory (eg. domain/tmp-svn/r1234/resources/test) and it must work right away (without needing database or LocalConfig or permission rules to avoid the wiki being modified). For that reason I chose for a static html page for now. Right now it loads mediawiki.js and mediawiki.util.js modules and I created complete tests for these modules. --- resources/test/index.html | 56 ++++++ resources/test/unit/main.css | 5 + .../unit/mediawiki.util/mediawiki.util.js | 109 +++++++++++ resources/test/unit/mediawiki/mediawiki.js | 169 ++++++++++++++++++ 4 files changed, 339 insertions(+) create mode 100644 resources/test/index.html create mode 100644 resources/test/unit/main.css create mode 100644 resources/test/unit/mediawiki.util/mediawiki.util.js create mode 100644 resources/test/unit/mediawiki/mediawiki.js diff --git a/resources/test/index.html b/resources/test/index.html new file mode 100644 index 0000000000..7255234427 --- /dev/null +++ b/resources/test/index.html @@ -0,0 +1,56 @@ + + + + MediaWiki JavaScript Test Suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

MediaWiki JavaScript Test Suite

+

+
+

+
    + +
    +
    +
    +
    + +
    +
    +
    + + diff --git a/resources/test/unit/main.css b/resources/test/unit/main.css new file mode 100644 index 0000000000..b4b24e123d --- /dev/null +++ b/resources/test/unit/main.css @@ -0,0 +1,5 @@ +/* Hide mediawiki elements */ +div#mw-js-message, +#mw-content { + display: none !important; +} \ No newline at end of file diff --git a/resources/test/unit/mediawiki.util/mediawiki.util.js b/resources/test/unit/mediawiki.util/mediawiki.util.js new file mode 100644 index 0000000000..b5be0b308e --- /dev/null +++ b/resources/test/unit/mediawiki.util/mediawiki.util.js @@ -0,0 +1,109 @@ +module( 'mediawiki.util.js' ); + +test( '-- Initial check', function(){ + + ok( mw.util, 'mw.util defined' ); + +}); + +test( 'rawurlencode', function(){ + + equals( mw.util.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' ); + +}); + +test( 'wikiUrlencode', function(){ + + equals( mw.util.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' ); + +}); + +test( 'addCSS', function(){ + + var a = mw.util.addCSS( '#bodyContent { background-color: rgb(170, 255, 170); }' ); + ok( a, 'function works' ); + same( a.disabled, false, 'property "disabled" is available and set to false' ); + + var $b = $('#bodyContent'); + equals( $b.css('background-color'), 'rgb(170, 255, 170)', 'Style color matches.' ); + +}); + +test( 'toggleToc', function(){ + + ok( mw.util.toggleToc ); + +}); + +test( 'wikiGetlink', function(){ + + // Not part of startUp module + mw.config.set( 'wgArticlePath', '/wiki/$1' ); + + var hrefA = mw.util.wikiGetlink( 'Sandbox' ); + + equals( hrefA, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' ); + + var hrefB = mw.util.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' ); + + equals( hrefB, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' ); + +}); + +test( 'getParamValue', function(){ + + equals( mw.util.getParamValue( 'foo', 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad' ), 'right', 'Use latest one, ignore hash' ); + same( mw.util.getParamValue( 'bar', 'http://mediawiki.org/?foo=right' ), null, 'Return null when not found' ); + +}); + +test( 'tooltipAccessKey', function(){ + + equals( typeof mw.util.tooltipAccessKeyPrefix, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' ); + ok( mw.util.tooltipAccessKeyRegexp instanceof RegExp, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' ); + ok( mw.util.updateTooltipAccessKeys, 'mw.util.updateTooltipAccessKeys' ); + +}); + +test( '$content', function(){ + + ok( mw.util.$content instanceof jQuery, 'mw.util.$content instance of jQuery' ); + same( mw.util.$content.length, 1, 'mw.util.$content must have length of 1' ); + +}); + +test( 'addPortletLink', function(){ + + var a = mw.util.addPortletLink( 'p-tb', 'http://mediawiki.org/wiki/ResourceLoader', 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l', '#t-specialpages' ); + + ok( $.isDomElement(a), 'addPortletLink returns a DomElement' ); + + var b = mw.util.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-rl" ); + + equals( $(a).text(), 'ResourceLoader', 'Link contains correct text' ); + equals( $(b).next().text(), 'ResourceLoader', 'Link was inserted in correct nextnode position' ); + +}); + +test( 'jsMessage', function(){ + + var a = mw.util.jsMessage( "MediaWiki is Awesome." ); + + ok( a, 'Basic return value checking' ); + +}); + +test( 'validateEmail', function(){ + + same( mw.util.validateEmail( "" ), null, 'Empty string should return null' ); + same( mw.util.validateEmail( "user@localhost" ), true ); + + // testEmailWithCommasAreInvalids + same( mw.util.validateEmail( "user,foo@example.org" ), false, 'Comma' ); + same( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Comma' ); + + // testEmailWithHyphens + same( mw.util.validateEmail( "user-foo@example.org" ), true, 'Hyphen' ); + same( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Hyphen' ); + +}); diff --git a/resources/test/unit/mediawiki/mediawiki.js b/resources/test/unit/mediawiki/mediawiki.js new file mode 100644 index 0000000000..2e75b7271f --- /dev/null +++ b/resources/test/unit/mediawiki/mediawiki.js @@ -0,0 +1,169 @@ +module( 'mediawiki.js' ); + +test( '-- Initial check', function(){ + + ok( window.jQuery, 'jQuery defined' ); + ok( window.$j, '$j defined' ); + equals( window.$j, window.jQuery, '$j alias to jQuery' ); + + ok( window.mediaWiki, 'mediaWiki defined' ); + ok( window.mw, 'mw defined' ); + equals( window.mw, window.mediaWiki, 'mw alias to mediaWiki' ); + +}); + +test( 'jQuery.extend', function(){ + + equals( $j.trimLeft( ' foo bar ' ), 'foo bar ', 'trimLeft' ); + equals( $j.trimRight( ' foo bar ' ), ' foo bar', 'trimRight' ); + equals( $j.ucFirst( 'foo'), 'Foo', 'ucFirst' ); + + equals( $j.escapeRE( '