Jackmcbarn has uploaded a new change for review. https://gerrit.wikimedia.org/r/164560
Change subject: Convert Capiunto to a delayed-load module ...................................................................... Convert Capiunto to a delayed-load module Instead of storing Capiunto inside mw, let it be loaded via require('capiunto'). Also, fold _render into it now that there's no reason for it to be separate. Change-Id: I23083cddb638a294aae96dc9f43f2d4f70457eb7 --- M Capiunto.hooks.php M Capiunto.php M includes/LuaLibrary.php M includes/lua/Infobox.lua D includes/lua/InfoboxRender.lua M tests/phpunit/includes/lua/InfoboxRenderTests.lua M tests/phpunit/includes/lua/InfoboxTests.lua M tests/phpunit/output/BasicRowTest.lua M tests/phpunit/output/BasicTest.lua 9 files changed, 354 insertions(+), 393 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Capiunto refs/changes/60/164560/1 diff --git a/Capiunto.hooks.php b/Capiunto.hooks.php index 70bd562..905fe1f 100644 --- a/Capiunto.hooks.php +++ b/Capiunto.hooks.php @@ -47,13 +47,10 @@ * @return bool */ public static function registerScribuntoLibraries( $engine, array &$extraLibraries ) { - if ( $engine !== 'lua' ) { - return true; + if ( $engine === 'lua' ) { + $extraLibraries['capiunto'] = array( + 'class' => '\Capiunto\LuaLibrary', 'deferLoad' => true ); } - - $extraLibraries['mw.capiunto.Infobox'] = '\Capiunto\LuaLibrary'; - $extraLibraries['mw.capiunto.Infobox._render'] = '\Capiunto\LuaLibrary'; - return true; } diff --git a/Capiunto.php b/Capiunto.php index b4b4128..f626253 100644 --- a/Capiunto.php +++ b/Capiunto.php @@ -28,7 +28,6 @@ $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'; diff --git a/includes/LuaLibrary.php b/includes/LuaLibrary.php index 0ff7575..6308269 100644 --- a/includes/LuaLibrary.php +++ b/includes/LuaLibrary.php @@ -17,8 +17,7 @@ * Register the library */ 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..14b51e6 100644 --- a/includes/lua/Infobox.lua +++ b/includes/lua/Infobox.lua @@ -12,7 +12,8 @@ @author Marius Hoch < h...@online.de > ]] -local infobox = {} +local render = {} +local infobox = { _render = render } local metatable = {} local methodtable = {} @@ -48,11 +49,281 @@ end end +-- Renders the outer wrapper for an infobox. +-- Returns the mw.html object for the new infobox +-- +-- @param html +-- @param args +function render.renderWrapper( html, args ) + if not args.isChild then + local table = html + :tag( 'table' ) + :addClass( 'mw-capiunto-infobox' ) + :attr( 'cellspacing', 3 ) + :css( 'border-spacing', '3px' ) + + if args.bodyClass then + table + :addClass( args.bodyClass ) + end + + if args.isSubbox then + table + :addClass( 'mw-capiunto-infobox-subbox' ) + else + table + :css( 'width', '22em' ) + end + + if args.bodyStyle then + table + :cssText( args.bodyStyle ) + end + + return table + else + html + :wikitext( args.title ) + + return html + end +end + +-- Adds a header to html +-- +-- @param html +-- @param args +-- @param header +-- @param class +function render.renderHeader( html, args, header, class ) + local th = html:tag( 'tr' ) + :tag( 'th' ) + :attr( 'colspan', 2 ) + :css( 'text-align', 'center' ) + :wikitext( header ) + + if class then + th:addClass( class ) + end + + if args.headerStyle then + th:cssText( args.headerStyle ) + end +end + +-- Adds a row to the infobox, with either a header cell +-- or a label/data cell combination. +-- +-- @param html +-- @param args +-- @param row +function render.renderRow( html, args, row ) + local tr = html:tag( 'tr' ) + + if row.rowClass then + tr:addClass( row.rowClass ) + end + + if row.label then + local th = tr:tag( 'th' ) + :attr( 'scope', 'row' ) + :css( 'text-align', 'left' ) + :wikitext( row.label ) + + if args.labelStyle then + th:cssText( args.labelStyle ) + end + end + + local dataCell = tr:tag( 'td' ) + if not row.label then + dataCell + :attr( 'colspan', 2 ) + :css( 'text-align', 'center' ) + end + + if row.class then + dataCell + :addClass( row.class ) + end + + if row.dataStyle then + dataCell + :cssText( row.dataStyle ) + end + + dataCell + :newline() + :wikitext( row.data ) +end + +-- Adds arbitrary wikitext +-- +-- @param html +-- @param text +function render.renderWikitext( html, text ) + render.renderRow( html, {}, { data = text } ) +end + +-- Renders the title of the infobox into a caption +-- +-- @param args +function render.renderTitle( html, args ) + if not args.title then return end + + local caption = html + :tag( 'caption' ) + :wikitext( args.title ) + + if args.titleClass then + caption:addClass( args.titleClass ) + end + if args.titleStyle then + caption:cssText( args.titleStyle ) + end +end + +-- Adds a <tr><th> with the top row to the html +-- +-- @param html +-- @param args +function render.renderTopRow( html, args ) + if not args.top then return end + + local th = html + :tag( 'tr' ) + :tag( 'th' ) + :attr( 'colspan', 2 ) + :css( { + ['text-align'] = 'center', + ['font-size'] = '125%', + ['font-weight'] = 'bold' + } ) + :wikitext( args.top ) + + if args.topClass then + th:addClass( args.topClass ) + end + + if args.topStyle then + th:cssText( args.topStyle ) + end +end + +-- Adds a <tr><td> with the bottom row to the html +-- +-- @param html +-- @param args +function render.renderBottomRow( html, args ) + if not args.bottom then return end + + local td = html + :tag( 'tr' ) + :tag( 'td' ) + :attr( 'colspan', '2' ) + :css( 'text-align', 'center' ) + :newline() + :wikitext( args.bottom ) + + if args.bottomClass then + td:addClass( args.bottomClass ) + end + + if args.bottomStyle then + td:cssText( args.bottomStyle ) + end +end + +-- Add subheader rows to the given html +-- +-- @param html +-- @param args +function render.renderSubHeaders( html, args ) + if not args.subHeaders then return end + + for i, value in pairs( args.subHeaders ) do + render.renderRow( + html, + args, + { + data = value.text, + dataStyle = value.style, + rowClass = value.class + } + ) + end +end + +-- Add images (wiki syntax) to the html +-- +-- @param html +-- @param args +function render.renderImages( html, args ) + if not args.images then return end + + for i, image in pairs( args.images ) do + local data = mw.html.create( '' ):wikitext( image.image ) + + if image.caption then + data + :tag( 'br' ) + :done() + + local div = data + :tag( 'div' ) + :wikitext( image.caption ) + + if args.captionStyle then + div:cssText( args.captionStyle ) + end + end + + render.renderRow( + html, + args, + { + data = tostring( data ), + dataStyle = args.imageStyle, + class = args.imageClass, + rowClass = image.class + } + ) + + end +end + +-- Renders all rows in order using addRow / addHeader. +-- +-- @param html +-- @param args +function render.renderRows( html, args ) + if not args.rows then return end + + for k, row in pairs( args.rows ) do + if row.header then + render.renderHeader( html, args, row.header, row.class ) + elseif row.wikitext then + render.renderWikitext( html, row.wikitext ) + else + render.renderRow( + html, + args, + { + label = row.label, + data = row.data, + dataStyle = args.dataStyle, + class = row.class, + rowClass = row.rowClass + } + ) + end + end +end + -- Gets an mw.html table representing the infobox function methodtable.getHtml( t ) local html = mw.html.create( '' ) local args = t.args - local render = mw.capiunto.Infobox._render html = render.renderWrapper( html, args ) @@ -230,12 +501,5 @@ end mw_interface = nil - --- Register this module in the "mw.capiunto" global -mw = mw or {} -mw.capiunto = mw.capiunto or {} -mw.capiunto.Infobox = infobox - -package.loaded['mw.capiunto.Infobox'] = infobox return infobox diff --git a/includes/lua/InfoboxRender.lua b/includes/lua/InfoboxRender.lua deleted file mode 100644 index bd67e3a..0000000 --- a/includes/lua/InfoboxRender.lua +++ /dev/null @@ -1,298 +0,0 @@ ---[[ - A Lua helper module for rendering Capiunto infoboxes. - - Originally written on the English Wikipedia by - Toohool and Mr. Stradivarius. - - Code released under the GPL v2+ as per: - https://en.wikipedia.org/w/index.php?diff=next&oldid=581399786 - https://en.wikipedia.org/w/index.php?diff=next&oldid=581403025 - - @license GNU GPL v2+ - @author Marius Hoch < h...@online.de > -]] - -local render = {} - --- Renders the outer wrapper for an infobox. --- Returns the mw.html object for the new infobox --- --- @param html --- @param args -function render.renderWrapper( html, args ) - if not args.isChild then - local table = html - :tag( 'table' ) - :addClass( 'mw-capiunto-infobox' ) - :attr( 'cellspacing', 3 ) - :css( 'border-spacing', '3px' ) - - if args.bodyClass then - table - :addClass( args.bodyClass ) - end - - if args.isSubbox then - table - :addClass( 'mw-capiunto-infobox-subbox' ) - else - table - :css( 'width', '22em' ) - end - - if args.bodyStyle then - table - :cssText( args.bodyStyle ) - end - - return table - else - html - :wikitext( args.title ) - - return html - end -end - --- Adds a header to html --- --- @param html --- @param args --- @param header --- @param class -function render.renderHeader( html, args, header, class ) - local th = html:tag( 'tr' ) - :tag( 'th' ) - :attr( 'colspan', 2 ) - :css( 'text-align', 'center' ) - :wikitext( header ) - - if class then - th:addClass( class ) - end - - if args.headerStyle then - th:cssText( args.headerStyle ) - end -end - --- Adds a row to the infobox, with either a header cell --- or a label/data cell combination. --- --- @param html --- @param args --- @param row -function render.renderRow( html, args, row ) - local tr = html:tag( 'tr' ) - - if row.rowClass then - tr:addClass( row.rowClass ) - end - - if row.label then - local th = tr:tag( 'th' ) - :attr( 'scope', 'row' ) - :css( 'text-align', 'left' ) - :wikitext( row.label ) - - if args.labelStyle then - th:cssText( args.labelStyle ) - end - end - - local dataCell = tr:tag( 'td' ) - if not row.label then - dataCell - :attr( 'colspan', 2 ) - :css( 'text-align', 'center' ) - end - - if row.class then - dataCell - :addClass( row.class ) - end - - if row.dataStyle then - dataCell - :cssText( row.dataStyle ) - end - - dataCell - :newline() - :wikitext( row.data ) -end - --- Adds arbitrary wikitext --- --- @param html --- @param text -function render.renderWikitext( html, text ) - render.renderRow( html, {}, { data = text } ) -end - --- Renders the title of the infobox into a caption --- --- @param args -function render.renderTitle( html, args ) - if not args.title then return end - - local caption = html - :tag( 'caption' ) - :wikitext( args.title ) - - if args.titleClass then - caption:addClass( args.titleClass ) - end - if args.titleStyle then - caption:cssText( args.titleStyle ) - end -end - --- Adds a <tr><th> with the top row to the html --- --- @param html --- @param args -function render.renderTopRow( html, args ) - if not args.top then return end - - local th = html - :tag( 'tr' ) - :tag( 'th' ) - :attr( 'colspan', 2 ) - :css( { - ['text-align'] = 'center', - ['font-size'] = '125%', - ['font-weight'] = 'bold' - } ) - :wikitext( args.top ) - - if args.topClass then - th:addClass( args.topClass ) - end - - if args.topStyle then - th:cssText( args.topStyle ) - end -end - --- Adds a <tr><td> with the bottom row to the html --- --- @param html --- @param args -function render.renderBottomRow( html, args ) - if not args.bottom then return end - - local td = html - :tag( 'tr' ) - :tag( 'td' ) - :attr( 'colspan', '2' ) - :css( 'text-align', 'center' ) - :newline() - :wikitext( args.bottom ) - - if args.bottomClass then - td:addClass( args.bottomClass ) - end - - if args.bottomStyle then - td:cssText( args.bottomStyle ) - end -end - --- Add subheader rows to the given html --- --- @param html --- @param args -function render.renderSubHeaders( html, args ) - if not args.subHeaders then return end - - for i, value in pairs( args.subHeaders ) do - render.renderRow( - html, - args, - { - data = value.text, - dataStyle = value.style, - rowClass = value.class - } - ) - end -end - --- Add images (wiki syntax) to the html --- --- @param html --- @param args -function render.renderImages( html, args ) - if not args.images then return end - - for i, image in pairs( args.images ) do - local data = mw.html.create( '' ):wikitext( image.image ) - - if image.caption then - data - :tag( 'br' ) - :done() - - local div = data - :tag( 'div' ) - :wikitext( image.caption ) - - if args.captionStyle then - div:cssText( args.captionStyle ) - end - end - - render.renderRow( - html, - args, - { - data = tostring( data ), - dataStyle = args.imageStyle, - class = args.imageClass, - rowClass = image.class - } - ) - - end -end - --- Renders all rows in order using addRow / addHeader. --- --- @param html --- @param args -function render.renderRows( html, args ) - if not args.rows then return end - - for k, row in pairs( args.rows ) do - if row.header then - render.renderHeader( html, args, row.header, row.class ) - elseif row.wikitext then - render.renderWikitext( html, row.wikitext ) - else - render.renderRow( - html, - args, - { - label = row.label, - data = row.data, - dataStyle = args.dataStyle, - class = row.class, - rowClass = row.rowClass - } - ) - end - 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 4f647e1..a27b9a0 100644 --- a/tests/phpunit/includes/lua/InfoboxRenderTests.lua +++ b/tests/phpunit/includes/lua/InfoboxRenderTests.lua @@ -1,15 +1,15 @@ --[[ - Unit tests for the mw.capiunto.Infobox._render module + Unit tests for the capiunto._render module @license GNU GPL v2+ @author Marius Hoch < h...@online.de > ]] local testframework = require 'Module:TestFramework' -local render = mw.capiunto.Infobox._render +local render = require('capiunto')._render local function testExists() - return type( mw.capiunto.Infobox._render ) + return type( render ) end -- Tests @@ -86,113 +86,113 @@ -- Tests local tests = { - { name = 'mw.capiunto.Infobox._render exists', func = testExists, type='ToString', + { name = 'capiunto._render exists', func = testExists, type='ToString', expect = { 'table' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 1', func = testRenderWrapper, type='ToString', + { name = 'capiunto._render.renderWrapper 1', func = testRenderWrapper, type='ToString', args = { {} }, expect = { '<table class="mw-capiunto-infobox" cellspacing="3" style="border-spacing:3px;width:22em"></table>' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 2', func = testRenderWrapper, type='ToString', + { name = 'capiunto._render.renderWrapper 2', func = testRenderWrapper, type='ToString', args = { { isChild = true } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderWrapper 3', func = testRenderWrapper, type='ToString', + { name = 'capiunto._render.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 = 'capiunto._render.renderWrapper 4', func = testRenderWrapper, type='ToString', args = { { isSubbox = true } }, expect = { '<table class="mw-capiunto-infobox mw-capiunto-infobox-subbox" cellspacing="3" ' .. 'style="border-spacing:3px"></table>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 1', func = testRenderHeader, type='ToString', + { name = 'capiunto._render.renderHeader 1', func = testRenderHeader, type='ToString', args = { {}, 'foo' }, expect = { '<tr><th colspan="2" style="text-align:center">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 2', func = testRenderHeader, type='ToString', + { name = 'capiunto._render.renderHeader 2', func = testRenderHeader, type='ToString', args = { {}, 'foo', 'bar' }, expect = { '<tr><th colspan="2" class="bar" style="text-align:center">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderHeader 3', func = testRenderHeader, type='ToString', + { name = 'capiunto._render.renderHeader 3', func = testRenderHeader, type='ToString', args = { { headerStyle = 'what:ever' }, 'foo', 'bar' }, expect = { '<tr><th colspan="2" class="bar" style="text-align:center;what:ever">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 1', func = testRenderRow, type='ToString', + { name = 'capiunto._render.renderRow 1', func = testRenderRow, type='ToString', args = { {}, { data = 'foo' } }, expect = { '<tr><td colspan="2" style="text-align:center">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 2', func = testRenderRow, type='ToString', + { name = 'capiunto._render.renderRow 2', func = testRenderRow, type='ToString', args = { {}, { data = 'foo', label = 'bar' } }, expect = { '<tr><th scope="row" style="text-align:left">bar</th><td>\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 3', func = testRenderRow, type='ToString', + { name = 'capiunto._render.renderRow 3', func = testRenderRow, type='ToString', args = { { labelStyle = 'a:b' }, { data = 'foo', label = 'bar' } }, expect = { '<tr><th scope="row" style="text-align:left;a:b">bar</th><td>\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRow 4', func = testRenderRow, type='ToString', + { name = 'capiunto._render.renderRow 4', func = testRenderRow, type='ToString', args = { {}, { data = 'foo', class='meh', dataStyle="a:b" } }, expect = { '<tr><td colspan="2" class="meh" style="text-align:center;a:b">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderWikitext 1', func = testRenderWikitext, type='ToString', + { name = 'capiunto._render.renderWikitext 1', func = testRenderWikitext, type='ToString', args = { 'abc' }, expect = { '<tr><td colspan="2" style="text-align:center">\nabc</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTitle 1', func = testRenderTitle, type='ToString', + { name = 'capiunto._render.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 = 'capiunto._render.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 = 'capiunto._render.renderSubHeaders 1', func = testRenderSubHeader, type='ToString', args = { { subHeaders = { { text = 'foo' } } } }, expect = { '<tr><td colspan="2" style="text-align:center">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderSubHeaders 2', func = testRenderSubHeader, type='ToString', + { name = 'capiunto._render.renderSubHeaders 2', func = testRenderSubHeader, type='ToString', args = { { subHeaders = { { text = 'foo', style = 'a' } } } }, expect = { '<tr><td colspan="2" style="text-align:center;a">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 1', func = testRenderTopRow, type='ToString', + { name = 'capiunto._render.renderTopRow 1', func = testRenderTopRow, type='ToString', args = { {} }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 2', func = testRenderTopRow, type='ToString', + { name = 'capiunto._render.renderTopRow 2', func = testRenderTopRow, type='ToString', args = { { top = 'foo' } }, expect = { '<tr><th colspan="2" style="font-weight:bold;text-align:center;font-size:125%">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderTopRow 3', func = testRenderTopRow, type='ToString', + { name = 'capiunto._render.renderTopRow 3', func = testRenderTopRow, type='ToString', args = { { top = 'foo', topClass = 'a', topStyle='b' } }, expect = { '<tr><th colspan="2" class="a" style="font-weight:bold;text-align:center;font-size:125%;b">foo</th></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 1', func = testRenderBottomRow, type='ToString', + { name = 'capiunto._render.renderBottomRow 1', func = testRenderBottomRow, type='ToString', args = { {} }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', + { name = 'capiunto._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', args = { { bottom = 'foo' } }, expect = { '<tr><td colspan="2" style="text-align:center">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', + { name = 'capiunto._render.renderBottomRow 2', func = testRenderBottomRow, type='ToString', args = { { bottom = 'foo', bottomClass = 'a', bottomStyle = 'b' } }, expect = { '<tr><td colspan="2" class="a" style="text-align:center;b">\nfoo</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 1', func = testRenderImages, type='ToString', + { name = 'capiunto._render.renderImages 1', func = testRenderImages, type='ToString', args = { { } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 2', func = testRenderImages, type='ToString', + { name = 'capiunto._render.renderImages 2', func = testRenderImages, type='ToString', args = { { captionStyle = 'a:b', images = { { image = '[[File:Foo.bar]]', caption="a" } }, } }, expect = { '<tr><td colspan="2" style="text-align:center">\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 = 'capiunto._render.renderImages 3', func = testRenderImages, type='ToString', args = { { imageStyle = 'a', imageClass="b", images = { { image = 'img' } }, } }, expect = { '<tr><td colspan="2" class="b" style="text-align:center;a">\nimg</td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderImages 4', func = testRenderImages, type='ToString', + { name = 'capiunto._render.renderImages 4', func = testRenderImages, type='ToString', args = { { images = { { image = '[[File:Foo.bar]]' }, @@ -205,11 +205,11 @@ '<tr class="D-Class"><td colspan="2" style="text-align:center">\n[[File:B]]<br /><div>C</div></td></tr>' } }, - { name = 'mw.capiunto.Infobox._render.renderRows 1', func = testRenderRows, type='ToString', + { name = 'capiunto._render.renderRows 1', func = testRenderRows, type='ToString', args = { { } }, expect = { '' } }, - { name = 'mw.capiunto.Infobox._render.renderRows 2', func = testRenderRows, type='ToString', + { name = 'capiunto._render.renderRows 2', func = testRenderRows, type='ToString', args = { { rows = { { data = 'foo', label = 'bar' }, 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..4d567b3 100644 --- a/tests/phpunit/output/BasicRowTest.lua +++ b/tests/phpunit/output/BasicRowTest.lua @@ -1,7 +1,7 @@ local p = {} p.run = function() - local box = mw.capiunto.Infobox.create( { + local box = require('capiunto').create( { title = 'Infobox Data Test!' } ) box diff --git a/tests/phpunit/output/BasicTest.lua b/tests/phpunit/output/BasicTest.lua index 5cdba70..b251fe6 100644 --- a/tests/phpunit/output/BasicTest.lua +++ b/tests/phpunit/output/BasicTest.lua @@ -1,7 +1,7 @@ local p = {} p.run = function() - local box = mw.capiunto.Infobox.create( { + local box = require('capiunto').create( { name = 'Foo bar', top = 'Text in uppermost cell of infobox', } ) -- To view, visit https://gerrit.wikimedia.org/r/164560 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I23083cddb638a294aae96dc9f43f2d4f70457eb7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Capiunto Gerrit-Branch: master Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits