1 module( 'mediawiki.util.js' );
3 test( '-- Initial check', function(){
5 ok( mw
.util
, 'mw.util defined' );
9 test( 'rawurlencode', function(){
11 equal( mw
.util
.rawurlencode( 'Test:A & B/Here' ), 'Test%3AA%20%26%20B%2FHere' );
15 test( 'wikiUrlencode', function(){
17 equal( mw
.util
.wikiUrlencode( 'Test:A & B/Here' ), 'Test:A_%26_B/Here' );
21 test( 'addCSS', function(){
23 var a
= mw
.util
.addCSS( '#bodyContent { visibility: hidden; }' );
24 ok( a
, 'function works' );
25 deepEqual( a
.disabled
, false, 'property "disabled" is available and set to false' );
27 var $b
= $('#bodyContent');
28 equal( $b
.css('visibility'), 'hidden', 'Added style properties are in effect.' );
33 test( 'toggleToc', function(){
35 ok( mw
.util
.toggleToc
);
39 test( 'wikiGetlink', function(){
41 // Not part of startUp module
42 mw
.config
.set( 'wgArticlePath', '/wiki/$1' );
44 var hrefA
= mw
.util
.wikiGetlink( 'Sandbox' );
46 equal( hrefA
, '/wiki/Sandbox', 'Simple title; Get link for "Sandbox"' );
48 var hrefB
= mw
.util
.wikiGetlink( 'Foo:Sandbox ? 5+5=10 ! (test)/subpage' );
50 equal( hrefB
, '/wiki/Foo:Sandbox_%3F_5%2B5%3D10_%21_%28test%29/subpage', 'Advanced title; Get link for "Foo:Sandbox ? 5+5=10 ! (test)/subpage"' );
54 test( 'getParamValue', function(){
56 var url
= 'http://mediawiki.org/?foo=wrong&foo=right#&foo=bad';
58 equal( mw
.util
.getParamValue( 'foo', url
), 'right', 'Use latest one, ignore hash' );
59 deepEqual( mw
.util
.getParamValue( 'bar', url
), null, 'Return null when not found' );
63 test( 'getActionFrom', function(){
66 var urlA
= 'http://mediawiki.org/wiki/Article',
67 urlB
= 'http://mediawiki.org/w/index.php?title=Article&action=edit',
68 urlC
= 'http://mediawiki.org/edit/Article',
69 urlD
= 'http://mediawiki.org/w/index.php/Article';
74 'wgArticlePath': '/wiki/$1'
77 equal( mw
.util
.getActionFrom( urlA
), 'view', 'wgArticlePath (/wiki/$1) support' );
78 equal( mw
.util
.getActionFrom( urlB
), 'edit', 'action-parameter support' );
81 mw
.config
.set( 'wgActionPaths', {
86 equal( mw
.util
.getActionFrom( urlC
), 'edit', 'wgActionPaths support' );
91 'wgArticlePath': '/w/index.php/$1'
93 equal( mw
.util
.getActionFrom( urlD
), 'view', 'wgArticlePath (/index.php/$1) support' );
97 test( 'getTitleFrom', function(){
100 var urlA
= 'http://mediawiki.org/wiki/Article',
101 urlB
= 'http://mediawiki.org/w/index.php?title=Article&action=edit',
102 urlC
= 'http://mediawiki.org/edit/Article',
103 urlD
= 'http://mediawiki.org/w/index.php/Article';
108 'wgArticlePath': '/wiki/$1'
111 equal( mw
.util
.getTitleFrom( urlA
), 'Article', 'wgArticlePath (/wiki/$1) support' );
112 equal( mw
.util
.getTitleFrom( urlB
), 'Article', 'action-parameter support' );
115 mw
.config
.set( 'wgActionPaths', {
120 equal( mw
.util
.getTitleFrom( urlC
), 'Article', 'wgActionPaths support' );
125 'wgArticlePath': '/w/index.php/$1'
128 equal( mw
.util
.getTitleFrom( urlD
), 'Article', 'wgArticlePath (/index.php/$1) support' );
132 test( 'tooltipAccessKey', function(){
134 equal( typeof mw
.util
.tooltipAccessKeyPrefix
, 'string', 'mw.util.tooltipAccessKeyPrefix must be a string' );
135 ok( mw
.util
.tooltipAccessKeyRegexp
instanceof RegExp
, 'mw.util.tooltipAccessKeyRegexp instance of RegExp' );
136 ok( mw
.util
.updateTooltipAccessKeys
, 'mw.util.updateTooltipAccessKeys' );
140 test( '$content', function(){
142 ok( mw
.util
.$content
instanceof jQuery
, 'mw.util.$content instance of jQuery' );
143 deepEqual( mw
.util
.$content
.length
, 1, 'mw.util.$content must have length of 1' );
147 test( 'addPortletLink', function(){
149 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' );
151 ok( $.isDomElement(a
), 'addPortletLink returns a DomElement' );
153 var b
= mw
.util
.addPortletLink( "p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-rl" );
155 equal( $(a
).text(), 'ResourceLoader', 'Link contains correct text' );
156 equal( $(b
).next().text(), 'ResourceLoader', 'Link was inserted in correct nextnode position' );
160 test( 'jsMessage', function(){
162 var a
= mw
.util
.jsMessage( "MediaWiki is <b>Awesome</b>." );
164 ok( a
, 'Basic return value checking' );
168 test( 'validateEmail', function(){
170 deepEqual( mw
.util
.validateEmail( "" ), null, 'Empty string should return null' );
171 deepEqual( mw
.util
.validateEmail( "user@localhost" ), true );
173 // testEmailWithCommasAreInvalids
174 deepEqual( mw
.util
.validateEmail( "user,foo@example.org" ), false, 'Comma' );
175 deepEqual( mw
.util
.validateEmail( "userfoo@ex,ample.org" ), false, 'Comma' );
177 // testEmailWithHyphens
178 deepEqual( mw
.util
.validateEmail( "user-foo@example.org" ), true, 'Hyphen' );
179 deepEqual( mw
.util
.validateEmail( "userfoo@ex-ample.org" ), true, 'Hyphen' );
183 test( 'isIPv6Address', function(){
185 // Based on IPTest.php > IPv6
186 deepEqual( mw
.util
.isIPv6Address( "" ), false, 'Empty string is not an IP' );
187 deepEqual( mw
.util
.isIPv6Address( ":fc:100::" ), false, 'IPv6 starting with lone ":"' );
188 deepEqual( mw
.util
.isIPv6Address( "fc:100::" ), true );
189 deepEqual( mw
.util
.isIPv6Address( "fc:100:a:d:1:e:ac::" ), true );
190 deepEqual( mw
.util
.isIPv6Address( ":::" ), false );
191 deepEqual( mw
.util
.isIPv6Address( "::0:" ), false );
195 test( 'isIPv4Address', function(){
197 // Based on IPTest.php > IPv4
198 deepEqual( mw
.util
.isIPv4Address( "" ), false, 'Empty string is not an IP' );
199 deepEqual( mw
.util
.isIPv4Address( "...." ), false );
200 deepEqual( mw
.util
.isIPv4Address( "1.24.52.13" ), true );