Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / resources / src / mediawiki.util.js
index 65fe3d3..66c1fe7 100644 (file)
@@ -1,7 +1,9 @@
 ( function () {
        'use strict';
 
-       var util;
+       var util,
+               config = require( './config.json' ),
+               origConfig = config;
 
        /**
         * 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
                 *
@@ -68,7 +84,7 @@
                 * @return {string} Encoded string
                 */
                escapeIdForAttribute: function ( str ) {
-                       var mode = mw.config.get( 'wgFragmentMode' )[ 0 ];
+                       var mode = config.FragmentMode[ 0 ];
 
                        return escapeIdInternal( str, mode );
                },
@@ -83,7 +99,7 @@
                 * @return {string} Encoded string
                 */
                escapeIdForLink: function ( str ) {
-                       var mode = mw.config.get( 'wgFragmentMode' )[ 0 ];
+                       var mode = config.FragmentMode[ 0 ];
 
                        return escapeIdInternal( str, mode );
                },
                        if ( str === 'index' ) {
                                return mw.config.get( 'wgScript' );
                        } else if ( str === 'load' ) {
-                               return mw.config.get( 'wgLoadScript' );
+                               return config.LoadScript;
                        } else {
                                return mw.config.get( 'wgScriptPath' ) + '/' + str + '.php';
                        }
                        $portlet.removeClass( 'emptyPortlet' );
 
                        // Setup the list item (and a span if $portlet is a Vector tab)
+                       // eslint-disable-next-line no-jquery/no-class-state
                        if ( $portlet.hasClass( 'vectorTabs' ) ) {
                                item = $( '<li>' ).append( $( '<span>' ).append( link )[ 0 ] )[ 0 ];
                        } else {