QUnit reorganization
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.js
1 module( 'mediawiki.js' );
2
3 test( '-- Initial check', function(){
4
5 ok( window.jQuery, 'jQuery defined' );
6 ok( window.$j, '$j defined' );
7 equal( window.$j, window.jQuery, '$j alias to jQuery' );
8
9 ok( window.mediaWiki, 'mediaWiki defined' );
10 ok( window.mw, 'mw defined' );
11 equal( window.mw, window.mediaWiki, 'mw alias to mediaWiki' );
12
13 });
14
15 test( 'mw.Map / mw.config', function(){
16
17 ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
18 ok( mw.config.get, 'get' );
19 ok( mw.config.set, 'set' );
20 ok( mw.config.exists, 'exists' );
21
22 ok( !mw.config.exists( 'lipsum' ), 'exists: lipsum (inexistant)' );
23 ok( mw.config.set( 'lipsum', 'Lorem ipsum' ), 'set: lipsum' );
24 ok( mw.config.exists( 'lipsum' ), 'exists: lipsum (existant)' );
25
26 equal( mw.config.get( 'lipsum' ), 'Lorem ipsum', 'get: lipsum' );
27 equal( mw.config.get( ['lipsum'] ).lipsum, 'Lorem ipsum', 'get: lipsum (multiple)' );
28
29 });
30
31 test( 'mw.message / mw.msg / mw.messages', function(){
32 ok( mw.message, 'mw.message defined' );
33 ok( mw.msg, 'mw.msg defined' );
34 ok( mw.messages, 'messages defined' );
35 ok( mw.messages instanceof mw.Map, 'mw.messages instance of mw.Map' );
36 ok( mw.messages.set( 'hello', 'Hello <b>awesome</b> world' ), 'mw.messages.set: Register' );
37
38 var hello = mw.message( 'hello' );
39 ok( hello, 'hello: Instance of Message' );
40
41 equal( hello.format, 'parse', 'Message property "format" (default value)' );
42 equal( hello.key, 'hello', 'Message property "key" (currect key)' );
43 deepEqual( hello.parameters, [], 'Message property "parameters" (default value)' );
44
45
46 ok( hello.params, 'Message prototype "params"');
47 ok( hello.toString, 'Message prototype "toString"');
48 ok( hello.parse, 'Message prototype "parse"');
49 ok( hello.plain, 'Message prototype "plain"');
50 ok( hello.escaped, 'Message prototype "escaped"');
51 ok( hello.exists, 'Message prototype "exists"');
52
53 equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString() test');
54 equal( hello.escaped(), 'Hello &lt;b&gt;awesome&lt;/b&gt; world', 'Message.escaped() test');
55 deepEqual( hello.exists(), true, 'Message.exists() test');
56
57 equal( mw.msg( 'random' ), '<random>', 'square brackets around inexistant messages' );
58 equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'get message with default options' );
59
60 // params, toString, parse, plain, escaped, exists
61 });
62
63 test( 'mw.loader', function(){
64 expect(2);
65
66 ok( location.href.match(/[^#\?]*/) && location.href.match(/[^#\?]*/)[0], true, 'Extracting file path from location' );
67
68 stop();
69
70 mw.loader.implement( 'is.awesome', [location.href.match(/[^#\?]*/)[0] + 'sample/awesome.js'], {}, {} );
71 mw.loader.using( 'is.awesome', function(){
72 start();
73 deepEqual( window.awesome, true, 'Implementing a module, is the callback timed properly ?');
74
75 // Clean up
76 delete window.awesome;
77
78 }, function(){
79 start();
80 deepEqual( 'mw.loader.using error callback fired', true, 'Implementing a module, is the callback timed properly ?');
81 });
82
83 });
84
85 test( 'mw.html', function(){
86
87 equal( mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
88 '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;', 'html.escape()' );
89
90 equal( mw.html.element( 'div' ), '<div/>', 'mw.html.element() DIV (simple)' );
91
92 equal( mw.html.element( 'div',
93 { id: 'foobar' } ),
94 '<div id="foobar"/>',
95 'mw.html.element() DIV (attribs)' );
96
97 equal( mw.html.element( 'div',
98 null, 'a' ),
99 '<div>a</div>',
100 'mw.html.element() DIV (content)' );
101
102 equal( mw.html.element( 'a',
103 { href: 'http://mediawiki.org/w/index.php?title=RL&action=history' }, 'a' ),
104 '<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
105 'mw.html.element() DIV (attribs + content)' );
106
107 });