Module:Information/sandbox/testcases

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

✘[No] 4 tests failed.

Name Expected Actual
✓[OK] test_SDC_author
✘[No] test_SDC_date <time class="dtstart" datetime="2012-09-17" lang="en" dir="ltr" style="white-space:nowrap">17 September 2012</time> 17 September 2012
✘[No] test_SDC_description <div class="description mw-content-ltr en" dir="ltr" lang="en"><span class="language en" title="English"><b>English&#58; </b></span> A five year old hanging around bouldering wall in Sportrock climbing gym in Alexandria, Virginia, USA</div> <div class="description mw-content-ltr" dir="ltr" lang="en"><span class="language en"><b>English:</b></span> A five year old hanging around bouldering wall in Sportrock climbing gym in Alexandria, Virginia, USA</div>
✓[OK] test_SDC_location
✘[No] test_SDC_source <span class="int-own-work" lang="">Own work by the original uploader</span> <span class="int-own-work" lang="en">own work by the original uploader</span>
✘[No] test_outer Lua error -- Module:Information/sandbox/testcases:10: attempt to call field '_Wikitext_Date' (a nil value)

Code

-- Unit tests for [[Module:Name]] date function. Click talk page to run tests.
require('strict')
local TUT = mw.title.new(mw.getCurrentFrame():getTitle()).basePageTitle -- the title under test
local Info = require(TUT.prefixedText) -- the module to be tested
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:test_outer()
	local mod = '{{#invoke:' .. TUT.text .. '| '
	self:assertSameResult(Info._Wikitext_Date('2012-09-17', 'en'),                                   mod..'Wikitext_Date  |date=2012-09-17|lang=en}}')
	self:assertSameResult(Info._Wikitext_Source('Q98140374/Q98057938', 'en'),                        mod..'Wikitext_Source|source=Q98140374/Q98057938|lang=en}}')
	self:assertSameResult(Info._SDC_Author(      mw.wikibase.getEntity( 'M21436087' ), 'en', false), mod..'SDC_Author     |mid=M21436087 |lang=en|icon=0}}')
	self:assertSameResult(Info._SDC_Date(        mw.wikibase.getEntity( 'M21436087' ), 'en', false), mod..'SDC_Date       |mid=M21436087 |lang=en|icon=0}}')
	self:assertSameResult(Info._SDC_Description( mw.wikibase.getEntity( 'M4184419'  ), 'en', false), mod..'SDC_Description|mid=M4184419  |lang=en|icon=0}}')
	self:assertSameResult(Info._SDC_Source(      mw.wikibase.getEntity( 'M92783235' ), 'en', false), mod..'SDC_Source     |mid=M92783235 |lang=en|icon=0}}')
end 
 
function suite:test_SDC_author()
	self:assertSameResult('[[User:HildaMorassi|Hilda Morassi]]',               Info._SDC_Author(mw.wikibase.getEntity( 'M21436087' ), 'en', false))
	self:assertSameResult('[[User:Bijay chaurasia|Bijay chaurasia]]',          Info._SDC_Author(mw.wikibase.getEntity( 'M51870570' ), 'en', false))
	self:assertSameResult('[https://www.geograph.org.uk/profile/17899 Row17]', Info._SDC_Author(mw.wikibase.getEntity( 'M13811643' ), 'en', false))
	self:assertSameResult('{{Label|Q34788025}}',                               Info._SDC_Author(mw.wikibase.getEntity( 'M37557200' ), 'en', false))
end 

function suite:test_SDC_date()
	self:assertSameResult('{{Date|2012|09|17|lang=en}}',                                      Info._SDC_Date(mw.wikibase.getEntity( 'M21436087' ), 'en', false))
	self:assertSameResult('{{Date|2008|12|25|lang=en}}',                                      Info._SDC_Date(mw.wikibase.getEntity( 'M13811643' ), 'en', false))
	self:assertSameResult('{{#invoke:Wikidata date|date|item=M99950|property=P571|lang=en}}', Info._SDC_Date(mw.wikibase.getEntity( 'M99950'    ), 'en', false))
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Date|mid=M99950    |lang=en|icon=0}} <div style="display: none;">date QS:P,+2005-00-00T00:00:00Z/9,P1480,Q5727902</div>', '{{other date|~|2005|lang=en}}')
end

function suite:xtest_wikitext_date()
	self:assertSameResult('{{Date|2012|09|17|20|17|40|lang=en}}', Info._Wikitext_Date('2012-09-17 20:17:40', 'en'))
	self:assertSameResult('{{Date|2012|09|17|20|17   |lang=en}}', Info._Wikitext_Date('2012-09-17 20:17',    'en'))
	self:assertSameResult('{{Date|2012|09|17         |lang=en}}', Info._Wikitext_Date('2012-09-17',          'en'))
	self:assertSameResult('{{Date|2012|09            |lang=en}}', Info._Wikitext_Date('2012-09',             'en'))
	self:assertSameResult('{{Date|2012               |lang=en}}', Info._Wikitext_Date('2012',                'en'))
end

function suite:test_SDC_description()
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Description|mid=M4184419  |lang=en|icon=0}}', '{{en|1=A five year old hanging around bouldering wall in Sportrock climbing gym in Alexandria, Virginia, USA}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Description|mid=M13811643 |lang=en|icon=0}}', '{{en|1=Footbridge near Mill House}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Description|mid=M3050001  |lang=pl|icon=0}}', '{{Description |text_lang=pl |text=Tablica pamiątkowa - Saperom którzy zginęli koło Jasła|user_lang=pl}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Description|mid=M3050001 |lang=en|icon=0}}', '{{pl|1=Tablica pamiątkowa - Saperom którzy zginęli koło Jasła}}')
end  

function suite:test_SDC_source()
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M21436087 |lang=en|icon=0}}', '{{Own}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M17273462 |lang=en|icon=0}}', '{{Own work by original uploader|lang=en}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M13811643 |lang=pl|icon=0}}', '[https://www.geograph.org.uk/photo/1101914 Geograph Britain and Ireland]')
	
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M92783235 |lang=en|icon=0}}', 'published in&#58; \n* {{#invoke:Cite Wikidata|citeWikidata|item=Q97940059|lang=en}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M92783235 |lang=pl|icon=0}}', 'opublikowano w&#58; \n* {{#invoke:Cite Wikidata|citeWikidata|item=Q97940059|lang=pl}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Source|mid=M3307691  |lang=en|icon=0}}', 'published in&#58; \n* {{#invoke:Cite Wikidata|citeWikidata|item=Q98140374|lang=en|page=164}}\n* {{#invoke:Cite Wikidata|citeWikidata|item=Q98057938|lang=en|page=63}}', {nowiki=1})
end

function suite:test_SDC_location()
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Location|mid=M13422936 |lang=en|icon=0}}', '{{Label|Q5523606}}')
	self:assertSameResult('{{#invoke:Information/sandbox|SDC_Location|mid=M13811643 |lang=en|icon=0}}', '')
end

return suite