Модуль:Wikidata/Medals/testcases
< Модуль:Wikidata | Medals
Для документации этого модуля может быть создана страница Модуль:Wikidata/Medals/testcases/doc
local scribuntoUnit = require( 'Module:ScribuntoUnit' ) local testUtils = require( 'Module:Wikidata/TestUtils' ) local p = scribuntoUnit:new() local libName = 'Wikidata/Medals' -- Helper to run all tests using sandbox version of the library from the debug console. To run against main lib, use =p.run() function p.runSandbox() local frame = mw.getCurrentFrame():newChild{title='testcases', args={module=libName .. '/sandbox', displayMode='log'}} return p.run( frame ) end -- Allow test runner to use both the main library and the sandbox of the library with the same testcases function p:module() return self.frame and self.frame.args.module or libName end function p:invokeLib( wikicode ) return '{{#invoke:' .. p:module() .. '|' .. wikicode .. '}}' end local function buildImage( image, size, border ) mw.logObject( image, 'image' ) mw.logObject( size, 'size' ) mw.logObject( border, 'border' ) if not image or not size then return nil end local out = '[[File:' .. image .. '|' .. size if border then out = out .. '|border' end out = out .. ']]' return out end function p:testGetImageFromEntity() local wdMedals = require( 'Module:' .. p:module() ) -- Пиктограмма self:assertEquals( '[[File:Золотая Звезда Героя Советского Союза.svg|40x40px]]', buildImage( wdMedals.getImageFromEntity( 'Q178473' ) ) ) -- Лента ордена self:assertEquals( '[[File:RUS Imperial Order of Saint Catherine ribbon.svg|x17px|border]]', buildImage( wdMedals.getImageFromEntity( 'Q512272' ) ) ) -- Разные версии в разные даты self:assertEquals( '[[File:AZ fexri adinin dos nisani.png|40x40px]]', buildImage( wdMedals.getImageFromEntity( 'Q5939643' ) ) ) self:assertEquals( '[[File:People\'s Artist of the Republic of Azerbaijan.png|40x40px]]', buildImage( wdMedals.getImageFromEntity( 'Q5939643', testUtils.parseTimeFromDate( '2000-01-01' ) ) ) ) self:assertEquals( nil, buildImage( wdMedals.getImageFromEntity( 'Q5939643' ), testUtils.parseTimeFromDate( '1990' ) ) ) end return p