diff options
Diffstat (limited to 'MLEB/Babel/tests/phpunit')
-rw-r--r-- | MLEB/Babel/tests/phpunit/BabelAutoCreateTest.php | 6 | ||||
-rw-r--r-- | MLEB/Babel/tests/phpunit/BabelTest.php | 40 |
2 files changed, 28 insertions, 18 deletions
diff --git a/MLEB/Babel/tests/phpunit/BabelAutoCreateTest.php b/MLEB/Babel/tests/phpunit/BabelAutoCreateTest.php index df7b48c5..c8ce8204 100644 --- a/MLEB/Babel/tests/phpunit/BabelAutoCreateTest.php +++ b/MLEB/Babel/tests/phpunit/BabelAutoCreateTest.php @@ -3,7 +3,7 @@ namespace Babel\Tests; use BabelAutoCreate; -use MediaWikiTestCase; +use MediaWikiIntegrationTestCase; use Title; use WikiPage; @@ -16,9 +16,9 @@ use WikiPage; * @license GPL-2.0-or-later * @author Thiemo Kreuz */ -class BabelAutoCreateTest extends MediaWikiTestCase { +class BabelAutoCreateTest extends MediaWikiIntegrationTestCase { - protected function setUp() : void { + protected function setUp(): void { parent::setUp(); $this->setContentLang( 'qqx' ); 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' ); |