Module:Dokumentasie/toetsgevalle

Dokumentasie vir hierdie module kan geskep word by: Module:Dokumentasie/toetsgevalle/doc

-- Test cases page for [[Module:Dokumentasie]]. See talk page to run tests.

local doc = require('Module:Dokumentasie')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

--------------------------------------------------------------------------------------------
-- Test case helper functions
--------------------------------------------------------------------------------------------

local function getEnv(page)
	-- Gets an env table using the specified page.
	return doc.getEnvironment{page = page}
end

--------------------------------------------------------------------------------------------
-- Test helper functions
--------------------------------------------------------------------------------------------

function suite:testMessage()
	self:assertEquals('sandput', doc.message('sandbox-subpage'))
	self:assertEquals('Subblaaie vir die foobar', doc.message('subpages-link-display', {'foobar'}))
	self:assertEquals(true, doc.message('display-print-category', nil, 'boolean'))
end

function suite:testMakeToolbar()
	self:assertEquals(nil, doc.makeToolbar())
	self:assertEquals('<small style="font-style: normal;">(Foo)</small>', doc.makeToolbar('Foo'))
	self:assertEquals('<small style="font-style: normal;">(Foo &#124; Bar)</small>', doc.makeToolbar('Foo', 'Bar'))
end

function suite:testMakeWikilink()
	self:assertEquals('[[Foo]]', doc.makeWikilink('Foo'))
	self:assertEquals('[[Foo|Bar]]', doc.makeWikilink('Foo', 'Bar'))
end

function suite:testMakeCategoryLink()
	self:assertEquals('[[Kategorie:Foo]]', doc.makeCategoryLink('Foo'))
	self:assertEquals('[[Kategorie:Foo|Bar]]', doc.makeCategoryLink('Foo', 'Bar'))
end

function suite:testMakeUrlLink()
	self:assertEquals('[Foo Bar]', doc.makeUrlLink('Foo', 'Bar'))
end

--------------------------------------------------------------------------------------------
-- Test env table
--------------------------------------------------------------------------------------------

function suite:assertEnvFieldEquals(expected, page, field)
	local env = getEnv(page)
	self:assertEquals(expected, env[field])
end	

function suite:assertEnvTitleEquals(expected, page, titleField)
	local env = getEnv(page)
	local title = env[titleField]
	self:assertEquals(expected, title.prefixedText)
end	

function suite:testEnvTitle()
	self:assertEnvTitleEquals('Wikipedia:Sandput', 'Wikipedia:Sandput', 'title')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/sandput', 'Sjabloon:Voorbeeld/sandput', 'title')
end

function suite:testEnvBadTitle()
	local env = doc.getEnvironment{page = 'Bad[]Title'}
	local title = env.title
	self:assertEquals(nil, title)
end

function suite:testEnvTemplateTitle()
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld', 'Sjabloon:Voorbeeld', 'templateTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld', 'Sjabloonbespreking:Voorbeeld', 'templateTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld', 'Sjabloon:Voorbeeld/sandput', 'templateTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld', 'Sjabloonbespreking:Voorbeeld/sandput', 'templateTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld', 'Sjabloon:Voorbeeld/toetsgevalle', 'templateTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/foo', 'Sjabloon:Voorbeeld/foo', 'templateTitle')
	self:assertEnvTitleEquals('Lêer:Voorbeeld', 'Lêerbespreking:Voorbeeld', 'templateTitle')
	self:assertEnvTitleEquals('Lêer:Voorbeeld', 'Lêerbespreking:Voorbeeld/sandput', 'templateTitle')
end

function suite:testEnvDocTitle()
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/doc', 'Sjabloon:Voorbeeld', 'docTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/doc', 'Sjabloonbespreking:Voorbeeld', 'docTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/doc', 'Sjabloon:Voorbeeld/sandput', 'docTitle')
	self:assertEnvTitleEquals('Bespreking:Voorbeeld/doc', 'Voorbeeld', 'docTitle')
	self:assertEnvTitleEquals('Lêerbespreking:Voorbeeld.png/doc', 'Lêer:Voorbeeld.png', 'docTitle')
	self:assertEnvTitleEquals('Lêerbespreking:Voorbeeld.png/doc', 'Lêerbespreking:Voorbeeld.png/sandput', 'docTitle')
end

function suite:testEnvSandboxTitle()
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/sandput', 'Sjabloon:Voorbeeld', 'sandboxTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/sandput', 'Sjabloonbespreking:Voorbeeld', 'sandboxTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/sandput', 'Sjabloon:Voorbeeld/sandput', 'sandboxTitle')
	self:assertEnvTitleEquals('Bespreking:Voorbeeld/sandput', 'Voorbeeld', 'sandboxTitle')
	self:assertEnvTitleEquals('Lêerbespreking:Voorbeeld.png/sandput', 'Lêer:Voorbeeld.png', 'sandboxTitle')
