diff options
Diffstat (limited to 'MLEB/Babel/tests/phpunit/BabelTest.php')
-rw-r--r-- | MLEB/Babel/tests/phpunit/BabelTest.php | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/MLEB/Babel/tests/phpunit/BabelTest.php b/MLEB/Babel/tests/phpunit/BabelTest.php index e8262ac9..d31cc177 100644 --- a/MLEB/Babel/tests/phpunit/BabelTest.php +++ b/MLEB/Babel/tests/phpunit/BabelTest.php @@ -4,11 +4,12 @@ namespace Babel\Tests; use Babel; use MediaWiki\MediaWikiServices; -use MediaWikiTestCase; +use MediaWikiIntegrationTestCase; use Parser; use ParserOptions; use ParserOutput; use Title; +use TitleValue; use User; /** @@ -20,7 +21,7 @@ use User; * @license GPL-2.0-or-later * @author Thiemo Kreuz */ -class BabelTest extends MediaWikiTestCase { +class BabelTest extends MediaWikiIntegrationTestCase { public function addDBDataOnce() { // The '#babel' parser function normally auto-creates category pages via @@ -38,28 +39,37 @@ class BabelTest extends MediaWikiTestCase { // because that also means updates from core itself (such as the saving of category // links) would be deferred, which we do need to observe below. // - // Workaround this by mocking LinkCache to that BabelAutoCreate/Title::exists() - // perceives these as existing already and will skip auto-creation logic. + // Work around this by faking entries in LinkCache so that Title::exists() + // returns true in BabelAutoCreate and no auto-creation is attempted. $this->setMwGlobals( 'wgCapitalLinks', false ); - MediaWikiServices::getInstance()->resetServiceForTesting( 'NamespaceInfo' ); - $linkCache = new \LinkCache( - MediaWikiServices::getInstance()->getTitleFormatter(), - \WANObjectCache::newEmpty(), - $this->createMock( \NamespaceInfo::class ) - ); + + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); foreach ( [ 'en', 'en-N', 'en-1', 'es', 'es-2', 'de', 'de-N', - 'simple', 'simple-1', 'zh-Hant', 'zh-Hant-3' - ] as $name ) { - $linkCache->addGoodLinkObj( 1, new \TitleValue( NS_CATEGORY, $name ) ); + 'simple', 'simple-1', 'zh-Hant', 'zh-Hant-3' + ] as $name ) { + $page = new TitleValue( NS_CATEGORY, $name ); + // TODO: use LinkCacheTestTrait once the minimum MW version is 1.37 + $linkCache->addGoodLinkObjFromRow( $page, (object)[ + 'page_id' => 1, + 'page_namespace' => $page->getNamespace(), + 'page_title' => $page->getDBkey(), + 'page_len' => -1, + 'page_is_redirect' => 0, + 'page_latest' => 0, + 'page_content_model' => null, + 'page_lang' => null, + 'page_restrictions' => null, + 'page_is_new' => 0, + 'page_touched' => '', + ] ); } - $this->setService( 'LinkCache', $linkCache ); $user = User::newFromName( 'User-1' ); $user->addToDatabase(); $this->insertPage( 'User:User-1', '{{#babel:en-1|es-2|de|SIMPLE-1|zh-hant-3}}' ); } - protected function setUp() : void { + protected function setUp(): void { parent::setUp(); $this->setContentLang( 'qqx' ); |