Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Cat main/testcases
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local mCatMain = require('Module:Cat main/sandbox') -- the module to be tested local ScribuntoUnit = require('Module:ScribuntoUnit') local suite = ScribuntoUnit:new() -------------------------------------------------------------------------------- -- Helper functions -------------------------------------------------------------------------------- local function patchCurrentTitle(newTitle, func) local oldGetCurrentTitle = mw.title.getCurrentTitle mw.title.getCurrentTitle = function () return mw.title.new("Category:Example") end func() mw.title.getCurrentTitle = oldGetCurrentTitle end -------------------------------------------------------------------------------- -- Custom assert methods -------------------------------------------------------------------------------- function suite:assertHasClass(expectedClass, result) result = mw.text.killMarkers(result) -- remove TemplateStyles marker local classes = result:match('^<div[^>]*class="([^"]*)"') classes = mw.text.split(classes, ' ') local hasClass = false for _, actualClass in ipairs(classes) do if actualClass == expectedClass then hasClass = true break end end self:assertTrue( hasClass, string.format( 'Class "%s" %s in result "%s"', expectedClass, hasClass and "found" or "not found", result ) ) end -------------------------------------------------------------------------------- -- Tests -------------------------------------------------------------------------------- function suite:testWholeOutput() self:assertEquals( [=[<div role="note" class="hatnote navigation-not-searchable">The main article for this [[Help:Categories|category]] is '''[[:Foo]]'''.</div>]=], mw.text.killMarkers(mCatMain._catMain(nil, 'Foo')) ) end function suite:testOneArticle() self:assertStringContains( "The main article for this [[Help:Categories|category]] is '''[[:Foo]]'''.", mCatMain._catMain(nil, 'Foo'), true ) end function suite:testTwoArticles() self:assertStringContains( "The main articles for this [[Help:Categories|category]] are '''[[:Foo]]''' and '''[[:Bar]]'''.", mCatMain._catMain(nil, 'Foo', 'Bar'), true ) end function suite:testThreeArticles() self:assertStringContains( "The main articles for this [[Help:Categories|category]] are '''[[:Foo]]''', '''[[:Bar]]''' and '''[[:Baz]]'''.", mCatMain._catMain(nil, 'Foo', 'Bar', 'Baz'), true ) end function suite:testNonArticle() self:assertStringContains( "The main page for this [[Help:Categories|category]] is '''[[:Foo]]'''.", mCatMain._catMain({article = false}, 'Foo'), true ) end function suite:testSelfReference() self:assertHasClass("selfref", mCatMain._catMain({selfref = true}, 'Foo')) end function suite:testNoArticles() patchCurrentTitle( "Category:Example", function () self:assertStringContains( "The main article for this [[Help:Categories|category]] is '''[[:Example]]'''.", mCatMain._catMain(), true ) end ) end return suite
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Cat main/testcases/doc
(
edit
)