Module:Pagetype/testcases
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=Wikipedia:Namespace', 'page'},
{'|page=Wikipedia talk:Namespace', 'page'},
{'|page=Project:Namespace', 'page'},
{'|page=Project talk:Namespace', 'page'},
{'|page=WP: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:Wikipedians', 'category'},
{'|page=Category talk:Wikipedians', '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=Wikipedia:Namespace|defaultns=none', 'page'},
{'|page=Wikipedia talk:Namespace|defaultns=none', 'page'},
{'|page=Project:Namespace|defaultns=none', 'page'},
{'|page=Project talk:Namespace|defaultns=none', 'page'},
{'|page=WP: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:Wikipedians|defaultns=none', 'page'},
{'|page=Category talk:Wikipedians|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=Wikipedia:Namespace|defaultns=extended', 'project page'},
{'|page=Wikipedia talk:Namespace|defaultns=extended', 'project page'},
{'|page=Project:Namespace|defaultns=extended', 'project page'},
{'|page=Project talk:Namespace|defaultns=extended', 'project page'},
{'|page=WP: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:Wikipedians|defaultns=extended', 'category'},
{'|page=Category talk:Wikipedians|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=Wikipedia:Namespace|defaultns=all', 'project page'},
{'|page=Wikipedia talk:Namespace|defaultns=all', 'talk page'},
{'|page=Project:Namespace|defaultns=all', 'project page'},
{'|page=Project talk:Namespace|defaultns=all', 'talk page'},
{'|page=WP: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:Wikipedians|defaultns=all', 'category'},
{'|page=Category talk:Wikipedians|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=Wikipedia:Namespace|wikipedia=custom text', 'custom text'},
{'|page=Wikipedia talk:Namespace|wikipedia=custom text', 'custom text'},
{'|page=Wikipedia 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=WP:Namespace|wp=custom text', 'custom text'},
{'|page=WT:Namespace|wp=custom text', 'custom text'},
{'|page=WT:Namespace|talk=custom text', 'custom text'},
{'|page=WT:Namespace|wt=custom text', 'page'},
{'|page=Wikipedia:Namespace|project=custom text', 'custom text'},
{'|page=Wikipedia talk:Namespace|project=custom text', 'custom text'},
{'|page=WP:Namespace|project=custom text', 'custom text'},
{'|page=WT:Namespace|project=custom text', 'custom text'},
{'|page=Wikipedia:Namespace|wp=custom text', 'custom text'},
{'|page=Wikipedia talk:Namespace|wp=custom text', 'custom text'},
{'|page=Project:Namespace|wp=custom text', 'custom text'},
{'|page=Project talk:Namespace|wp=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:Wikipedians|category=custom text', 'custom text'},
{'|page=Category talk:Wikipedians|category=custom text', 'custom text'},
{'|page=Category talk:Wikipedians|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=Wikipedia:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Wikipedia:Namespace|wp=foo|project=bar', 'bar'},
{'|page=Wikipedia:Namespace|wp=foo', 'foo'},
{'|page=Wikipedia:Namespace|wikipedia=foo|wp=bar', 'foo'},
{'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Wikipedia talk:Namespace|wp=foo|project=bar|wikipedia=baz|talk=bin', 'bin'},
{'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=baz', 'baz'},
{'|page=Project talk:Namespace|wp=foo|project=bar|wikipedia=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=Wikipedia:Namespace', 'page'},
{'|page=Wikipedia:Namespace|other=custom text', 'custom text'},
{'|page=Wikipedia:Namespace|other=no', 'page'},
{'|page=Wikipedia:Namespace|other=yes', 'page'},
{'|page=Wikipedia:Namespace|other=custom text|wikipedia=wikipedia-space text', 'wikipedia-space text'},
})
end
function p:test_yesno()
self:preprocess_equals_many('{{#invoke:pagetype/sandbox|main', '}}', {
{'|page=Wikipedia:Namespace|wikipedia=yes', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=Yes', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=YeS', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=y', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=Y', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=true', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=True', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=TrUe', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=1', 'project page'},
{'|page=Wikipedia:Namespace|wikipedia=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=Wikipedia:Namespace|caps=y', 'Page'},
{'|page=Wikipedia:Namespace|caps=n', 'page'},
{'|page=Wikipedia:Namespace|caps=y|plural=y', 'Pages'}
})
end
return p