Merge "user: Allow "CAS update failed" exceptions to be normalised"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.jqueryMsg.test.js
index 7701170..8c6f788 100644 (file)
@@ -1,4 +1,4 @@
-( function ( mw, $ ) {
+( function () {
        /* eslint-disable camelcase */
        var formatText, formatParse, formatnumTests, specialCharactersPageName, expectedListUsers,
                expectedListUsersSitename, expectedLinkPagenamee, expectedEntrypoints,
                                        skin: mw.config.get( 'skin' ),
                                        lang: langCode,
                                        debug: mw.config.get( 'debug' ),
-                                       modules: [
-                                               'mediawiki.language.data',
-                                               'mediawiki.language'
-                                       ].join( '|' ),
+                                       modules: 'mediawiki.language',
                                        only: 'scripts'
                                },
                                dataType: 'script',
        QUnit.test( 'Match PHP parser', function ( assert ) {
                var tasks;
                mw.messages.set( mw.libs.phpParserData.messages );
-               tasks = $.map( mw.libs.phpParserData.tests, function ( test ) {
+               tasks = mw.libs.phpParserData.tests.map( function ( test ) {
                        var done = assert.async();
                        return function ( next, abort ) {
                                getMwLanguage( test.lang )
                                getMwLanguage( test.lang )
                                        .then( function ( langClass ) {
                                                var parser;
+                                               // The unit tests perform hot-reloading of mw.language (in hacky way).
+                                               // For the languages/*.js script files to work, they need to statically
+                                               // access mw.language.getData() for the "current" language.
+                                               mw.language = langClass;
                                                mw.config.set( 'wgUserLanguage', test.lang );
                                                parser = new mw.jqueryMsg.Parser( { language: langClass } );
                                                assert.strictEqual(
                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-int
+               mw.messages.set( 'x', 'y' );
+               // 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: '<b>x</b>'
+                       },
+                       {
+                               key: 'jquery-param-int',
+                               msg: '{{int:$1}}',
+                               expected: 'y'
+                       },
+                       {
+                               key: 'jquery-param-ns',
+                               msg: '{{ns:$1}}',
+                               expected: ''
+                       },
+                       {
+                               key: 'jquery-param-formatnum',
+                               msg: '{{formatnum:$1}}',
+                               expected: '<b>x</b>'
+                       },
+                       {
+                               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;
 
                        'setParserDefaults is deep if requested'
                );
        } );
-}( mediaWiki, jQuery ) );
+}() );