diff --git a/includes/engines/LuaCommon/LuaEngine.php b/includes/engines/LuaCommon/LuaEngine.php index 969c6b8b..5f136864 100644 --- a/includes/engines/LuaCommon/LuaEngine.php +++ b/includes/engines/LuaCommon/LuaEngine.php @@ -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 ); } diff --git a/tests/phpunit/engines/LuaCommon/CommonTests.lua b/tests/phpunit/engines/LuaCommon/CommonTests.lua index fef18edf..80fd5f85 100644 --- a/tests/phpunit/engines/LuaCommon/CommonTests.lua +++ b/tests/phpunit/engines/LuaCommon/CommonTests.lua @@ -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)", + }, } ) diff --git a/tests/phpunit/engines/LuaCommon/LuaCommonTest.php b/tests/phpunit/engines/LuaCommon/LuaCommonTest.php index eac72fda..e8be6108 100644 --- a/tests/phpunit/engines/LuaCommon/LuaCommonTest.php +++ b/tests/phpunit/engines/LuaCommon/LuaCommonTest.php @@ -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() ); + } }