TitleLibraryTest: Don't use deprecated InterwikiLoadPrefix hook

Use $wgInterwikiCache to setup interwiki prefixes for testing instead
of the deprecated InterwikiLoadPrefix hook.  This simplifies the test
setup quite a bit as well.

Bug: T270444
Change-Id: Icb772fcee07103a06548011ddd653487477ebfcc
This commit is contained in:
C. Scott Ananian 2020-12-22 09:21:38 -05:00 committed by C. Scott Ananian
parent 0a1f6d74a8
commit 93662aabf1

View file

@ -1,6 +1,6 @@
<?php
use PHPUnit\Framework\TestSuite;
use MediaWiki\Interwiki\ClassicInterwikiLookup;
/**
* @covers Scribunto_LuaTitleLibrary
@ -14,45 +14,27 @@ class Scribunto_LuaTitleLibraryTest extends Scribunto_LuaEngineTestBase {
private $testPageId = null;
public static function suite( $className ) {
global $wgInterwikiCache;
if ( $wgInterwikiCache ) {
$suite = new TestSuite;
$suite->setName( $className );
$suite->addTest(
new Scribunto_LuaEngineTestSkip(
$className, 'Cannot run TitleLibrary tests when $wgInterwikiCache is set'
), [ 'Lua' ]
);
return $suite;
}
return parent::suite( $className );
}
protected function setUp() : void {
global $wgHooks;
$this->setTestTitle( null );
parent::setUp();
// Hook to inject our interwiki prefix
$this->hooks = $wgHooks;
$wgHooks['InterwikiLoadPrefix'][] = function ( $prefix, &$data ) {
if ( $prefix !== 'interwikiprefix' ) {
return true;
}
$data = [
'iw_prefix' => 'interwikiprefix',
'iw_url' => '//test.wikipedia.org/wiki/$1',
'iw_api' => 1,
'iw_wikiid' => 0,
'iw_local' => 0,
'iw_trans' => 0,
];
return false;
};
// Set up interwikis (via wgInterwikiCache) before creating any Titles
$this->setMwGlobals( [
'wgServer' => '//wiki.local',
'wgCanonicalServer' => 'http://wiki.local',
'wgUsePathInfo' => true,
'wgActionPaths' => [],
'wgScript' => '/w/index.php',
'wgScriptPath' => '/w',
'wgArticlePath' => '/wiki/$1',
'wgInterwikiCache' => ClassicInterwikiLookup::buildCdbHash( [
[
'iw_prefix' => 'interwikiprefix',
'iw_url' => '//test.wikipedia.org/wiki/$1',
'iw_local' => 0,
],
] ),
] );
// Page for getContent test
$page = WikiPage::factory( Title::newFromText( 'ScribuntoTestPage' ) );
@ -123,22 +105,6 @@ class Scribunto_LuaTitleLibraryTest extends Scribunto_LuaEngineTestBase {
$interpreter->callFunction(
$interpreter->loadString( "mw.title.testPageId = $this->testPageId", 'fortest' )
);
$this->setMwGlobals( [
'wgServer' => '//wiki.local',
'wgCanonicalServer' => 'http://wiki.local',
'wgUsePathInfo' => true,
'wgActionPaths' => [],
'wgScript' => '/w/index.php',
'wgScriptPath' => '/w',
'wgArticlePath' => '/wiki/$1',
] );
}
protected function tearDown() : void {
global $wgHooks;
$wgHooks = $this->hooks;
parent::tearDown();
}
protected function getTestTitle() {