Add RL template module with HTML markup language
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.template.test.js
1 ( function ( mw, $ ) {
2
3 QUnit.module( 'Templates', {
4 setup: function () {
5 var abcCompiler = {
6 registerPartial: $.noop,
7 compile: function () {
8 return 'abc default compiler';
9 }
10 };
11 // Register some template compiler languages
12 mw.template.registerCompiler( 'abc', abcCompiler );
13 mw.template.registerCompiler( 'xyz', {
14 registerPartial: $.noop,
15 compile: function () {
16 return 'xyz compiler';
17 }
18 } );
19
20 // register some templates
21 mw.templates.set( {
22 'test.mediawiki.templates': {
23 'test_templates_foo.xyz': 'goodbye',
24 'test_templates_foo.abc': 'thankyou'
25 }
26 } );
27 }
28 } );
29
30 QUnit.test( 'Template, getCompiler - default case', 4, function ( assert ) {
31 assert.throws( function () {
32 mw.template.add( 'module', 'test_templates_foo', 'hello' );
33 }, 'When no prefix throw exception.' );
34 assert.throws( function () {
35 mw.template.compile( '{{foo}}', 'rainbow' );
36 }, 'Unknown compiler names throw exceptions.' );
37 assert.strictEqual( mw.template.get( 'test.mediawiki.templates', 'test_templates_foo.xyz' ), 'xyz compiler' );
38 assert.strictEqual( mw.template.get( 'test.mediawiki.templates', 'test_templates_foo.abc' ), 'abc default compiler' );
39 } );
40
41 QUnit.test( 'Template, get module that is not loaded.', 2, function ( assert ) {
42 assert.throws( function () {
43 mw.template.get( 'this.should.not.exist', 'hello' );
44 }, 'When bad module name given throw error.' );
45
46 assert.throws( function () {
47 mw.template.get( 'mediawiki.templates', 'hello' );
48 }, 'The template hello should not exist in the mediawiki.templates module and should throw an exception.' );
49 } );
50
51 }( mediaWiki, jQuery ) );