Jump to content

Module:Commons link/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hike395 (talk | contribs) at 16:33, 26 March 2020 (missed one). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = require('Module:UnitTests')

function p:testGallery()
	-- known link
	self:preprocess_equals('{{#invoke:Commons link| getGallery | Mount Whitney}}',
		'[[Commons:Mount Whitney|Mount Whitney]]')
	-- known link with linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Mount Whitney|Big Mountain]]')
	-- forced search
	self:preprocess_equals('{{#invoke:Commons link| getGallery | search=Mount Whitney}}',
		'[[Commons:Special:Search/Mount Whitney|Mount Whitney]]')
	-- forced search + linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | search=Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Special:Search/Mount Whitney|Big Mountain]]')
	-- P935 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q2217963}}',
		'[[Commons:Samuel Baker House|Samuel Baker House]]')
	-- P935 matches sitelink + linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q2217963 |linktext=Big House}}',
		'[[Commons:Samuel Baker House|Big House]]')
	-- sitelink only
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q816044 | lcfirst=1}}',
		'[[Commons:Bellows Falls, Vermont|bellows Falls, Vermont]]')
	-- sitelink + linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q816044|linktext=Little Town}}',
		'[[Commons:Bellows Falls, Vermont|Little Town]]')
	-- sitelink and P935 inconsistent
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q139289}}',
		'[[Commons:Special:Search/Boeing 737 MAX|Boeing 737 MAX]]')
	-- sitelink and P935 inconsistent + linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q139289|linktext=Not a plane}}',
		'[[Commons:Special:Search/Boeing 737 MAX|Not a plane]]')
	-- no sitelink or P935
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q29017978}}',
		'[[Commons:Special:Search/Bell FCX-001|Bell FCX-001]]')
	-- no sitelink or P935, but linktext
	self:preprocess_equals('{{#invoke:Commons link| getGallery | qid=Q29017978|linktext=Medium Helicopter}}',
		'[[Commons:Special:Search/Bell FCX-001|Medium Helicopter]]')
end

function p:testCategory()
	-- known link
	self:preprocess_equals('{{#invoke:Commons link| getCategory | Mount Whitney}}',
		'[[Commons:Category:Mount Whitney|Mount Whitney]]')
	-- known link with linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Category:Mount Whitney|Big Mountain]]')
	-- forced search
	self:preprocess_equals('{{#invoke:Commons link| getCategory | search=Mount Whitney}}',
		'[[Commons:Special:Search/Category:Mount Whitney|Mount Whitney]]')
	-- forced search + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | search=Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Special:Search/Category:Mount Whitney|Big Mountain]]')
	-- P373 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2601154|lcfirst=1}}',
		'[[Commons:Category:Agama lionotus|agama lionotus]]')
	-- P373 matches sitelink + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2601154|linktext=Small Lizard|lcfirst=1}}',
		'[[Commons:Category:Agama lionotus|small Lizard]]')
	-- P910 matches P373
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q853037}}',
		'[[Commons:Category:Bánhida|Bánhida]]')
	-- P910 matches P373 + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q853037|linktext=Old Neighborhood}}',
		'[[Commons:Category:Bánhida|Old Neighborhood]]')
	-- P1754 matches P373
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2551907}}',
		'[[Commons:Category:Lakes of Turkey|Lakes of Turkey]]')
	-- P1754 matches P373 + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2551907|linktext=Turkey Lakes}}',
		'[[Commons:Category:Lakes of Turkey|Turkey Lakes]]')
	-- inconsistency between P373 and P1754
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q1002229}}',
		'[[Commons:Special:Search/Category:Municipality of Vipava|Municipality of Vipava]]')
	-- inconsistency between P373 and P1754 + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q1002229|linktext=Little Town}}',
		'[[Commons:Special:Search/Category:Municipality of Vipava|Little Town]]')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2963317}}',
		'[[Commons:Special:Search/Category:Chicago Lawn, Chicago|Chicago Lawn, Chicago]]')
	-- missing data + linktext
	self:preprocess_equals('{{#invoke:Commons link| getCategory | qid=Q2963317|linktext=Big Neighborhood}}',
		'[[Commons:Special:Search/Category:Chicago Lawn, Chicago|Big Neighborhood]]')
	
