2014-05-23 09:57:58 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki test utilities.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2014-05-23 09:57:58 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
( function () {
|
|
|
|
var getDomElementSummaryCore;
|
2017-04-13 00:17:29 +00:00
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
function MWDummyTarget() {
|
|
|
|
MWDummyTarget.super.call( this );
|
2017-04-13 00:17:29 +00:00
|
|
|
}
|
2018-04-30 17:53:50 +00:00
|
|
|
OO.inheritClass( MWDummyTarget, ve.test.utils.DummyTarget );
|
|
|
|
MWDummyTarget.prototype.setDefaultMode = function () {};
|
|
|
|
MWDummyTarget.prototype.parseWikitextFragment = function () {
|
|
|
|
// Ensure a mock server is used (e.g. as in ve.ui.MWWikitextStringTransferHandler)
|
|
|
|
return new mw.Api().post();
|
|
|
|
};
|
|
|
|
ve.test.utils.MWDummyTarget = MWDummyTarget;
|
|
|
|
|
|
|
|
// Unregister MW override nodes.
|
|
|
|
// They are temporarily registered in setup/teardown.
|
|
|
|
ve.dm.modelRegistry.unregister( ve.dm.MWHeadingNode );
|
|
|
|
ve.dm.modelRegistry.unregister( ve.dm.MWPreformattedNode );
|
|
|
|
ve.dm.modelRegistry.unregister( ve.dm.MWTableNode );
|
|
|
|
ve.dm.modelRegistry.unregister( ve.dm.MWExternalLinkAnnotation );
|
|
|
|
// Re-register unregistered nodes.
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.InlineImageNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.BlockImageNode );
|
|
|
|
|
|
|
|
ve.test.utils.mwEnvironment = ( function () {
|
|
|
|
var mwPlatform, corePlatform, mwTarget, coreTarget,
|
|
|
|
overrides = [
|
|
|
|
ve.dm.MWHeadingNode,
|
|
|
|
ve.dm.MWPreformattedNode,
|
|
|
|
ve.dm.MWTableNode,
|
|
|
|
ve.dm.MWExternalLinkAnnotation
|
|
|
|
],
|
|
|
|
overridden = [
|
|
|
|
ve.dm.InlineImageNode,
|
|
|
|
ve.dm.BlockImageNode
|
|
|
|
];
|
|
|
|
|
|
|
|
corePlatform = ve.init.platform;
|
|
|
|
coreTarget = ve.init.target;
|
|
|
|
mwPlatform = new ve.init.mw.Platform();
|
|
|
|
// Disable some API requests from platform
|
|
|
|
mwPlatform.imageInfoCache = null;
|
|
|
|
// Unregister mwPlatform
|
|
|
|
ve.init.platform = corePlatform;
|
2015-05-17 09:37:34 +00:00
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
mwTarget = new ve.test.utils.MWDummyTarget();
|
|
|
|
// Unregister mwTarget
|
|
|
|
ve.init.target = coreTarget;
|
2016-10-11 19:48:02 +00:00
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
function setupOverrides() {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < overrides.length; i++ ) {
|
|
|
|
ve.dm.modelRegistry.register( overrides[ i ] );
|
|
|
|
}
|
|
|
|
for ( i = 0; i < overridden.length; i++ ) {
|
|
|
|
ve.dm.modelRegistry.unregister( overridden[ i ] );
|
|
|
|
}
|
|
|
|
ve.init.platform = mwPlatform;
|
|
|
|
ve.init.target = mwTarget;
|
|
|
|
// Ensure the current target is appended to the current fixture
|
|
|
|
$( '#qunit-fixture' ).append( ve.init.target.$element );
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
function teardownOverrides() {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < overrides.length; i++ ) {
|
|
|
|
ve.dm.modelRegistry.unregister( overrides[ i ] );
|
|
|
|
}
|
|
|
|
for ( i = 0; i < overridden.length; i++ ) {
|
|
|
|
ve.dm.modelRegistry.register( overridden[ i ] );
|
|
|
|
}
|
|
|
|
ve.init.platform = corePlatform;
|
|
|
|
ve.init.target = coreTarget;
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
// On load, teardown overrides so the first core tests run correctly
|
|
|
|
teardownOverrides();
|
2015-05-17 09:37:34 +00:00
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
return {
|
|
|
|
setup: setupOverrides,
|
|
|
|
teardown: teardownOverrides
|
|
|
|
};
|
|
|
|
}() );
|
2015-09-24 15:37:21 +00:00
|
|
|
|
2018-04-30 17:53:50 +00:00
|
|
|
getDomElementSummaryCore = ve.getDomElementSummary;
|
2015-09-24 15:37:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override getDomElementSummary to extract HTML from data-mw/body.html
|
|
|
|
* and make it comparable.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @inheritdoc ve#getDomElementSummary
|
|
|
|
*/
|
|
|
|
ve.getDomElementSummary = function ( element, includeHtml ) {
|
|
|
|
// "Parent" method
|
|
|
|
return getDomElementSummaryCore( element, includeHtml, function ( name, value ) {
|
|
|
|
var obj, html;
|
|
|
|
if ( name === 'data-mw' ) {
|
|
|
|
obj = JSON.parse( value );
|
|
|
|
html = ve.getProp( obj, 'body', 'html' );
|
|
|
|
if ( html ) {
|
|
|
|
obj.body.html = ve.getDomElementSummary( $( '<div>' ).html( html )[ 0 ] );
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
} );
|
|
|
|
};
|
2016-11-12 14:43:43 +00:00
|
|
|
}() );
|