Merge "Convert MWBlockImage dimensions to numbers and update tests"

This commit is contained in:
jenkins-bot 2013-10-16 09:56:43 +00:00 committed by Gerrit Code Review
commit fdf40f1655
3 changed files with 227 additions and 235 deletions

View file

@ -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+/ ) : [];

View file

@ -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++;

View file

@ -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="{&quot;tsr&quot;:[0,24],&quot;optList&quot;:[{&quot;ck&quot;:&quot;width&quot;,&quot;ak&quot;:&quot;500px&quot;}],&quot;cacheKey&quot;:&quot;[[Image:Wiki.png|500px]]&quot;,&quot;img&quot;:{&quot;h&quot;:155,&quot;w&quot;:135,&quot;wdset&quot;:true},&quot;dsr&quot;:[0,24,null,null]}"><a href="./File:Wiki.png" data-parsoid="{&quot;a&quot;:{&quot;href&quot;:&quot;./File:Wiki.png&quot;}}"><img resource="./File:Wiki.png" src="http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png" height="155" width="135" data-parsoid="{&quot;a&quot;:{&quot;resource&quot;:&quot;./File:Wiki.png&quot;,&quot;width&quot;:&quot;135&quot;},&quot;sa&quot;:{&quot;resource&quot;:&quot;Image:Wiki.png&quot;,&quot;width&quot;:&quot;500&quot;}}"></a></span>';
ve.dm.mwExample.MWTransclusion = {
'blockOpen': '<div about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;target&quot;:{&quot;wt&quot;:&quot;Test&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;Hello, world!&quot;}},&quot;id&quot;:&quot;mwt1&quot;}" data-parsoid="{&quot;tsr&quot;:[18,40],&quot;src&quot;:&quot;{{Test|Hello, world!}}&quot;,&quot;dsr&quot;:[18,40,null,null]}"></div>',
'blockOpenModified': '<div about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;id&quot;:&quot;mwt1&quot;,&quot;target&quot;:{&quot;wt&quot;:&quot;Test&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;Hello, globe!&quot;}}}" data-parsoid="{&quot;tsr&quot;:[18,40],&quot;src&quot;:&quot;{{Test|Hello, world!}}&quot;,&quot;dsr&quot;:[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': []