end

function p:testGalleryOrCategory()
	-- known link
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | Mount Whitney}}',
		'[[Commons:Mount Whitney|Mount Whitney]]')
	-- known link with linktext
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Mount Whitney|Big Mountain]]')
	-- forced search
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | search=Mount Whitney}}',
		'[[Commons:Special:Search/Mount Whitney|Mount Whitney]]')
	-- forced search + linktext
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | search=Mount Whitney |linktext=Big Mountain}}',
		'[[Commons:Special:Search/Mount Whitney|Big Mountain]]')
	-- P935 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q2217963}}',
		'[[Commons:Samuel Baker House|Samuel Baker House]]')
	-- sitelink only
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q816044}}',
		'[[Commons:Bellows Falls, Vermont|Bellows Falls, Vermont]]')
	-- sitelink and P935 inconsistent, fallback to Category instead
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q139289}}',
		'[[Commons:Category:Boeing 737 MAX|Boeing 737 MAX]]')
	-- no sitelink or P935 or category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q29017978}}',
		'[[Commons:Special:Search/Bell FCX-001|Bell FCX-001]]')
	-- P373 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q2601154}}',
		'[[Commons:Category:Agama lionotus|Agama lionotus]]')
	-- P910 matches P373
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q853037}}',
		'[[Commons:Category:Bánhida|Bánhida]]')
	-- P1754 matches P373
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q2551907}}',
		'[[Commons:Category:Lakes of Turkey|Lakes of Turkey]]')
	-- missing gallery, inconsistent category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q1002229}}',
		'[[Commons:Special:Search/Municipality of Vipava|Municipality of Vipava]]')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| getGalleryOrCategory | qid=Q2963317}}',
		'[[Commons:Special:Search/Chicago Lawn, Chicago|Chicago Lawn, Chicago]]')
end


function p:testHasGallery()
	-- P935 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q2217963}}','Samuel Baker House')
	-- sitelink only
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q816044}}','Bellows Falls, Vermont')
	-- sitelink and P935 inconsistent
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q139289}}','')
	-- no sitelink or P935 or category
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q29017978}}','')
	-- P373 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q2601154}}','')
	-- P910 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q853037}}','')
	-- P1754 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q2551907}}','')
	-- missing gallery, inconsistent category
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q1002229}}','')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| hasGallery | qid=Q2963317}}','')
end


function p:testHasCategory()
	-- P935 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q2217963}}','')
	-- sitelink only
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q816044}}','Category:Bellows Falls, Vermont')
	-- sitelink and P935 inconsistent, fallback to Category instead
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q139289}}','Category:Boeing 737 MAX')
	-- no sitelink or P935 or category
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q29017978}}','')
	-- P373 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q2601154}}','Category:Agama lionotus')
	-- P910 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q853037}}','Category:Bánhida')
	-- P1754 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q2551907}}','Category:Lakes of Turkey')
	-- missing gallery, inconsistent category
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q1002229}}','')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| hasCategory | qid=Q2963317}}','')
end

function p:testHasGalleryOrCategory()
	-- P935 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q2217963}}','Samuel Baker House')
	-- sitelink only
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q816044}}','Bellows Falls, Vermont')
	-- sitelink and P935 inconsistent, fallback to Category instead
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q139289}}','Category:Boeing 737 MAX')
	-- no sitelink or P935 or category
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q29017978}}','')
	-- P373 matches sitelink
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q2601154}}','Category:Agama lionotus')
	-- P910 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q853037}}','Category:Bánhida')
	-- P1754 matches P373
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q2551907}}','Category:Lakes of Turkey')
	-- missing gallery, inconsistent category
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q1002229}}','')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| hasGalleryOrCategory | qid=Q2963317}}','')
end


