2013-02-07 17:50:21 +00:00
|
|
|
local testframework = require 'Module:TestFramework'
|
|
|
|
|
2013-10-31 15:49:14 +00:00
|
|
|
local title, title_copy, title2, title3, title4, title5, title6u, title6s, title4p
|
2013-03-21 13:36:03 +00:00
|
|
|
if mw.title.testPageId then
|
2013-03-07 00:04:24 +00:00
|
|
|
title = mw.title.getCurrentTitle()
|
|
|
|
title_copy = mw.title.getCurrentTitle()
|
|
|
|
title2 = mw.title.new( 'Module:TestFramework' )
|
2017-01-19 08:47:26 +00:00
|
|
|
title3 = mw.title.new( 'interwikiprefix:Module:TestFramework' )
|
2013-03-07 00:04:24 +00:00
|
|
|
title4 = mw.title.new( 'Talk:Has/A/Subpage' )
|
|
|
|
title5 = mw.title.new( 'Not/A/Subpage' )
|
|
|
|
title4.fragment = 'frag'
|
2013-02-07 17:50:21 +00:00
|
|
|
|
2013-03-07 00:04:24 +00:00
|
|
|
title4p = mw.title.new( 'Talk:Has/A' )
|
2013-10-31 15:49:14 +00:00
|
|
|
|
|
|
|
title6u = mw.title.new( 'Module_talk:Test_Framework' )
|
|
|
|
title6u.fragment = '__frag__frag__'
|
|
|
|
|
|
|
|
title6s = mw.title.new( 'Module talk:Test Framework' )
|
|
|
|
title6s.fragment = ' frag frag '
|
2013-03-07 00:04:24 +00:00
|
|
|
end
|
2013-02-07 17:50:21 +00:00
|
|
|
|
|
|
|
local function prop_foreach( prop )
|
2013-10-31 15:49:14 +00:00
|
|
|
return title[prop], title2[prop], title3[prop], title4[prop], title5[prop], title6u[prop], title6s[prop]
|
2013-02-07 17:50:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function func_foreach( func, ... )
|
|
|
|
return title[func]( title, ... ),
|
|
|
|
title2[func]( title2, ... ),
|
|
|
|
title3[func]( title3, ... ),
|
|
|
|
title4[func]( title4, ... ),
|
2013-10-31 15:49:14 +00:00
|
|
|
title5[func]( title5, ... ),
|
|
|
|
title6u[func]( title6u, ... ),
|
|
|
|
title6s[func]( title6s, ... )
|
2013-02-07 17:50:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function identity( ... )
|
|
|
|
return ...
|
|
|
|
end
|
|
|
|
|
2013-10-31 15:49:14 +00:00
|
|
|
local function test_space_normalization( s )
|
|
|
|
local title = mw.title.new( s )
|
|
|
|
return tostring( title ), tostring( title.fragment )
|
|
|
|
end
|
|
|
|
|
2014-12-09 23:01:40 +00:00
|
|
|
local function test_expensive_10()
|
2013-02-07 17:50:21 +00:00
|
|
|
for i = 1, 10 do
|
2014-12-09 23:01:40 +00:00
|
|
|
local _ = mw.title.new( tostring( i ) ).id
|
|
|
|
end
|
|
|
|
return 'did not error'
|
|
|
|
end
|
|
|
|
|
|
|
|
local function test_expensive_11()
|
|
|
|
for i = 1, 11 do
|
|
|
|
local _ = mw.title.new( tostring( i ) ).id
|
2013-02-07 17:50:21 +00:00
|
|
|
end
|
|
|
|
return 'did not error'
|
|
|
|
end
|
|
|
|
|
|
|
|
local function test_expensive_cached()
|
|
|
|
for i = 1, 100 do
|
2014-12-09 23:01:40 +00:00
|
|
|
local _ = mw.title.new( 'Title' ).id
|
|
|
|
end
|
|
|
|
return 'did not error'
|
|
|
|
end
|
|
|
|
|
|
|
|
local function test_inexpensive()
|
|
|
|
for i = 1, 100 do
|
|
|
|
local _ = mw.title.new( 'Title' ).prefixedText
|
2013-02-07 17:50:21 +00:00
|
|
|
end
|
|
|
|
return 'did not error'
|
|
|
|
end
|
|
|
|
|
2013-03-05 02:11:23 +00:00
|
|
|
local function test_getContent()
|
2014-10-23 13:15:52 +00:00
|
|
|
return mw.title.new( 'ScribuntoTestPage' ):getContent(),
|
|
|
|
mw.title.new( 'ScribuntoTestNonExistingPage' ):getContent()
|
|
|
|
end
|
|
|
|
|
2023-12-14 20:14:12 +00:00
|
|
|
local function test_content()
|
|
|
|
return mw.title.new( 'ScribuntoTestPage' ).content,
|
|
|
|
mw.title.new( 'ScribuntoTestNonExistingPage' ).content
|
|
|
|
end
|
|
|
|
|
2014-10-23 13:15:52 +00:00
|
|
|
local function test_redirectTarget()
|
|
|
|
local targets = {}
|
|
|
|
local titles = {
|
|
|
|
'ScribuntoTestRedirect',
|
|
|
|
'ScribuntoTestNonRedirect',
|
|
|
|
'ScribuntoTestNonExistingPage'
|
|
|
|
}
|
|
|
|
for _, title in ipairs( titles ) do
|
|
|
|
local target = mw.title.new( title ).redirectTarget
|
|
|
|
if title.prefixedText ~= nil then
|
|
|
|
target = title.prefixedText
|
|
|
|
end
|
|
|
|
table.insert( targets, target )
|
|
|
|
end
|
|
|
|
return unpack( targets )
|
2013-03-05 02:11:23 +00:00
|
|
|
end
|
|
|
|
|
2015-07-25 15:53:07 +00:00
|
|
|
local function test_getCurrentTitle_fragment()
|
|
|
|
mw.title.getCurrentTitle().fragment = 'bad'
|
|
|
|
return mw.title.getCurrentTitle().fragment
|
|
|
|
end
|
|
|
|
|
2022-10-19 20:01:40 +00:00
|
|
|
local function test_pageLang()
|
|
|
|
local l = mw.title.getCurrentTitle().pageLang
|
|
|
|
if l:getCode() ~= mw.language.getContentLanguage():getCode() then
|
|
|
|
return 'error'
|
|
|
|
end
|
|
|
|
return 'did not error'
|
|
|
|
end
|
|
|
|
|
2013-02-07 17:50:21 +00:00
|
|
|
-- Tests
|
|
|
|
local tests = {
|
|
|
|
{ name = 'tostring', func = identity, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title2, title3, title4, title5, title6u, title6s },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
|
|
|
|
'Talk:Has/A/Subpage', 'Not/A/Subpage',
|
|
|
|
'Module talk:Test Framework', 'Module talk:Test Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ name = 'title.equal', func = mw.title.equals,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title },
|
|
|
|
expect = { true }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.equal (2)', func = mw.title.equals,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title_copy },
|
|
|
|
expect = { true }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.equal (3)', func = mw.title.equals,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title2 },
|
|
|
|
expect = { false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '==', func = function ()
|
|
|
|
return rawequal( title, title_copy ), title == title, title == title_copy, title == title2
|
2020-10-23 15:39:12 +00:00
|
|
|
end,
|
|
|
|
expect = { false, true, true, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ name = 'title.compare', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title },
|
|
|
|
expect = { 0 }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.compare (2)', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title_copy },
|
|
|
|
expect = { 0 }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.compare (3)', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title, title2 },
|
|
|
|
expect = { -1 }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.compare (4)', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title2, title },
|
|
|
|
expect = { 1 }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.compare (5)', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title2, title3 },
|
|
|
|
expect = { -1 }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2013-10-31 15:49:14 +00:00
|
|
|
{ name = 'title.compare (6)', func = mw.title.compare,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { title6s, title6u },
|
|
|
|
expect = { 0 }
|
2013-10-31 15:49:14 +00:00
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
{ name = '<', func = function ()
|
|
|
|
return title < title, title < title_copy, title < title2, title2 < title
|
2020-10-23 15:39:12 +00:00
|
|
|
end,
|
|
|
|
expect = { false, false, true, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '<=', func = function ()
|
|
|
|
return title <= title, title <= title_copy, title <= title2, title2 <= title
|
2020-10-23 15:39:12 +00:00
|
|
|
end,
|
|
|
|
expect = { true, true, true, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ name = 'title.new with namespace', func = mw.title.new, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'TestFramework', 'Module' },
|
|
|
|
expect = { 'Module:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.new with namespace (2)', func = mw.title.new, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'TestFramework', mw.site.namespaces.Module.id },
|
|
|
|
expect = { 'Module:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.new with namespace (3)', func = mw.title.new, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'Template:TestFramework', 'Module' },
|
|
|
|
expect = { 'Template:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2013-10-31 15:49:14 +00:00
|
|
|
{ name = 'title.new space normalization', func = test_space_normalization,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { ' __ Template __ : __ Test _ Framework __ # _ frag _ frag _ ' },
|
|
|
|
expect = { 'Template:Test Framework', ' frag frag' }
|
2013-10-31 15:49:14 +00:00
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
{ name = 'title.new with invalid title', func = mw.title.new,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { '<bad title>' },
|
|
|
|
expect = { nil }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2013-03-21 13:36:03 +00:00
|
|
|
{ name = 'title.new with nonexistent pageid', func = mw.title.new,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { -1 },
|
|
|
|
expect = { nil }
|
2013-03-21 13:36:03 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.new with pageid 0', func = mw.title.new,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 0 },
|
|
|
|
expect = { nil }
|
2013-03-21 13:36:03 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.new with existing pageid', func = mw.title.new, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { mw.title.testPageId },
|
|
|
|
expect = { 'ScribuntoTestPage' }
|
2013-03-21 13:36:03 +00:00
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
|
|
|
|
{ name = 'title.makeTitle', func = mw.title.makeTitle, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'Module', 'TestFramework' },
|
|
|
|
expect = { 'Module:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.makeTitle (2)', func = mw.title.makeTitle, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { mw.site.namespaces.Module.id, 'TestFramework' },
|
|
|
|
expect = { 'Module:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = 'title.makeTitle (3)', func = mw.title.makeTitle, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { mw.site.namespaces.Module.id, 'Template:TestFramework' },
|
|
|
|
expect = { 'Module:Template:TestFramework' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{ name = '.isLocal', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'isLocal' },
|
|
|
|
expect = { true, true, false, true, true, true, true }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.isTalkPage', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'isTalkPage' },
|
2023-12-15 13:48:56 +00:00
|
|
|
expect = { false, false, nil, true, false, true, true }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.isSubpage', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'isSubpage' },
|
|
|
|
expect = { false, false, false, true, false, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.text', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'text' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
|
|
|
|
'Test Framework', 'Test Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.prefixedText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'prefixedText' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
|
|
|
|
'Talk:Has/A/Subpage', 'Not/A/Subpage', 'Module talk:Test Framework', 'Module talk:Test Framework',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.rootText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'rootText' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has', 'Not/A/Subpage',
|
|
|
|
'Test Framework', 'Test Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.baseText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'baseText' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'TestFramework', 'Module:TestFramework', 'Has/A', 'Not/A/Subpage',
|
|
|
|
'Test Framework', 'Test Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.subpageText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'subpageText' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'TestFramework', 'Module:TestFramework', 'Subpage', 'Not/A/Subpage',
|
|
|
|
'Test Framework', 'Test Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.fullText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'fullText' },
|
|
|
|
expect = {
|
|
|
|
'Main Page', 'Module:TestFramework', 'interwikiprefix:Module:TestFramework',
|
|
|
|
'Talk:Has/A/Subpage#frag', 'Not/A/Subpage',
|
|
|
|
'Module talk:Test Framework# frag frag', 'Module talk:Test Framework# frag frag'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.subjectNsText', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'subjectNsText' },
|
2023-12-15 13:48:56 +00:00
|
|
|
expect = { '', 'Module', nil, '', '', 'Module', 'Module' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2017-11-19 16:22:03 +00:00
|
|
|
{ name = '.canTalk', func = prop_foreach,
|
|
|
|
args = { 'canTalk' },
|
2023-12-15 13:48:56 +00:00
|
|
|
expect = { true, true, nil, true, true, true, true }
|
2017-11-19 16:22:03 +00:00
|
|
|
},
|
|
|
|
{ name = '.talkNsText', func = prop_foreach,
|
|
|
|
args = { 'talkNsText' },
|
|
|
|
expect = { 'Talk', 'Module talk', nil, 'Talk', 'Talk', 'Module talk', 'Module talk' }
|
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
{ name = '.fragment', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'fragment' },
|
|
|
|
expect = { '', '', '', 'frag', '', ' frag frag', ' frag frag' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.interwiki', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'interwiki' },
|
|
|
|
expect = { '', '', 'interwikiprefix', '', '', '', '' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.namespace', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'namespace' },
|
|
|
|
expect = {
|
|
|
|
0, mw.site.namespaces.Module.id, 0, 1, 0,
|
|
|
|
mw.site.namespaces.Module_talk.id, mw.site.namespaces.Module_talk.id
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2014-01-12 20:08:20 +00:00
|
|
|
{ name = '.protectionLevels', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'protectionLevels' },
|
|
|
|
expect = {
|
|
|
|
{ edit = {}, move = {} }, { edit = { 'sysop', 'bogus' }, move = { 'sysop', 'bogus' } },
|
|
|
|
{}, { create = { 'sysop' } }, { edit = { 'autoconfirmed' }, move = { 'sysop' } },
|
|
|
|
{ edit = {}, move = { 'sysop' } }, { edit = {}, move = { 'sysop' } }
|
|
|
|
}
|
2014-01-12 20:08:20 +00:00
|
|
|
},
|
2014-05-10 19:05:45 +00:00
|
|
|
{ name = '.cascadingProtection', func = prop_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'cascadingProtection' },
|
|
|
|
expect = {
|
|
|
|
{ restrictions = { edit = { 'sysop' } }, sources = { 'Lockbox', 'Lockbox2' } }, { restrictions = {}, sources = {} },
|
|
|
|
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }, { restrictions = {}, sources = {} },
|
|
|
|
{ restrictions = {}, sources = {} }, { restrictions = {}, sources = {} }
|
|
|
|
}
|
2014-05-10 19:05:45 +00:00
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
{ name = '.inNamespace()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'inNamespace', 'Module' },
|
|
|
|
expect = { false, true, false, false, false, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.inNamespace() 2', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'inNamespace', mw.site.namespaces.Module.id },
|
|
|
|
expect = { false, true, false, false, false, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.inNamespaces()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'inNamespaces', 0, 1 },
|
|
|
|
expect = { true, false, true, true, true, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.hasSubjectNamespace()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'hasSubjectNamespace', 0 },
|
|
|
|
expect = { true, false, true, true, true, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.isSubpageOf() 1', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'isSubpageOf', title },
|
|
|
|
expect = { false, false, false, false, false, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.isSubpageOf() 2', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'isSubpageOf', title4p },
|
|
|
|
expect = { false, false, false, true, false, false, false }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.partialUrl()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'partialUrl' },
|
|
|
|
expect = {
|
|
|
|
'Main_Page', 'TestFramework', 'Module:TestFramework', 'Has/A/Subpage', 'Not/A/Subpage',
|
|
|
|
'Test_Framework', 'Test_Framework'
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.fullUrl()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'fullUrl' },
|
|
|
|
expect = {
|
|
|
|
'//wiki.local/wiki/Main_Page',
|
|
|
|
'//wiki.local/wiki/Module:TestFramework',
|
|
|
|
'//test.wikipedia.org/wiki/Module:TestFramework',
|
|
|
|
'//wiki.local/wiki/Talk:Has/A/Subpage#frag',
|
|
|
|
'//wiki.local/wiki/Not/A/Subpage',
|
|
|
|
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
'//wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.fullUrl() 2', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'fullUrl', { action = 'test' } },
|
|
|
|
expect = {
|
|
|
|
'//wiki.local/w/index.php?title=Main_Page&action=test',
|
|
|
|
'//wiki.local/w/index.php?title=Module:TestFramework&action=test',
|
|
|
|
'//test.wikipedia.org/wiki/Module:TestFramework?action=test',
|
|
|
|
'//wiki.local/w/index.php?title=Talk:Has/A/Subpage&action=test#frag',
|
|
|
|
'//wiki.local/w/index.php?title=Not/A/Subpage&action=test',
|
|
|
|
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
|
|
|
|
'//wiki.local/w/index.php?title=Module_talk:Test_Framework&action=test#_frag_frag',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.fullUrl() 3', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'fullUrl', nil, 'http' },
|
|
|
|
expect = {
|
|
|
|
'http://wiki.local/wiki/Main_Page',
|
|
|
|
'http://wiki.local/wiki/Module:TestFramework',
|
|
|
|
'http://test.wikipedia.org/wiki/Module:TestFramework',
|
|
|
|
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
|
|
|
|
'http://wiki.local/wiki/Not/A/Subpage',
|
|
|
|
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.localUrl()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'localUrl' },
|
|
|
|
expect = {
|
|
|
|
'/wiki/Main_Page',
|
|
|
|
'/wiki/Module:TestFramework',
|
|
|
|
'//test.wikipedia.org/wiki/Module:TestFramework',
|
|
|
|
'/wiki/Talk:Has/A/Subpage',
|
|
|
|
'/wiki/Not/A/Subpage',
|
|
|
|
'/wiki/Module_talk:Test_Framework',
|
|
|
|
'/wiki/Module_talk:Test_Framework',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
{ name = '.canonicalUrl()', func = func_foreach,
|
2020-10-23 15:39:12 +00:00
|
|
|
args = { 'canonicalUrl' },
|
|
|
|
expect = {
|
|
|
|
'http://wiki.local/wiki/Main_Page',
|
|
|
|
'http://wiki.local/wiki/Module:TestFramework',
|
|
|
|
'http://test.wikipedia.org/wiki/Module:TestFramework',
|
|
|
|
'http://wiki.local/wiki/Talk:Has/A/Subpage#frag',
|
|
|
|
'http://wiki.local/wiki/Not/A/Subpage',
|
|
|
|
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
'http://wiki.local/wiki/Module_talk:Test_Framework#_frag_frag',
|
|
|
|
}
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
|
|
|
|
2013-03-05 02:11:23 +00:00
|
|
|
{ name = '.getContent()', func = test_getContent,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = {
|
|
|
|
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>',
|
|
|
|
nil,
|
|
|
|
}
|
2014-10-23 13:15:52 +00:00
|
|
|
},
|
|
|
|
|
2023-12-14 20:14:12 +00:00
|
|
|
{ name = '.content', func = test_content,
|
|
|
|
expect = {
|
|
|
|
'{{int:mainpage}}<includeonly>...</includeonly><noinclude>...</noinclude>',
|
|
|
|
false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-10-23 13:15:52 +00:00
|
|
|
{ name = '.redirectTarget', func = test_redirectTarget, type = 'ToString',
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { 'ScribuntoTestTarget', false, false }
|
2013-03-05 02:11:23 +00:00
|
|
|
},
|
|
|
|
|
2014-12-09 23:01:40 +00:00
|
|
|
{ name = 'not quite too many expensive functions', func = test_expensive_10,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { 'did not error' }
|
2014-12-09 23:01:40 +00:00
|
|
|
},
|
|
|
|
{ name = 'too many expensive functions', func = test_expensive_11,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = 'too many expensive function calls'
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2014-12-09 23:01:40 +00:00
|
|
|
{ name = "previously cached titles shouldn't count as expensive", func = test_expensive_cached,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { 'did not error' }
|
2014-12-09 23:01:40 +00:00
|
|
|
},
|
|
|
|
{ name = "inexpensive actions shouldn't count as expensive", func = test_inexpensive,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { 'did not error' }
|
2013-02-07 17:50:21 +00:00
|
|
|
},
|
2015-07-25 15:53:07 +00:00
|
|
|
{ name = "fragments don't leak via getCurrentTitle()", func = test_getCurrentTitle_fragment,
|
2020-10-23 15:39:12 +00:00
|
|
|
expect = { '' }
|
2015-07-25 15:53:07 +00:00
|
|
|
},
|
2022-10-19 20:01:40 +00:00
|
|
|
{ name = "sample page language returns current content language", func = test_pageLang,
|
|
|
|
expect = { 'did not error' }
|
|
|
|
},
|
2013-02-07 17:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return testframework.getTestProvider( tests )
|