mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-24 00:05:00 +00:00
Add tests and type checking for mw.addWarning()
Testing was overlooked when this was added in Ibdd2506f. Change-Id: Ie17020e3082668180dfa1d6532946891ea7951ea
This commit is contained in:
parent
5644e235b1
commit
34fc672f6d
|
@ -874,6 +874,9 @@ abstract class Scribunto_LuaEngine extends ScribuntoEngineBase {
|
|||
* @param string $text wikitext
|
||||
*/
|
||||
public function addWarning( $text ) {
|
||||
$args = func_get_args();
|
||||
$this->checkString( 'addWarning', $args, 0 );
|
||||
|
||||
$this->getParser()->getOutput()->addWarning( $text );
|
||||
}
|
||||
|
||||
|
|
|
@ -384,4 +384,13 @@ return testframework.getTestProvider( {
|
|||
func = test.loadData.rawset,
|
||||
expect = { 'ugh', 'foo bar', 'foo bar' },
|
||||
},
|
||||
|
||||
{ name = 'mw.addWarning',
|
||||
func = mw.addWarning, args = { 'warn' },
|
||||
expect = {},
|
||||
},
|
||||
{ name = 'mw.addWarning, bad type',
|
||||
func = mw.addWarning, args = { true },
|
||||
expect = "bad argument #1 to 'addWarning' (string expected)",
|
||||
},
|
||||
} )
|
||||
|
|
|
@ -828,4 +828,27 @@ class Scribunto_LuaCommonTest extends Scribunto_LuaEngineTestBase {
|
|||
$text = $parser->mStripState->unstripBoth( $text );
|
||||
$this->assertSame( '>false<', $text );
|
||||
}
|
||||
|
||||
public function testAddWarning() {
|
||||
$engine = $this->getEngine();
|
||||
$parser = $engine->getParser();
|
||||
$pp = $parser->getPreprocessor();
|
||||
|
||||
$this->extraModules['Module:TestAddWarning'] = '
|
||||
local p = {}
|
||||
|
||||
p.foo = function ()
|
||||
mw.addWarning( "Don\'t panic!" )
|
||||
return "ok"
|
||||
end
|
||||
|
||||
return p
|
||||
';
|
||||
|
||||
$frame = $pp->newFrame();
|
||||
$text = $frame->expand( $pp->preprocessToObj( ">{{#invoke:TestAddWarning|foo}}<" ) );
|
||||
$text = $parser->mStripState->unstripBoth( $text );
|
||||
$this->assertSame( '>ok<', $text );
|
||||
$this->assertSame( [ 'Don\'t panic!' ], $parser->getOutput()->getWarnings() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue