Jump to content

Module:Protection banner/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 16:21, 16 July 2014 (create a fake-title-object-getting framework). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Load necessary modules
local mProtectionBanner = require('Module:Protection banner')
local mFakeObject = require('Module:Fake object')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local mainCfg = require('Module:Protection banner/config')

-- Get the classes
local Protection = mProtectionBanner._exportClasses().Protection
local Blurb = mProtectionBanner._exportClasses().Blurb
local BannerTemplate = mProtectionBanner._exportClasses().BannerTemplate
local Banner = mProtectionBanner._exportClasses().Banner
local Padlock = mProtectionBanner._exportClasses().Padlock

-- Initialise test suite
local suite = ScribuntoUnit:new()

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

function suite:assertError(func, args, msg, isPlain)
	args = args or {}
	local success, result = pcall(func, unpack(args))
	self:assertFalse(success)
	if msg then
		self:assertStringContains(msg, result, msg, isPlain)
	end
end

local function makeDefaultProtectionLevels()
	return {
		edit = {},
		move = {},
		autoreview = {}
	}
end

local function getFakeTitleObject(page, action, level)
	local levels = makeDefaultProtectionLevels()
	levels[action][1] = level
	local overwriteFields = {protectionLevels = levels}
	return mFakeObject.new(overwriteFields, mw.title.new, page)
end

--------------------------------------------------------------------------------
-- Protection object tests
--------------------------------------------------------------------------------

return suite