Module:Commons link/testcases

local p = require('Module:UnitTests')

function p:testGallery -- known link self:preprocess_equals('',		'Mount Whitney') -- known link with linktext self:preprocess_equals('',		'Big Mountain') -- forced search self:preprocess_equals('',		'Mount Whitney') -- forced search + linktext self:preprocess_equals('',		'Big Mountain') -- P935 matches sitelink self:preprocess_equals('',		'Samuel Baker House') -- P935 matches sitelink + linktext self:preprocess_equals('',		'Big House') -- sitelink only, lcfirst self:preprocess_equals('',		'bellows Falls, Vermont') -- sitelink only, bold self:preprocess_equals('',		' Bellows Falls, Vermont ') -- sitelink only, italic self:preprocess_equals('',		' Bellows Falls, Vermont ') -- sitelink only, nowrap self:preprocess_equals('',		' Bellows Falls, Vermont ') -- sitelink + linktext self:preprocess_equals('',		'Little Town') -- sitelink and P935 inconsistent self:preprocess_equals('',		'Boeing 737 MAX') -- sitelink and P935 inconsistent + linktext self:preprocess_equals('',		'Not a plane') -- no sitelink or P935 self:preprocess_equals('',		'Bell FCX-001') -- no sitelink or P935, but linktext self:preprocess_equals('',		'Medium Helicopter') end

function p:testCategory -- known link self:preprocess_equals('',		'Mount Whitney') -- known link with linktext self:preprocess_equals('',		'Big Mountain') -- forced search self:preprocess_equals('',		'Mount Whitney') -- forced search + linktext self:preprocess_equals('',		'Big Mountain') -- P373 matches sitelink + lcfirst self:preprocess_equals('',		'agama lionotus') -- bold self:preprocess_equals('',		' Agama lionotus ') -- italic self:preprocess_equals('',		' Agama lionotus ') -- nowrap self:preprocess_equals('',		' Agama lionotus ') -- P373 matches sitelink + linktext self:preprocess_equals('',		'small Lizard') -- P910 matches P373 self:preprocess_equals('',		'Bánhida') -- P910 matches P373 + linktext self:preprocess_equals('',		'Old Neighborhood') -- P1754 matches P373 self:preprocess_equals('',		'Lakes of Turkey') -- P1754 matches P373 + linktext self:preprocess_equals('',		'Turkey Lakes') -- inconsistency between P373 and P1754 self:preprocess_equals('',		'Municipality of Vipava') -- test fallback self:preprocess_equals('',		'Boing') -- inconsistency between P373 and P1754 + linktext self:preprocess_equals('',		'Little Town') -- missing data self:preprocess_equals('',		'Chicago Lawn, Chicago') -- missing data + linktext self:preprocess_equals('',		'Big Neighborhood') end

function p:testGalleryOrCategory -- known link self:preprocess_equals('',		'Mount Whitney') -- known link with linktext self:preprocess_equals('',		'Big Mountain') -- forced search self:preprocess_equals('',		'Mount Whitney') -- forced search + linktext self:preprocess_equals('',		'Big Mountain') -- P935 matches sitelink self:preprocess_equals('',		'Samuel Baker House') -- sitelink only self:preprocess_equals('',		'Bellows Falls, Vermont') -- inconsistent data, fall back to search self:preprocess_equals('',		'Russian military intervention in the Syrian civil war') -- P373 matches sitelink self:preprocess_equals('',		'Agama lionotus') -- P910 matches P373 self:preprocess_equals('',		'Bánhida') -- P1754 matches P373 self:preprocess_equals('',		'Lakes of Turkey') -- missing gallery, inconsistent category self:preprocess_equals('',		'Municipality of Vipava') -- test fallback self:preprocess_equals('',		'Boing') -- missing data self:preprocess_equals('',		'Chicago Lawn, Chicago') end

function p:testHasGallery -- P935 matches sitelink self:preprocess_equals('','Samuel Baker House') -- sitelink only self:preprocess_equals('','Bellows Falls, Vermont') -- sitelink and P935 inconsistent self:preprocess_equals(,) -- no sitelink or P935 or category self:preprocess_equals(,) -- P373 matches sitelink self:preprocess_equals(,) -- P910 matches P373 self:preprocess_equals(,) -- P1754 matches P373 self:preprocess_equals(,) -- missing gallery, inconsistent category self:preprocess_equals(,) -- missing data self:preprocess_equals(,) end

function p:testHasCategory -- P935 matches sitelink self:preprocess_equals(,) -- sitelink only self:preprocess_equals('','Category:Bellows Falls, Vermont') -- sitelink and P935 inconsistent, fallback to Category instead self:preprocess_equals('','Category:Boeing 737 MAX') -- P373 matches sitelink self:preprocess_equals('','Category:Agama lionotus') -- P910 matches P373 self:preprocess_equals('','Category:Bánhida') -- P1754 matches P373 self:preprocess_equals('','Category:Lakes of Turkey') -- missing gallery, inconsistent category self:preprocess_equals('','Category:Municipality of Vipava') -- missing data self:preprocess_equals(,) end

