jenkins-bot has submitted this change and it was merged. Change subject: Require users to load the "capiunto" module per hand ......................................................................
Require users to load the "capiunto" module per hand Bug: 69540 Change-Id: Ib73cffd929e894820d80ca9a539d448994dade4b --- M Capiunto.php M docs/infobox.wiki R includes/Hooks.php M includes/LuaLibrary.php M includes/lua/Infobox.lua R includes/lua/pure/CapiuntoInfoboxRender.lua M tests/phpunit/includes/lua/InfoboxRenderTests.lua M tests/phpunit/includes/lua/InfoboxTest.php M tests/phpunit/includes/lua/InfoboxTests.lua M tests/phpunit/output/BasicRowTest.lua M tests/phpunit/output/BasicTest.lua 11 files changed, 137 insertions(+), 122 deletions(-) Approvals: Jackmcbarn: Looks good to me, approved jenkins-bot: Verified diff --git a/Capiunto.php b/Capiunto.php index a50b718..bf7b416 100644 --- a/Capiunto.php +++ b/Capiunto.php @@ -23,14 +23,14 @@ $wgMessagesDirs['Capiunto'] = __DIR__ . '/i18n'; $wgExtensionMessagesFiles['Capiunto'] = __DIR__ . '/Capiunto.i18n.php'; -$wgAutoloadClasses['Capiunto\CapiuntoHooks'] = __DIR__ . '/Capiunto.hooks.php'; +$wgAutoloadClasses['Capiunto\Hooks'] = __DIR__ . '/includes/Hooks.php'; $wgAutoloadClasses['Capiunto\LuaLibrary'] = __DIR__ . '/includes/LuaLibrary.php'; $wgAutoloadClasses['Capiunto\Test\InfoboxModuleTest'] = __DIR__ . '/tests/phpunit/includes/lua/InfoboxTest.php'; -$wgHooks['UnitTestsList'][] = '\Capiunto\CapiuntoHooks::registerUnitTests'; -# XXX: Rather use ScribuntoExternalLibraryPaths ? -$wgHooks['ScribuntoExternalLibraries'][] = '\Capiunto\CapiuntoHooks::registerScribuntoLibraries'; -$wgHooks['BeforePageDisplay'][] = '\Capiunto\CapiuntoHooks::onBeforePageDisplay'; +$wgHooks['UnitTestsList'][] = '\Capiunto\Hooks::registerUnitTests'; +$wgHooks['ScribuntoExternalLibraries'][] = '\Capiunto\Hooks::registerScribuntoLibraries'; +$wgHooks['ScribuntoExternalLibraryPaths'][] = '\Capiunto\Hooks::registerScribuntoExternalLibraryPaths'; +$wgHooks['BeforePageDisplay'][] = '\Capiunto\Hooks::onBeforePageDisplay'; $commonModuleInfo = array( 'localBasePath' => __DIR__ . '/resources', diff --git a/docs/infobox.wiki b/docs/infobox.wiki index 8bd962f..c6a2c1c 100644 --- a/docs/infobox.wiki +++ b/docs/infobox.wiki @@ -2,7 +2,8 @@ With Capiunto Lua code to create a basic Infobox might look like this: <source lang="lua"> -mw.capiunto.Infobox.create( { +local capiunto = require 'capiunto' +capiunto.create( { title = 'Title of the Infobox' } ) :addRow( 'A label', 'some data' ) @@ -10,14 +11,14 @@ :addRow( 'Another label', 'more data' ) </source> -After creating an Infobox using the [[#mw.capiunto.Infobox.create|create]] method, content can be added in the order it will appear on the page using the various add* functions explained below. Calls +After creating an Infobox using the [[#capiunto.create|create]] method, content can be added in the order it will appear on the page using the various add* functions explained below. Calls -To convert the Infobox metatable to html either call [[#mw.capiunto.Infobox:getHtml|infobox:getHtml]] (which will return a mw.html instance with the infobox) or Lua's tostring() can be used. Also just returning the Infobox metatable is ok as Scribunto will automatically convert it to a string in order to display it on the wiki page. +To convert the Infobox metatable to html either call [[#capiunto:getHtml|infobox:getHtml]] (which will return a mw.html instance with the infobox) or Lua's tostring() can be used. Also just returning the Infobox metatable is ok as Scribunto will automatically convert it to a string in order to display it on the wiki page. -Functions documented as <code>mw.capiunto.Infobox.name</code> are available on the global <code>mw.capiunto.Infobox</code> table; functions documented as <code>mw.capiunto.Infobox:name</code> are methods of an mw.capiunto.Infobox object (see [[#mw.capiunto.Infobox.create|<code>mw.capiunto.Infobox.create</code>]]). +Functions documented as <code>capiunto.name</code> are available on the global <code>capiunto</code> table; functions documented as <code>capiunto:name</code> are methods of an capiunto object (see [[#capiunto.create|<code>capiunto.create</code>]]). -== mw.capiunto.Infobox.create == -<code>mw.capiunto.Infobox.create( options )</code> +== capiunto.create == +<code>capiunto.create( options )</code> Creates a new Infobox object, with the given <code>options</code>. Supported <code>options</code> are: @@ -51,53 +52,57 @@ *<code>options.labelStyle</code>: Applies to all label cells. *<code>options.dataStyle</code>: Applies to all data cells. -== mw.capiunto.Infobox:getHtml == +== capiunto:getHtml == <code>infobox:getHtml()</code><br> Returns a mw.html object holding the html the Infobox consists of. This can easily be converted into a string using tostring(). Example: <source lang="lua"> -local infobx = mw.capiunto.Infobox.create( { +local capiunto = require 'capiunto' +local infobx = capiunto.create( { -- ... } ) local html = tostring( infobox:getHtml() ) </source> -== mw.capiunto.Infobox:addSubHeader == +== capiunto:addSubHeader == <code>infobox:addSubHeader( text )</code><br> <code>infobox:addSubHeader( text, class )</code><br> <code>infobox:addSubHeader( text, class, style )</code><br> Adds a subheader, which will show at the top of the infobox, below the title and top text, with the given <code>text</code> to the Infobox. Optionally it's possible to pass raw CSS in the <code>style</code> parameter and a CSS class in the <code>class</code> one. -== mw.capiunto.Infobox:addImage == +== capiunto:addImage == <code>infobox:addImage( image )</code><br> <code>infobox:addImage( image, caption )</code><br> <code>infobox:addImage( image, caption, class )</code><br> Adds an <code>image</code> (passed as wikitext like <nowiki>[[File:Foo.png]]</nowiki>) to the Infobox. Optionally a <code>caption</code> can be added after the image. Also a CSS <code>class</code> can be passed which will be added to the table row wrapping the image. -== mw.capiunto.Infobox:addRow == +== capiunto:addRow == <code>infobox:addRow( label, data )</code><br> <code>infobox:addRow( label, data, class )</code><br> <code>infobox:addRow( label, data, class, rowClass )</code><br> Adds a data row to the Infobox with the given <code>label</code> (can also be left empty) and <code>data</code>. Optionally a <code>rowClass</code> which will apply to the whole table row and a <code>class</code> which will only apply to data can be added. -Please note that the rows added with this function, [[#mw.capiunto.Infobox:addWikitext|<code>mw.capiunto.Infobox:addWikitext</code>]] and [[#mw.capiunto.Infobox:addHeader|<code>mw.capiunto.Infobox:addHeader</code>]] will be rendered in the order they have been added to the Infobox. +Please note that the rows added with this function, [[#capiunto:addWikitext|<code>capiunto:addWikitext</code>]] and [[#capiunto:addHeader|<code>capiunto:addHeader</code>]] will be rendered in the order they have been added to the Infobox. -== mw.capiunto.Infobox:addHeader == +== capiunto:addHeader == <code>infobox:addHeader( header )</code><br> <code>infobox:addHeader( header, class )</code><br> Adds a header row to the Infobox with the given text (<code>header</code>). Optionally a <code>class</code> which will apply to header can be added. -Please note that the rows added with this function, [[#mw.capiunto.Infobox:addWikitext|<code>mw.capiunto.Infobox:addWikitext</code>]] and [[#mw.capiunto.Infobox:addRow|<code>mw.capiunto.Infobox:addRow</code>]] will be rendered in the order they have been added to the Infobox. +Please note that the rows added with this function, [[#capiunto:addWikitext|<code>capiunto:addWikitext</code>]] and [[#capiunto:addRow|<code>capiunto:addRow</code>]] will be rendered in the order they have been added to the Infobox. -== mw.capiunto.Infobox:addWikitext == +== capiunto:addWikitext == <code>infobox:addWikitext( text )</code><br> -Adds arbitrary wikitext to the Infobox. This can eg. be a child <code>mw.capiunto.Infobox</code> instance which has been casted to string by using Lua's <code>tostring()</code>. +Adds arbitrary wikitext to the Infobox. This can eg. be a child <code>capiunto</code> instance which has been casted to string by using Lua's <code>tostring()</code>. -Please note that the rows added with this function, [[#mw.capiunto.Infobox:addHeader|<code>mw.capiunto.Infobox:addHeader</code>]] and [[#mw.capiunto.Infobox:addRow|<code>mw.capiunto.Infobox:addRow</code>]] will be rendered in the order they have been added to the Infobox. +Please note that the rows added with this function, [[#capiunto:addHeader|<code>capiunto:addHeader</code>]] and [[#capiunto:addRow|<code>capiunto:addRow</code>]] will be rendered in the order they have been added to the Infobox. + +== CapiuntoInfoboxRender == +CapiuntoInfoboxRender is a module internally used for the rendering the Infobox. It is not supposed to be used outside of Capiunto as its interfaces can change at any time. diff --git a/Capiunto.hooks.php b/includes/Hooks.php similarity index 72% rename from Capiunto.hooks.php rename to includes/Hooks.php index 70bd562..3534048 100644 --- a/Capiunto.hooks.php +++ b/includes/Hooks.php @@ -13,7 +13,7 @@ * * @author Marius Hoch < h...@online.de > */ -final class CapiuntoHooks { +class Hooks { /** * Hook to add PHPUnit test cases. * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList @@ -24,7 +24,7 @@ */ public static function registerUnitTests( array &$files ) { // @codeCoverageIgnoreStart - $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/phpunit/' ); + $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/../tests/phpunit/' ); /** * @var SplFileInfo $fileInfo @@ -51,8 +51,28 @@ return true; } - $extraLibraries['mw.capiunto.Infobox'] = '\Capiunto\LuaLibrary'; - $extraLibraries['mw.capiunto.Infobox._render'] = '\Capiunto\LuaLibrary'; + $extraLibraries['capiunto'] = array( + 'class' => '\Capiunto\LuaLibrary', + 'deferLoad' => true + ); + + return true; + } + + /** + * External Lua library paths for Scribunto + * + * @param string $engine + * @param array $extraLibraryPaths + * @return bool + */ + public static function registerScribuntoExternalLibraryPaths( $engine, array &$extraLibraryPaths ) { + if ( $engine !== 'lua' ) { + return true; + } + + // Path containing pure Lua libraries that don't need to interact with PHP + $extraLibraryPaths[] = __DIR__ . '/lua/pure'; return true; } diff --git a/includes/LuaLibrary.php b/includes/LuaLibrary.php index 0ff7575..6d689eb 100644 --- a/includes/LuaLibrary.php +++ b/includes/LuaLibrary.php @@ -15,10 +15,15 @@ /** * Register the library + * + * @return array */ public function register() { - $this->getEngine()->registerInterface( __DIR__ . '/lua/Infobox.lua', array(), array() ); - $this->getEngine()->registerInterface( __DIR__ . '/lua/InfoboxRender.lua', array(), array() ); + return $this->getEngine()->registerInterface( + __DIR__ . '/lua/Infobox.lua', + array(), + array() + ); } } diff --git a/includes/lua/Infobox.lua b/includes/lua/Infobox.lua index 60997d6..f29ad0d 100644 --- a/includes/lua/Infobox.lua +++ b/includes/lua/Infobox.lua @@ -52,7 +52,7 @@ function methodtable.getHtml( t ) local html = mw.html.create( '' ) local args = t.args - local render = mw.capiunto.Infobox._render + local render = require( 'CapiuntoInfoboxRender' ) html = render.renderWrapper( html, args ) diff --git a/includes/lua/InfoboxRender.lua b/includes/lua/pure/CapiuntoInfoboxRender.lua similarity index 94% rename from includes/lua/InfoboxRender.lua rename to includes/lua/pure/CapiuntoInfoboxRender.lua index 66f3cd0..01ad548 100644 --- a/includes/lua/InfoboxRender.lua +++ b/includes/lua/pure/CapiuntoInfoboxRender.lua @@ -277,14 +277,4 @@ end end -mw_interface = nil - --- Register this module in the "mw.capiunto" global -mw = mw or {} -mw.capiunto = mw.capiunto or {} -mw.capiunto.Infobox = mw.capiunto.Infobox or {} -mw.capiunto.Infobox._render = render - -package.loaded['mw.capiunto.Infobox._render'] = render - return render diff --git a/tests/phpunit/includes/lua/InfoboxRenderTests.lua b/tests/phpunit/includes/lua/InfoboxRenderTests.lua index 175cc43..cb5c62e 100644 --- a/tests/phpunit/includes/lua/InfoboxRenderTests.lua +++ b/tests/phpunit/includes/lua/InfoboxRenderTests.lua @@ -1,16 +1,12 @@ --[[ - Unit tests for the mw.capiunto.Infobox._render module + Unit tests for the CapiuntoInfoboxRender module @license GNU GPL v2+ @author Marius Hoch < h...@online.de > ]] local testframework = require 'Module:TestFramework' -local render = mw.capiunto.Infobox._render - -local function testExists() - return type( mw.capiunto.Infobox._render ) -end +local render = require 'CapiuntoInfoboxRender' -- Tests @@ -86,112 +82,109 @@ -- Tests local tests = { - { name = 'mw.capiunto.Infobox._render exists', func = testExists, type='ToString', - expect = { 'table' } - }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 1', func = testRenderWrapper, type='ToString', + { name = 'CapiuntoInfoboxRender.renderWrapper 1', func = testRenderWrapper, type='ToString', args = { {} }, expect = { '<table class="mw-capiunto-infobox" cellspacing="3"></table>' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 2', func = testRenderWrapper, type='ToString', + { name = 'CapiuntoInfoboxRender.renderWrapper 2', func = testRenderWrapper, type='ToString', args = { { isChild = true } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 3', func = testRenderWrapper, type='ToString', + { name = 'CapiuntoInfoboxRender.renderWrapper 3', func = testRenderWrapper, type='ToString', args = { { isChild = true, title = 'foo' } }, expect = { 'foo' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 4', func = testRenderWrapper, type='ToString', + { name = 'CapiuntoInfoboxRender.renderWrapper 4', func = testRenderWrapper, type='ToString', args = { { isSubbox = true } }, expect = { '<table class="mw-capiunto-infobox mw-capiunto-infobox-subbox" cellspacing="3"></table>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 1', func = testRenderHeader, type='ToString', + { name = 'CapiuntoInfoboxRender.renderHeader 1', func = testRenderHeader, type='ToString', args = { {}, 'foo' }, expect = { '<tr><th colspan="2" class="mw-capiunto-infobox-header">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 2', func = testRenderHeader, type='ToString', + { name = 'CapiuntoInfoboxRender.renderHeader 2', func = testRenderHeader, type='ToString', args = { {}, 'foo', 'bar' }, expect = { '<tr><th colspan="2" class="mw-capiunto-infobox-header bar">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 3', func = testRenderHeader, type='ToString', + { name = 'CapiuntoInfoboxRender.renderHeader 3', func = testRenderHeader, type='ToString', args = { { headerStyle = 'what:ever' }, 'foo', 'bar' }, expect = { '<tr><th colspan="2" class="mw-capiunto-infobox-header bar" style="what:ever">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 1', func = testRenderRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRow 1', func = testRenderRow, type='ToString', args = { {}, { data = 'foo' } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 2', func = testRenderRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRow 2', func = testRenderRow, type='ToString', args = { {}, { data = 'foo', label = 'bar' } }, expect = { '<tr><th scope="row" class="mw-capiunto-infobox-label">bar</th><td>\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 3', func = testRenderRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRow 3', func = testRenderRow, type='ToString', args = { { labelStyle = 'a:b' }, { data = 'foo', label = 'bar' } }, expect = { '<tr><th scope="row" class="mw-capiunto-infobox-label" style="a:b">bar</th><td>\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 4', func = testRenderRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRow 4', func = testRenderRow, type='ToString', args = { {}, { data = 'foo', class='meh', dataStyle="a:b" } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning meh" style="a:b">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderWikitext 1', func = testRenderWikitext, type='ToString', + { name = 'CapiuntoInfoboxRender.renderWikitext 1', func = testRenderWikitext, type='ToString', args = { 'abc' }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning">\nabc</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTitle 1', func = testRenderTitle, type='ToString', + { name = 'CapiuntoInfoboxRender.renderTitle 1', func = testRenderTitle, type='ToString', args = { { title = 'cd' } }, expect = { '<caption>cd</caption>' } }, - { name = 'mw.capiunto.Infobox._render.renderTitle 2', func = testRenderTitle, type='ToString', + { name = 'CapiuntoInfoboxRender.renderTitle 2', func = testRenderTitle, type='ToString', args = { { title = 'cd', titleClass = 'ab', titleStyle = 'wikidata:awesome' } }, expect = { '<caption class="ab" style="wikidata:awesome">cd</caption>' } }, - { name = 'mw.capiunto.Infobox._render.renderSubHeaders 1', func = testRenderSubHeader, type='ToString', + { name = 'CapiuntoInfoboxRender.renderSubHeaders 1', func = testRenderSubHeader, type='ToString', args = { { subHeaders = { { text = 'foo' } } } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderSubHeaders 2', func = testRenderSubHeader, type='ToString', + { name = 'CapiuntoInfoboxRender.renderSubHeaders 2', func = testRenderSubHeader, type='ToString', args = { { subHeaders = { { text = 'foo', style = 'a' } } } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning" style="a">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 1', func = testRenderTopRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderTopRow 1', func = testRenderTopRow, type='ToString', args = { {} }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 2', func = testRenderTopRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderTopRow 2', func = testRenderTopRow, type='ToString', args = { { top = 'foo' } }, expect = { '<tr><th colspan="2" class="mw-capiunto-infobox-top">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 3', func = testRenderTopRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderTopRow 3', func = testRenderTopRow, type='ToString', args = { { top = 'foo', topClass = 'a', topStyle='b' } }, expect = { '<tr><th colspan="2" class="mw-capiunto-infobox-top a" style="b">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 1', func = testRenderBottomRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderBottomRow 1', func = testRenderBottomRow, type='ToString', args = { {} }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderBottomRow 2', func = testRenderBottomRow, type='ToString', args = { { bottom = 'foo' } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-bottom">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', + { name = 'CapiuntoInfoboxRender.renderBottomRow 2', func = testRenderBottomRow, type='ToString', args = { { bottom = 'foo', bottomClass = 'a', bottomStyle = 'b' } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-bottom a" style="b">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 1', func = testRenderImages, type='ToString', + { name = 'CapiuntoInfoboxRender.renderImages 1', func = testRenderImages, type='ToString', args = { { } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 2', func = testRenderImages, type='ToString', + { name = 'CapiuntoInfoboxRender.renderImages 2', func = testRenderImages, type='ToString', args = { { captionStyle = 'a:b', images = { { image = '[[File:Foo.bar]]', caption="a" } }, } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning">\n[[File:Foo.bar]]<br /><div style="a:b">a</div></td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 3', func = testRenderImages, type='ToString', + { name = 'CapiuntoInfoboxRender.renderImages 3', func = testRenderImages, type='ToString', args = { { imageStyle = 'a', imageClass="b", images = { { image = 'img' } }, } }, expect = { '<tr><td colspan="2" class="mw-capiunto-infobox-spanning b" style="a">\nimg</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 4', func = testRenderImages, type='ToString', + { name = 'CapiuntoInfoboxRender.renderImages 4', func = testRenderImages, type='ToString', args = { { images = { { image = '[[File:Foo.bar]]' }, @@ -204,11 +197,11 @@ '<tr class="D-Class"><td colspan="2" class="mw-capiunto-infobox-spanning">\n[[File:B]]<br /><div>C</div></td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRows 1', func = testRenderRows, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRows 1', func = testRenderRows, type='ToString', args = { { } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderRows 2', func = testRenderRows, type='ToString', + { name = 'CapiuntoInfoboxRender.renderRows 2', func = testRenderRows, type='ToString', args = { { rows = { { data = 'foo', label = 'bar' }, diff --git a/tests/phpunit/includes/lua/InfoboxTest.php b/tests/phpunit/includes/lua/InfoboxTest.php index 99ad99b..4461872 100644 --- a/tests/phpunit/includes/lua/InfoboxTest.php +++ b/tests/phpunit/includes/lua/InfoboxTest.php @@ -4,7 +4,7 @@ use Scribunto_LuaEngineTestBase; /** - * Tests for mw.capiunto.Infobox + * Tests for capiunto * * @license GNU GPL v2+ * diff --git a/tests/phpunit/includes/lua/InfoboxTests.lua b/tests/phpunit/includes/lua/InfoboxTests.lua index a5b38e1..b260d4e 100644 --- a/tests/phpunit/includes/lua/InfoboxTests.lua +++ b/tests/phpunit/includes/lua/InfoboxTests.lua @@ -7,10 +7,10 @@ local testframework = require 'Module:TestFramework' -require 'mw.capiunto.Infobox' +local capiunto = require 'capiunto' local function getNewEmpty() - return mw.capiunto.Infobox.create() + return capiunto.create() end local function getStringNumNilError( name ) @@ -48,11 +48,11 @@ end local function createType( val ) - return type( mw.capiunto.Infobox.create( { bodyClass = val } ) ) + return type( capiunto.create( { bodyClass = val } ) ) end local function getHtmlType( child ) - local box = mw.capiunto.Infobox.create( { isChild = child } ) + local box = capiunto.create( { isChild = child } ) return type( box:getHtml() ) end @@ -61,7 +61,7 @@ options = options or {} options.isChild = true - local box = mw.capiunto.Infobox.create( options ) + local box = capiunto.create( options ) return box:getHtml() end @@ -69,7 +69,7 @@ -- Tests local function testExists() - return type( mw.capiunto.Infobox ) + return type( capiunto ) end local function testCreate() @@ -115,150 +115,150 @@ -- Tests local tests = { - { name = 'mw.capiunto.Infobox exists', func = testExists, type='ToString', + { name = 'capiunto exists', func = testExists, type='ToString', expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.create', func = testCreate, type='ToString', + { name = 'capiunto.create', func = testCreate, type='ToString', expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.create (validation 1)', func = createType, type='ToString', + { name = 'capiunto.create (validation 1)', func = createType, type='ToString', args = { {} }, expect = 'Option bodyClass must be either of type string, number or nil' }, - { name = 'mw.capiunto.Infobox.create (validation 2)', func = createType, type='ToString', + { name = 'capiunto.create (validation 2)', func = createType, type='ToString', args = { function() end }, expect = 'Option bodyClass must be either of type string, number or nil' }, - { name = 'mw.capiunto.Infobox.create (validation 3)', func = createType, type='ToString', + { name = 'capiunto.create (validation 3)', func = createType, type='ToString', args = { nil }, expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.create (validation 4)', func = createType, type='ToString', + { name = 'capiunto.create (validation 4)', func = createType, type='ToString', args = { 123 }, expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.create (validation 5)', func = createType, type='ToString', + { name = 'capiunto.create (validation 5)', func = createType, type='ToString', args = { 'foo' }, expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.getHtml (type)', func = getHtmlType, type='ToString', + { name = 'capiunto.getHtml (type)', func = getHtmlType, type='ToString', args = { false }, expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.getHtml (type - child box)', func = getHtmlType, type='ToString', + { name = 'capiunto.getHtml (type - child box)', func = getHtmlType, type='ToString', args = { true }, expect = { 'table' } }, - { name = 'mw.capiunto.Infobox.getHtml (child box - empty)', func = getHtmlChild, type='ToString', + { name = 'capiunto.getHtml (child box - empty)', func = getHtmlChild, type='ToString', expect = { '' } }, - { name = 'mw.capiunto.Infobox.getHtml (child box - title)', func = getHtmlChild, type='ToString', + { name = 'capiunto.getHtml (child box - title)', func = getHtmlChild, type='ToString', args = { { title = 'Lalalala' } }, expect = { 'Lalalala' } }, - { name = 'mw.capiunto.Infobox.addSubHeader 1', func = addSubHeader, + { name = 'capiunto.addSubHeader 1', func = addSubHeader, args = { 'foo' }, expect = { { { text = 'foo', style = nil, class = nil } } } }, - { name = 'mw.capiunto.Infobox.addSubHeader 2', func = addSubHeader, + { name = 'capiunto.addSubHeader 2', func = addSubHeader, args = { 'foo', 'cd', 'ab' }, expect = { { { text = 'foo', style = 'ab', class = 'cd' } } } }, - { name = 'mw.capiunto.Infobox.addSubHeader (invalid input 1)', func = addSubHeader, + { name = 'capiunto.addSubHeader (invalid input 1)', func = addSubHeader, args = {}, expect = getStringNumError( 'text' ) }, - { name = 'mw.capiunto.Infobox.addSubHeader (invalid input 2)', func = addSubHeader, + { name = 'capiunto.addSubHeader (invalid input 2)', func = addSubHeader, args = { {} }, expect = getStringNumError( 'text' ) }, - { name = 'mw.capiunto.Infobox.addSubHeader (invalid input 3)', func = addSubHeader, + { name = 'capiunto.addSubHeader (invalid input 3)', func = addSubHeader, args = { 'whatever', {} }, expect = getStringNumNilError( 'class' ) }, - { name = 'mw.capiunto.Infobox.addSubHeader (invalid input 4)', func = addSubHeader, + { name = 'capiunto.addSubHeader (invalid input 4)', func = addSubHeader, args = { 'whatever', nil, function() end }, expect = getStringNumNilError( 'style' ) }, - { name = 'mw.capiunto.Infobox.addImage 1', func = addImage, + { name = 'capiunto.addImage 1', func = addImage, args = { 'foo' }, expect = { { { image = 'foo', caption = nil, class = nil } } } }, - { name = 'mw.capiunto.Infobox.addImage 2', func = addImage, + { name = 'capiunto.addImage 2', func = addImage, args = { 'foo', 'ab', 'cd' }, expect = { { { image = 'foo', caption = 'ab', class = 'cd' } } } }, - { name = 'mw.capiunto.Infobox.addImage (invalid input 1)', func = addImage, + { name = 'capiunto.addImage (invalid input 1)', func = addImage, expect = getStringNumError( 'image' ) }, - { name = 'mw.capiunto.Infobox.addImage (invalid input 2)', func = addImage, + { name = 'capiunto.addImage (invalid input 2)', func = addImage, args = { {} }, expect = getStringNumError( 'image' ) }, - { name = 'mw.capiunto.Infobox.addImage (invalid input 3)', func = addImage, + { name = 'capiunto.addImage (invalid input 3)', func = addImage, args = { 'a', {}, 'da' }, expect = getStringNumNilError( 'caption' ) }, - { name = 'mw.capiunto.Infobox.addImage (invalid input 4)', func = addImage, + { name = 'capiunto.addImage (invalid input 4)', func = addImage, args = { 'what', nil, {} }, expect = getStringNumNilError( 'class' ) }, - { name = 'mw.capiunto.Infobox.addHeader (invalid input 1)', func = addHeader, + { name = 'capiunto.addHeader (invalid input 1)', func = addHeader, expect = getStringNumError( 'header' ) }, - { name = 'mw.capiunto.Infobox.addHeader (invalid input 3)', func = addHeader, + { name = 'capiunto.addHeader (invalid input 3)', func = addHeader, args = { {} }, expect = getStringNumError( 'header' ) }, - { name = 'mw.capiunto.Infobox.addHeader (invalid input 3)', func = addHeader, + { name = 'capiunto.addHeader (invalid input 3)', func = addHeader, args = { 'foo', function() end }, expect = getStringNumNilError( 'class' ) }, - { name = 'mw.capiunto.Infobox.addRow (no label)', func = addRow, + { name = 'capiunto.addRow (no label)', func = addRow, args = { nil, 'foo' }, expect = { { { data = 'foo' } } } }, - { name = 'mw.capiunto.Infobox.addRow (invalid input 1)', func = addRow, + { name = 'capiunto.addRow (invalid input 1)', func = addRow, expect = getStringNumError( 'data' ) }, - { name = 'mw.capiunto.Infobox.addRow (invalid input 2)', func = addRow, + { name = 'capiunto.addRow (invalid input 2)', func = addRow, args = { {}, 'a' }, expect = getStringNumNilError( 'label' ) }, - { name = 'mw.capiunto.Infobox.addRow (invalid input 3)', func = addRow, + { name = 'capiunto.addRow (invalid input 3)', func = addRow, args = { nil, 'a', {} }, expect = getStringNumNilError( 'class' ) }, - { name = 'mw.capiunto.Infobox.addRow (invalid input 4)', func = addRow, + { name = 'capiunto.addRow (invalid input 4)', func = addRow, args = { nil, 'a', nil, function() end }, expect = getStringNumNilError( 'rowClass' ) }, - { name = 'mw.capiunto.Infobox.addWikitext (invalid input 1)', func = addWikitext, + { name = 'capiunto.addWikitext (invalid input 1)', func = addWikitext, expect = 'text must be either of type string, number or table' }, - { name = 'mw.capiunto.Infobox.addWikitext (invalid input 2)', func = addWikitext, + { name = 'capiunto.addWikitext (invalid input 2)', func = addWikitext, args = { function() end }, expect = 'text must be either of type string, number or table' }, - { name = 'mw.capiunto.Infobox.addWikitext (table)', func = addWikitext, + { name = 'capiunto.addWikitext (table)', func = addWikitext, args = { stringTable }, expect = { { { wikitext = 'called proper tostring' } } } }, - { name = 'mw.capiunto.Infobox.addSubHeader', func = testAddSubHeader, + { name = 'capiunto.addSubHeader', func = testAddSubHeader, expect = { { { text = 'Subheader' }, { text = 'woo', style = 'hoo' }, { text = 'abc', class = 'def' }, } } }, - { name = 'mw.capiunto.Infobox.addImage', func = testAddImage, + { name = 'capiunto.addImage', func = testAddImage, expect = { { { image = '[[File:Foo]]' }, { image = 'woo', caption = 'hoo' }, { image = 'abc', class = 'def' }, } } }, - { name = 'mw.capiunto.Infobox.addRow/addHeader/addWikitext', func = testAddRowAddHeaderAddWikitext, + { name = 'capiunto.addRow/addHeader/addWikitext', func = testAddRowAddHeaderAddWikitext, expect = { { { header = 'Header 1' }, { data = '#1 row->data', label = '#1 row->label' }, diff --git a/tests/phpunit/output/BasicRowTest.lua b/tests/phpunit/output/BasicRowTest.lua index 77b90cf..8e8c7f3 100644 --- a/tests/phpunit/output/BasicRowTest.lua +++ b/tests/phpunit/output/BasicRowTest.lua @@ -1,7 +1,8 @@ local p = {} p.run = function() - local box = mw.capiunto.Infobox.create( { + local capiunto = require 'capiunto' + local box = capiunto.create( { title = 'Infobox Data Test!' } ) box diff --git a/tests/phpunit/output/BasicTest.lua b/tests/phpunit/output/BasicTest.lua index 5cdba70..84fd7a2 100644 --- a/tests/phpunit/output/BasicTest.lua +++ b/tests/phpunit/output/BasicTest.lua @@ -1,7 +1,8 @@ local p = {} p.run = function() - local box = mw.capiunto.Infobox.create( { + local capiunto = require 'capiunto' + local box = capiunto.create( { name = 'Foo bar', top = 'Text in uppermost cell of infobox', } ) -- To view, visit https://gerrit.wikimedia.org/r/163063 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib73cffd929e894820d80ca9a539d448994dade4b Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/Capiunto Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> Gerrit-Reviewer: Adrian Lang <adrian.he...@wikimedia.de> Gerrit-Reviewer: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Jens Ohlig <jens.oh...@wikimedia.de> Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits