Jump to content

Module:Redirect hatnote/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 11:38, 7 May 2014 (shorter names and fix duplicate name). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mRedirectHatnote = require('Module:Redirect hatnote')
local mHatnote = require('Module:Hatnote')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

--------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------

function suite.runRedirect(args)
	-- Runs the "redirect" function with an args table passed from a
	-- parent frame.
	local frame = mw.getCurrentFrame()
	local parent = frame:newChild{args = args}
	local child = parent:newChild{}
	return mRedirectHatnote.redirect(child)
end

--------------------------------------------------------------------------
-- Test #invoke function
--------------------------------------------------------------------------

function suite:testBlank()
	local result = suite.runRedirect{}
	self:assertStringContains('no redirect specified', result, true)
	self:assertStringContains('Template:Redirect#Errors', result, true)
end

function suite:testRedirectOnly()
	local result = suite.runRedirect{'REDIRECT'}
	self:assertStringContains('"REDIRECT" redirects here. For other uses, see [[REDIRECT (disambiguation)]].', result, true)
end

function suite:testUse1()
	local result = suite.runRedirect{'REDIRECT', 'USE1'}
	self:assertStringContains('"REDIRECT" redirects here. For USE1, see [[REDIRECT (disambiguation)]].', result, true)
end

function suite:testUse1Page1()
	local result = suite.runRedirect{'REDIRECT', 'USE1', 'PAGE1'}
	self:assertStringContains('"REDIRECT" redirects here. For USE1, see [[PAGE1]].', result, true)
end

function suite:testPage1()
	local result = suite.runRedirect{'REDIRECT', '', 'PAGE1'}
	self:assertStringContains('"REDIRECT" redirects here. For other uses, see [[PAGE1]].', result, true)
end

function suite:testUse2()
	local result = suite.runRedirect{'REDIRECT', 'USE1', 'PAGE1', 'USE2'}
	self:assertStringContains('"REDIRECT" redirects here. For USE1, see [[PAGE1]]. For USE2, see [[USE2 (disambiguation)]].', result, true)
end

return suite