qunit: Make use of 'config' and 'messages' shortcuts in module setup
authorumherirrender <umherirrender_de.wp@web.de>
Wed, 7 May 2014 18:41:01 +0000 (20:41 +0200)
committerMatthew Flaschen <mflaschen@wikimedia.org>
Wed, 14 May 2014 00:00:40 +0000 (20:00 -0400)
While calling mw.config and mw.messages manually works fine (the sandbox
covers mw.config and mw.messages in general, not just when using the
shortcut), let's consistently use the shortcuts.

Also clean up the extra local variable in some cases.

Change-Id: I9ac467ad87816c7dc681b62e9b085b643024c15e

tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.Title.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.jqueryMsg.test.js
tests/qunit/suites/resources/mediawiki/mediawiki.test.js

index d9801d9..9216ac9 100644 (file)
@@ -1,5 +1,5 @@
 ( function ( $, mw ) {
-       var config, header,
+       var header,
 
                // Data set "simple"
                a1 = [ 'A', '1' ],
                        ['February 05 2010']
                ];
 
-       config = {
-               wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
-               wgMonthNamesShort: ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
-               wgDefaultDateFormat: 'dmy',
-               wgSeparatorTransformTable: ['', ''],
-               wgDigitTransformTable: ['', ''],
-               wgContentLanguage: 'en'
-       };
-
-       QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment( { config: config } ) );
+       QUnit.module( 'jquery.tablesorter', QUnit.newMwEnvironment( {
+               config: {
+                       wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
+                       wgMonthNamesShort: ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
+                       wgDefaultDateFormat: 'dmy',
+                       wgSeparatorTransformTable: ['', ''],
+                       wgDigitTransformTable: ['', ''],
+                       wgContentLanguage: 'en'
+               }
+       } ) );
 
        /**
         * Create an HTML table from an array of row arrays containing text strings.
index 61d662b..077ce70 100644 (file)
@@ -1,60 +1,6 @@
 /*jshint -W024 */
 ( function ( mw, $ ) {
-       // mw.Title relies on these three config vars
-       // Restore them after each test run
-       var config = {
-               wgFormattedNamespaces: {
-                       '-2': 'Media',
-                       '-1': 'Special',
-                       0: '',
-                       1: 'Talk',
-                       2: 'User',
-                       3: 'User talk',
-                       4: 'Wikipedia',
-                       5: 'Wikipedia talk',
-                       6: 'File',
-                       7: 'File talk',
-                       8: 'MediaWiki',
-                       9: 'MediaWiki talk',
-                       10: 'Template',
-                       11: 'Template talk',
-                       12: 'Help',
-                       13: 'Help talk',
-                       14: 'Category',
-                       15: 'Category talk',
-                       // testing custom / localized namespace
-                       100: 'Penguins'
-               },
-               wgNamespaceIds: {
-                       'media': -2,
-                       'special': -1,
-                       '': 0,
-                       'talk': 1,
-                       'user': 2,
-                       'user_talk': 3,
-                       'wikipedia': 4,
-                       'wikipedia_talk': 5,
-                       'file': 6,
-                       'file_talk': 7,
-                       'mediawiki': 8,
-                       'mediawiki_talk': 9,
-                       'template': 10,
-                       'template_talk': 11,
-                       'help': 12,
-                       'help_talk': 13,
-                       'category': 14,
-                       'category_talk': 15,
-                       'image': 6,
-                       'image_talk': 7,
-                       'project': 4,
-                       'project_talk': 5,
-                       // Testing custom namespaces and aliases
-                       'penguins': 100,
-                       'antarctic_waterfowl': 100
-               },
-               wgCaseSensitiveNamespaces: []
-       },
-       repeat = function ( input, multiplier ) {
+       var repeat = function ( input, multiplier ) {
                return new Array( multiplier + 1 ).join( input );
        },
        cases = {
                ]
        };
 
-       QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment( { config: config } ) );
+       QUnit.module( 'mediawiki.Title', QUnit.newMwEnvironment( {
+               // mw.Title relies on these three config vars
+               // Restore them after each test run
+               config: {
+                       wgFormattedNamespaces: {
+                               '-2': 'Media',
+                               '-1': 'Special',
+                               0: '',
+                               1: 'Talk',
+                               2: 'User',
+                               3: 'User talk',
+                               4: 'Wikipedia',
+                               5: 'Wikipedia talk',
+                               6: 'File',
+                               7: 'File talk',
+                               8: 'MediaWiki',
+                               9: 'MediaWiki talk',
+                               10: 'Template',
+                               11: 'Template talk',
+                               12: 'Help',
+                               13: 'Help talk',
+                               14: 'Category',
+                               15: 'Category talk',
+                               // testing custom / localized namespace
+                               100: 'Penguins'
+                       },
+                       wgNamespaceIds: {
+                               'media': -2,
+                               'special': -1,
+                               '': 0,
+                               'talk': 1,
+                               'user': 2,
+                               'user_talk': 3,
+                               'wikipedia': 4,
+                               'wikipedia_talk': 5,
+                               'file': 6,
+                               'file_talk': 7,
+                               'mediawiki': 8,
+                               'mediawiki_talk': 9,
+                               'template': 10,
+                               'template_talk': 11,
+                               'help': 12,
+                               'help_talk': 13,
+                               'category': 14,
+                               'category_talk': 15,
+                               'image': 6,
+                               'image_talk': 7,
+                               'project': 4,
+                               'project_talk': 5,
+                               // Testing custom namespaces and aliases
+                               'penguins': 100,
+                               'antarctic_waterfowl': 100
+                       },
+                       wgCaseSensitiveNamespaces: []
+               }
+       } ) );
 
        QUnit.test( 'constructor', cases.invalid.length, function ( assert ) {
                var i, title;
index 995c1ed..682eb3d 100644 (file)
                setup: function () {
                        this.originalMwLanguage = mw.language;
 
-                       // Messages that are reused in multiple tests
-                       mw.messages.set( {
-                               // The values for gender are not significant,
-                               // what matters is which of the values is choosen by the parser
-                               'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
-                               'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
-
-                               'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
-
-                               // Assume the grammar form grammar_case_foo is not valid in any language
-                               'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
-
-                               'formatnum-msg': '{{formatnum:$1}}',
-
-                               'portal-url': 'Project:Community portal',
-                               'see-portal-url': '{{Int:portal-url}} is an important community page.',
-
-                               'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
-
-                               'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
-
-                               'external-link-replace': 'Foo [$1 bar]'
-                       } );
-
-                       mw.config.set( {
-                               wgArticlePath: '/wiki/$1'
-                       } );
-
                        specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
 
                        expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
                },
                teardown: function () {
                        mw.language = this.originalMwLanguage;
+               },
+               config: {
+                       wgArticlePath: '/wiki/$1'
+               },
+               // Messages that are reused in multiple tests
+               messages: {
+                       // The values for gender are not significant,
+                       // what matters is which of the values is choosen by the parser
+                       'gender-msg': '$1: {{GENDER:$2|blue|pink|green}}',
+                       'gender-msg-currentuser': '{{GENDER:|blue|pink|green}}',
+
+                       'plural-msg': 'Found $1 {{PLURAL:$1|item|items}}',
+
+                       // Assume the grammar form grammar_case_foo is not valid in any language
+                       'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
+
+                       'formatnum-msg': '{{formatnum:$1}}',
+
+                       'portal-url': 'Project:Community portal',
+                       'see-portal-url': '{{Int:portal-url}} is an important community page.',
+
+                       'jquerymsg-test-statistics-users': '注册[[Special:ListUsers|用户]]',
+
+                       'jquerymsg-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
+
+                       'external-link-replace': 'Foo [$1 bar]'
                }
        } ) );
 
