summaryrefslogtreecommitdiff
path: root/www/wiki/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js
blob: 74da0098b057d9241a708d16dce5595cebd177c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
( function ( mw ) {
	QUnit.module( 'mediawiki.api.parse', QUnit.newMwEnvironment( {
		setup: function () {
			this.server = this.sandbox.useFakeServer();
			this.server.respondImmediately = true;
		}
	} ) );

	QUnit.test( '.parse( string )', function ( assert ) {
		this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
			{ 'Content-Type': 'application/json' },
			'{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
		] );

		return new mw.Api().parse( '\'\'\'Hello world\'\'\'' ).done( function ( html ) {
			assert.equal( html, '<p><b>Hello world</b></p>', 'Parse wikitext by string' );
		} );
	} );

	QUnit.test( '.parse( Object.toString )', function ( assert ) {
		this.server.respondWith( /action=parse.*&text='''Hello(\+|%20)world'''/, [ 200,
			{ 'Content-Type': 'application/json' },
			'{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
		] );

		return new mw.Api().parse( {
			toString: function () {
				return '\'\'\'Hello world\'\'\'';
			}
		} ).done( function ( html ) {
			assert.equal( html, '<p><b>Hello world</b></p>', 'Parse wikitext by toString object' );
		} );
	} );

	QUnit.test( '.parse( mw.Title )', function ( assert ) {
		this.server.respondWith( /action=parse.*&page=Earth/, [ 200,
			{ 'Content-Type': 'application/json' },
			'{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }'
		] );

		return new mw.Api().parse( new mw.Title( 'Earth' ) ).done( function ( html ) {
			assert.equal( html, '<p><b>Earth</b> is a planet.</p>', 'Parse page by Title object' );
		} );
	} );
}( mediaWiki ) );