From 76e72fd4c4262e71b7dc927cb07bf4957cc78554 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 10 Sep 2018 11:03:42 +0200 Subject: [PATCH] mw.jqueryMsg: Add tests for non-string parameters to functions that expect strings I'm changing some of these behaviors in the next commit. Bug: T203892 Change-Id: Ie806a4c3aac18d1df6d5eac1b77c8032f88cf18e --- .../mediawiki/mediawiki.jqueryMsg.test.js | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js index e4cf4461d5..2bbc2b57e7 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js @@ -1154,6 +1154,69 @@ 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: 'x 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, $( '' ).text( 'x' ) ).parse(), + cases[ i ].expected, + cases[ i ].key + ); + } + } ); + QUnit.test( 'Integration', function ( assert ) { var expected, msg; -- 2.20.1