mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-26 07:15:32 +00:00
1d7f929a91
New changes: d79138b Overwrite selected content when pasting via DataTransferItem 3c4737f Ensure clipboard is never empty text 3b1339e Create dummy platform and target for tests 4d63c8e Pass text as string to insertDocument when detected as plain text Local change: Remove VE standalone module Flow used to use it, but not anymore. Going forward no one should be using it in MW. Bug: T154020 Bug: T156302 Bug: T156498 Depends-On: I078c244ef524669da477a43f9b37c847252e5ad7 Change-Id: Ifc4be16269f819890f2dcdddbbdebf9694ad2868
115 lines
3.1 KiB
JavaScript
115 lines
3.1 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki test utilities.
|
|
*
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
ve.test.utils.createSurfaceFromDocument = function ( doc ) {
|
|
// eslint-disable-next-line no-unused-vars
|
|
var target, mwTarget;
|
|
|
|
// Prevent the target from setting up the surface immediately
|
|
ve.init.platform.initialized = $.Deferred();
|
|
|
|
// HACK: MW targets are async and heavy, use a DummyTarget
|
|
// but override the global registration
|
|
target = new ve.test.utils.DummyTarget();
|
|
mwTarget = new ve.init.mw.ArticleTarget();
|
|
|
|
$( '#qunit-fixture' ).append( target.$element );
|
|
target.addSurface( doc );
|
|
|
|
ve.init.platform.initialized.resolve();
|
|
mwTarget = null;
|
|
return target.addSurface( doc );
|
|
};
|
|
|
|
// 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,
|
|
overrides = [
|
|
ve.dm.MWHeadingNode,
|
|
ve.dm.MWPreformattedNode,
|
|
ve.dm.MWTableNode,
|
|
ve.dm.MWExternalLinkAnnotation
|
|
],
|
|
overridden = [
|
|
ve.dm.InlineImageNode,
|
|
ve.dm.BlockImageNode
|
|
];
|
|
|
|
corePlatform = ve.init.platform;
|
|
mwPlatform = new ve.init.mw.Platform();
|
|
// Disable some API requests from platform
|
|
mwPlatform.imageInfoCache = null;
|
|
// Unregister mwPlatform
|
|
ve.init.platform = corePlatform;
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// On load, teardown overrides so the first core tests run correctly
|
|
teardownOverrides();
|
|
|
|
return QUnit.newMwEnvironment( {
|
|
setup: setupOverrides,
|
|
teardown: teardownOverrides
|
|
} );
|
|
}() );
|
|
|
|
( function () {
|
|
var getDomElementSummaryCore = ve.getDomElementSummary;
|
|
|
|
/**
|
|
* 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;
|
|
} );
|
|
};
|
|
}() );
|