Follows-up
1c7c9bdf1f.
* Define the method only in test context, instead of
a run-time check.
* Return the old value, and re-use function for restoring
the result afterwards.
* Make the test define its options by default, so at to not
rely on local-wiki defaults in any way.
Change-Id: I71e92d5b9ee789b594e6e64ca3e425583fc1ee1c
- config = require( './config.json' ),
- origConfig = config;
+ config = require( './config.json' );
/**
* Encode the string like PHP's rawurlencode
/**
* Encode the string like PHP's rawurlencode
- /* Main body */
-
- setOptionsForTest: function ( opts ) {
- if ( !window.QUnit ) {
- throw new Error( 'Modifying options not allowed outside unit tests' );
- }
- config = $.extend( {}, config, opts );
- },
-
- resetOptionsForTest: function () {
- if ( !window.QUnit ) {
- throw new Error( 'Resetting options not allowed outside unit tests' );
- }
- config = origConfig;
- },
-
/**
* Encode the string like PHP's rawurlencode
*
/**
* Encode the string like PHP's rawurlencode
*
+ // Not allowed outside unit tests
+ if ( window.QUnit ) {
+ util.setOptionsForTest = function ( opts ) {
+ var oldConfig = config;
+ config = $.extend( {}, config, opts );
+ return oldConfig;
+ };
+ }
+
/**
* Initialisation of mw.util.$content
*/
/**
* Initialisation of mw.util.$content
*/
QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
setup: function () {
$.fn.updateTooltipAccessKeys.setTestMode( true );
QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
setup: function () {
$.fn.updateTooltipAccessKeys.setTestMode( true );
+ this.origConfig = mw.util.setOptionsForTest( {
+ FragmentMode: [ 'legacy', 'html5' ],
+ LoadScript: '/w/load.php'
+ } );
},
teardown: function () {
$.fn.updateTooltipAccessKeys.setTestMode( false );
},
teardown: function () {
$.fn.updateTooltipAccessKeys.setTestMode( false );
- mw.util.resetOptionsForTest();
+ mw.util.setOptionsForTest( this.origConfig );
},
messages: {
// Used by accessKeyLabel in test for addPortletLink
},
messages: {
// Used by accessKeyLabel in test for addPortletLink