mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
Merge "Convert MWBlockImage dimensions to numbers and update tests"
This commit is contained in:
commit
fdf40f1655
|
@ -62,11 +62,14 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
|
|||
type: this.rdfaToType[typeofAttr],
|
||||
href: $imgWrapper.attr( 'href' ) || '',
|
||||
src: $img.attr( 'src' ),
|
||||
width: $img.attr( 'width' ),
|
||||
height: $img.attr( 'height' ),
|
||||
resource: $img.attr( 'resource' ),
|
||||
originalClasses: classes
|
||||
};
|
||||
},
|
||||
width = $img.attr( 'width' ),
|
||||
height = $img.attr( 'height' );
|
||||
|
||||
attributes.width = width !== undefined && width !== '' ? Number( width ) : null;
|
||||
attributes.height = height !== undefined && height !== '' ? Number( height ) : null;
|
||||
|
||||
// Extract individual classes
|
||||
classes = typeof classes === 'string' ? classes.trim().split( /\s+/ ) : [];
|
||||
|
|
|
@ -12,10 +12,11 @@ QUnit.module( 've.ce.Document' );
|
|||
// FIXME runner copypasted from core, use data provider
|
||||
QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert ) {
|
||||
var documentModel, documentView, i, j, expectCount = 0,
|
||||
store = new ve.dm.IndexValueStore(),
|
||||
tests = [
|
||||
{
|
||||
data: [
|
||||
/* 0 */ { type: 'mwBlockImage' },
|
||||
/* 0 */ ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
||||
/* 1 */ { type: '/mwBlockImage' }
|
||||
],
|
||||
cases: [
|
||||
|
@ -83,9 +84,9 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert
|
|||
},
|
||||
{
|
||||
data: [
|
||||
/* 0 */ { type: 'mwBlockImage' },
|
||||
/* 0 */ ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
||||
/* 1 */ { type: '/mwBlockImage' },
|
||||
/* 2 */ { type: 'mwBlockImage' },
|
||||
/* 2 */ ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
||||
/* 3 */ { type: '/mwBlockImage' }
|
||||
],
|
||||
cases: [
|
||||
|
@ -125,7 +126,7 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert
|
|||
data: [
|
||||
/* 0 */ { type: 'alienBlock' },
|
||||
/* 1 */ { type: '/alienBlock' },
|
||||
/* 2 */ { type: 'mwBlockImage' },
|
||||
/* 2 */ ve.copy( ve.dm.mwExample.MWBlockImage.data[0] ),
|
||||
/* 3 */ { type: '/mwBlockImage' },
|
||||
/* 4 */ { type: 'alienBlock' },
|
||||
/* 5 */ { type: '/alienBlock' }
|
||||
|
@ -180,7 +181,7 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert
|
|||
/* 0 */ { type: 'paragraph' },
|
||||
/* 1 */ { type: 'alienInline' },
|
||||
/* 2 */ { type: '/alienInline' },
|
||||
/* 3 */ { type: 'mwInlineImage' },
|
||||
/* 3 */ ve.copy( ve.dm.mwExample.MWInlineImage.data ),
|
||||
/* 4 */ { type: '/mwInlineImage' },
|
||||
/* 5 */ { type: 'alienInline' },
|
||||
/* 6 */ { type: '/alienInline' },
|
||||
|
@ -202,8 +203,9 @@ QUnit.test( 'getRelativeRange (mwBlockImage / mwInlineImage)', function ( assert
|
|||
]
|
||||
}
|
||||
];
|
||||
|
||||
for ( i = 0; i < tests.length; i++ ) {
|
||||
documentModel = new ve.dm.Document( tests[i].data );
|
||||
documentModel = new ve.dm.Document( new ve.dm.ElementLinearData( store, tests[i].data ) );
|
||||
documentView = new ve.ce.Document( documentModel );
|
||||
for ( j = 0; j < tests[i].cases.length; j++ ) {
|
||||
expectCount++;
|
||||
|
|
|
@ -16,7 +16,6 @@ ve.dm.mwExample.createExampleDocument = function ( name, store ) {
|
|||
return ve.dm.example.createExampleDocumentFromObject( name, store, ve.dm.mwExample );
|
||||
};
|
||||
|
||||
ve.dm.mwExample.MWInlineImageHtml = '<span typeof="mw:Image" class="foo mw-valign-text-top" data-parsoid="{"tsr":[0,24],"optList":[{"ck":"width","ak":"500px"}],"cacheKey":"[[Image:Wiki.png|500px]]","img":{"h":155,"w":135,"wdset":true},"dsr":[0,24,null,null]}"><a href="./File:Wiki.png" data-parsoid="{"a":{"href":"./File:Wiki.png"}}"><img resource="./File:Wiki.png" src="http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png" height="155" width="135" data-parsoid="{"a":{"resource":"./File:Wiki.png","width":"135"},"sa":{"resource":"Image:Wiki.png","width":"500"}}"></a></span>';
|
||||
ve.dm.mwExample.MWTransclusion = {
|
||||
'blockOpen': '<div about="#mwt1" typeof="mw:Transclusion" data-mw="{"target":{"wt":"Test"},"params":{"1":{"wt":"Hello, world!"}},"id":"mwt1"}" data-parsoid="{"tsr":[18,40],"src":"{{Test|Hello, world!}}","dsr":[18,40,null,null]}"></div>',
|
||||
'blockOpenModified': '<div about="#mwt1" typeof="mw:Transclusion" data-mw="{"id":"mwt1","target":{"wt":"Test"},"params":{"1":{"wt":"Hello, globe!"}}}" data-parsoid="{"tsr":[18,40],"src":"{{Test|Hello, world!}}","dsr":[18,40,null,null]}"></div>',
|
||||
|
@ -140,8 +139,8 @@ ve.dm.mwExample.MWBlockImage = {
|
|||
'align': 'right',
|
||||
'href': 'Foo',
|
||||
'src': 'Bar',
|
||||
'width': '1',
|
||||
'height': '2',
|
||||
'width': 1,
|
||||
'height': 2,
|
||||
'resource': 'FooBar',
|
||||
'originalClasses': 'mw-halign-right foobar',
|
||||
'unrecognizedClasses': ['foobar']
|
||||
|
@ -156,6 +155,29 @@ ve.dm.mwExample.MWBlockImage = {
|
|||
]
|
||||
};
|
||||
|
||||
ve.dm.mwExample.MWInlineImage = {
|
||||
'html':
|
||||
'<span typeof="mw:Image" class="foo mw-valign-text-top">' +
|
||||
'<a href="./File:Wiki.png">' +
|
||||
'<img resource="./File:Wiki.png" src="http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png" height="155" width="135">' +
|
||||
'</a>' +
|
||||
'</span>',
|
||||
'data': {
|
||||
'type': 'mwInlineImage',
|
||||
'attributes': {
|
||||
'src': 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png',
|
||||
'href': './File:Wiki.png',
|
||||
'width': 135,
|
||||
'height': 155,
|
||||
'isLinked': true,
|
||||
'valign': 'text-top',
|
||||
'resource': './File:Wiki.png',
|
||||
'type': 'inline',
|
||||
'originalClasses': 'foo mw-valign-text-top',
|
||||
'unrecognizedClasses': ['foo']
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
ve.dm.mwExample.MWReference = {
|
||||
'referenceList':
|
||||
|
@ -740,45 +762,10 @@ ve.dm.mwExample.domToDataCases = {
|
|||
'</body>'
|
||||
},
|
||||
'mw:Image': {
|
||||
'html': '<body><p>' + ve.dm.mwExample.MWInlineImageHtml + '</p></body>',
|
||||
'html': '<body><p>' + ve.dm.mwExample.MWInlineImage.html + '</p></body>',
|
||||
'data': [
|
||||
{ 'type': 'paragraph' },
|
||||
{
|
||||
'type': 'mwInlineImage',
|
||||
'attributes': {
|
||||
'src': 'http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png',
|
||||
'href': './File:Wiki.png',
|
||||
'width': 135,
|
||||
'height': 155,
|
||||
'isLinked': true,
|
||||
'valign': 'text-top',
|
||||
'resource': './File:Wiki.png',
|
||||
'type': 'inline',
|
||||
'originalClasses': 'foo mw-valign-text-top',
|
||||
'unrecognizedClasses': ['foo']
|
||||
},
|
||||
'htmlAttributes': [
|
||||
{
|
||||
'values': {
|
||||
'data-parsoid': '{\"tsr\":[0,24],\"optList\":[{\"ck\":\"width\",\"ak\":\"500px\"}],\"cacheKey\":\"[[Image:Wiki.png|500px]]\",\"img\":{\"h\":155,\"w\":135,\"wdset\":true},\"dsr\":[0,24,null,null]}'
|
||||
},
|
||||
'children': [
|
||||
{
|
||||
'values': {
|
||||
'data-parsoid': '{\"a\":{\"href\":\"./File:Wiki.png\"}}'
|
||||
},
|
||||
'children': [
|
||||
{
|
||||
'values': {
|
||||
'data-parsoid': '{\"a\":{\"resource\":\"./File:Wiki.png\",\"width\":\"135\"},\"sa\":{\"resource\":\"Image:Wiki.png\",\"width\":\"500\"}}'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
ve.dm.mwExample.MWInlineImage.data,
|
||||
{ 'type': '/mwInlineImage' },
|
||||
{ 'type': '/paragraph' },
|
||||
{ 'type': 'internalList' },
|
||||
|
@ -1670,8 +1657,8 @@ ve.dm.mwExample.domToDataCases = {
|
|||
'align': 'default',
|
||||
'href': 'Foo',
|
||||
'src': 'Bar',
|
||||
'width': '1',
|
||||
'height': '2',
|
||||
'width': 1,
|
||||
'height': 2,
|
||||
'resource': 'FooBar',
|
||||
'originalClasses': undefined,
|
||||
'unrecognizedClasses': []
|
||||
|
|
Loading…
Reference in a new issue