Module:Edition/testcases

From Wikisource
Jump to: navigation, search
-- Unit tests for [[Module:Edition]]. Go to the talk page to view test results.
local testSuit = require('Module:UnitTests')

function testSuit:test_author_list()

	-- Persuasion by Jane Austen
	self:preprocess_equals(
		'{{#invoke:Edition|author_list|page=Persuasion}}',
		'[[Author:Jane Austen|<span itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name">Jane Austen</span></span>]]',
		{nowiki=1}
	)

	-- Base Facilities Report by US Navy
	self:preprocess_equals(
		'{{#invoke:Edition|author_list|page=Base Facilities Report}}',
		'[[Portal:United States Navy|<span itemprop="author" itemscope="" itemtype="http://schema.org/GovernmentOrganization"><span itemprop="name">United States Navy</span></span>]]',
		{nowiki=1}
	)

	-- Subpages should look for their root-page's author, if they don't have one
	self:preprocess_equals(
		'{{#invoke:Edition|author_list|page=The Nether World/Volume 2/Chapter 1}}',
		'[[Author:George Robert Gissing|<span itemprop="author" itemscope="" itemtype="http://schema.org/Person"><span itemprop="name">George Robert Gissing</span></span>]]',
		{nowiki=1}
	)

end

function testSuit:test_inline()

	-- Not an edition.
	self:preprocess_equals(
		'{{#invoke:Edition|inline|wikidata_id=Q1}}',
		'<span class="error">Q1 is not an edition or translation of a work (missing P629)</span>',
		{nowiki=1}
	)

	-- Edition of a book with no Wikisource page.
	self:preprocess_equals(
		'{{#invoke:Edition|inline|wikidata_id=Q28913867}}',
		'A Pair of Blue Eyes (1873) {{small scan link|A Pair of Blue Eyes (Thomas Hardy, 1873).djvu}} '
			.. '{{commons link|A Pair of Blue Eyes (Thomas Hardy, 1873).djvu}} [[File:Wikidata-books-task-force-logo.svg|20px|alt=Wikidata books task force logo|link=d:Q28913867|View on Wikidata]]',
		{nowiki=1}
	)

	-- With a Wikisource page.
	self:preprocess_equals(
		'{{#invoke:Edition|inline|wikidata_id=Q28919083}}',
		'[[Cape Cod (1865) Thoreau|Cape Cod]] (1865) [[File:Wikidata-books-task-force-logo.svg|20px|alt=Wikidata books task force logo|link=d:Q28919083|View on Wikidata]]',
		{nowiki=1}
	)

end


function testSuit:test_badge()

	-- Not an edition.
	self:preprocess_equals(
		'{{#invoke:Edition|badge|wikidata=Q1}}',
		'',
		{nowiki=1}
	)
	
	-- Not an edition.
	self:preprocess_equals(
		'{{#invoke:Edition|badge|wikidata=Q28020002}}',
		'<span class="badge digital-document-badge Q28064618">[[File:Digital Electronics Icon.svg|16px|link=d:Q28020002]]</span>',
		{nowiki=1}
	)
	

end

return testSuit