Module:Special page interlanguage links/testcases

From Bonkipedia
< Module:Special page interlanguage links
Revision as of 18:20, 12 November 2022 by ManfredoDo (talk | contribs) (1 revision imported: Module Import)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Module:Special page interlanguage links

N1 test failed.

Name Expected Actual
N test Module:Special_page_interlanguage_links/testcases:52: Failed to find plain string "[[en:Special:RecentChanges]]" in string ""


Module:Special page interlanguage links/sandbox

N1 test failed.

Name Expected Actual
N test Module:Special_page_interlanguage_links/testcases:52: Failed to find plain string "[[en:Special:RecentChanges]]" in string ""

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