Module:Protection banner/config/testcases: Difference between revisions

Content deleted Content added
m Mr. Stradivarius moved page Module:Protection banner/testcases to Module:Protection banner/config/testcases without leaving a redirect: really, these are testcases for the config file, not the main module
fix one
 
(48 intermediate revisions by 9 users not shown)
Line 1:
-- Unit tests for [[Module:Protection banner/config]]. Click talk page to run tests.
 
local pp = require('Module:Protection banner')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
 
-- Get the classes
local Protection = pp._exportClasses().Protection
local Blurb = pp._exportClasses().Blurb
local BannerTemplate = pp._exportClasses().BannerTemplate
local Banner = pp._exportClasses().Banner
local Padlock = pp._exportClasses().Padlock
 
-- Get the config
local mainCfgcfgModule = require('Module:Protection banner/config/sandbox')
 
--------------------------------------------------------------------------------
Line 20 ⟶ 14:
 
function suite.makeFakeProtectionObj(fields, cfg, title)
local obj = Protection:.new({}, cfg, title)
for k, v in pairs(fields) do
obj[k] = v
end
return obj
end
 
function suite.escapePattern(s)
-- Escapes the magic characters ()%.[]*+-?^$ for use in Lua patterns.
return s:gsub('([%(%)%.%[%]%*%+%-%?%^%$%%])', '%%%1')
end
 
function suite:assertProtectionCategoryEquals(expected, action, level, namespace, reason, expiry)
local fakeTitleObjfakePageName = {namespace = namespace}'Foobar'
local fakeTitleObj = mw.title.new(fakePageName, namespace)
local protectionObj = suite.makeFakeProtectionObj(
{
Line 42 ⟶ 32:
expiry = expiry
},
cfgModule,
mainCfg
fakeTitleObj
)
local actual = protectionObj:makeProtectionCategory()
expected = string.format('[[Category:%s|%s]]', expected, fakePageName)
self:assertEquals(expected, actual)
end
Line 58 ⟶ 49:
d.pc = 'autoreview'
d.semi = 'autoconfirmed'
d.extended = 'extendedconfirmed'
d.template = 'templateeditor'
d.full = 'sysop'
d.dispute = 'dispute'
d.pc1 = 'autoconfirmed'
d.pc2 = 'reviewer'
d.vand = 'vandalism'
d.blp = 'blp'
Line 150 ⟶ 141:
--------------------------------------------------------------------------------
 
function suite:testCategory_move_full_template_dispute_alltestCategory_move_full_main_dispute_all()
self:assertProtectionCategoryEquals('Wikipedia pages move-protected due to dispute', d.move, d.full, 0, d.dispute, nil)
end
Line 195 ⟶ 186:
 
function suite:testCategory_edit_semi_file_vandalism_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected imagesfiles', d.edit, d.semi, 6, d.vand, nil)
end
 
function suite:testCategory_edit_semi_wikipedia_vandalism_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 4, d.vand, nil)
end
 
function suite:testCategory_edit_semi_help_vandalism_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 12, d.vand, nil)
end
 
function suite:testCategory_edit_semi_portal_vandalism_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected portals', d.edit, d.semi, 100, d.vand, nil)
end
 
Line 215 ⟶ 206:
 
function suite:testCategory_edit_semi_talk_vandalism_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected talk pages', d.edit, d.semi, 1, d.vand, nil)
end
 
Line 231 ⟶ 222:
 
function suite:testCategory_edit_semi_file_vandalism_temp()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected imagesfiles', d.edit, d.semi, 6, d.vand, d.temp)
end
 
function suite:testCategory_edit_semi_wikipedia_vandalism_temp()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 4, d.vand, d.temp)
end
 
function suite:testCategory_edit_semi_help_vandalism_temp()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 12, d.vand, d.temp)
end
 
function suite:testCategory_edit_semi_portal_vandalism_temp()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected portals', d.edit, d.semi, 100, d.vand, d.temp)
end
 
Line 251 ⟶ 242:
 
function suite:testCategory_edit_semi_talk_vandalism_temp()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected talk pages', d.edit, d.semi, 1, d.vand, d.temp)
end
 
Line 263 ⟶ 254:
 
function suite:testCategory_edit_full_user_vandalism_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 2, d.vand, nil)
end
 
function suite:testCategory_edit_full_usertalk_vandalism_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 3, d.vand, nil)
end
 
function suite:testCategory_edit_full_file_vandalism_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia imagesfully protected files', d.edit, d.full, 6, d.vand, nil)
end
 
function suite:testCategory_edit_full_wikipedia_vandalism_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 4, d.vand, nil)
end
 
function suite:testCategory_edit_full_help_vandalism_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 12, d.vand, nil)
end
 
Line 287 ⟶ 278:
 
function suite:testCategory_edit_full_template_vandalism_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected templates', d.edit, d.full, 10, d.vand, nil)
end
 
function suite:testCategory_edit_full_talk_vandalism_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected talk pages', d.edit, d.full, 1, d.vand, nil)
end
 
Line 299 ⟶ 290:
 
