Jump to content

Module:Plain sister/testcases

From Wikisource
require('strict')

local testSuite = require('Module:UnitTests')

local PS = require('Module:Plain sister')
local PSsandbox = require('Module:Plain sister/sandbox')

-- test the core getLinks functions
function testSuite:test_getLinks()
	self:equals_deep(
		'From Wikidata: Q1',
		PS.getLinks({
			wikidata = 'Q1',
		}),
		{
			w = 'Universe',
			['c:Category'] = 'Universe',
			q = 'Universe',
			v = 'Universe',
			d = 'Q1',
		}
	)
	self:equals_deep(
		'From Wikidata: Q1',
		PS.getLinks({
			wikidata = 'Q1',
		}),
		PSsandbox.getLinks({
			wikidata = 'Q1',
		})
	)
	
	self:equals_deep(
		'From an edition (Stella Dallas)',
		PS.getLinks({
			wikidata = 'Q106388874',
		}),
		{
			w = 'Stella Dallas (novel)', -- from the work
			['c:Category'] = 'Stella Dallas (1923 edition of novel)', -- from the edition
			d = 'Q106388874',
		}
	)
	self:equals_deep(
		'From an edition (Stella Dallas)',
		PS.getLinks({
			wikidata = 'Q106388874',
		}),
		PSsandbox.getLinks({
			wikidata = 'Q106388874',
		})
	)
	
	-- A topic
	self:equals_deep(
		'A topic via P921',
		PS.getLinks({
			wikidata = 'Q19064858',
		}),
		{
			w = 'Banksia spinulosa',
			wikispecies = 'Banksia spinulosa',
			d = 'Q19064858',
		}
	)
	self:equals_deep(
		'A topic via P921',
		PS.getLinks({
			wikidata = 'Q19064858',
		}),
		PSsandbox.getLinks({
			wikidata = 'Q19064858',
		})
	)
	
	-- An author.
	self:equals_deep(
		'Author',
		PS.getLinks({
			wikidata = 'Q15712330',
		}),
		{
			w = 'Alice Hay Wadsworth',
			['c:Category'] = 'Alice Wadsworth', -- from the edition
			d = 'Q15712330',
		}
	)
	self:equals_deep(
		'Author',
		PS.getLinks({
			wikidata = 'Q15712330',
		}),
		PSsandbox.getLinks({
			wikidata = 'Q15712330',
		})
	)
	
	-- A biographical article
	--		should NOT include the commons category via the P921 claim
	self:equals_deep(
		'Biographical article',
		PS.getLinks({
			wikidata = 'Q84635865',
		}),
		{
			w = 'William Adams (samurai)',
			d = 'Q84635865',
		}
	)
	self:equals_deep(
		'Biographical article',
		PS.getLinks({
			wikidata = 'Q84635865',
		}),
		PSsandbox.getLinks({
			wikidata = 'Q84635865',
		})
	)
end

function testSuite:test_inline()
	local prefix = '<li class="sisitem"><span class="sisicon">[[File:Wikimedia-logo.svg|frameless|18px|link=Special:sitematrix|alt=Sister Projects.]]</span>[[Special:sitematrix|sister projects]]: '
	
	-- Not a Wikisource item
	self:equals_deep(
		'Not a Wikisource item',
		tostring(PS._interprojectPart({wikidata = 'Q1'})),
		prefix .. '[[w:Universe|Wikipedia article]], [[c:Category:Universe|Commons category]], [[q:Universe|quotes]], [[v:Universe|course]], [[d:Q1|Wikidata item]].</li>',
		{nowiki=1}
	)
	self:equals_deep(
		'Not a Wikisource item',
		tostring(PS._interprojectPart({wikidata = 'Q1'})),
		tostring(PSsandbox._interprojectPart({wikidata = 'Q1'})),
		{nowiki=1}
	)
	
	-- Wikisource edition
	self:equals_deep(
		'Wikisource edition',
		PS._plain_sister({wikidata = 'Q23308118'}),
		mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Plain sister/styles.css'})
		.. '<ul class="plainSister">'
		.. prefix .. '[[w:The Nether World|Wikipedia article]], [[c:Category:The Nether World (novel)|Commons category]], [[d:Q23308118|Wikidata item]].</li></ul>',
		{nowiki=1}
	)
	self:equals_deep(
		'Wikisource edition',
		PS._plain_sister({wikidata = 'Q23308118'}),
		PSsandbox._plain_sister({wikidata = 'Q23308118'}),
		{nowiki=1}
	)
end

return testSuite