mediawiki-extensions-Popups/tests/node-qunit/stubs.js
Sam Smith fb8d54c7ce actions/rest: Use DB-key version of title
This reduces the number of 301 Redirect responses when fetching previews
from RESTBase.

Bug: T167633
Change-Id: I830947ab79e72dcc023193412c8d5bcee986e23f
2017-06-12 11:22:55 +01:00

68 lines
1.5 KiB
JavaScript

/**
* Creates a **minimal** stub that can be used in place of an `mw.User`
* instance.
*
* @param {boolean} isAnon The return value of the `#isAnon`.
* @return {Object}
*/
exports.createStubUser = function createStubUser( isAnon ) {
return {
isAnon: function () {
return isAnon;
},
sessionId: function () {
return '0123456789';
}
};
};
/**
* Creates a **minimal** stub that can be used in place of an `mw.Map`
* instance.
*
* @return {mw.Map}
*/
exports.createStubMap = function createStubMap() {
var m = new Map(); /* global Map */
m.get = function ( key, fallback ) {
fallback = arguments.length > 1 ? fallback : null;
if ( typeof key === 'string' ) {
return m.has( key ) ? Map.prototype.get.call( m, key ) : fallback;
}
// Invalid selection key
return null;
};
return m;
};
/**
* Creates a stub that can be used as a replacement to mw.experiements
* @param {bool} isSampled If `true` then the `getBucket` method will
* return 'A' otherwise 'control'.
* @return {object}
*/
exports.createStubExperiments = function createStubExperiments( isSampled ) {
return {
getBucket: function () {
return isSampled ? 'A' : 'control';
}
};
};
/**
* Creates a **minimal** stub that can be used in place of an instance of
* `mw.Title`.
*
* @param {Number} namespace
* @param {String} prefixedDb, e.g. Foo, or File:Bar.jpg
* @return {Object}
*/
exports.createStubTitle = function createStubTitle( namespace, prefixedDb ) {
return {
namespace: namespace,
getPrefixedDb: function () {
return prefixedDb;
}
};
};