Avoid DB access in databaseless tests

- Force a content model on the title used by LuaEngineTestBase, so that
  calls to getPageLanguage() won't end up hitting the DB
- Don't actually use SiteStats from SiteLibrary in unit tests. There
  seem to be no test actually using this data.

Bug: T345372
Change-Id: I35884f04b582678982fb5f64d9199bab41cd8bce
This commit is contained in:
Daimona Eaytoy 2023-08-31 18:28:08 +02:00 committed by jenkins-bot
parent ea0707c437
commit 7e54c088ac
2 changed files with 26 additions and 10 deletions

View file

@ -91,15 +91,27 @@ class SiteLibrary extends LibraryBase {
}
$info['namespaces'] = self::$namespacesCache;
$info['stats'] = [
'pages' => (int)SiteStats::pages(),
'articles' => (int)SiteStats::articles(),
'files' => (int)SiteStats::images(),
'edits' => (int)SiteStats::edits(),
'users' => (int)SiteStats::users(),
'activeUsers' => (int)SiteStats::activeUsers(),
'admins' => (int)SiteStats::numberingroup( 'sysop' ),
];
if ( defined( 'MW_PHPUNIT_TEST' ) ) {
$info['stats'] = [
'pages' => 1,
'articles' => 1,
'files' => 0,
'edits' => 1,
'users' => 1,
'activeUsers' => 1,
'admins' => 1,
];
} else {
$info['stats'] = [
'pages' => (int)SiteStats::pages(),
'articles' => (int)SiteStats::articles(),
'files' => (int)SiteStats::images(),
'edits' => (int)SiteStats::edits(),
'users' => (int)SiteStats::users(),
'activeUsers' => (int)SiteStats::activeUsers(),
'admins' => (int)SiteStats::numberingroup( 'sysop' ),
];
}
return $this->getEngine()->registerInterface( 'mw.site.lua', $lib, $info );
}

View file

@ -98,7 +98,11 @@ abstract class LuaEngineTestBase extends MediaWikiLangTestCase {
* @return Title
*/
protected function getTestTitle() {
return Title::newMainPage();
// XXX This should use a dedicated test page, not the main page
$t = Title::newMainPage();
// Force content model to avoid DB queries
$t->setContentModel( CONTENT_MODEL_WIKITEXT );
return $t;
}
public function toString(): string {