end

function suite:testEnvTestcasesTitle()
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/toetsgevalle', 'Sjabloon:Voorbeeld', 'testcasesTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/toetsgevalle', 'Sjabloonbespreking:Voorbeeld', 'testcasesTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/toetsgevalle', 'Sjabloon:Voorbeeld/toetsgevalle', 'testcasesTitle')
	self:assertEnvTitleEquals('Bespreking:Voorbeeld/toetsgevalle', 'Voorbeeld', 'testcasesTitle')
	self:assertEnvTitleEquals('Lêerbespreking:Voorbeeld.png/toetsgevalle', 'Lêer:Voorbeeld.png', 'testcasesTitle')
end

function suite:testEnvPrintTitle()
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/Druk', 'Sjabloon:Voorbeeld', 'printTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/Druk', 'Sjabloonbespreking:Voorbeeld', 'printTitle')
	self:assertEnvTitleEquals('Sjabloon:Voorbeeld/Druk', 'Sjabloon:Voorbeeld/sandput', 'printTitle')
end

function suite:testEnvProtectionLevels()
	local pipeEnv = getEnv('Sjabloon:!')
	self:assertEquals('sysop', pipeEnv.protectionLevels.edit[1])
	local sandboxEnv = getEnv('Wikipedia:Sandput')
	local sandboxEditLevels = sandboxEnv.protectionLevels.edit
	if sandboxEditLevels then -- sandboxEditLevels may also be nil if the page is unprotected
		self:assertEquals(nil, sandboxEditLevels[1])
	else
		self:assertEquals(nil, sandboxEditLevels)
	end
end

function suite:testEnvSubjectSpace()
	self:assertEnvFieldEquals(10, 'Sjabloon:Sandput', 'subjectSpace')
	self:assertEnvFieldEquals(10, 'Sjabloonbespreking:Sandput', 'subjectSpace')
	self:assertEnvFieldEquals(0, 'Foo', 'subjectSpace')
	self:assertEnvFieldEquals(0, 'Bespreking:Foo', 'subjectSpace')
end

function suite:testEnvDocSpace()
	self:assertEnvFieldEquals(10, 'Sjabloon:Sandput', 'docSpace')
	self:assertEnvFieldEquals(828, 'Module:Sandput', 'docSpace')
	self:assertEnvFieldEquals(1, 'Foo', 'docSpace')
	self:assertEnvFieldEquals(7, 'Lêer:Voorbeeld.png', 'docSpace')
	self:assertEnvFieldEquals(9, 'MediaWiki:Watchlist-details', 'docSpace')
	self:assertEnvFieldEquals(15, 'Kategorie:Wikipedians', 'docSpace')
end

function suite:testEnvDocpageBase()
	self:assertEnvFieldEquals('Sjabloon:Voorbeeld', 'Sjabloon:Voorbeeld', 'docpageBase')
	self:assertEnvFieldEquals('Sjabloon:Voorbeeld', 'Sjabloon:Voorbeeld/sandput', 'docpageBase')
	self:assertEnvFieldEquals('Sjabloon:Voorbeeld', 'Sjabloonbespreking:Voorbeeld', 'docpageBase')
	self:assertEnvFieldEquals('Lêerbespreking:Voorbeeld.png', 'Lêer:Voorbeeld.png', 'docpageBase')
	self:assertEnvFieldEquals('Lêerbespreking:Voorbeeld.png', 'Lêerbespreking:Voorbeeld.png', 'docpageBase')
	self:assertEnvFieldEquals('Lêerbespreking:Voorbeeld.png', 'Lêerbespreking:Voorbeeld.png/sandput', 'docpageBase')
end

function suite:testEnvCompareUrl()
	-- We use "Template:Edit protected" rather than "Template:Voorbeeld" here as it has a space in the title.
	local expected = '//af.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=Sjabloon%3AEdit+protected&page2=Sjabloon%3AEdit+protected%2Fsandbox'
	self:assertEnvFieldEquals(expected, 'Sjabloon:Edit protected', 'compareUrl') 
	self:assertEnvFieldEquals(expected, 'Sjabloon:Edit protected/sandput', 'compareUrl')
	self:assertEnvFieldEquals(nil, 'Sjabloon:Non-existent template adsfasdg', 'compareUrl')
	self:assertEnvFieldEquals(nil, 'Sjabloon:Fact', 'compareUrl') -- Exists but doesn't have a sandbox.
end

--------------------------------------------------------------------------------------------
-- Test sandbox notice
--------------------------------------------------------------------------------------------

