2014-05-23 09:57:58 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki test utilities.
|
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2014-05-23 09:57:58 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
ve.test.utils.createSurfaceFromDocument = function ( doc ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var target, mwTarget;
|
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
// Prevent the target from setting up the surface immediately
|
2014-08-13 19:35:15 +00:00
|
|
|
ve.init.platform.initialized = $.Deferred();
|
2015-08-19 18:05:01 +00:00
|
|
|
|
2014-05-23 09:57:58 +00:00
|
|
|
// HACK: MW targets are async and heavy, use an SA target but
|
|
|
|
// override the global registration
|
2015-08-19 18:05:01 +00:00
|
|
|
target = new ve.init.sa.Target();
|
2015-12-10 16:07:50 +00:00
|
|
|
mwTarget = new ve.init.mw.ArticleTarget();
|
2014-05-23 09:57:58 +00:00
|
|
|
|
2014-12-09 22:09:35 +00:00
|
|
|
$( '#qunit-fixture' ).append( target.$element );
|
2014-12-03 00:04:07 +00:00
|
|
|
target.addSurface( doc );
|
|
|
|
|
2014-08-13 19:35:15 +00:00
|
|
|
ve.init.platform.initialized.resolve();
|
2014-05-23 09:57:58 +00:00
|
|
|
mwTarget = null;
|
2014-12-03 00:04:07 +00:00
|
|
|
target.addSurface( doc );
|
2014-05-23 09:57:58 +00:00
|
|
|
return target.surface;
|
|
|
|
};
|
2015-05-17 09:37:34 +00:00
|
|
|
|
|
|
|
// 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 );
|
2016-03-17 15:30:59 +00:00
|
|
|
ve.dm.modelRegistry.unregister( ve.dm.MWExternalLinkAnnotation );
|
2015-05-17 09:37:34 +00:00
|
|
|
// Re-register unregistered nodes.
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.InlineImageNode );
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.BlockImageNode );
|
|
|
|
|
|
|
|
ve.test.utils.mwEnvironment = ( function () {
|
|
|
|
var overrides = [
|
|
|
|
ve.dm.MWHeadingNode,
|
|
|
|
ve.dm.MWPreformattedNode,
|
2016-03-17 15:30:59 +00:00
|
|
|
ve.dm.MWTableNode,
|
|
|
|
ve.dm.MWExternalLinkAnnotation
|
2015-05-17 09:37:34 +00:00
|
|
|
],
|
2015-05-16 17:02:33 +00:00
|
|
|
overridden = [
|
|
|
|
ve.dm.InlineImageNode,
|
|
|
|
ve.dm.BlockImageNode
|
|
|
|
];
|
2015-05-17 09:37:34 +00:00
|
|
|
|
|
|
|
function setupOverrides() {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < overrides.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.dm.modelRegistry.register( overrides[ i ] );
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
for ( i = 0; i < overridden.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.dm.modelRegistry.unregister( overridden[ i ] );
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function teardownOverrides() {
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < overrides.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.dm.modelRegistry.unregister( overrides[ i ] );
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
for ( i = 0; i < overridden.length; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
ve.dm.modelRegistry.register( overridden[ i ] );
|
2015-05-17 09:37:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// On load, teardown overrides so the first core tests run correctly
|
|
|
|
teardownOverrides();
|
|
|
|
|
|
|
|
return QUnit.newMwEnvironment( {
|
|
|
|
setup: setupOverrides,
|
|
|
|
teardown: teardownOverrides
|
|
|
|
} );
|
|
|
|
} )();
|
2015-09-24 15:37:21 +00:00
|
|
|
|
|
|
|
( 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;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
} )();
|