mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
381472ac99
Rewrite VisualEditorMessagesModule: * Replace copy-paste dump of user-css module with stuff for VisualEditor (class commend and module::$origin). * Remove duplication between getMessages and getScript. * Actually implement getModifiedTime so that the comment in getMessages() about cache invalidation is actually true Fixes bug 42670: ext.visualEditor.specialMessages cache broken ve.init: * Implement addParsedMessages and getParsedMessage so that we don't mix up plain messages with raw html messages (minoredit was previously overloaded in mw.msg storage with a parsed html message and retrieved though ve.msg, which is documented as retuning plain text, not raw html). This is now separated into a different method. * Improved documentation of the other msg methods to emphasise their differences * Removed redundant code in attachSaveDialog() that was (partially) already done in setupSaveDialog() and moved the remaining bits into it as well. Checked all callers of these and they are both only called from ViewPageTarget.prototype.onLoad * Also implement them in the standalone platform implementation, with the html escaper based on mw.html.escape * Update init.platform.getMessage to use undefined instead of discouraged 'if-in' statement. * Add test suite. demos/test: * Re-run makeStaticLoader.php on test to add ve.init.Platform.test * Re-run makeStaticLoader.php on demos and update i18n caller to use ve.init.platform.addParsedMessages (also moved out of the auto-generated block for easier updating) Change-Id: I7f26b47e9467e850c08b9c217c4f1098590de109
99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
/**
|
|
* VisualEditor initialization tests.
|
|
*
|
|
* @copyright 2011-2012 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.copyObject( 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'
|
|
);
|
|
} );
|