mediawiki-extensions-Visual.../modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterSearchWidget.test.js
Thiemo Kreuz 6757a1bfa9 Character = is not allowed in template parameter names
It's allowed in values, but not in parameter names. The moment
a parameter name contains an `=` the parameter name will be cut
off at this point, and what's behind the `=` will become part
of the value.

You can test this on any live wiki. Open VisualEditor. Edit any
template. Add a parameter with a name like `a=` and some value.
Switch to wikitext mode and back. Edit the template. The `=` is
now part of the value.

Bug: T98065
Change-Id: I5e00e8fac987471243605816b041d3638927ac3b
2021-07-04 14:03:21 +02:00

51 lines
1.5 KiB
JavaScript

( function () {
/**
* @param {string[]} [knownParameters]
* @return {ve.dm.MWTemplateModel} but it's a mock
*/
function makeTemplateMock( knownParameters ) {
const spec = {
getKnownParameterNames: () => knownParameters || [],
getParameterLabel: () => '',
getParameterAliases: () => [],
getParameterDescription: () => '',
isParameterDeprecated: () => false
};
return {
connect: () => {},
getSpec: () => spec,
hasParameter: () => false
};
}
QUnit.module( 've.ui.MWParameterSearchWidget' );
QUnit.test( 'Forbidden characters in parameter names', ( assert ) => {
const template = makeTemplateMock(),
widget = new ve.ui.MWParameterSearchWidget( template );
widget.query.setValue( '{{|p=}}' );
widget.addResults();
const items = widget.results.getItems();
assert.strictEqual( items.length, 1 );
assert.strictEqual( items[ 0 ].getData().name, 'p' );
} );
QUnit.test( 'Unknown parameter partly matches a known parameter', ( assert ) => {
const template = makeTemplateMock( [ 'abbreviation' ] ),
widget = new ve.ui.MWParameterSearchWidget( template );
widget.query.setValue( 'abbr' );
widget.addResults();
const items = widget.results.getItems();
assert.strictEqual( items.length, 2 );
assert.strictEqual( items[ 0 ].getData().name, 'abbr' );
assert.strictEqual( items[ 0 ].getData().description, 'visualeditor-parameter-search-unknown' );
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
} );
}() );