mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-18 19:55:55 +00:00
44623c9b2a
These have been pointing to the same method for a while now, we can safely remove these obsolete aliases and just use it as generic copy. * Each file touched by my editor had its new line at EOF fixed where absent * Don't copy an otherwise unused empty object (ve.dm.Converter) * Use common ve#copy syntax instead to create a link (ve.dm.Document, ve.dm.example) * Remove redundant conditionals for isArray/copyArray/copyObject (ve.dm.example) Change-Id: If560e658dc1fb59bf01f702c97e3e82a50a8a255
99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
/*!
|
|
* VisualEditor initialization tests.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.init.Platform', {
|
|
setup: function () {
|
|
this.platform = ve.init.platform;
|
|
|
|
// Clone and deference instance
|
|
ve.init.platform = ve.cloneObject( ve.init.platform );
|
|
|
|
// Reset internal properties needed to keep tests atomic
|
|
ve.init.platform.parsedMessages = {};
|
|
|
|
// Platform specific properties
|
|
// TODO: Perhaps this warrants a clearMessages() method?
|
|
if ( ve.init.sa && ve.init.platform instanceof ve.init.sa.Platform ) {
|
|
ve.init.platform.messages = {};
|
|
} else if ( ve.init.mw && ve.init.platform instanceof ve.init.mw.Platform ) {
|
|
/*global mw */
|
|
this.mwMessagesValues = ve.copy( mw.messages.values );
|
|
}
|
|
},
|
|
teardown: function () {
|
|
ve.init.platform = this.platform;
|
|
if ( ve.init.mw && ve.init.platform instanceof ve.init.mw.Platform ) {
|
|
/*global mw */
|
|
mw.messages.values = this.mwMessagesValues;
|
|
}
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'messages', 4, function ( assert ) {
|
|
var platform = ve.init.platform;
|
|
|
|
assert.strictEqual(
|
|
platform.getMessage( 'foo' ),
|
|
'<foo>',
|
|
'return bracket-wrapped key as fallback'
|
|
);
|
|
|
|
platform.addMessages( {
|
|
foo: 'Foo & Bar <quux action="followed">by</quux>!',
|
|
bacon: 'Bacon <&> Ipsum: $1'
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
platform.getMessage( 'foo' ),
|
|
'Foo & Bar <quux action="followed">by</quux>!',
|
|
'return plain message'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
platform.getMessage( 'bacon', 10 ),
|
|
'Bacon <&> Ipsum: 10',
|
|
'return plain message with $# replacements'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
platform.getMessage( 'quux' ),
|
|
'<quux>',
|
|
'return bracket-wrapped key as fallback (after set up)'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'parsedMessage', 3, function ( assert ) {
|
|
var platform = ve.init.platform;
|
|
|
|
assert.strictEqual(
|
|
platform.getParsedMessage( 'foo' ),
|
|
'<foo>',
|
|
'return html escaped brackets in wrapped-key fallback'
|
|
);
|
|
|
|
platform.addMessages( {
|
|
foo: 'Foo & Bar <quux action="followed">by</quux>!',
|
|
bacon: 'Bacon <&> Ipsum: $1'
|
|
} );
|
|
|
|
platform.addParsedMessages( {
|
|
foo: 'Foo <quux><html></quux>'
|
|
} );
|
|
|
|
assert.strictEqual(
|
|
platform.getParsedMessage( 'foo' ),
|
|
'Foo <quux><html></quux>',
|
|
'prefer value from parsedMessage store'
|
|
);
|
|
|
|
assert.strictEqual(
|
|
platform.getParsedMessage( 'bacon', 10 ),
|
|
'Bacon <&> Ipsum: $1',
|
|
'fall back to html-escaped version of plain message, no $# replacements'
|
|
);
|
|
} );
|