Modul:Wikidata/tests
Megjelenés
Wikidata modul tesztek[mi ez?]
Név | Várt | Tényleges | |
---|---|---|---|
testIsOfType | |||
testFilterByQualifier | |||
testArguments | |||
testContainsPropertyWithValue | |||
testPageTitle | |||
testContainsProperty | |||
testSortDesc | |||
testFormatSnaks | |||
testPropertyName | |||
testRoundDec | |||
testExternalId | |||
testAtDate |
local p = require("Modul:Wikidata")
local ScribuntoUnit = require("Modul:ScribuntoUnit")
local suite = ScribuntoUnit:new()
local frame = mw.getCurrentFrame()
local item = mw.wikibase.getEntity("Q11842329") -- Modul:Wikidata/tests
function suite:testContainsProperty()
self:assertEquals(true, p.containsProperty(nil, {property = "P31"}, item))
self:assertEquals(nil, p.containsProperty(nil, {property = "P31"}, {}))
self:assertEquals(nil, p.containsProperty(nil, {property = "ABC"}, item))
self:assertFalse(pcall(p.containsProperty, nil, {}, item))
self:assertEquals(true, p.containsProperty(nil, {value = "DEF", property = "P31"}, item))
self:assertEquals(true, p.containsProperty(nil, {value = "DEF", property = "ABC"}, item))
self:assertFalse(pcall(p.containsProperty, nil, {value = "DEF"}, item))
self:assertEquals(nil, p.containsProperty(nil, {value = "-", property = "P31"}, item))
self:assertEquals(nil, p.containsProperty(nil, {value = "-", property = "ABC"}, item))
self:assertFalse(pcall(p.containsProperty, nil, {value = "-"}, item))
end
function suite:testContainsPropertyWithValue()
item.containsPropertyWithValue = p.containsPropertyWithValue
self:assertTrue(item:containsPropertyWithValue("P31", "Q15145755") or item:containsPropertyWithValue("P31", "Q15184295"))
self:assertFalse(item:containsPropertyWithValue("ABC", "Q15145755"))
self:assertFalse(item:containsPropertyWithValue("P31", "Q42"))
end
function suite:testArguments()
self:assertEquals("Wikimédia-egyértelműsítőlap", p.formatStatements(frame, {property = "P31", entityId = "Q1212864", link = "nem"}))
self:assertEquals("Leningrád", p.formatStatements(frame, {property = "P1448", entityId = "Q656",
atDate = "1950-01-01", rank = "valid", firstAfter = true})
); -- firstAfter
end
function suite:testAtDate()
self:assertEquals('Leningrád', p.formatStatements(frame, {property = "P1448", entityId = "Q656",
atDate = "1950-01-01", rank = "valid", lang = "hu"})
);
self:assertEquals("[[Szentpétervár|Ленинград]]", p.formatStatements(frame, {property = "P19", entityId = "Q2448637",
chrProperty = "P1448", chrDate = "P569", lang = "ru"})
);
self:assertEquals('[[Szentpétervár|Leningrád]], [[Szovjetunió]]', p.formatStatements(frame, {property = 'P19', entityId = 'Q2448637',
chrProperty = 'P1448', chrDate = 'P569', format = 'with_country'
}))
self:assertEquals('Carlisle, [[Egyesült Királyság]]', p.formatStatements(frame, {property = 'P19', entityId = 'Q939606',
chrProperty = 'P1448', chrDate = 'P569', format = 'with_country'
}))
end
function suite:testIsOfType()
self:assertTrue(p.isOfType(mw.wikibase.getEntity"Q8206", "Q106658"))
self:assertFalse(p.isOfType(mw.wikibase.getEntity"Q8206", "ABC"))
self:assertTrue(p.isOfType(mw.wikibase.getEntity"Q10451", "Q106658"))
end
function suite:testPageTitle()
self:assertTemplateEquals('1998-11-20', 'wikidata', { 'P575', pageTitle = '14181 Koromházi', format = 'iso' })
self:assertTemplateEquals('', 'wikidata', { 'P575', pageTitle = 'Nincs ilyen lap', format = 'iso' })
self:assertFalse(pcall(p.formatStatements, frame, { property = 'P575', entityId = 'Q929959', pageTitle = '14181 Koromházi', format = 'iso' }))
self:assertTemplateEquals('true', 'wikidata-f', { 'P575', pageTitle = '14181 Koromházi', format = 'iso' })
self:assertTemplateEquals('', 'wikidata-f', { 'P575', pageTitle = 'Nincs ilyen lap', format = 'iso' })
self:assertTemplateEquals('true', 'wikidata-f', { 'P575', entityId = 'Q929959', pageTitle = '14181 Koromházi', format = 'iso' })
end
function suite:testExternalId()
self:assertTemplateEquals('[https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=20014181 20014181]', 'wikidata', { 'P716', pageTitle = '14181 Koromházi' })
self:assertTemplateEquals('20014181', 'wikidata', { 'P716', pageTitle = '14181 Koromházi', format = 'raw' })
self:assertTemplateEquals('https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=20014181', 'wikidata', { 'P716', pageTitle = '14181 Koromházi', format = 'url' })
self:assertTemplateEquals('[https://ssd.jpl.nasa.gov/sbdb.cgi?sstr=20014181 JPL]', 'wikidata', { 'P716', pageTitle = '14181 Koromházi', externalIdLabel = 'JPL' })
self:assertTemplateEquals('https://www.wolframalpha.com/input/?i=Entity%5B%22MinorPlanet%22%2C%20%22MinorPlanet14109Provisional1998OM14%22%5D', 'wikidata', { 'P4839', pageTitle = '(14109) 1998 OM14', format = 'url' })
self:assertTemplateEquals('[https://whc.unesco.org/en/list/__XYZ__ __XYZ__]', 'wikidata', { 'P757', externalId = '__XYZ__' })
self:assertTemplateEquals('', 'wikidata', { 'P757', externalId = '-' })
end
function suite:testPropertyName()
self:assertTemplateEquals('Q3863', 'wikidata', { 'p31', pageTitle = '14181 Koromházi', format = 'raw' })
self:assertTemplateEquals('Q3863', 'wikidata', { 'osztály, amelynek példánya', pageTitle = '14181 Koromházi', format = 'raw' })
self:assertFalse(pcall(p.formatStatements, frame, { property = '__XYZ__', pageTitle = '14181 Koromházi', format = 'raw' }))
end
function suite:testFilterByQualifier()
self:assertEquals(1, #p.formatStatements(frame, { property='P348', pageTitle='MariaDB', qualProp='P548', qualValue='Q2804309', ['felsorolás']='table' }))
self:assertEquals(nil, p.formatStatements(frame, { property='P348', pageTitle='MariaDB', qualProp='P548', qualValue='__XYZ__' }))
self:assertEquals(nil, p.formatStatements(frame, { property='P348', pageTitle='MariaDB', qualProp='P31' }))
end
function suite:testFormatSnaks()
self:assertEquals('', p.formatters.formatSnaks({}, {}))
end
function suite:testSortDesc()
self:assertTemplateEquals('110', 'wikidata', { 'P1082', first='', sort='P585', entityId='Q11842329' } )
self:assertTemplateEquals('130', 'wikidata', { 'P1082', first='', sort='P585', sortDesc='', entityId='Q11842329' } )
end
function suite:testRoundDec()
self:assertEquals('1 023 456,78', p.formatters.formatDatavalue( {
value={ amount='+1023456780912', unit='http://www.wikidata.org/entity/Q25343' },
type='quantity'
}, { unit='km2', roundDec='2' }))
end
return suite