mediawiki-extensions-Scribunto/tests/engines/LuaCommon/TitleLibraryTest.php
Brad Jorsch 04a0a580e3 Add mw.title library
Note that fetching any title besides the one for the current page is
considered "expensive". It also records the title fetched in the
ParserOutput so it will be listed in pagelinks, just like #ifexists.

This also moves the ToString test formatter into TestFramework.lua, so
TitleLibraryTests.lua can use it too.

Change-Id: I799f3289a37fe1349b6bca5758829acf82cb718f
2013-02-28 11:57:11 -08:00

78 lines
2.1 KiB
PHP

<?php
// Hook to inject our interwiki prefix
$wgHooks['InterwikiLoadPrefix'][] = function ( $prefix, &$data ) {
if ( $prefix !== 'scribuntotitletest' ) {
return true;
}
$data = array(
'iw_prefix' => 'scribuntotitletest',
'iw_url' => '//test.wikipedia.org/wiki/$1',
'iw_api' => 1,
'iw_wikiid' => 0,
'iw_local' => 0,
'iw_trans' => 0
);
return false;
};
class Scribunto_LuaTitleLibraryTests extends Scribunto_LuaEngineTestBase {
protected static $moduleName = 'TitleLibraryTests';
public static function suite( $className ) {
global $wgInterwikiCache;
if ( $wgInterwikiCache ) {
$suite = new PHPUnit_Framework_TestSuite;
$suite->setName( $className );
$suite->addTest(
new Scribunto_LuaEngineTestSkip(
$className, 'Cannot run TitleLibrary tests when $wgInterwikiCache is set'
), array( 'Lua' )
);
return $suite;
}
return parent::suite( $className );
}
function setUp() {
parent::setUp();
// Note this depends on every iteration of the data provider running with a clean parser
$this->getEngine()->getParser()->getOptions()->setExpensiveParserFunctionLimit( 10 );
$this->setMwGlobals( array(
'wgServer' => '//wiki.local',
'wgCanonicalServer' => 'http://wiki.local',
'wgUsePathInfo' => true,
'wgActionPaths' => array(),
'wgScript' => '/w/index.php',
'wgScriptPath' => '/w',
'wgArticlePath' => '/wiki/$1',
) );
}
function getTestModules() {
return parent::getTestModules() + array(
'TitleLibraryTests' => __DIR__ . '/TitleLibraryTests.lua',
);
}
function testAddsLinks() {
$engine = $this->getEngine();
$interpreter = $engine->getInterpreter();
$links = $engine->getParser()->getOutput()->getLinks();
$this->assertFalse( isset( $links[NS_PROJECT]['Referenced_from_Lua'] ) );
$interpreter->callFunction(
$interpreter->loadString( 'mw.title.new( "Project:Referenced from Lua" )', 'reference title' )
);
$links = $engine->getParser()->getOutput()->getLinks();
$this->assertArrayHasKey( NS_PROJECT, $links );
$this->assertArrayHasKey( 'Referenced_from_Lua', $links[NS_PROJECT] );
}
}