Merge "mw.jqueryMsg: Add tests for non-string parameters to functions that expect...
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jqueryMsg.test.js
index 2491ca3..7e6ceb7 100644 (file)
                assert.strictEqual( logSpy.callCount, 2, 'mw.log.warn calls' );
        } );
 
+       QUnit.test( 'Non-string parameters to various functions', function ( assert ) {
+               var i, cases;
+
+               // For jquery-param-grammar
+               mw.language.setData( 'en', 'grammarTransformations', {
+                       test: [
+                               [ 'x', 'y' ]
+                       ]
+               } );
+
+               cases = [
+                       {
+                               key: 'jquery-param-wikilink',
+                               msg: '[[$1]] [[$1|a]]',
+                               expected: '<a title="x" href="/wiki/x">x</a> <a title="x" href="/wiki/x">a</a>'
+                       },
+                       {
+                               key: 'jquery-param-plural',
+                               msg: '{{PLURAL:$1|a|b}}',
+                               expected: 'b'
+                       },
+                       {
+                               key: 'jquery-param-gender',
+                               msg: '{{GENDER:$1|a|b}}',
+                               expected: 'a'
+                       },
+                       {
+                               key: 'jquery-param-grammar',
+                               msg: '{{GRAMMAR:test|$1}}',
+                               expected: '{{GRAMMAR:test|$1}}'
+                       },
+                       {
+                               key: 'jquery-param-int',
+                               msg: '{{int:$1}}',
+                               expected: '{{int:$1}}'
+                       },
+                       {
+                               key: 'jquery-param-ns',
+                               msg: '{{ns:$1}}',
+                               expected: ''
+                       },
+                       {
+                               key: 'jquery-param-formatnum',
+                               msg: '{{formatnum:$1}}',
+                               expected: '[object Object]'
+                       },
+                       {
+                               key: 'jquery-param-case',
+                               msg: '{{lc:$1}} {{uc:$1}} {{lcfirst:$1}} {{ucfirst:$1}}',
+                               expected: 'x X x X'
+                       }
+               ];
+
+               for ( i = 0; i < cases.length; i++ ) {
+                       mw.messages.set( cases[ i ].key, cases[ i ].msg );
+                       assert.strictEqual(
+                               mw.message( cases[ i ].key, $( '<b>' ).text( 'x' ) ).parse(),
+                               cases[ i ].expected,
+                               cases[ i ].key
+                       );
+               }
+       } );
+
        QUnit.test( 'Integration', function ( assert ) {
                var expected, msg;