Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Database report/testcases

From Wikipedia, the free encyclopedia
local Report = require('Module:Database report')
local ScribuntoUnit = require('Module:ScribuntoUnit')

local suite = ScribuntoUnit:new()

function suite:assertLines(lines, report)
	local expectedOutput = '{{Database report'
	for _, line in ipairs(lines) do
		expectedOutput = expectedOutput .. '\n|' .. line
	end
	expectedOutput = expectedOutput .. '\n}}'
	self:assertEquals(expectedOutput, report:generate())
end

function suite:testOnlySqlParam()
	local report = Report:new()
	report:setSQL('SELECT 1 FROM page LIMIT 1')
	self:assertLines({'sql = SELECT 1 FROM page LIMIT 1'}, report)
end

function suite:testBasicWikilinks()
	local report = Report:new()
	report:setSQL('SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1')
	report:useWikilinks(1)
	self:assertLines({
		'sql = SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1', 
		'wikilinks = 1'
	}, report)
end

function suite:testWikilinksWithNamespace()
	local report = Report:new()
	report:setSQL('SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1')
	report:useWikilinks(1, 0)
	self:assertLines({
		'sql = SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1', 
		'wikilinks = 1:0'
	}, report)
end

function suite:testWikilinksWithNamespaceAndShow()
	local report = Report:new()
	report:setSQL('SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1')
	report:useWikilinks(1, 0, true)
	self:assertLines({
		'sql = SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1', 
		'wikilinks = 1:0:show'
	}, report)
end

function suite:testWidths()
	local report = Report:new()
	report:setSQL('SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1')
	report:setWidth(1, '10px')
	self:assertLines({
		'sql = SELECT page_title FROM page WHERE page_namespace = 0 LIMIT 1', 
		'widths = 1:10px'
	}, report)
end

function suite:testCommentColumns()
	local report = Report:new()
	report:setSQL('SELECT comment_text, comment_text AS ct2 FROM comment LIMIT 1')
	report:setCommentColumns(1, 2)
	self:assertLines({
		'sql = SELECT comment_text, comment_text AS ct2 FROM comment LIMIT 1', 
		'comments = 1, 2'
	}, report)
end

function suite:testRemoveUnderscores()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_latest FROM page WHERE page_namespace = 0 LIMIT 1')
	report:removeUnderscores(1, 2)
	self:assertLines({
		'sql = SELECT page_title, page_latest FROM page WHERE page_namespace = 0 LIMIT 1', 
		'remove_underscores = 1, 2'
	}, report)
end

function suite:testHideColumns()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace, page_latest FROM page LIMIT 1')
	report:hideColumns(2, 3)
	self:assertLines({
		'sql = SELECT page_title, page_namespace, page_latest FROM page LIMIT 1', 
		'hide = 2, 3'
	}, report)
end

function suite:testExcerpts()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:useExcerpt(1, 3, 'c1', 100, 200)
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'excerpts = 1:3:c1:100:200'
	}, report)
end

function suite:testTableStyles()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:setTableStyle('color: green')
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'table_style = color: green'
	}, report)
end

function suite:testTableClass()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:setTableClass('report')
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'table_class = report'
	}, report)
end

function suite:testInterval()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:setInterval(2)
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'interval = 2'
	}, report)
end

function suite:testPagination()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:setPagination(1000)
	report:setMaxPages(10)
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'max_pages = 10',
		'pagination = 1000',
	}, report)
end

function suite:testBooleanParams()
	local report = Report:new()
	report:setSQL('SELECT page_title, page_namespace FROM page LIMIT 1')
	report:setRowTemplate('Row template')
	report:setSilent(true)
	report:skipTable(false)
	report:useNamedParamsInRowTemplate(nil)
	self:assertLines({
		'sql = SELECT page_title, page_namespace FROM page LIMIT 1', 
		'row_template = Row template',
		'silent = true',
	}, report)
end

return suite