Jump to content

Module:Infobox television/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 16:48, 27 September 2021 (Created page with '-- Unit tests for Module:Infobox television. Click talk page to run tests. local p = require('Module:UnitTests') local function expandTemplate(template, value) local frame = mw.getCurrentFrame() return frame:expandTemplate{title = template, args = value} end function p:test_01_1_infobox_title_equal_to_article_title_live() self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', { {'page_title_test=Long article title|name...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
-- Unit tests for [[Module:Infobox television]]. Click talk page to run tests.
local p = require('Module:UnitTests')

local function expandTemplate(template, value)
	local frame = mw.getCurrentFrame()
	return frame:expandTemplate{title = template, args = value}
end

function p:test_01_1_infobox_title_equal_to_article_title_live()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'page_title_test=Long article title|name=' .. expandTemplate("Nowrap", {"Long article title"}), ''},
		{'page_title_test=Long article title|name=Long article <br>title', ''},
		{'page_title_test=Long article title|name=Long article <br >title', ''},
		{'page_title_test=Long article title|name=Long article <br/>title', ''},
		{'page_title_test=Long article title|name=Long article <br />title', ''},
		{'page_title_test=Long article title|name=Long article <br/> title', ''},
		{'page_title_test=Long article title (dab)|name=' .. expandTemplate("Nowrap", {"Long article title"}), ''},
		{'page_title_test=Long article title (dab)|name=Long article <br>title', ''},
		{'page_title_test=Test|name=Test', '[[Category:Pages using infobox television with unnecessary name parameter]]'},
		{'page_title_test=Test (dab)|name=Test', '[[Category:Pages using infobox television with unnecessary name parameter]]'},
		{'page_title_test=Test|name=test', '[[Category:Pages using infobox television with non-matching title]]'},
		{'page_title_test=Long article title|name=' .. expandTemplate("Nowrap", {"Long article Title"}), '[[Category:Pages using infobox television with non-matching title]]'},
		{'page_title_test=Long article title|name=Long article <br/> Title', '[[Category:Pages using infobox television with non-matching title]]'},
    }, {nowiki=1})
end

function p:test_01_2_infobox_title_equal_to_article_title_sandbox()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'page_title_test=Long article title|name=' .. expandTemplate("Nowrap", {"Long article title"}), ''},
		{'page_title_test=Long article title|name=Long article <br>title', ''},
		{'page_title_test=Long article title|name=Long article <br >title', ''},
		{'page_title_test=Long article title|name=Long article <br/>title', ''},
		{'page_title_test=Long article title|name=Long article <br />title', ''},
		{'page_title_test=Long article title|name=Long article <br/> title', ''},
		{'page_title_test=Long article title (dab)|name=' .. expandTemplate("Nowrap", {"Long article title"}), ''},
		{'page_title_test=Long article title (dab)|name=Long article <br>title', ''},
		{'page_title_test=Test|name=Test', '[[Category:Pages using infobox television with unnecessary name parameter]]'},
		{'page_title_test=Test (dab)|name=Test', '[[Category:Pages using infobox television with unnecessary name parameter]]'},
		{'page_title_test=Test|name=test', '[[Category:Pages using infobox television with non-matching title]]'},
		{'page_title_test=Long article title|name=' .. expandTemplate("Nowrap", {"Long article Title"}), '[[Category:Pages using infobox television with non-matching title]]'},
		{'page_title_test=Long article title|name=Long article <br/> Title', '[[Category:Pages using infobox television with non-matching title]]'},
    }, {nowiki=1})
end

function p:test_03_1_image_auxiliary_values_live()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'image=test|image_size=1', ''},
		{'image_size=1', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'image_upright=1', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'image_alt=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'alt=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'caption=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
    }, {nowiki=1})
end

function p:test_03_2_image_auxiliary_values_sandbox()
	self:preprocess_equals_many('{{#invoke:Infobox television/sandbox|validate_values|', '}}', {
		{'image=test|image_size=1', ''},
		{'image_size=1', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'image_upright=1', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'image_alt=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'alt=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
		{'caption=test', '[[Category:Pages using infobox television with image-related values without an image]]'},
    }, {nowiki=1})
end

function p:test_04_1_has_icons_local_live()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'director=' .. expandTemplate("USA", {}) .. 'test', '[[Category:Pages using infobox television with flag icon]]'},
	}, {nowiki=1})
end

function p:test_04_2_has_icons_local_sandbox()
	self:preprocess_equals_many('{{#invoke:Infobox television/sandbox|validate_values|', '}}', {
		{'director=' .. expandTemplate("USA", {}) .. 'test', '[[Category:Pages using infobox television with flag icon]]'},
	}, {nowiki=1})
end

function p:test_05_1_are_dates_formatted_correctly_live()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'first_aired=4/3/1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'first_aired=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'released=4/3/1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'released=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=Present', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=' .. expandTemplate("Start date", {"1999", "3", "4"}), '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'first_aired=' .. expandTemplate("Start date", {"1999", "3", "4"}), ''},
		{'released=' .. expandTemplate("Start date", {"1999", "3", "4"}), ''},
		{'last_aired=' .. expandTemplate("End date", {"1999", "3", "4"}), ''},
		{'last_aired=present', ''},
	}, {nowiki=1})
end

function p:test_05_2_are_dates_formatted_correctly_sandbox()
	self:preprocess_equals_many('{{#invoke:Infobox television/sandbox|validate_values|', '}}', {
		{'first_aired=4/3/1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'first_aired=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'released=4/3/1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'released=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=March 4, 1999', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=Present', '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'last_aired=' .. expandTemplate("Start date", {"1999", "3", "4"}), '[[Category:Pages using infobox television with nonstandard dates]]'},
		{'first_aired=' .. expandTemplate("Start date", {"1999", "3", "4"}), ''},
		{'released=' .. expandTemplate("Start date", {"1999", "3", "4"}), ''},
		{'last_aired=' .. expandTemplate("End date", {"1999", "3", "4"}), ''},
		{'last_aired=present', ''},
	}, {nowiki=1})
end

function p:test_08_1_all_errors_live()
	self:preprocess_equals_many('{{#invoke:Infobox television|validate_values|', '}}', {
		{'page_title_test=Test|name=Test|image_size=1|series=Lost|director=' .. expandTemplate("USA", {}) .. 'test|first_aired=4/3/1999', '[[Category:Pages using infobox television with unnecessary name parameter]][[Category:Pages using infobox television with image-related values without an image]][[Category:Pages using infobox television with flag icon]][[Category:Pages using infobox television with nonstandard dates]]'},
    }, {nowiki=1})
end

function p:test_08_2_all_errors_sandbox()
	self:preprocess_equals_many('{{#invoke:Infobox television/sandbox|validate_values|', '}}', {
		{'page_title_test=Test|name=Test|image_size=1|series=Lost|director=' .. expandTemplate("USA", {}) .. 'test|first_aired=4/3/1999', '[[Category:Pages using infobox television with unnecessary name parameter]][[Category:Pages using infobox television with image-related values without an image]][[Category:Pages using infobox television with flag icon]][[Category:Pages using infobox television with nonstandard dates]]'},
    }, {nowiki=1})
end

return p