Module:Mock title/testcases
Appearance
![]() | This is the test cases page for the module Module:Mock title. Results of the test cases. |
local mMockTitle = require("Module:Mock title")
local ScribuntoUnit = require("Module:ScribuntoUnit")
local suite = ScribuntoUnit:new()
--------------------------------------------------------------------------------
-- MockTitle tests
--------------------------------------------------------------------------------
suite["test MockTitle: when no argument table is supplied, an error is raised"] = function (self)
self:assertThrows(
function () mMockTitle.MockTitle() end,
"bad argument #1 to 'MockTitle' (table expected, got nil)"
)
end
suite["test MockTitle: when no page argument is supplied, an error is raised"] = function (self)
self:assertThrows(
function () mMockTitle.MockTitle{} end,
"bad named argument page to 'MockTitle' (string expected, got nil)"
)
end
local pageNames = {
"Example",
"fr:Example",
"Module:Sandbox",
"Module:Sandbox/subpage",
"mw:Test",
"fr:b:Example",
}
for _, pageName in ipairs(pageNames) do
suite[
string.format(
'test MockTitle: when using page name "%s", the prefixedText property equals the page name',
pageName
)
] = function (self)
self:assertEquals("Example", mMockTitle.MockTitle({page = "Example"}).prefixedText)
end
end
local protectionLevelTestData = {
{
optionName = "editProtection",
optionValue = "sysop",
expectedProtectionAction = "edit",
},
{
optionName = "moveProtection",
optionValue = "sysop",
expectedProtectionAction = "move",
},
{
optionName = "createProtection",
optionValue = "sysop",
expectedProtectionAction = "create",
},
{
optionName = "uploadProtection",
optionValue = "sysop",
expectedProtectionAction = "upload",
},
}
for _, testData in ipairs(protectionLevelTestData) do
suite[
string.format(
'test MockTitle: when setting option %s to "%s", the protectionLevels table is updated accordingly',
testData.optionName,
testData.optionValue
)
] = function (self)
local title = mMockTitle.MockTitle{page = "Example", [testData.optionName] = testData.optionValue}
self:assertEquals(testData.optionValue, title.protectionLevels[testData.expectedProtectionAction][1])
end
end
suite["test MockTitle: if no protection option is specified, the real protectionLevels table is used"] = function (self)
suite:assertDeepEquals(
mw.title.new("Main Page").protectionLevels,
mMockTitle.MockTitle{page = "Main Page"}.protectionLevels
)
end
return suite