Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.template.test.js
1 ( function () {
2
3 QUnit.module( 'mediawiki.template', {
4 beforeEach: function () {
5 var abcCompiler = {
6 compile: function () {
7 return 'abc default compiler';
8 }
9 };
10
11 // Register some template compiler languages
12 mw.template.registerCompiler( 'abc', abcCompiler );
13 mw.template.registerCompiler( 'xyz', {
14 compile: function () {
15 return 'xyz compiler';
16 }
17 } );
18
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 } );
24 }
25 } );
26
27 QUnit.test( 'add', function ( assert ) {
28 assert.throws(
29 function () {
30 mw.template.add( 'module', 'test_templates_foo', 'hello' );
31 },
32 'When no prefix throw exception'
33 );
34 } );
35
36 QUnit.test( 'compile', function ( assert ) {
37 assert.throws(
38 function () {
39 mw.template.compile( '{{foo}}', 'rainbow' );
40 },
41 'Unknown compiler names throw exceptions'
42 );
43 } );
44
45 QUnit.test( 'get', 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' );
51 },
52 'When bad module name given throw error.'
53 );
54
55 assert.throws(
56 function () {
57 mw.template.get( 'mediawiki.template', 'hello' );
58 },
59 'The template hello should not exist in the mediawiki.templates module and should throw an exception.'
60 );
61 } );
62
63 }() );