Module:SDC tracking/testcases

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

✓[OK] All tests passed.

Name Expected Actual
✓[OK] test_outer
✓[OK] test_statement_exist
✓[OK] test_statement_has_value

Code

local TUT  = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local p = require(TUT.prefixedText) -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:test_statement_exist()
	local entity = mw.wikibase.getEntity("M7500199") -- [[File:Joshua Tree - Sweet Band belay.jpg]]
	self:assertEquals('positive', p._statement_exist(entity, 'P170', 'positive', 'negative'))
	self:assertEquals('negative', p._statement_exist(entity, 'P1',   'positive', 'negative'))
end
	
function suite:test_statement_has_value()
	local entity = mw.wikibase.getEntity("M7500199") -- [[File:Joshua Tree - Sweet Band belay.jpg]]
	self:assertEquals('matching',    p._statement_has_value(entity, 'P6216', 'Q50423863', 'matching', 'mismatching', 'missing'))
	self:assertEquals('missing',     p._statement_has_value(entity, 'P1',    'Q50423863', 'matching', 'mismatching', 'missing'))
	self:assertEquals('mismatching', p._statement_has_value(entity, 'P6216', 'Q1',        'matching', 'mismatching', 'missing'))
end

function suite:test_outer()
	local mod = '{{#invoke:' .. TUT.text .. '|'
	self:assertSameResult( mod..'SDC_statement_exist|item=M7500199|property=P170|positive_category=positive| negative_category=negative}}', '[[Category:positive]]')
	self:assertSameResult( mod..'SDC_statement_has_value|item=M7500199|property=P6216|value=Q50423863|matching_category=matching|mismatching_category=mismatching|missing_category=missing}}', '[[Category:matching]]')
end
 
return suite