70e3a22687784a900d4b0671efa2c85625b1e687
3 test( '-- Initial check', function() {
6 ok( window
.jQuery
, 'jQuery defined' );
7 ok( window
.$, '$j defined' );
8 ok( window
.$j
, '$j defined' );
9 strictEqual( window
.$, window
.jQuery
, '$ alias to jQuery' );
10 strictEqual( window
.$j
, window
.jQuery
, '$j alias to jQuery' );
12 ok( window
.mediaWiki
, 'mediaWiki defined' );
13 ok( window
.mw
, 'mw defined' );
14 strictEqual( window
.mw
, window
.mediaWiki
, 'mw alias to mediaWiki' );
17 test( 'mw.Map', function() {
20 ok( mw
.Map
, 'mw.Map defined' );
22 var conf
= new mw
.Map(),
24 funky = function() {},
28 // Tests for input validation
29 strictEqual( conf
.get( 'inexistantKey' ), null, 'Map.get returns null if selection was a string and the key was not found' );
30 strictEqual( conf
.set( 'myKey', 'myValue' ), true, 'Map.set returns boolean true if a value was set for a valid key string' );
31 strictEqual( conf
.set( funky
, 'Funky' ), false, 'Map.set returns boolean false if key was invalid (Function)' );
32 strictEqual( conf
.set( arry
, 'Arry' ), false, 'Map.set returns boolean false if key was invalid (Array)' );
33 strictEqual( conf
.set( nummy
, 'Nummy' ), false, 'Map.set returns boolean false if key was invalid (Number)' );
34 equal( conf
.get( 'myKey' ), 'myValue', 'Map.get returns a single value value correctly' );
35 strictEqual( conf
.get( nummy
), null, 'Map.get ruturns null if selection was invalid (Number)' );
36 strictEqual( conf
.get( funky
), null, 'Map.get ruturns null if selection was invalid (Function)' );
38 // Multiple values at once
44 strictEqual( conf
.set( someValues
), true, 'Map.set returns boolean true if multiple values were set by passing an object' );
45 deepEqual( conf
.get( ['foo', 'lorem'] ), {
48 }, 'Map.get returns multiple values correctly as an object' );
50 deepEqual( conf
.get( ['foo', 'notExist'] ), {
53 }, 'Map.get return includes keys that were not found as null values' );
55 strictEqual( conf
.exists( 'foo' ), true, 'Map.exists returns boolean true if a key exists' );
56 strictEqual( conf
.exists( 'notExist' ), false, 'Map.exists returns boolean false if a key does not exists' );
58 // Interacting with globals and accessing the values object
59 strictEqual( conf
.get(), conf
.values
, 'Map.get returns the entire values object by reference (if called without arguments)' );
61 conf
.set( 'globalMapChecker', 'Hi' );
63 ok( false === 'globalMapChecker' in window
, 'new mw.Map did not store its values in the global window object by default' );
65 var globalConf
= new mw
.Map( true );
66 globalConf
.set( 'anotherGlobalMapChecker', 'Hello' );
68 ok( 'anotherGlobalMapChecker' in window
, 'new mw.Map( true ) did store its values in the global window object' );
70 // Whitelist this global variable for QUnit's 'noglobal' mode
71 if ( QUnit
.config
.noglobals
) {
72 QUnit
.config
.pollution
.push( 'anotherGlobalMapChecker' );
76 test( 'mw.config', function() {
79 ok( mw
.config
instanceof mw
.Map
, 'mw.config instance of mw.Map' );
82 test( 'mw.message & mw.messages', function() {
85 ok( mw
.messages
, 'messages defined' );
86 ok( mw
.messages
instanceof mw
.Map
, 'mw.messages instance of mw.Map' );
87 ok( mw
.messages
.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
89 var hello
= mw
.message( 'hello' );
91 equal( hello
.format
, 'plain', 'Message property "format" defaults to "parse"' );
92 strictEqual( hello
.map
, mw
.messages
, 'Message property "map" defaults to the global instance in mw.messages' );
93 equal( hello
.key
, 'hello', 'Message property "key" (currect key)' );
94 deepEqual( hello
.parameters
, [], 'Message property "parameters" defaults to an empty array' );
97 ok( hello
.params
, 'Message prototype "params"' );
99 hello
.format
= 'plain';
100 equal( hello
.toString(), 'Hello <b>awesome</b> world', 'Message.toString returns the message as a string with the current "format"' );
102 equal( hello
.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped returns the escaped message' );
103 equal( hello
.format
, 'escaped', 'Message.escaped correctly updated the "format" property' );
106 equal( hello
.format
, 'parse', 'Message.parse correctly updated the "format" property' );
109 equal( hello
.format
, 'plain', 'Message.plain correctly updated the "format" property' );
111 strictEqual( hello
.exists(), true, 'Message.exists returns true for existing messages' );
113 var goodbye
= mw
.message( 'goodbye' );
114 strictEqual( goodbye
.exists(), false, 'Message.exists returns false for inexisting messages' );
116 equal( goodbye
.toString(), '<goodbye>', 'Message.toString returns <key> if key does not exist' );
119 test( 'mw.msg', function() {
122 equal( mw
.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
123 equal( mw
.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' );
126 test( 'mw.loader', function() {
129 // Asynchronous ahead
132 mw
.loader
.implement( 'is.awesome', [QUnit
.fixurl( mw
.config
.get( 'wgScriptPath' ) + '/tests/qunit/data/defineTestCallback.js' )], {}, {} );
134 mw
.loader
.using( 'is.awesome', function() {
136 // /sample/awesome.js declares the "mw.loader.testCallback" function
137 // which contains a call to start() and ok()
138 mw
.loader
.testCallback();
139 mw
.loader
.testCallback
= undefined;
143 ok( false, 'Error callback fired while implementing "is.awesome" module' );
148 test( 'mw.loader.bug29107' , function() {
151 // Message doesn't exist already
152 ok( !mw
.messages
.exists( 'bug29107' ) );
154 // Async! Include a timeout, as failure in this test leads to neither the
155 // success nor failure callbacks getting called.
158 mw
.loader
.implement( 'bug29107.messages-only', [], {}, {'bug29107': 'loaded'} );
159 mw
.loader
.using( 'bug29107.messages-only', function() {
161 ok( mw
.messages
.exists( 'bug29107' ), 'Bug 29107: messages-only module should implement ok' );
164 ok( false, 'Error callback fired while implementing "bug29107.messages-only" module' );
168 test( 'mw.html', function() {
173 }, TypeError
, 'html.escape throws a TypeError if argument given is not a string' );
175 equal( mw
.html
.escape( '<mw awesome="awesome" value=\'test\' />' ),
176 '<mw awesome="awesome" value='test' />', 'html.escape escapes html snippet' );
178 equal( mw
.html
.element(),
179 '<undefined/>', 'html.element Always return a valid html string (even without arguments)' );
181 equal( mw
.html
.element( 'div' ), '<div/>', 'html.element DIV (simple)' );
183 equal( mw
.html
.element( 'div',
185 '<div id="foobar"/>',
186 'html.element DIV (attribs)' );
188 equal( mw
.html
.element( 'div',
191 'html.element DIV (content)' );
193 equal( mw
.html
.element( 'a',
194 { href
: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
195 '<a href="http://mediawiki.org/w/index.php?title=RL&action=history">a</a>',
196 'html.element DIV (attribs + content)' );