Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.parse.test.js
1 ( function () {
2 QUnit.module( 'mediawiki.api.parse', QUnit.newMwEnvironment( {
3 setup: function () {
4 this.server = this.sandbox.useFakeServer();
5 this.server.respondImmediately = true;
6 }
7 } ) );
8
9 QUnit.test( '.parse( string )', function ( assert ) {
10 this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
11 { 'Content-Type': 'application/json' },
12 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
13 ] );
14
15 return new mw.Api().parse( '\'\'\'Hello world\'\'\'' ).done( function ( html ) {
16 assert.strictEqual( html, '<p><b>Hello world</b></p>', 'Parse wikitext by string' );
17 } );
18 } );
19
20 QUnit.test( '.parse( Object.toString )', function ( assert ) {
21 this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
22 { 'Content-Type': 'application/json' },
23 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
24 ] );
25
26 return new mw.Api().parse( {
27 toString: function () {
28 return '\'\'\'Hello world\'\'\'';
29 }
30 } ).done( function ( html ) {
31 assert.strictEqual( html, '<p><b>Hello world</b></p>', 'Parse wikitext by toString object' );
32 } );
33 } );
34
35 QUnit.test( '.parse( mw.Title )', function ( assert ) {
36 this.server.respondWith( /action=parse.*&page=Earth/, [ 200,
37 { 'Content-Type': 'application/json' },
38 '{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }'
39 ] );
40
41 return new mw.Api().parse( new mw.Title( 'Earth' ) ).done( function ( html ) {
42 assert.strictEqual( html, '<p><b>Earth</b> is a planet.</p>', 'Parse page by Title object' );
43 } );
44 } );
45 }() );