Module:Pagetype/testcases
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Pagetype/testcases/doc
-- Unit tests for [[Module:Pagetype]]. Click talk page to run tests.
local p = require('Module:UnitTests')
function p:test_current_page()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'', 'module'},
{'|module=no', 'page'},
{'|module=foo', 'foo'},
})
end
function p:test_spaces()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'', 'module'},
{'|module= no ', 'page'},
{'|module= foo ', 'foo'},
{'|page= UK |redirect= No ', 'article'},
})
end
function p:test_all_namespaces()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=UK', 'redirect'},
{'|page=Talk:UK', 'redirect'},
{'|page=United Kingdom', 'article'},
{'|page=Talk:United Kingdom', 'article'},
{'|page=User:Example', 'page'},
{'|page=User talk:Example', 'page'},
{'|page=Stiles.casa Wiki:Namespace', 'page'},
{'|page=Stiles.casa Wiki talk:Namespace', 'page'},
{'|page=Project:Namespace', 'page'},
{'|page=Project talk:Namespace', 'page'},
{'|page=SW:Namespace', 'page'},
{'|page=WT:Namespace', 'page'},
{'|page=File:Example.jpg', 'file'},
{'|page=File talk:Example.jpg', 'file'},
{'|page=Image:Example.jpg', 'file'},
{'|page=Image talk:Example.jpg', 'file'},
{'|page=MediaWiki:Watchlist-details', 'page'},
{'|page=MediaWiki talk:Watchlist-messages', 'page'},
{'|page=Template:Pagetype', 'template'},
{'|page=Template talk:Pagetype', 'template'},
{'|page=Help:Contents', 'page'},
{'|page=Help talk:Contents', 'page'},
{'|page=Category:Stiles.casa Wikins', 'category'},
{'|page=Category talk:Stiles.casa Wikins', 'category'},
{'|page=Portal:Arts', 'page'},
{'|page=Portal talk:Arts', 'page'},
{'|page=Book:Countries', 'book'},
{'|page=Book talk:Countries', 'book'},
{'|page=Draft:Example', 'page'},
{'|page=Draft talk:Example', 'page'},
{'|page=Education Program:Foo', 'page'},
{'|page=Education Program talk:Foo', 'page'},
{'|page=TimedText:Foo', 'page'},
{'|page=TimedText talk:Foo', 'page'},
{'|page=Special:PrefixIndex', 'page'},
{'|page=Media:Example.jpg', 'page'},
})
end
function p:test_defaultns_none()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=UK|defaultns=none', 'redirect'},
{'|page=Talk:UK|defaultns=none', 'redirect'},
{'|page=United Kingdom|defaultns=none', 'page'},
{'|page=Talk:United Kingdom|defaultns=none', 'page'},
{'|page=User:Example|defaultns=none', 'page'},
{'|page=User talk:Example|defaultns=none', 'page'},
{'|page=Stiles.casa Wiki:Namespace|defaultns=none', 'page'},
{'|page=Stiles.casa Wiki talk:Namespace|defaultns=none', 'page'},
{'|page=Project:Namespace|defaultns=none', 'page'},
{'|page=Project talk:Namespace|defaultns=none', 'page'},
{'|page=SW:Namespace|defaultns=none', 'page'},
{'|page=WT:Namespace|defaultns=none', 'page'},
{'|page=File:Example.jpg|defaultns=none', 'page'},
{'|page=File talk:Example.jpg|defaultns=none', 'page'},
{'|page=Image:Example.jpg|defaultns=none', 'page'},
{'|page=Image talk:Example.jpg|defaultns=none', 'page'},
{'|page=MediaWiki:Watchlist-details|defaultns=none', 'page'},
{'|page=MediaWiki talk:Watchlist-messages|defaultns=none', 'page'},
{'|page=Template:Pagetype|defaultns=none', 'page'},
{'|page=Template talk:Pagetype|defaultns=none', 'page'},
{'|page=Help:Contents|defaultns=none', 'page'},
{'|page=Help talk:Contents|defaultns=none', 'page'},
{'|page=Category:Stiles.casa Wikins|defaultns=none', 'page'},
{'|page=Category talk:Stiles.casa Wikins|defaultns=none', 'page'},
{'|page=Portal:Arts|defaultns=none', 'page'},
{'|page=Portal talk:Arts|defaultns=none', 'page'},
{'|page=Book:Countries|defaultns=none', 'page'},
{'|page=Book talk:Countries|defaultns=none', 'page'},
{'|page=Draft:Example|defaultns=none', 'page'},
{'|page=Draft talk:Example|defaultns=none', 'page'},
{'|page=Education Program:Foo|defaultns=none', 'page'},
{'|page=Education Program talk:Foo|defaultns=none', 'page'},
{'|page=TimedText:Foo|defaultns=none', 'page'},
{'|page=TimedText talk:Foo|defaultns=none', 'page'},
{'|page=Special:PrefixIndex|defaultns=none', 'page'},
{'|page=Media:Example.jpg|defaultns=none', 'page'},
})
end
function p:test_defaultns_extended()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=UK|defaultns=extended', 'redirect'},
{'|page=Talk:UK|defaultns=extended', 'redirect'},
{'|page=United Kingdom|defaultns=extended', 'article'},
{'|page=Talk:United Kingdom|defaultns=extended', 'article'},
{'|page=User:Example|defaultns=extended', 'user page'},
{'|page=User talk:Example|defaultns=extended', 'user page'},
{'|page=Stiles.casa Wiki:Namespace|defaultns=extended', 'project page'},
{'|page=Stiles.casa Wiki talk:Namespace|defaultns=extended', 'project page'},
{'|page=Project:Namespace|defaultns=extended', 'project page'},
{'|page=Project talk:Namespace|defaultns=extended', 'project page'},
{'|page=SW:Namespace|defaultns=extended', 'project page'},
{'|page=WT:Namespace|defaultns=extended', 'project page'},
{'|page=File:Example.jpg|defaultns=extended', 'file'},
{'|page=File talk:Example.jpg|defaultns=extended', 'file'},
{'|page=Image:Example.jpg|defaultns=extended', 'file'},
{'|page=Image talk:Example.jpg|defaultns=extended', 'file'},
{'|page=MediaWiki:Watchlist-details|defaultns=extended', 'interface page'},
{'|page=MediaWiki talk:Watchlist-messages|defaultns=extended', 'interface page'},
{'|page=Template:Pagetype|defaultns=extended', 'template'},
{'|page=Template talk:Pagetype|defaultns=extended', 'template'},
{'|page=Help:Contents|defaultns=extended', 'help page'},
{'|page=Help talk:Contents|defaultns=extended', 'help page'},
{'|page=Category:Stiles.casa Wikins|defaultns=extended', 'category'},
{'|page=Category talk:Stiles.casa Wikins|defaultns=extended', 'category'},
{'|page=Portal:Arts|defaultns=extended', 'portal'},
{'|page=Portal talk:Arts|defaultns=extended', 'portal'},
{'|page=Book:Countries|defaultns=extended', 'book'},
{'|page=Book talk:Countries|defaultns=extended', 'book'},
{'|page=Draft:example|defaultns=extended', 'draft'},
{'|page=Draft talk:example|defaultns=extended', 'draft'},
{'|page=Education Program:Foo|defaultns=extended', 'page'},
{'|page=Education Program talk:Foo|defaultns=extended', 'page'},
{'|page=TimedText:Foo|defaultns=extended', 'page'},
{'|page=TimedText talk:Foo|defaultns=extended', 'page'},
{'|page=Special:PrefixIndex|defaultns=extended', 'page'},
{'|page=Media:Example.jpg|defaultns=extended', 'page'},
})
end
function p:test_defaultns_all()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=UK|defaultns=all', 'redirect'},
{'|page=Talk:UK|defaultns=all', 'redirect'},
{'|page=United Kingdom|defaultns=all', 'article'},
{'|page=Talk:United Kingdom|defaultns=all', 'talk page'},
{'|page=User:Example|defaultns=all', 'user page'},
{'|page=User talk:Example|defaultns=all', 'talk page'},
{'|page=Stiles.casa Wiki:Namespace|defaultns=all', 'project page'},
{'|page=Stiles.casa Wiki talk:Namespace|defaultns=all', 'talk page'},
{'|page=Project:Namespace|defaultns=all', 'project page'},
{'|page=Project talk:Namespace|defaultns=all', 'talk page'},
{'|page=SW:Namespace|defaultns=all', 'project page'},
{'|page=WT:Namespace|defaultns=all', 'talk page'},
{'|page=File:Example.jpg|defaultns=all', 'file'},
{'|page=File talk:Example.jpg|defaultns=all', 'talk page'},
{'|page=Image:Example.jpg|defaultns=all', 'file'},
{'|page=Image talk:Example.jpg|defaultns=all', 'talk page'},
{'|page=MediaWiki:Watchlist-details|defaultns=all', 'interface page'},
{'|page=MediaWiki talk:Watchlist-messages|defaultns=all', 'talk page'},
{'|page=Template:Pagetype|defaultns=all', 'template'},
{'|page=Template talk:Pagetype|defaultns=all', 'talk page'},
{'|page=Help:Contents|defaultns=all', 'help page'},
{'|page=Help talk:Contents|defaultns=all', 'talk page'},
{'|page=Category:Stiles.casa Wikins|defaultns=all', 'category'},
{'|page=Category talk:Stiles.casa Wikins|defaultns=all', 'talk page'},
{'|page=Portal:Arts|defaultns=all', 'portal'},
{'|page=Portal talk:Arts|defaultns=all', 'talk page'},
{'|page=Book:Countries|defaultns=all', 'book'},
{'|page=Book talk:Countries|defaultns=all', 'talk page'},
{'|page=Draft:Example|defaultns=all', 'draft'},
-- the fact that this is now a redirect spoils the point,
-- but AfC have noted that they do not want a test in their namespace
-- see https://w.wiki/UXv
{'|page=Draft talk:Example|defaultns=all', 'redirect'},
{'|page=Education Program:Foo|defaultns=all', 'education program page'},
{'|page=Education Program talk:Foo|defaultns=all', 'talk page'},
{'|page=TimedText:Foo|defaultns=all', 'Timed Text page'},
{'|page=TimedText talk:Foo|defaultns=all', 'talk page'},
{'|page=Special:PrefixIndex|defaultns=all', 'special page'},
{'|page=Media:Example.jpg|defaultns=all', 'file'},
})
end
function p:test_custom_namespace_text()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=UK|redirect=custom text', 'custom text'},
{'|page=Talk:UK|redirect=custom text', 'custom text'},
{'|page=Talk:UK|talk=custom text', 'redirect'},
{'|page=United Kingdom|main=custom text', 'custom text'},
{'|page=Talk:United Kingdom|main=custom text', 'custom text'},
{'|page=Talk:United Kingdom|talk=custom text', 'custom text'},
{'|page=User:Example|user=custom text', 'custom text'},
{'|page=User talk:Example|user=custom text', 'custom text'},
{'|page=User talk:Example|talk=custom text', 'custom text'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=custom text', 'custom text'},
{'|page=Stiles.casa Wiki talk:Namespace|stiles.casa_wiki=custom text', 'custom text'},
{'|page=Stiles.casa Wiki talk:Namespace|talk=custom text', 'custom text'},
{'|page=Project:Namespace|project=custom text', 'custom text'},
{'|page=Project talk:Namespace|project=custom text', 'custom text'},
{'|page=Project talk:Namespace|talk=custom text', 'custom text'},
{'|page=SW:Namespace|sw=custom text', 'custom text'},
{'|page=WT:Namespace|sw=custom text', 'custom text'},
{'|page=WT:Namespace|talk=custom text', 'custom text'},
{'|page=WT:Namespace|wt=custom text', 'page'},
{'|page=Stiles.casa Wiki:Namespace|project=custom text', 'custom text'},
{'|page=Stiles.casa Wiki talk:Namespace|project=custom text', 'custom text'},
{'|page=SW:Namespace|project=custom text', 'custom text'},
{'|page=WT:Namespace|project=custom text', 'custom text'},
{'|page=Stiles.casa Wiki:Namespace|sw=custom text', 'custom text'},
{'|page=Stiles.casa Wiki talk:Namespace|sw=custom text', 'custom text'},
{'|page=Project:Namespace|sw=custom text', 'custom text'},
{'|page=Project talk:Namespace|sw=custom text', 'custom text'},
{'|page=File:Example.jpg|file=custom text', 'custom text'},
{'|page=File talk:Example.jpg|file=custom text', 'custom text'},
{'|page=File talk:Example.jpg|talk=custom text', 'custom text'},
{'|page=Image:Example.jpg|file=custom text', 'custom text'},
{'|page=Image talk:Example.jpg|file=custom text', 'custom text'},
{'|page=Image talk:Example.jpg|talk=custom text', 'custom text'},
{'|page=File:Example.jpg|image=custom text', 'custom text'},
{'|page=File talk:Example.jpg|image=custom text', 'custom text'},
{'|page=File talk:Example.jpg|image=custom text', 'custom text'},
{'|page=Image:Example.jpg|image=custom text', 'custom text'},
{'|page=Image talk:Example.jpg|image=custom text', 'custom text'},
{'|page=Image talk:Example.jpg|image=custom text', 'custom text'},
{'|page=MediaWiki:Watchlist-details|mediawiki=custom text', 'custom text'},
{'|page=MediaWiki talk:Watchlist-messages|mediawiki=custom text', 'custom text'},
{'|page=MediaWiki talk:Watchlist-messages|talk=custom text', 'custom text'},
{'|page=Template:Pagetype|template=custom text', 'custom text'},
{'|page=Template talk:Pagetype|template=custom text', 'custom text'},
{'|page=Template talk:Pagetype|talk=custom text', 'custom text'},
{'|page=Help:Contents|help=custom text', 'custom text'},
{'|page=Help talk:Contents|help=custom text', 'custom text'},
{'|page=Help talk:Contents|talk=custom text', 'custom text'},
{'|page=Category:Stiles.casa Wikins|category=custom text', 'custom text'},
{'|page=Category talk:Stiles.casa Wikins|category=custom text', 'custom text'},
{'|page=Category talk:Stiles.casa Wikins|talk=custom text', 'custom text'},
{'|page=Portal:Arts|portal=custom text', 'custom text'},
{'|page=Portal talk:Arts|portal=custom text', 'custom text'},
{'|page=Portal talk:Arts|talk=custom text', 'custom text'},
{'|page=Book:Countries|book=custom text', 'custom text'},
{'|page=Book talk:Countries|book=custom text', 'custom text'},
{'|page=Book talk:Countries|talk=custom text', 'custom text'},
{'|page=Draft:Example|draft=custom text', 'custom text'},
{'|page=Draft talk:Example|draft=custom text', 'custom text'},
-- as above, the below is now a redirect, so the test is sort of moot
-- {'|page=Draft talk:Example|talk=custom text', 'custom text'},
{'|page=Education Program:Foo|education program=custom text', 'custom text'},
{'|page=Education Program talk:Foo|education program=custom text', 'custom text'},
{'|page=Education Program talk:Foo|talk=custom text', 'custom text'},
{'|page=TimedText:Foo|timedtext=custom text', 'custom text'},
{'|page=TimedText talk:Foo|timedtext=custom text', 'custom text'},
{'|page=TimedText talk:Foo|talk=custom text', 'custom text'},
{'|page=Special:PrefixIndex|special=custom text', 'custom text'},
{'|page=Media:Example.jpg|media=custom text', 'custom text'},
{'|page=Media:Example.jpg|file=custom text', 'page'},
})
end
function p:test_order_of_precedence()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|module=foo', 'foo'}, -- This should be run on the talk page - it will not work if run in other places.
{'|talk=bar', 'bar'}, -- This should be run on the talk page - it will not work if run in other places.
{'|module=foo|talk=bar', 'bar'}, -- This should be run on the talk page - it will not work if run in other places.
{'|page=Module:Pagetype/testcases|module=foo|talk=bar', 'foo'},
{'|page=UK|defaultns=none|redirect=foo', 'foo'}, -- UK is a redirect page.
{'|page=UK|defaultns=none|redirect=foo|main=bar', 'foo'},
{'|page=UK|defaultns=extended|redirect=foo', 'foo'},
{'|page=UK|defaultns=extended|main=foo|redirect=bar', 'bar'},
{'|page=UK|main=foo|redirect=bar', 'bar'},
{'|page=UK|dab|main=foo|redirect=bar|dab=baz', 'bar'},
{'|page=UK|na|main=foo|redirect=bar|na=baz', 'bar'},
{'|page=Talk:UK|main=foo|redirect=bar', 'bar'}, -- Talk:UK is a redirect.
{'|page=Talk:UK|main=foo|redirect=bar|talk=baz', 'bar'},
{'|page=Foo|main=foo|redirect=bar', 'bar'}, -- Foo is a redirect.
{'|page=Talk:Foo|main=foo|redirect=bar', 'bar'}, -- Talk:Foo is not a redirect.
{'|page=Talk:Foo|main=foo|redirect=bar|talk=baz', 'baz'},
{'|page=United Kingdom|main=foo|redirect=bar|talk=baz', 'foo'},
{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz', 'page'},
{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz|dab=yes', 'page'},
{'|page=United Kingdom|dab|main=foo|redirect=bar|talk=baz|dab=bin', 'bin'},
{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz', 'page'},
{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz|na=yes', 'page'},
{'|page=United Kingdom|na|main=foo|redirect=bar|talk=baz|na=bin', 'bin'},
{'|page=Stiles.casa Wiki:Namespace|sw=foo|project=bar|stiles.casa_wiki=baz', 'baz'},
{'|page=Stiles.casa Wiki:Namespace|sw=foo|project=bar', 'bar'},
{'|page=Stiles.casa Wiki:Namespace|sw=foo', 'foo'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=foo|sw=bar', 'foo'},
{'|page=Stiles.casa Wiki talk:Namespace|sw=foo|project=bar|stiles.casa_wiki=baz', 'baz'},
{'|page=Stiles.casa Wiki talk:Namespace|sw=foo|project=bar|stiles.casa_wiki=baz|talk=bin', 'bin'},
{'|page=Project talk:Namespace|sw=foo|project=bar|stiles.casa_wiki=baz', 'baz'},
{'|page=Project talk:Namespace|sw=foo|project=bar|stiles.casa_wiki=baz|talk=bin', 'bin'},
{'|page=File:Example.jpg|file=foo|image=bar', 'foo'},
{'|page=File talk:Example.jpg|file=foo|image=bar', 'foo'},
{'|page=File talk:Example.jpg|file=foo|image=bar|talk=baz', 'baz'},
{'|page=Image:Example.jpg|file=foo|image=bar', 'foo'},
{'|page=Image talk:Example.jpg|file=foo|image=bar', 'foo'},
{'|page=Image talk:Example.jpg|file=foo|image=bar|talk=baz', 'baz'},
})
end
function p:test_other_parameter()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=Stiles.casa Wiki:Namespace', 'page'},
{'|page=Stiles.casa Wiki:Namespace|other=custom text', 'custom text'},
{'|page=Stiles.casa Wiki:Namespace|other=no', 'page'},
{'|page=Stiles.casa Wiki:Namespace|other=yes', 'page'},
{'|page=Stiles.casa Wiki:Namespace|other=custom text|stiles.casa_wiki=stiles.casa_wiki-space text', 'stiles.casa_wiki-space text'},
})
end
function p:test_yesno()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=yes', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=Yes', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=YeS', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=y', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=Y', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=true', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=True', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=TrUe', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=1', 'project page'},
{'|page=Stiles.casa Wiki:Namespace|stiles.casa_wiki=1.0', 'project page'},
{'|page=Template:Pagetype|template=no', 'page'},
{'|page=Template:Pagetype|template=No', 'page'},
{'|page=Template:Pagetype|template=nO', 'page'},
{'|page=Template:Pagetype|template=n', 'page'},
{'|page=Template:Pagetype|template=N', 'page'},
{'|page=Template:Pagetype|template=false', 'page'},
{'|page=Template:Pagetype|template=False', 'page'},
{'|page=Template:Pagetype|template=fAlSe', 'page'},
{'|page=Template:Pagetype|template=0', 'page'},
{'|page=Template:Pagetype|template=0.0', 'page'},
})
end
function p:test_subject_redirect_defaultns_all()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=MediaWiki talk:Spam-blacklist/log|defaultns=all', 'talk page'},
})
end
function p:test_caps()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=Stiles.casa Wiki:Namespace|caps=y', 'Page'},
{'|page=Stiles.casa Wiki:Namespace|caps=n', 'page'},
{'|page=Stiles.casa Wiki:Namespace|caps=y|plural=y', 'Pages'}
})
end
return p