function p:testGalleryAndCategory()
	-- known link
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | Mount Whitney}}',
		'[[Commons:Mount Whitney|Mount Whitney]]')
	-- known link with linktext
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | Mount Whitney |linktext=Big Mountain | italic=1}}',
		'<i>[[Commons:Mount Whitney|Big Mountain]]</i>')
	-- known category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | | Mount Whitney | bold=1}}',
		'<b>[[Commons:Category:Mount Whitney|Mount Whitney]]</b>')
	-- known category with categorytext
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | | Mount Whitney |linktext=Big Mountain|bold=1|italic=1}}',
		'<b><i>[[Commons:Category:Mount Whitney|Big Mountain]]</i></b>')
	-- known link and category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | Mount Whitney | Mount Whitney}}',
		'[[Commons:Mount Whitney|Mount Whitney]] ([[Commons:Category:Mount Whitney|category]])')
	-- known link and category with linktext
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | Mount Whitney | Mount Whitney | linktext=Big Mountain|bold=1|italic=1}}',
		'<b><i>[[Commons:Mount Whitney|Big Mountain]]</i></b> ([[Commons:Category:Mount Whitney|category]])')
	-- only gallery exists
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q2217963|italic=1}}',
		'<i>[[Commons:Samuel Baker House|Samuel Baker House]]</i>')
	-- both gallery and category exist
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q816044|bold=1|categoryText=cat}}',
		'<b>[[Commons:Bellows Falls, Vermont|Bellows Falls, Vermont]]</b> ([[Commons:Category:Bellows Falls, Vermont|cat]])')
	-- sitelink and P935 inconsistent, fallback to Category instead
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q139289}}',
		'[[Commons:Category:Boeing 737 MAX|Boeing 737 MAX]]')
	-- no sitelink or P935 or category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q29017978|italic=1}}',
		'<i>[[Commons:Special:Search/Bell FCX-001|Bell FCX-001]]</i> ([[Commons:Special:Search/Category:Bell FCX-001|category]])')
	-- P373 matches sitelink, category only
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q2601154|bold=1}}',
		'<b>[[Commons:Category:Agama lionotus|Agama lionotus]]</b>')
	-- P910 matches P373, category only
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q853037|italic=1|bold=1}}',
		'<b><i>[[Commons:Category:Bánhida|Bánhida]]</i></b>')
	-- P1754 matches P373, category only
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q2551907}}',
		'[[Commons:Category:Lakes of Turkey|Lakes of Turkey]]')
	-- missing gallery, inconsistent category
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q1002229|italic=1|linktext=Vipava|categoryText=cat}}',
		'<i>[[Commons:Special:Search/Municipality of Vipava|Vipava]]</i> ([[Commons:Special:Search/Category:Municipality of Vipava|cat]])')
	-- missing data
	self:preprocess_equals('{{#invoke:Commons link| getGalleryAndCategory | qid=Q2963317|bold=1|linktext=Chicago Lawn|oneSearch=1}}',
		'<b>[[Commons:Special:Search/Chicago Lawn, Chicago|Chicago Lawn]]</b>')
end


function p:testTitleQID()
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID }}','Commons link/testcases,829,nil')
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID | Q42}}','Douglas Adams,829,Q42')
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID | Q15048757}}','Python,829,Q15048757')
	-- no page corresponding to QID
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID | Q0}}',',829,Q0')
	-- QID doesn't link back to en
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID | Q68979196}}',',829,Q68979196')
	-- gibberish QID
	self:preprocess_equals('{{#invoke:Commons link| getTitleQID | 1234}}','Commons link/testcases,829,nil')
end

function p:testLookupFallback()
	-- P910 doesn't exist
	self:preprocess_equals('{{#invoke:Commons link| lookupFallback | Q2217963 | P910}}','nil')
	-- P910 exists, but isn't a category
	self:preprocess_equals('{{#invoke:Commons link| lookupFallback | Q3495319 | P910}}','nil')
	-- normal P910
	self:preprocess_equals('{{#invoke:Commons link| lookupFallback | Q853037 | P910}}','Bánhida')
	-- normal P1754
	self:preprocess_equals('{{#invoke:Commons link| lookupFallback | Q2551907 | P1754}}','Lakes of Turkey')
	-- gibberish prop string
	self:preprocess_equals('{{#invoke:Commons link| lookupFallback | Q2551907 | xyzzy}}','nil')
end

return p