Module:Italic title/testcases
Appearance
![]() | This is the test cases page for the module Module:Italic title. Results of the test cases. |
local mItalicTitle = require('Module:Italic title')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local Spy = require('Module:Lua-mock/Spy')
local suite = ScribuntoUnit:new()
local function patchCurrentTitle(page, func)
local oldGetCurrentTitle = mw.title.getCurrentTitle
mw.title.getCurrentTitle = function ()
return mw.title.new(page)
end
func()
mw.title.getCurrentTitle = oldGetCurrentTitle
end
local function patchDisplayTitle(func)
local oldGetCurrentFrame = mw.getCurrentFrame
local frame = oldGetCurrentFrame()
local oldCallParserFunction = frame.callParserFunction
local callParserFunctionSpy = Spy(oldCallParserFunction)
mw.getCurrentFrame = function ()
return frame
end
frame.callParserFunction = callParserFunctionSpy
func(callParserFunctionSpy, frame)
frame.callParserFunction = oldCallParserFunction
mw.getCurrentFrame = oldGetCurrentFrame
end
local displayTitleTestData = {
{
func = mItalicTitle._main,
description = 'test _main: Italicize all - single-word titles',
page = "Example",
args = {},
expectedDisplayTitleArgs = {"<i>Example</i>"},
},
{
func = mItalicTitle._main,
description = 'test _main: Italicize all - multi-word titles',
page = "Star Wars",
args = {},
expectedDisplayTitleArgs = {"<i>Star Wars</i>"},
},
{
func = mItalicTitle._main,
description = 'test _main: Only specified string argument italicized',
page = "List of Ally McBeal episodes",
args = {string = "Ally McBeal"},
expectedDisplayTitleArgs = {"List of <i>Ally McBeal</i> episodes"},
},
{
func = mItalicTitle._main,
description = 'test _main: Only specified string argument italicized - in disambiguation',
page = "Peter (Fringe episode)",
args = {string = "Fringe", all = "yes"},
expectedDisplayTitleArgs = {"Peter (<i>Fringe</i> episode)"},
},
{
func = mItalicTitle._dabonly,
description = 'test _dabonly: Italicize disambiguation',
page = "The End (Lost)",
args = {},
expectedDisplayTitleArgs = {"The End (<i>Lost</i>)"},
},
{
func = mItalicTitle._dabonly,
description = 'test _dabonly: Italicize disambiguation with parentheses',
page = "The Ghost Talks (Randall and Hopkirk (Deceased))",
args = {},
expectedDisplayTitleArgs = {"The Ghost Talks (<i>Randall and Hopkirk (Deceased)</i>)"},
},
{
func = mItalicTitle._dabonly,
description = 'test _dabonly: Italicize disambiguation without parentheses before',
page = "Title (not disambiguation) (disambiguation)",
args = {},
expectedDisplayTitleArgs = {"Title (not disambiguation) (<i>disambiguation</i>)"},
},
{
func = mItalicTitle._dabonly,
description = 'test _dabonly: Only specified string argument italicized - in disambiguation',
page = "Hell on Wheels (Hell on Wheels episode)",
args = {string = "Hell on Wheels"},
expectedDisplayTitleArgs = {"Hell on Wheels (<i>Hell on Wheels</i> episode)"},
},
}
for _, testData in ipairs(displayTitleTestData) do
suite[testData.description] = function (self)
patchCurrentTitle(
testData.page,
function ()
patchDisplayTitle(
function (callParserFunctionSpy, frame)
testData.func(testData.args)
callParserFunctionSpy:assertCallMatches{
atIndex = 1,
arguments = {
frame,
'DISPLAYTITLE',
unpack(testData.expectedDisplayTitleArgs),
}
}
end
)
end
)
end
end
return suite