function p:testHasGalleryOrCategory -- P935 matches sitelink self:preprocess_equals('','Samuel Baker House') -- sitelink only self:preprocess_equals('','Bellows Falls, Vermont') -- sitelink and P935 inconsistent self:preprocess_equals('','Category:Boeing 737 MAX') -- P373 matches sitelink self:preprocess_equals('','Category:Agama lionotus') -- P910 matches P373 self:preprocess_equals('','Category:Bánhida') -- P1754 matches P373 self:preprocess_equals('','Category:Lakes of Turkey') -- missing gallery self:preprocess_equals('','Category:Municipality of Vipava') -- missing data self:preprocess_equals(,) -- another test self:preprocess_equals('','Category:Fado') -- inconsistent results, P373 should not be invoked here self:preprocess_equals(,) end

function p:testGalleryAndCategory -- known link self:preprocess_equals('',		'Mount Whitney') -- known link with linktext self:preprocess_equals('',		' Big Mountain ') -- known category self:preprocess_equals('',		' Mount Whitney ') -- known category with categorytext self:preprocess_equals('',		' Big Mountain ') -- known link and category self:preprocess_equals('',		'Mount Whitney (category)') -- known link and category with linktext self:preprocess_equals('',		' Big Mountain (category)') -- only gallery exists self:preprocess_equals('',		' Samuel Baker House ') -- both gallery and category exist self:preprocess_equals('',		' Bellows Falls, Vermont (cat)') -- P373 matches sitelink, category only self:preprocess_equals('',		' Agama lionotus ') -- P910 matches P373, category only self:preprocess_equals('',		' Bánhida ') -- P1754 matches P373, category only self:preprocess_equals('',		'Lakes of Turkey') -- missing data self:preprocess_equals('',		' Chicago Lawn ') end

function p:testTitleQID self:preprocess_equals('','Commons link/testcases,Module talk,nil') self:preprocess_equals('','Douglas Adams,,Q42') self:preprocess_equals('','Python (genus),Category,Q15048757') -- no page corresponding to QID self:preprocess_equals('',',Module talk,Q0') -- QID doesn't link back to en	self:preprocess_equals('',',,Q68979196') -- gibberish QID self:preprocess_equals('','Commons link/testcases,Module talk,nil') end

function p:testLookupFallback -- P910 doesn't exist self:preprocess_equals('','nil') -- normal P910 self:preprocess_equals('','Bánhida') -- normal P1754 self:preprocess_equals('','Lakes of Turkey') -- gibberish prop string self:preprocess_equals('','nil') end

function p:testTracking local galPrefix = '[[Category:Commons link '	local catPrefix = '[[Category:Commons category link '	local onWikidata = 'is on Wikidata]]'	local definedAsPagename = 'is defined as the pagename]]' local locallyDefined = 'is locally defined]]' local fromWikidata = 'from Wikidata]]' local isPagename = 'is the pagename]]' local galInconsistent = '' local catInconsistent = '' -- default gallery is specified and is Commons gallery on wikidata self:preprocess_equals('',		galPrefix..onWikidata,{nowiki=1}) -- default gallery is specified and is Commons category on wikidata self:preprocess_equals('',		galPrefix..definedAsPagename,{nowiki=1}) -- default category is specified and is Commons category on wikidata self:preprocess_equals('',		catPrefix..onWikidata,{nowiki=1}) -- inconsistent wikidata returns nil, so doesn't match title. Called from Template:Commons self:preprocess_equals('',		galPrefix..definedAsPagename,{nowiki=1}) -- Default string is not the same as either title or wikidata. Called from Template:Commons self:preprocess_equals('',		galPrefix..locallyDefined,{nowiki=1}) -- Default string is not the same as either title or wikidata. Called from Template:Commonscat self:preprocess_equals('',		catPrefix..locallyDefined,{nowiki=1}) -- No string. Commons gallery on Wikidata self:preprocess_equals('',		galPrefix..fromWikidata,{nowiki=1}) -- No string. Commons category on Wikidata self:preprocess_equals('',		catPrefix..fromWikidata,{nowiki=1}) -- No string. Nothing on Wikidata. Called from Template:Commons self:preprocess_equals('',		galPrefix..isPagename,{nowiki=1}) -- No string. Nothing on Wikidata. Called from Template:CommonsCat self:preprocess_equals('',		catPrefix..isPagename,{nowiki=1}) -- Inconsistent wikidata for category self:preprocess_equals('',		catInconsistent,{nowiki=1}) end

return p