Jump to content

Module:Page assessment/testcases: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
test getting wikitext of non-existent page
test getting wikitext from talk page name
Line 6: Line 6:
local suite = ScribuntoUnit:new()
local suite = ScribuntoUnit:new()


--[[
function suite:testGetWikitext(modToTest)
Tescase naming convention:
-- From article
- 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.
]]--

function suite:testGetWikitext_fromArticle(modToTest)
modToTest = modToTest or liveMod
modToTest = modToTest or liveMod
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipedia")
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipedia")
Line 14: Line 24:
self:assertFalse(subjectWikitext == talkWikitext, "Subject page is different to talk page")
self:assertFalse(subjectWikitext == talkWikitext, "Subject page is different to talk page")
end
end
function suite:testGetWikitext_fromArticle__sandbox() return self:testGetWikitext_fromArticle(sandbox) end
function suite:testGetWikitext__sandbox()

self:testGetWikitext(sandbox)
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
end
function suite:testGetWikitext_fromTalk__sandbox() return self:testGetWikitext_fromTalk(sandbox) end


function suite:testGetWikitext_nonexisting(modToTest)
function suite:testGetWikitext_nonExisting(modToTest)
modToTest = modToTest or liveMod
modToTest = modToTest or liveMod
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipediadsgvbjfdoibtdhbntrsnsr")
local subjectWikitext, talkWikitext = modToTest.getWikitext("Wikipediadsgvbjfdoibtdhbntrsnsr")
Line 24: Line 41:
self:assertEquals(talkWikitext, nil, "Nil result for talk page wikitext")
self:assertEquals(talkWikitext, nil, "Nil result for talk page wikitext")
end
end
function suite:testGetWikitext_nonexisting__sandbox() return self:testGetWikitext_nonexisting(sandbox) end
function suite:testGetWikitext_nonExisting__sandbox() return self:testGetWikitext_nonExisting(sandbox) end




--[[
--[[

Revision as of 04:02, 30 December 2020

-- 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.
]]--

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



--[[
function suite:testSomeOtherCall()
    self:assertEquals('expected value', myModule.someOtherCall(123))
    self:assertEquals('other expected value', myModule.someOtherCall(456))
end
]]--

return suite