index a9b2f33..90700ca 100644 (file)
@@ -9,26 +9,24 @@
 
        QUnit.module( 'mediawiki', QUnit.newMwEnvironment( {
                setup: function () {
-                       // Messages used in multiple tests
-                       mw.messages.set( {
-                               'other-message': 'Other Message',
-                               'mediawiki-test-pagetriage-del-talk-page-notify-summary': 'Notifying author of deletion nomination for [[$1]]',
-                               'gender-plural-msg': '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome',
-                               'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
-                               'formatnum-msg': '{{formatnum:$1}}',
-                               'int-msg': 'Some {{int:other-message}}',
-                               'mediawiki-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
-                               'external-link-replace': 'Foo [$1 bar]'
-                       } );
-
-                       mw.config.set( {
-                               wgArticlePath: '/wiki/$1',
-
-                               // For formatnum tests
-                               wgUserLanguage: 'en'
-                       } );
-
                        specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
+               },
+               config: {
+                       wgArticlePath: '/wiki/$1',
+
+                       // For formatnum tests
+                       wgUserLanguage: 'en'
+               },
+               // Messages used in multiple tests
+               messages: {
+                       'other-message': 'Other Message',
+                       'mediawiki-test-pagetriage-del-talk-page-notify-summary': 'Notifying author of deletion nomination for [[$1]]',
+                       'gender-plural-msg': '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome',
+                       'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
+                       'formatnum-msg': '{{formatnum:$1}}',
+                       'int-msg': 'Some {{int:other-message}}',
+                       'mediawiki-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
+                       'external-link-replace': 'Foo [$1 bar]'
                }
        } ) );