Module:Infobox television/testcases

-- 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_is_infobox_title_equal_to_article_title self:preprocess_equals_sandbox_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 title', },		{'page_title_test=Long article title|name=Long article title', },		{'page_title_test=Long article title|name=Long article title', },		{'page_title_test=Long article title|name=Long article title', },		{'page_title_test=Long article title|name=Long article title', },		{'page_title_test=Long article title (dab)|name=' .. expandTemplate("Nowrap", {"Long article title"}), },		{'page_title_test=Long article title (dab)|name=Long article title', },		{'page_title_test=Title (not dab)|name=' .. expandTemplate("Nowrap", {"Title (not dab)"}), },		{'page_title_test=Title (not dab)|name=Title (not dab)', },				{'page_title_test=Test|name=Test', ''}, {'page_title_test=Test (not dab)|name=Test (not dab)', ''}, {'page_title_test=Test (dab)|name=Test', ''}, {'page_title_test=Test|name=test', ''}, {'page_title_test=Long article title|name=' .. expandTemplate("Nowrap", {"Long article Title"}), ''}, {'page_title_test=Long article title|name=Long article Title', ''}, }, {nowiki=1}) end

function p:test_02_has_display_title self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{, },		{'page_test=Template:Italic title/doc', },		--- {'page_test=News2day', }, --Displaytitle -- need a new example   }, {nowiki=1}) end

function p:test_03_are_image_auxiliary_values_used_for_no_image self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'image=test|image_size=1', },		{'image_size=1', },		{'image_upright=1', },		{'image_alt=test', },		{'alt=test', },		{'caption=test', },   }, {nowiki=1}) end

function p:test_04_is_image_using_incorrect_syntax self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'image=image.jpg', },		{'image=File:image.jpg', },		{'image=', },		{'image=Image:image.jpg', },		{'image=', ''},   }, {nowiki=1}) end

function p:test_05_is_image_size_using_px self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'image=test|image_size=100', },		{'image=test|image_size=100px', },   }, {nowiki=1}) end

function p:test_06_are_values_linked_or_formatted self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'language=English', },		{'language=English', },	}, {nowiki=1}) end

function p:test_08_has_flag_icon self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'director=' .. expandTemplate("USA", {}) .. 'test', ''},	}, {nowiki=1}) end

function p:test_09_are_dates_formatted_correctly self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'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', },		{'first_aired=4/3/1999', },		{'first_aired=March 4, 1999', },		{'released=4/3/1999', },		{'released=March 4, 1999', },		{'last_aired=March 4, 1999', },		{'last_aired=Present', },		{'last_aired=' .. expandTemplate("Start date", {"1999", "3", "4"}), ''},	}, {nowiki=1}) end

function p:test_10_is_italic_title_valid_value self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{, },		{'italic_title=no', },		{'italic_title=n', },		{'italic_title=y', ''},   }, {nowiki=1}) end

function p:test_11_all_errors self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'validate_values', {		{'page_title_test=Test|name=Test|page_test=Template:Italic title/doc|image_size=1|series=Lost|director=' .. expandTemplate("USA", {}) .. 'test|first_aired=4/3/1999|italic_title=y', ''},   }, {nowiki=1}) end

local function handle_title(text) return "''".. text .. "''" end

function p:test_20_above_title self:preprocess_equals_sandbox_many('{{#invoke:Infobox television', 'above_title', {		{'name=title', handle_title('title')},		{'name=title (dab)', handle_title('title (dab)')},		{'name=#title', handle_title('#title')},		{'page_test=Lost (TV series)', handle_title('Lost')},		{'page_test=I (Almost) Got Away With It|name=I (Almost) Got Away With It', handle_title('I (Almost) Got Away With It')},		{'page_test=I (Almost) Got Away With It', handle_title('I (Almost) Got Away With It')},		{'page_test=How to Live with Your Parents (For the Rest of Your Life)|name=How to Live with Your Parents (For the Rest of Your Life)', handle_title('How to Live with Your Parents (For the Rest of Your Life)')},		{'page_test=How to Live with Your Parents (For the Rest of Your Life)', handle_title('How to Live with Your Parents')},		{'page_test=Hashtag Like|italic_title=no', handle_title('#Like')}, --Correct title {'page_test=Hashtag Like|name=#Like', handle_title('#Like')}, --Correct title {'page_test=Das aktuelle sportstudio|italic_title=no', handle_title('das aktuelle sportstudio')}, --Lowercase title {'page_test=Das aktuelle sportstudio|name=das aktuelle sportstudio', handle_title('das aktuelle sportstudio')}, --Lowercase title {'page_test=News2day|italic_title=no', handle_title('news2day')}, --Displaytitle {'page_test=News2day|name=news2day', handle_title('news2day')}, --Displaytitle {'page_test=H2O (miniseries)|italic_title=no', handle_title('H{{sub|2}}O')}, --Displaytitle with special style {'page_test=H2O (miniseries)|name=H{{sub|2}}O', handle_title('H{{sub|2}}O')}, --Displaytitle with special style {'page_test=Wednesday 9:30 (8:30 Central)|italic_title=no', handle_title('Wednesday 9:30 (8:30 Central)')}, --Itatlic title|all=yes }, {nowiki=1}) end

return p