function suite:testCategory_edit_full_user_vandalism_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 2, d.vand, d.temp)
end
 
function suite:testCategory_edit_full_usertalk_vandalism_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 3, d.vand, d.temp)
end
 
function suite:testCategory_edit_full_file_vandalism_temp()
self:assertProtectionCategoryEquals('ProtectedWikipedia imagesfully protected files', d.edit, d.full, 6, d.vand, d.temp)
end
 
function suite:testCategory_edit_full_wikipedia_vandalism_temp()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 4, d.vand, d.temp)
end
 
function suite:testCategory_edit_full_help_vandalism_temp()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 12, d.vand, d.temp)
end
 
Line 323 ⟶ 314:
 
function suite:testCategory_edit_full_template_vandalism_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected templates', d.edit, d.full, 10, d.vand, d.temp)
end
 
function suite:testCategory_edit_full_talk_vandalism_temp()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected talk pages', d.edit, d.full, 1, d.vand, d.temp)
end
 
Line 423 ⟶ 414:
 
function suite:testCategory_edit_full_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected templates', d.edit, d.full, 10, nil, nil)
end
 
function suite:testCategory_edit_full_template_all_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected templates', d.edit, d.full, 10, nil, d.temp)
end
 
function suite:testCategory_edit_template_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia template-protected templates', d.edit, d.template, 10, nil, nil)
end
 
function suite:testCategory_edit_template_template_all_temp()
self:assertProtectionCategoryEquals('Wikipedia template-protected templates', d.edit, d.template, 10, nil, d.temp)
end
 
function suite:testCategory_edit_extended_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia extended-confirmed-protected templates', d.edit, d.extended, 10, nil, nil)
end
 
function suite:testCategory_move_template_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia template-protected templates', d.move, d.template, 10, nil, nil)
end
 
Line 444 ⟶ 443:
function suite:testCategory_edit_full_template_all_temp()
self:assertProtectionCategoryEquals('Wikipedia move-protected templates', d.move, d.full, 10, nil, d.temp)
end
 
function suite:testCategory_edit_template_templatetalk_all_all()
self:assertProtectionCategoryEquals('Wikipedia template-protected pages other than templates and modules', d.edit, d.template, 11, nil, nil)
end
 
--------------------------------------------------------------------------------
-- Categories: module
--------------------------------------------------------------------------------
 
function suite:testCategory_edit_semi_module_all_all()
self:assertProtectionCategoryEquals('Wikipedia semi-protected modules', d.edit, d.semi, 828, d.indef, nil)
end
 
function suite:testCategory_edit_semi_module_all_temp()
self:assertProtectionCategoryEquals('Wikipedia semi-protected modules', d.edit, d.semi, 828, nil, d.temp)
end
 
function suite:testCategory_edit_full_module_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected modules', d.edit, d.full, 828, nil, nil)
end
 
function suite:testCategory_edit_full_module_all_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected modules', d.edit, d.full, 828, nil, d.temp)
end
 
function suite:testCategory_edit_template_module_all_all()
self:assertProtectionCategoryEquals('Wikipedia template-protected modules', d.edit, d.template, 828, nil, nil)
end
 
function suite:testCategory_edit_template_module_all_temp()
self:assertProtectionCategoryEquals('Wikipedia template-protected modules', d.edit, d.template, 828, nil, d.temp)
end
 
Line 459 ⟶ 490:
 
function suite:testCategory_edit_full_user_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 2, nil, nil)
end
 
function suite:testCategory_edit_full_usertalk_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 3, nil, nil)
end
 
Line 475 ⟶ 506:
 
function suite:testCategory_edit_full_user_all_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 2, nil, d.temp)
end
 
function suite:testCategory_edit_full_usertalk_all_temp()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 3, nil, d.temp)
end
 
Line 663 ⟶ 694:
 
function suite:testCategory_edit_semi_file_all_indef()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected imagesfiles', d.edit, d.semi, 6, nil, d.indef)
end
 
function suite:testCategory_edit_semi_wikipedia_all_indef()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 4, nil, d.indef)
end
 
function suite:testCategory_edit_semi_help_all_indef()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 12, nil, d.indef)
end
 
function suite:testCategory_edit_semi_portal_all_indef()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected portals', d.edit, d.semi, 100, nil, d.indef)
end
 
Line 683 ⟶ 714:
 
function suite:testCategory_edit_semi_talk_all_indef()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected talk pages', d.edit, d.semi, 1, nil, d.indef)
end
 
function suite:testCategory_edit_semi_main_all_indef()
self:assertProtectionCategoryEquals('Wikipedia indefinitely semi-protected pages', d.edit, d.semi, 0, nil, d.indef)
end
 
function suite:testCategory_edit_semi_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia indefinitely semi-protected pages', d.edit, d.semi, 0, nil, nil)
end
 
Line 728 ⟶ 763:
function suite:testCategory_move_full_main_all_indef()
self:assertProtectionCategoryEquals('Wikipedia indefinitely move-protected pages', d.move, d.full, 0, nil, d.indef)
end
 
