Jump to content

Module:Special page interlanguage links/testcases

From mediawiki.org
Module documentation

Yes All tests passed.

Name Expected Actual
Yes test


Yes All tests passed.

Name Expected Actual
Yes test

require('strict')

local p = require('Module:ScribuntoUnit'):new()

-- Allow test runner to use both the Module:XXX itself and Module:XXX/sandbox with the same testcases
function p:module()
	return self.frame and self.frame.args and self.frame.args.module or 'Special page interlanguage links'
end

function p:setInterwikiMap(codes)
	self.interwikiMap = {}
	for _, v in ipairs(codes) do
		self.interwikiMap[v] = {}
	end
end
function p:getInterwikiMap(args)
	self:assertDeepEquals({'local'}, args)
	return self.interwikiMap
end
local oldInterwikiMap = mw.site.interwikiMap
mw.site.interwikiMap = function (...) return p:getInterwikiMap({...}) end

function p:getFrameWithArg(arg)
	return mw.getCurrentFrame()
		:newChild{ title = 'Template:Foo', args = {} }
		:newChild{ title = 'Module:Bar', args = { arg } }
end

function p:callMain(expected, interwikis)
	self:setInterwikiMap(interwikis)
	self:assertEquals(expected, self.m._main('RecentChanges'))
	self:assertEquals(expected, self.m.main(self:getFrameWithArg('RecentChanges')))
end

function p:test()
	self.m = require('Module:' .. p:module())
	
	-- Try using an interwiki map with some items. It should sort and leave out 'mw'.
	self:callMain(
		'[[de:Special:RecentChanges]][[en:Special:RecentChanges]][[fr:Special:RecentChanges]]',
		{ 'en', 'fr', 'de', 'mw' }
	)
	
	-- Try using an interwiki map with no interlanguage links.
	self:callMain('', { 'meta', 'mw', 'd' })
	
	-- Try using an empty interwiki map.
	self:callMain('', {})
	
	-- Try using the original interwiki map.
	self.interwikiMap = oldInterwikiMap('local')
	self:assertStringContains('[[en:Special:RecentChanges]]', self.m._main('RecentChanges'), true)
	self:assertStringContains('[[en:Special:RecentChanges]]', self.m.main(self:getFrameWithArg('RecentChanges')), true)
end

return p