mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-11 17:01:00 +00:00
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:
parent
ea0707c437
commit
7e54c088ac
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue