Module:Wikidata label/testcases
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
4 tests failed.
Name | Expected | Actual | |
---|---|---|---|
test_getLabel_1_entity_types | [[d:Property:P31|<span title="that class of which this subject is a particular example and member; different from P279 (subclass of); for example: K2 is an instance of mountain; volcano is a subclass of mountain (and an instance of volcanic landform)">instance of</span>]] | [[d:Property:P31|<span title="that class of which this subject is a particular example and member; different from P279 (subclass of); for example: K2 is an instance of mountain; volcano is a subclass of mountain (and an instance of volcanic landform)">instance of</span>]] | |
test_getLabel_2_capitalization | authority file | authority control | |
test_getLabel_3_show_id | [[d:Property:P31|<span title="that class of which this subject is a particular example and member; different from P279 (subclass of); for example: K2 is an instance of mountain; volcano is a subclass of mountain (and an instance of volcanic landform)">instance of <small>(P31)</small></span>]] | [[d:Property:P31|<span title="that class of which this subject is a particular example and member; different from P279 (subclass of); for example: K2 is an instance of mountain; volcano is a subclass of mountain (and an instance of volcanic landform)">instance of <small>(P31)</small></span>]] | |
test_getLabel_4_links | |||
test_getLabel_5_leyers | [[w:en:Authority file|<span title="unique headings used for bibliographic information">authority file</span>]] | [[w:en:Authority file|<span title="collection of authority records, where each record picks preferred heading, alternative heading and other information, used for bibliographic information">authority file</span>]] | |
test_getLabel_6_languages | |||
test_getLabel_7_redirects |
Code
require('strict')
local TUT = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local WL = require(TUT.prefixedText) -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
local function getLabel_lite(item)
local lab, desc = mw.wikibase.getLabel(item), mw.wikibase.getDescription(item)
return '|<span title="'.. desc ..'">'.. lab ..'</span>]]'
end
function suite:test_getLabel_1_entity_types()
local lab = '[[d:Property:P31' .. getLabel_lite('P31')
self:assertEquals( WL._getLabel('P31', nil), lab)
self:assertEquals( WL._getLabel('P31', nil, 'wikidata' ), lab)
self:assertEquals( WL._getLabel('P31', nil, 'wikipedia'), lab)
lab = '[[d:Q36524'..getLabel_lite('Q36524')
self:assertEquals( WL._getLabel('Q36524', nil, 'wikidata'), lab)
self:assertEquals( WL._getLabel( '36524', nil, 'wikidata'), lab)
lab = '[[c:Special:EntityPage/M4184419|' .. mw.wikibase.getLabelByLang('M4184419', 'en') .. ']]'
self:assertEquals( WL._getLabel( 'M4184419', 'en'), lab)
self:assertEquals( WL._getLabel( 'M4184419', 'en', 'wikidata' ), lab)
self:assertEquals( WL._getLabel( 'M4184419', 'en', 'wikipedia'), lab)
self:assertEquals( WL._getLabel( 'M4184419', 'en', 'commons' ), lab)
end
function suite:test_getLabel_2_capitalization()
local lab = mw.wikibase.getLabelByLang('Q36524', 'en')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'ucfirst'), mw.language.new('en'):ucfirst(lab))
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'lcfirst'), mw.language.new('en'):lcfirst(lab))
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'uc'), mw.language.new('en'):uc(lab))
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'lc'), mw.language.new('en'):lc(lab))
self:assertEquals( WL._getLabel('Q36524', 'en', '-'), lab)
self:assertEquals( WL._getLabel('Q36524', 'en', '-', ''), lab)
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'hello world'), lab)
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'lc'), 'authority control')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'uc'), 'AUTHORITY CONTROL')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'tc'), 'Authority Control')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'ucfirst'), 'Authority control')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', 'lcfirst'), 'authority control')
self:assertEquals( WL._getLabel('Q36524', 'en', '-'), 'authority control')
self:assertEquals( WL._getLabel('Q36524', 'en', '-', ''), 'authority control')
self:assertEquals( WL._getLabel('Q387616','en', '-', 'tc'), 'Yellow-winged Darter')
self:assertEquals( WL._getLabel('Q387616','pl', '-', 'tc'), 'Szablak Żółty')
self:assertEquals( WL._getLabel('Q387616','hu', '-', 'lc'), 'útszéli szitakötő')
self:assertEquals( WL._getLabel('Q387616','hu', '-', 'uc'), 'ÚTSZÉLI SZITAKÖTŐ')
self:assertEquals( WL._getLabel('Q387616','hu', '-', 'tc'), 'Útszéli Szitakötő')
self:assertEquals( WL._getLabel('Q387616','hu', '-', 'ucfirst'), 'Útszéli szitakötő')
-- the first letter should be U+0131 LATIN SMALL LETTER DOTLESS I, not U+0069 LATIN SMALL LETTER I
self:assertEquals( WL._getLabel('Q11711071','tr', '-', 'lcfirst'), 'ıgeşauş')
end
function suite:test_getLabel_3_show_id()
local lab, desc = mw.wikibase.getLabel('Q937'), mw.wikibase.getDescription('Q937')
self:assertSameResult('{{#invoke:' .. TUT.text .. '|getLabel|item=Q937|link=wikidata|show_id=true}}', '[[d:Q937|<span title="'.. desc ..'">'.. lab ..' <small>(Q937)</small></span>]]')
lab, desc = mw.wikibase.getLabel('P31'), mw.wikibase.getDescription('P31')
self:assertSameResult('{{#invoke:' .. TUT.text .. '|getLabel|item=P31|show_id=1}}', '[[d:Property:P31|<span title="'.. desc ..'">'.. lab .. ' <small>(P31)</small></span>]]')
end
function suite:test_getLabel_4_links()
self:assertEquals( WL._getLabel('Q2', 'pl'), WL._getLabel('Q2', 'pl','wikipedia'))
self:assertEquals( WL._getLabel('Q2', 'ru','wikidata'), WL._getLabel('Q2', 'ru','wIkIDAta'))
local lang = mw.getCurrentFrame():callParserFunction("int", "lang")
self:assertEquals( '[[w:en:'.. mw.wikibase.getSitelink('Q36524', lang..'wiki') ..getLabel_lite('Q36524'), WL._getLabel('Q36524'))
self:assertEquals( '[[d:Q2' ..getLabel_lite('Q2'), WL._getLabel('Q2', nil, 'wikidata'))
self:assertEquals( '[[d:Talk:Q2' ..getLabel_lite('Q2'), WL._getLabel('Q2', nil, 'wikidata talk'))
self:assertEquals( '[[c:'.. mw.wikibase.getSitelink('Q937', 'commonswiki')..getLabel_lite('Q937'), WL._getLabel('Q937', nil, 'COMMONS'))
self:assertEquals( '[[c:'.. mw.wikibase.getSitelink('Q6974121', 'commonswiki')..getLabel_lite('Q6974121'), WL._getLabel('Q6974121', nil, 'COMMONS'))
end
function suite:test_getLabel_5_leyers()
local desc = 'unique headings used for bibliographic information'
local link, lab = mw.wikibase.getSitelink('Q36524', 'enwiki'), mw.wikibase.getLabelByLang('Q36524', 'en')
local res = '[[w:en:'.. link..'|<span title="'.. desc ..'">'.. lab ..'</span>]]'
self:assertEquals (res, WL._getLabel('Q36524','en')) -- item id
self:assertEquals (res, WL._getLabel(mw.wikibase.getEntity('Q36524'),'en')) -- entity
self:assertSameResult(res, '{{#invoke:' .. TUT.text .. '|getLabel|item=Q36524|lang=en}}')
self:assertSameResult(res, '{{Q-|item=Q36524|lang=en}}')
local label, lang = mw.wikibase.getLabelWithLang('Q36524')
local res = '[[w:'..lang..':'.. mw.wikibase.getSitelink('Q36524', 'enwiki')..getLabel_lite('Q36524')
self:assertEquals(res, WL._getLabel('Q36524'))
self:assertEquals(res, WL._getLabel('Q36524', nil, "wikipedia"))
end
function suite:test_getLabel_6_languages()
local lang = mw.getCurrentFrame():callParserFunction("int", "lang")
self:assertSameResult('{{#invoke:' .. TUT.text .. '|getLabel|item=Q1|lang='..lang..'}}', '{{#invoke:' .. TUT.text .. '|getLabel|item=Q1}}')
self:assertSameResult('{{#invoke:' .. TUT.text .. '|getLabel|item=Q1|lang='..lang..'}}', '{{#invoke:' .. TUT.text .. '|getLabel|item=Q1|lang=}}')
self:assertEquals( WL._getLabel('Q6974121', lang), WL._getLabel('Q6974121'))
self:assertEquals( WL._getLabel('Q6974121', lang, 'commons', 'uc'), WL._getLabel('Q6974121', nil, 'commons', 'uc'))
end
function suite:test_getLabel_7_redirects()
local lab = getLabel_lite('Q50940519')
self:assertEquals(WL._getLabel('Q50940519', nil, 'wikidata'), '[[d:Q50940519'..lab)
end
return suite