function suite:testCategory_move_full_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia indefinitely move-protected pages', d.move, d.full, 0, nil, nil)
end
 
Line 743 ⟶ 782:
 
function suite:testCategory_edit_semi_file_all_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected imagesfiles', d.edit, d.semi, 6, nil, nil)
end
 
function suite:testCategory_edit_semi_wikipedia_all_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 4, nil, nil)
end
 
function suite:testCategory_edit_semi_help_all_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected project pages', d.edit, d.semi, 12, nil, nil)
end
 
function suite:testCategory_edit_semi_portal_all_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected portals', d.edit, d.semi, 100, nil, nil)
end
 
Line 767 ⟶ 806:
 
function suite:testCategory_edit_semi_talk_all_all()
self:assertProtectionCategoryEquals('SemiWikipedia semi-protected talk pages', d.edit, d.semi, 1, nil, nil)
end
 
function suite:testCategory_edit_semi_main_all_alltestCategory_edit_semi_main_all_temp()
self:assertProtectionCategoryEquals('Wikipedia semi-protected pages', d.edit, d.semi, 0, nil, nild.temp)
end
 
function suite:testCategory_edit_extended_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia extended-confirmed-protected pages', d.edit, d.extended, 0, nil, nil)
end
 
function suite:testCategory_edit_full_user_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 2, nil, nil)
end
 
function suite:testCategory_edit_full_usertalk_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected user and user talk pages', d.edit, d.full, 3, nil, nil)
end
 
function suite:testCategory_edit_full_file_all_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia imagesfully protected files', d.edit, d.full, 6, nil, nil)
end
 
function suite:testCategory_edit_full_wikipedia_all_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 4, nil, nil)
end
 
function suite:testCategory_edit_full_help_all_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected project pages', d.edit, d.full, 12, nil, nil)
end
 
function suite:testCategory_edit_full_portal_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected pages', d.edit, d.full, 100, nil, nil)
end
 
function suite:testCategory_edit_full_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected templates', d.edit, d.full, 10, nil, nil)
end
 
function suite:testCategory_edit_full_category_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected categories', d.edit, d.full, 14, nil, nil)
end
 
function suite:testCategory_edit_full_talk_all_all()
self:assertProtectionCategoryEquals('ProtectedWikipedia fully protected talk pages', d.edit, d.full, 1, nil, nil)
end
 
function suite:testCategory_edit_full_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia fully protected pages', d.edit, d.full, 0, nil, nil)
end
 
Line 854 ⟶ 897:
end
 
function suite:testCategory_move_full_main_all_alltestCategory_move_full_main_all_temp()
self:assertProtectionCategoryEquals('Wikipedia move-protected pages', d.move, d.full, 0, nil, nild.temp)
end
 
function suite:testCategory_move_extended_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia extended-confirmed-protected pages', d.move, d.extended, 0, nil, nil)
end
 
function suite:testCategory_move_extended_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia extended-confirmed-protected templates', d.move, d.extended, 10, nil, nil)
end
 
Line 895 ⟶ 946:
 
function suite:testCategory_pc_pc1_user_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 2, nil, nil)
end
 
function suite:testCategory_pc_pc1_usertalk_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 3, nil, nil)
end
 
function suite:testCategory_pc_pc1_file_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 6, nil, nil)
end
 
function suite:testCategory_pc_pc1_wikipedia_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 4, nil, nil)
end
 
function suite:testCategory_pc_pc1_help_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 12, nil, nil)
end
 
function suite:testCategory_pc_pc1_portal_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 100, nil, nil)
end
 
function suite:testCategory_pc_pc1_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 10, nil, nil)
end
 
function suite:testCategory_pc_pc1_category_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 14, nil, nil)
end
 
function suite:testCategory_pc_pc1_talk_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 1, nil, nil)
end
 
function suite:testCategory_pc_pc1_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 1)', d.pc, d.pc1, 0, nil, nil)
end
 
--------------------------------------------------------------------------------
-- Categories: pending changes level 2
--------------------------------------------------------------------------------
 
function suite:testCategory_pc_pc2_user_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 2, nil, nil)
end
 
function suite:testCategory_pc_pc2_usertalk_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 3, nil, nil)
end
 
function suite:testCategory_pc_pc2_file_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 6, nil, nil)
end
 
function suite:testCategory_pc_pc2_wikipedia_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 4, nil, nil)
end
 
function suite:testCategory_pc_pc2_help_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 12, nil, nil)
end
 
function suite:testCategory_pc_pc2_portal_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 100, nil, nil)
end
 
function suite:testCategory_pc_pc2_template_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 10, nil, nil)
end
 
function suite:testCategory_pc_pc2_category_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 14, nil, nil)
end
 
function suite:testCategory_pc_pc2_talk_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 1, nil, nil)
end
 
function suite:testCategory_pc_pc2_main_all_all()
self:assertProtectionCategoryEquals('Wikipedia pending changes protected pages (level 2)', d.pc, d.pc2, 0, nil, nil)
end