Module:Work/testcases

local p = require('Module:UnitTests') local Work = require('Module:Work')

local TESTDATA = { EskimoLife1893 = { source = 'Q110304643', id = 'Q110304643', workType = Work.TYPES.EDITION, wsPage = 'Eskimo Life', title = 'Eskimo Life', year = '1893', authorIds = { 'Q72292' -- Fridtjof Nansen }	},	WarPrisoners = { source = 'War Prisoners (Darrow)', id = 'Q19053527', wsPage = 'War Prisoners (Darrow)', workType = Work.TYPES.EDITION, title = 'War Prisoners', year = '1919', authorIds = { 'Q449791' -- Clarence Darrow }	},	Possession = { source = 'Possession (Roche)', id = 'Q107511838', wsPage = 'Possession (Roche)', workType = Work.TYPES.WORK, title = 'Possession', year = '1923', -- fron inception authorIds = { 'Q2742392' -- Mazo de Roche }	},	LemnaMinorAdie = { source = 'Q42350565', id = 'Q42350565', wsPage = nil, workType = Work.TYPES.ARTICLE, title = 'Lemna Minor as a Preventive against Mosquitoes', year = '1904', authorIds = { 'Q107507136' -- Joseph Rosamond Adie },		parentWorkId = 'Q26842241', volume = '39', issue = '6', pages = '207-208' } }

function p:do_test_case( name ) mw.logObject( name ) local data = TESTDATA[ name ] local w = Work.newWork( data.source ) -- check the item is loaded correctly self:equals('ID', w.item.id, data.id ) -- Check we detect the type correctly self:equals('Type', w.type, data.workType ) -- check sitelink self:equals('WS Page', w.wsPage, data.wsPage ) -- check bibliographic metadata if data.title then self:equals('Title', w.title, data.title ) end if data.parentWorkId then self:equals('Published in', w.parentWork.item.id, data.parentWorkId ) end if data.year then self:equals('Year', w.pubYear, data.year ) end -- just check the IDs, the actual handling of Creators is delegated to the Creator module for i, authorId in pairs( data.authorIds ) do self:equals('Author ' .. i, w.author[ i ].item.id, authorId ) end end

function p:test_edition_from_id self:do_test_case( 'EskimoLife1893' ) end

function p:test_edition_from_pagename self:do_test_case( 'WarPrisoners' ) end

function p:test_work_from_pagename self:do_test_case( 'Possession' ) end

function p:test_scientific_article self:do_test_case( 'LemnaMinorAdie' ) end

return p