function suite.getSandboxNoticeTestData(page)
	local env = getEnv(page)
	local templatePage = page:match('^(.*)/sandput$')
	local image = '[[Image:Sandbox.svg|50px|alt=|link=]]'
	local templateBlurb = 'This is the [[Wikipedia:Template test cases|template sandbox]] page for [[' .. templatePage .. ']]'
	local moduleBlurb = 'This is the [[Wikipedia:Template test cases|module sandbox]] page for [[' .. templatePage .. ']]'
	local otherBlurb = 'This is the sandbox page for [[' .. templatePage .. ']]'
	local diff = '[//af.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=' .. mw.uri.encode(templatePage) .. '&page2=' .. mw.uri.encode(page) .. ' diff]'
	local testcasesBlurb = 'See also the companion subpage for [[' .. templatePage .. '/toetsgevalle|test cases]].'
	local category = '[[Kategorie:Template sandboxes]]'
	local clear = '<div style="clear: both;"></div>'
	return env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category, clear
end	

function suite:testSandboxNoticeNotSandbox()
	local env = getEnv('Sjabloon:Voorbeeld')
	local notice = doc.sandboxNotice({}, env)
	self:assertEquals(nil, notice)
end

function suite:testSandboxNoticeStaticVals()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category, clear = suite.getSandboxNoticeTestData('Sjabloon:Voorbeeld/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertStringContains('^' .. clear, notice, false)
	self:assertStringContains(image, notice, true)
	self:assertStringContains(category, notice, true)
end

function suite:testSandboxNoticeTemplateBlurb()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Sjabloon:Voorbeeld/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertStringContains(templateBlurb, notice, true)
end

function suite:testSandboxNoticeModuleBlurb()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Module:Math/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertStringContains(moduleBlurb, notice, true)
end

function suite:testSandboxNoticeOtherBlurb()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('User:Mr. Stradivarius/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertStringContains(otherBlurb, notice, true)
end

function suite:testSandboxNoticeBlurbDiff()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Sjabloon:Voorbeeld/sandput')
	local notice = doc.sandboxNotice({}, env)
	if mw.title.getCurrentTitle().isTalk then
		-- This test doesn't work in the debug console due to the use of frame:preprocess({{REVISIONID}}).
		-- The frame test doesn't seem to be working for now, so adding a namespace hack.
		self:assertStringContains(diff, notice, true)
	end
end

function suite:testSandboxNoticeBlurbDiffNoBasePage()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Module:User:Mr. Stradivarius/sandput')
	local notice = doc.sandboxNotice({}, env)
	if mw.title.getCurrentTitle().isTalk then
		-- This test doesn't work in the debug console due to the use of frame:preprocess({{REVISIONID}}).
		-- The frame test doesn't seem to be working for now, so adding a namespace hack.
		self:assertNotStringContains(diff, notice, true)
	end
end

function suite:testSandboxNoticeTestcases()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Sjabloon:Edit protected/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertStringContains(testcasesBlurb, notice, true)
end

function suite:testSandboxNoticeNoTestcases()
	local env, image, templateBlurb, moduleBlurb, otherBlurb, diff, testcasesBlurb, category = suite.getSandboxNoticeTestData('Sjabloon:Voorbeeld/sandput')
	local notice = doc.sandboxNotice({}, env)
	self:assertNotStringContains(testcasesBlurb, notice, true)
end

--------------------------------------------------------------------------------------------
-- Test protection template
-- 
-- There's not much we can do with this until {{pp-meta}} gets rewritten in Lua. At the
-- moment the protection detection only works for the current page, and the testcases pages
-- will be unprotected.
--------------------------------------------------------------------------------------------

function suite:testProtectionTemplateUnprotectedTemplate()
	local env = getEnv('Sjabloon:Voorbeeld')
	self:assertEquals(nil, doc.protectionTemplate(env))
end

function suite:testProtectionTemplateProtectedTemplate()
	local env = getEnv('Sjabloon:Voorbladster')
	-- Test whether there is some content. We don't care what the content is, as the protection level
	-- detected will be for the current page, not the template.
	self:assertTrue(doc.protectionTemplate(env))
end

function suite:testProtectionTemplateUnprotectedModule()
	local env = getEnv('Module:Bananas')
	self:assertEquals(nil, doc.protectionTemplate(env))
end

function suite:testProtectionTemplateProtectedModule()
	local env = getEnv('Module:Yesno')
	-- Test whether there is some content. We don't care what the content is, as the protection level
	-- detected will be for the current page, not the template.
	self:assertTrue(doc.protectionTemplate(env))
end

--------------------------------------------------------------------------------------------
-- Test _startBox
--------------------------------------------------------------------------------------------

function suite:testStartBoxContentArg()
	local pattern = '<div style="padding%-bottom:3px;border%-bottom:1px solid #aaa;margin%-bottom:1ex;">\n<span style="font%-weight:bold;font%-size:125%%;">.-</span></div>'
	local startBox = doc._startBox({content = 'some documentation'}, getEnv('Sjabloon:Voorbeeld'))
	self:assertStringContains(pattern, startBox)
end

function suite:testStartBoxTemplateHtml()
	self:assertStringContains(
		'<div style="padding%-bottom:3px;border%-bottom:1px solid #aaa;margin%-bottom:1ex;">\n<span style="font%-weight:bold;font%-size:125%%;">.-</span><span class="mw%-editsection%-like plainlinks" id="doc_editlinks">.-</span></div>',
		doc._startBox({}, getEnv('Sjabloon:Voorbeeld'))
	)
end

function suite:testStartBoxMainHtml()
	self:assertStringContains(
		'<div style="padding%-bottom:3px;border%-bottom:1px solid #aaa;margin%-bottom:1ex;">\n<span style="font%-size:150%%;">.-</span><span class="mw%-editsection%-like plainlinks" id="doc_editlinks">.-</span></div>',
		doc._startBox({}, getEnv('Foo'))
	)
end

--------------------------------------------------------------------------------------------
-- Test makeStartBoxLinksData
--------------------------------------------------------------------------------------------

function suite:testMakeStartBoxLinksData()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxLinksData({}, env)
	self:assertEquals('Sjabloon:Voorbeeld', data.title.prefixedText)
	self:assertEquals('Sjabloon:Voorbeeld/doc', data.docTitle.prefixedText)
	self:assertEquals('sien', data.viewLinkDisplay)
	self:assertEquals('edit', data.editLinkDisplay)
	self:assertEquals('history', data.historyLinkDisplay)
	self:assertEquals('purge', data.purgeLinkDisplay)
	self:assertEquals('create', data.createLinkDisplay)
end

function suite:testMakeStartBoxLinksDataFilePreload()
	local env = getEnv('Lêer:Voorbeeld.png')
	local data = doc.makeStartBoxLinksData({}, env)
	self:assertEquals('Sjabloon:Dokumentasietoets/vooraflaailêernaamruimte', data.preload)
end

function suite:testMakeStartBoxLinksDataTemplatePreload()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxLinksData({}, env)
	self:assertEquals('Sjabloon:Dokumentasietoets/vooraflaai', data.preload)
end

function suite:testMakeStartBoxLinksDataArgsPreload()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxLinksData({preload = 'My custom preload'}, env)
	self:assertEquals('My custom preload', data.preload)
end

--------------------------------------------------------------------------------------------
-- Test renderStartBoxLinks
--------------------------------------------------------------------------------------------

function suite.makeExampleStartBoxLinksData(exists)
	-- Makes a data table to be used with testRenderStartBoxLinksExists and testRenderStartBoxLinksDoesntExist.
	local data = {}
	if exists then
		data.title = mw.title.new('Sjabloon:!')
		data.docTitle = mw.title.new('Sjabloon:!/doc')
	else
		data.title = mw.title.new('Sjabloon:NonExistentTemplate')
		data.docTitle = mw.title.new('Sjabloon:NonExistentTemplate/doc')
	end
	data.viewLinkDisplay = 'view'
	data.editLinkDisplay = 'edit'
	data.historyLinkDisplay = 'history'
	data.purgeLinkDisplay = 'purge'
	data.createLinkDisplay = 'create'
	data.preload = 'Sjabloon:MyPreload'
	return data
end

function suite:testRenderStartBoxLinksExists()
	local data = suite.makeExampleStartBoxLinksData(true)
	local expected = '&#91;[[Sjabloon:!/doc|view]]&#93; &#91;[//af.wikipedia.org/w/index.php?title=Sjabloon:!/doc&action=edit edit]&#93; &#91;[//af.wikipedia.org/w/index.php?title=Sjabloon:!/doc&action=history history]&#93; &#91;[//af.wikipedia.org/w/index.php?title=Sjabloon:!&action=purge purge]&#93;'
	self:assertEquals(expected, doc.renderStartBoxLinks(data))
end

function suite:testRenderStartBoxLinksDoesntExist()
	local data = suite.makeExampleStartBoxLinksData(false)
	local expected = '&#91;[//af.wikipedia.org/w/index.php?title=Sjabloon:NonExistentTemplate/doc&action=edit&preload=Sjabloon%3AMyPreload create]&#93;'
	self:assertEquals(expected, doc.renderStartBoxLinks(data))
end

--------------------------------------------------------------------------------------------
-- Test makeStartBoxData
--------------------------------------------------------------------------------------------

function suite:testStartBoxDataBlankHeading()
	local data = doc.makeStartBoxData({heading = ''}, {})
	self:assertEquals(nil, data)
end

function suite:testStartBoxDataHeadingTemplate()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxData({}, env)
	local expected = '[[Lêer:Test Template Info-Icon - Version (2).svg|50px|link=|alt=Documentation icon]] Template documentation'
	self:assertEquals(expected, data.heading)
end

function suite:testStartBoxDataHeadingModule()
	local env = getEnv('Module:Bananas')
	local data = doc.makeStartBoxData({}, env)
	local expected = '[[Lêer:Test Template Info-Icon - Version (2).svg|50px|link=|alt=Documentation icon]] Module documentation'
	self:assertEquals(expected, data.heading)
end

function suite:testStartBoxDataHeadingFile()
	local env = getEnv('Lêer:Voorbeeld.png')
	local data = doc.makeStartBoxData({}, env)
	local expected = 'Summary'
	self:assertEquals(expected, data.heading)
end

function suite:testStartBoxDataHeadingOther()
	local env = getEnv('User:Voorbeeld')
	local data = doc.makeStartBoxData({}, env)
	local expected = 'Dokumentasie'
	self:assertEquals(expected, data.heading)
end

function suite:testStartBoxDataHeadingStyle()
	local data = doc.makeStartBoxData({['heading-style'] = 'foo:bar'}, {})
	self:assertEquals('foo:bar', data.headingStyleText)
	self:assertEquals(nil, data.headingFontSize)
	self:assertEquals(nil, data.headingFontWeight)
end

function suite:testStartBoxDataHeadingStyleTemplate()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxData({}, env)
	self:assertEquals('bold', data.headingFontWeight)
	self:assertEquals('125%', data.headingFontSize)
	self:assertEquals(nil, data.headingStyleText)
end

function suite:testStartBoxDataHeadingStyleOther()
	local env = getEnv('User:Voorbeeld')
	local data = doc.makeStartBoxData({}, env)
	self:assertEquals('150%', data.headingFontSize)
	self:assertEquals(nil, data.headingFontWeight)
	self:assertEquals(nil, data.headingStyleText)
end

function suite:testStartBoxDataLinks()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxData({}, env, 'some links')
	self:assertEquals('some links', data.links)
	self:assertEquals('mw-editsection-like plainlinks', data.linksClass)
	self:assertEquals('doc_editlinks', data.linksId)
end

function suite:testStartBoxDataNoLinks()
	local env = getEnv('Sjabloon:Voorbeeld')
	local data = doc.makeStartBoxData({}, env)
	self:assertEquals(nil, data.links)
	self:assertEquals(nil, data.linksClass)
	self:assertEquals(nil, data.linksId)
end

--------------------------------------------------------------------------------------------
-- Test renderStartBox
--------------------------------------------------------------------------------------------

function suite:testRenderStartBox()
	local expected = '<div style="padding-bottom:3px;border-bottom:1px solid #aaa;margin-bottom:1ex">\n<span></span></div>'
	self:assertEquals(expected, doc.renderStartBox{})
end

function suite:testRenderStartBoxHeadingStyleText()
	self:assertStringContains('\n<span style="foo:bar;">', doc.renderStartBox{headingStyleText = 'foo:bar'}, true)
end

function suite:testRenderStartBoxHeadingFontWeight()
	self:assertStringContains('\n<span style="font-weight:bold">', doc.renderStartBox{headingFontWeight = 'bold'}, true)
end

function suite:testRenderStartBoxHeadingFontSize()
	self:assertStringContains('\n<span style="font-size:120%">', doc.renderStartBox{headingFontSize = '120%'}, true)
end

function suite:testRenderStartBoxHeading()
	self:assertStringContains('\n<span>Foobar</span>', doc.renderStartBox{heading = 'Foobar'}, true)
end

function suite:testRenderStartBoxLinks()
	self:assertStringContains('<span>list of links</span>', doc.renderStartBox{links = 'list of links'}, true)
end

function suite:testRenderStartBoxLinksClass()
	self:assertStringContains('<span class="linksclass">list of links</span>', doc.renderStartBox{linksClass = 'linksclass', links = 'list of links'}, true)
	self:assertNotStringContains('linksclass', doc.renderStartBox{linksClass = 'linksclass'}, true)
end

function suite:testRenderStartBoxLinksId()
	self:assertStringContains('<span id="linksid">list of links</span>', doc.renderStartBox{linksId = 'linksid', links = 'list of links'}, true)
	self:assertNotStringContains('linksid', doc.renderStartBox{linksId = 'linksid'}, true)
end

--------------------------------------------------------------------------------------------
-- Test _content
--------------------------------------------------------------------------------------------

function suite:testContentArg()
	self:assertEquals('\nsome documentation\n', doc._content({content = 'some documentation'}, {}))
end

function suite:testContentNoContent()
	local env = getEnv('Sjabloon:This is a non-existent template agauchvaiu')
	self:assertEquals('\n\n', doc._content({}, env))
end

function suite:testContentExists()
	local env = doc.getEnvironment{'Sjabloon:Dokumentasietoets/toetsgevalle/toets3'}
	local docs = mw.getCurrentFrame():preprocess('{{Sjabloon:Dokumentasietoets/toetsgevalle/toets3}}')
	local expected = '\n' .. docs .. '\n'
	self:assertEquals(expected, doc._content({}, env))
end

--------------------------------------------------------------------------------------------
-- Test _endBox
--------------------------------------------------------------------------------------------

function suite:testEndBoxLinkBoxOff()
	local env = getEnv()
	self:assertEquals(nil, doc._endBox({['link box'] = 'off'}, env))
end

function suite:testEndBoxNoDocsOtherNs()
	local env = {
		subjectSpace = 4,
		docTitle = {
			exists = false
		}
	}
	self:assertEquals(nil, doc._endBox({}, env))
end

function suite:testEndBoxAlwaysShowNs()
	self:assertTrue(doc._endBox({}, getEnv('Sjabloon:Non-existent template asdfalsdhaw')))
	self:assertTrue(doc._endBox({}, getEnv('Module:Non-existent module asdhewbydcyg')))
	self:assertTrue(doc._endBox({}, getEnv('User:Non-existent user ahfliwebalisyday')))
end

function suite:testEndBoxStyles()
	local env = getEnv('Sjabloon:Voorbeeld')
	local endBox = doc._endBox({}, env)
	self:assertStringContains('id="documentation-meta-data"', endBox, true)
	self:assertStringContains('style="background-color: #ecfcf4;"', endBox, true)
	self:assertStringContains('style="font-style: italic;">', endBox, true)
	self:assertNotStringContains('[[Lêer:', endBox, true)
	self:assertNotStringContains('[[Image:', endBox, true)
end

function suite:testEndBoxSandboxImage()
	local env = getEnv('Sjabloon:Voorbeeld/sandput')
	local endBox = doc._endBox({}, env)
	self:assertNotStringContains('[[Lêer:', endBox, true)
	self:assertNotStringContains('[[Image:', endBox, true)
end

function suite:testEndBoxLinkBoxArg()
	local env = getEnv()
	self:assertStringContains('Custom link box', doc._endBox({['link box'] = 'Custom link box'}, env))
end

function suite:testEndBoxExperimentBlurbValidNs()
	local expected = 'Redigeerders kan eksperimenteer met hierdie.-<br />'
	self:assertStringContains(expected, doc._endBox({}, getEnv('Sjabloon:Voorbeeld')))
	self:assertStringContains(expected, doc._endBox({}, getEnv('Module:Piesangs')))
	self:assertStringContains(expected, doc._endBox({}, getEnv('Gebruiker:Voorbeeld')))
end

function suite:testEndBoxExperimentBlurbInvalidNs()
	local expected = 'Redigeerders kan eksperimenteer met hierdie.-<br />'
	self:assertNotStringContains(expected, doc._endBox({}, getEnv('Wikipedia:Saadjie'))) -- Wikipedia:Twinkle has an existing /doc subpage
end

function suite:testEndBoxCategoriesBlurb()
	local expected = 'Voeg asseblief kategorieë by die %[%[.-|/doc%]%]%-subblad%.'
	self:assertStringContains(expected, doc._endBox({}, getEnv('Sjabloon:Voorbeeld')))
	self:assertStringContains(expected, doc._endBox({}, getEnv('Module:Piesangs')))
	self:assertStringContains(expected, doc._endBox({}, getEnv('Gebruiker:Voorbeeld')))
	self:assertNotStringContains(expected, doc._endBox({[1] = 'Foo'}, getEnv('Sjabloon:Voorbeeld')))
	self:assertNotStringContains(expected, doc._endBox({content = 'Bar'}, getEnv('Sjabloon:Voorbeeld')))
	--self:assertNotStringContains(expected, doc._endBox({}, getEnv('Wikipedia:Sandput')))
end

function suite:testEndBoxPrintBlurb()
	local expected = '<br />\'n %[%[Help:Books/for experts#Improving the book layout|drukweergawe%]%]'
		.. ' van hierdie sjabloon bestaan by %[%[.-|/Druk%]%]%.'
		.. ' Indien jy \'n verandering aan hierdie sjabloon maak, werk asseblief die drukweergawe ook by%.'
	self:assertStringContains(expected, doc._endBox({}, getEnv('Sjabloon:Dokumenttoets'))) -- Has a /Print subpage
	self:assertNotStringContains(expected, doc._endBox({}, getEnv('Sjabloon:!'))) -- Doesn't have a /Print subpage, and is not likely to.
end

--------------------------------------------------------------------------------------------
-- Test makeDocPageBlurb
--------------------------------------------------------------------------------------------

function suite:testDocPageBlurbError()
	self:assertEquals(nil, doc.makeDocPageBlurb({}, {}))
end

function suite:testDocPageBlurbTemplateDocExists()
	local env = getEnv('Sjabloon:Dokumentasietoets')
	local expected = 'Die bostaande [[Wikipedia:Sjabloondokumentasie|dokumentasie]] is [[Wikipedia:Transklusie|oorgebring]] uit [[Sjabloon:Dokumentasietoets/doc]]. <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Sjabloon:Dokumentasietoets/doc&action=edit wysig] &#124; [//af.wikipedia.org/w/index.php?title=Sjabloon:Dokumentasietoets/doc&action=history geskiedenis])</small><br />'
	self:assertEquals(expected, doc.makeDocPageBlurb({}, env))
end

function suite:testDocPageBlurbTemplateDocDoesntExist()
	local env = getEnv('Sjabloon:Non-existent template ajlkfdsa')
	self:assertEquals(nil, doc.makeDocPageBlurb({}, env))
end

function suite:testDocPageBlurbModuleDocExists()
	local env = getEnv('Module:Piesangs')
	local expected = 'Die bostaande [[Wikipedia:Sjabloondokumentasie|dokumentasie]] is [[Wikipedia:Transklusie|oorgebring]] uit [[Module:Piesangs/doc]]. <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Module:Piesangs/doc&action=edit wysig] &#124; [//af.wikipedia.org/w/index.php?title=Module:Piesangs/doc&action=history geskiedenis])</small><br />'
	self:assertEquals(expected, doc.makeDocPageBlurb({}, env))
end

function suite:testDocPageBlurbModuleDocDoesntExist()
	local env = getEnv('Module:Non-existent module ajlkfdsa')
	local expected = 'Jy wil dalk \'n dokumentblad [//af.wikipedia.org/w/index.php?title=Module:Non-existent_module_ajlkfdsa/doc&action=edit&preload=Sjabloon%3ADokumentasietoets%2Fvooraflaaimoduledoc skep] vir hierdie [[Wikipedia:Lua|Scribunto-module]].<br />'
	self:assertEquals(expected, doc.makeDocPageBlurb({}, env))
end

--------------------------------------------------------------------------------------------
-- Test makeExperimentBlurb
--------------------------------------------------------------------------------------------

function suite:testExperimentBlurbTemplate()
	local env = getEnv('Sjabloon:Voorbeeld')
	self:assertStringContains("Redigeerders kan eksperimenteer met hierdie sjabloon se .- en .- blaaie.", doc.makeExperimentBlurb({}, env))
end

function suite:testExperimentBlurbModule()
	local env = getEnv('Module:Piesangs')
	self:assertStringContains("Redigeerders kan eksperimenteer met hierdie module se .- en .- blaaie.", doc.makeExperimentBlurb({}, env))
end

function suite:testExperimentBlurbSandboxExists()
	local env = getEnv('Sjabloon:Edit protected')
	local pattern = '[[Sjabloon:Edit protected/sandput|sandput]] <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Sjabloon:Edit_protected/sandput&action=edit edit] &#124; [//af.wikipedia.org/w/index.php?title=Special%3AComparePages&page1=Sjabloon%3AEdit+protected&page2=Sjabloon%3AEdit+protected%2Fsandbox diff])</small>'
	self:assertStringContains(pattern, doc.makeExperimentBlurb({}, env), true)
end

function suite:testExperimentBlurbSandboxDoesntExist()
	local env = getEnv('Sjabloon:Non-existent template sajdfasd')
	local pattern = 'sandput <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Sjabloon:Non-existent_template_sajdfasd/sandput&action=edit&preload=Sjabloon%3ADocumentation%2Fpreload-sandbox create] &#124; [//af.wikipedia.org/w/index.php?title=Sjabloon:Non-existent_template_sajdfasd/sandput&preload=Sjabloon%3ANon-existent+template+sajdfasd&action=edit&summary=Create+sandbox+version+of+%5B%5BTemplate%3ANon-existent+template+sajdfasd%5D%5D spieël])</small>'
	self:assertStringContains(pattern, doc.makeExperimentBlurb({}, env), true)
end

function suite:testExperimentBlurbTestcasesExist()
	local env = getEnv('Sjabloon:Edit protected')
	local pattern = '[[Sjabloon:Edit protected/toetsgevalle|toetsgevalle]] <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Sjabloon:Edit_protected/toetsgevalle&action=edit edit])</small>'
	self:assertStringContains(pattern, doc.makeExperimentBlurb({}, env), true)
end

function suite:testExperimentBlurbTestcasesDontExist()
	local env = getEnv('Sjabloon:Non-existent template sajdfasd')
	local pattern = 'toetsgevalle <small style="font-style: normal;">([//af.wikipedia.org/w/index.php?title=Sjabloon:Non-existent_template_sajdfasd/toetsgevalle&action=edit&preload=Sjabloon%3ADocumentation%2Fpreload-testcases create])</small>'
	self:assertStringContains(pattern, doc.makeExperimentBlurb({}, env), true)
end

--------------------------------------------------------------------------------------------
-- Test makeCategoriesBlurb
--------------------------------------------------------------------------------------------

function suite:testMakeCategoriesBlurb()
	local env = getEnv('Sjabloon:Voorbeeld')
	self:assertEquals('Voeg asseblief kategorieë by die [[Sjabloon:Voorbeeld/doc|/doc]]-subblad.', doc.makeCategoriesBlurb({}, env))
end

--------------------------------------------------------------------------------------------
-- Test makeSubpagesBlurb
--------------------------------------------------------------------------------------------

function suite:testMakeSubpagesBlurbTemplate()
	local env = getEnv('Sjabloon:Voorbeeld')
	self:assertEquals('[[Special:PrefixIndex/Sjabloon:Voorbeeld/|Subpages of this template]].', doc.makeSubpagesBlurb({}, env))
end

function suite:testMakeSubpagesBlurbModule()
	local env = getEnv('Module:Bananas')
	self:assertEquals('[[Special:PrefixIndex/Module:Bananas/|Subpages of this module]].', doc.makeSubpagesBlurb({}, env))
end

function suite:testMakeSubpagesBlurbOther()
	local env = getEnv('Lêer:Voorbeeld.png')
	self:assertEquals('[[Special:PrefixIndex/Lêer:Voorbeeld.png/|Subpages of this page]].', doc.makeSubpagesBlurb({}, env))
end

--------------------------------------------------------------------------------------------
-- Test makePrintBlurb
--------------------------------------------------------------------------------------------

function suite:testMakePrintBlurbExists()
	local env = {
		printTitle = {
			exists = true,
			prefixedText = 'Sjabloon:Voorbeeld/Druk'
		}
	}
	local expected = '\'n [[Help:Books/for experts#Improving the book layout|drukweergawe]]'
		.. ' van hierdie sjabloon bestaan by [[Sjabloon:Voorbeeld/Druk|/Druk]].'
		.. ' Indien jy \'n verandering aan hierdie sjabloon maak, werk asseblief die drukweergawe ook by.'
		.. '[[Kategorie:Sjablone met drukweergawes]]'
	self:assertEquals(expected, doc.makePrintBlurb({}, env))
end

function suite:testMakePrintBlurbDoesntExist()
	local env = {
		printTitle = {
			exists = false,
			prefixedText = 'Sjabloon:Voorbeeld/Druk'
		}
	}
	self:assertEquals(nil, doc.makePrintBlurb({}, env))
end

--------------------------------------------------------------------------------------------
-- Test addTrackingCategories
--------------------------------------------------------------------------------------------

function suite.getStrangeUsageCat()
	return '[[Kategorie:Wikipedia-blaaie met ongewone ((dokumentasie))gebruik]]'
end

function suite:testAddTrackingCategoriesTemplatePage()
	local env = getEnv('Sjabloon:Voorbeeld')
	self:assertEquals('', doc.addTrackingCategories(env))
end

function suite:testAddTrackingCategoriesDocPage()
	local env = getEnv('Sjabloon:Voorbeeld/doc')
	self:assertEquals(self.getStrangeUsageCat(), doc.addTrackingCategories(env))
end

function suite:testAddTrackingCategoriesTestcasesPage()
	local env = getEnv('Sjabloon:Voorbeeld/toetsgevalle')
	self:assertEquals(self.getStrangeUsageCat(), doc.addTrackingCategories(env))
end

function suite:testAddTrackingCategoriesModuleDoc()
	local env = getEnv('Module:Math/doc')
	self:assertEquals(self.getStrangeUsageCat(), doc.addTrackingCategories(env))
end

function suite:testAddTrackingCategoriesModuleTestcases()
	local env = getEnv('Module:Math/toetsgevalle')
	self:assertEquals('', doc.addTrackingCategories(env))
end

function suite:testAddTrackingCategoriesInvalidTitle()
	local env = getEnv('Sjabloon:Foo[]Bar')
	self:assertEquals(nil, doc.addTrackingCategories(env))
end

--------------------------------------------------------------------------------------------
-- Whitespace tests
--------------------------------------------------------------------------------------------

function suite:testNoTrailingWhitespace()
	self:assertStringContains('</table>$', doc.main{page = 'Sjabloon:Voorbeeld'})
end

--------------------------------------------------------------------------------------------
-- Whole-module tests
--------------------------------------------------------------------------------------------

function suite:testSandboxImageBug()
	self:assertNotStringContains('<table id="documentation%-meta%-data".-%[%[%w+:Sandbox.svg', doc.main{page = 'Sjabloon:Voorbeeld/sandput'})
end

return suite