Module:Page assessment/testcases
Appearance
![]() | This is the test cases page for the module Module:Page assessment. Results of the test cases. |
-- Unit tests for [[Module:Page assessment}}]]. Click talk page to run tests.
local ScribuntoUnit = require('Module:ScribuntoUnit')
local liveMod = require('Module:Page assessment').util -- the module to be tested
local sandbox = require('Module:Page assessment/sandbox').test -- the module to be tested
local suite = ScribuntoUnit:new()
--[[
Tescase naming convention:
- Live module tests: "test" + MethodName + "_" + description
(use camel case either side of the underscore, e.g. testFoo_barBaz,
not testfoo_barBaz, nor testFoo_BarBaz, nor testfoo_barbaz, etc.)
- Sandbox module tests: As above, suffixed with "__sandbox"
(note the *double* undersecore)
This ensures the results page has descriptive names for all tests, and that
sandbox tests appear directly after live module tests.
]]--
---------- getWikitext ---------------------------------------------------------
function suite:testGetWikitext_fromArticle(modToTest)
modToTest = modToTest or liveMod
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipedia")
self:assertTrue(mw.ustring.len(subjectWikitext) > 100, "Wikitext of page 'Wikipedia' more than 100 chars")
self:assertTrue(mw.ustring.len(subjectWikitext) > 100, "Wikitext of page 'Talk:Wikipedia' more than 100 chars")
self:assertFalse(subjectWikitext == talkWikitext, "Subject page is different to talk page")
end
function suite:testGetWikitext_fromArticle__sandbox() return self:testGetWikitext_fromArticle(sandbox) end
function suite:testGetWikitext_fromTalk(modToTest)
modToTest = modToTest or liveMod
local subjectWikitext1, talkWikitext1 = modToTest.getWikitext("Wikipedia")
local subjectWikitext2, talkWikitext2 = modToTest.getWikitext("Talk:Wikipedia")
self:assertEquals(subjectWikitext1, subjectWikitext2, "Subject page of 'Wikipedia' is same as subject page of 'Talk:Wikipedia'")
self:assertEquals(talkWikitext1, talkWikitext2, "Talk page of 'Wikipedia' is same as talk page of 'Talk:Wikipedia'")
end
function suite:testGetWikitext_fromTalk__sandbox() return self:testGetWikitext_fromTalk(sandbox) end
function suite:testGetWikitext_nonExisting(modToTest)
modToTest = modToTest or liveMod
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipediadsgvbjfdoibtdhbntrsnsr")
self:assertEquals(subjectWikitext, nil, "Nil result for subject page wikitext")
self:assertEquals(talkWikitext, nil, "Nil result for talk page wikitext")
end
function suite:testGetWikitext_nonExisting__sandbox() return self:testGetWikitext_nonExisting(sandbox) end
---------- isRedirect ----------------------------------------------------------
function suite:testIsRedirect_fromWikitext(modToTest)
modToTest = modToTest or liveMod
self:assertTrue(modToTest.isRedirect("#REDIRECT [[Foo]]"), "uppercased")
self:assertTrue(modToTest.isRedirect("#Redirect [[Foo]]"), "sentence-cased")
self:assertTrue(modToTest.isRedirect("#redirect [[Foo]]"), "lower-cased")
self:assertFalse(modToTest.isRedirect("# REDIRECT [[Foo]]"), "space after #")
self:assertTrue(modToTest.isRedirect(" #REDIRECT [[Foo]]"), "space before #")
self:assertTrue(modToTest.isRedirect("#REDIRECT [[Foo]]"), "spaces before target")
self:assertFalse(modToTest.isRedirect("How to make a #REDIRECT [[Foo]]"), "Not at start")
self:assertFalse(modToTest.isRedirect("<pre>#REDIRECT [[Foo]]</pre>"), "Within pre tags")
end
function suite:testIsRedirect_fromWikitext__sandbox() return self:testIsRedirect_fromWikitext(sandbox) end
function suite:testIsRedirect_fromPages(modToTest)
modToTest = modToTest or liveMod
self:assertFalse(modToTest.isRedirect(modToTest.getWikitext("Wikipedia")), "page 'Wikipedia' is not a redirect")
self:assertTrue(modToTest.isRedirect(modToTest.getWikitext("MOS:ABBR")), "page 'MOS:ABBR' is a redirect")
end
function suite:testIsRedirect_fromPages__sandbox() return self:testIsRedirect_fromPages(sandbox) end
return suite