Make MessageCache::load() require a language code
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.template.test.js
blob86fd828a9a7d205bb0e8e28f38541687ace209f9
1 ( function ( mw ) {
3 QUnit.module( 'mediawiki.template', {
4 setup: function () {
5 var abcCompiler = {
6 compile: function () {
7 return 'abc default compiler';
9 };
11 // Register some template compiler languages
12 mw.template.registerCompiler( 'abc', abcCompiler );
13 mw.template.registerCompiler( 'xyz', {
14 compile: function () {
15 return 'xyz compiler';
17 } );
19 // Stub register some templates
20 this.sandbox.stub( mw.templates, 'get' ).returns( {
21 'test_templates_foo.xyz': 'goodbye',
22 'test_templates_foo.abc': 'thankyou'
23 } );
25 } );
27 QUnit.test( 'add', 1, function ( assert ) {
28 assert.throws(
29 function () {
30 mw.template.add( 'module', 'test_templates_foo', 'hello' );
32 'When no prefix throw exception'
34 } );
36 QUnit.test( 'compile', 1, function ( assert ) {
37 assert.throws(
38 function () {
39 mw.template.compile( '{{foo}}', 'rainbow' );
41 'Unknown compiler names throw exceptions'
43 } );
45 QUnit.test( 'get', 4, function ( assert ) {
46 assert.strictEqual( mw.template.get( 'test.mediawiki.template', 'test_templates_foo.xyz' ), 'xyz compiler' );
47 assert.strictEqual( mw.template.get( 'test.mediawiki.template', 'test_templates_foo.abc' ), 'abc default compiler' );
48 assert.throws(
49 function () {
50 mw.template.get( 'this.should.not.exist', 'hello' );
52 'When bad module name given throw error.'
55 assert.throws(
56 function () {
57 mw.template.get( 'mediawiki.template', 'hello' );
59 'The template hello should not exist in the mediawiki.templates module and should throw an exception.'
61 } );
63 }( mediaWiki ) );