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

Content deleted Content added
add renderPadlock test
fix renderImage test and add another
Line 8:
-- Helper functions
--------------------------------------------------------------------------------
 
function suite:testRenderPadlock.escapePattern(s)
-- Escapes the magic characters ()%.[]*+-?^$ for use in Lua patterns.
return s:gsub('([%(%)%.%[%]%*%+%-%?%^%$%%])', '%%%1')
end
 
function suite:assertCategoryEquals(expected, protType, protLevel, namespace, reason, expiry)
Line 954 ⟶ 959:
--------------------------------------------------------------------------------
 
d.padlockDivStartDefault = '<div class="metadata topicon nopopups" id="protected-icon" style="display:none;right:55px;">'
function suite:testRenderPadlock()
local expectedd.padlockDivStart65px = '<div class="metadata topicon nopopups" id="protected-icon" style="display:none;right:40px65px;">'
d.padlockDivEnd = '</div>'
.. '[[Image:foo.png|20px|link=[[bar]]|This is icon text|alt=This is alt text]]'
d.imagePattern = '%[%[Image:.-%]%]'
.. '</div>'
 
local actual = pp.renderPadlock{
function suite:testRenderPadlockDefault()
right = "40px",
local expected = suite.escapePattern(d.padlockDivStartDefault)
image = "foo.png",
.. d.imagePattern
iconLink = '[[bar]]',
.. suite.escapePattern(d.padlockDivEnd)
iconText = 'This is icon text',
local actual = pp.renderPadlock{('[[Image:Padlock.svg|20px]]')
altText = 'This is alt text'
self:assertEqualsassertStringContains(expected, actual)
}
end
self:assertEquals(expected, actual)
 
function suite:testRenderPadlockDefault()
local expected = suite.escapePattern(d.padlockDivStart65px)
.. d.imagePattern
.. suite.escapePattern(d.padlockDivEnd)
local actual = pp.renderPadlock('[[Image:Padlock.svg|20px]]', 65)
self:assertStringContains(expected, actual)
end