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:
Brad Jorsch 2020-04-03 11:26:59 -04:00 committed by Jforrester
parent 5644e235b1
commit 34fc672f6d
3 changed files with 35 additions and 0 deletions

View file

@ -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 );
}

View file

@ -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)",
},
} )

View file

@ -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() );
}
}