aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes
diff options
context:
space:
mode:
authorthiemowmde <thiemo.kreuz@wikimedia.de>2024-07-09 17:36:08 +0200
committerThiemo Kreuz (WMDE) <thiemo.kreuz@wikimedia.de>2024-07-10 10:11:22 +0000
commit4bd95cd96bd5c13424098dec38891596d68ff264 (patch)
tree356c0e303b3207ca8ba28c5abde9db8d4f3aeda1 /tests/phpunit/includes
parent17079782a776849ec51d5c3d3712edc217cce65b (diff)
downloadmediawikicore-4bd95cd96bd5c13424098dec38891596d68ff264.tar.gz
mediawikicore-4bd95cd96bd5c13424098dec38891596d68ff264.zip
Use MainConfigNames constants in tests where possible
I believe this makes the code less brittle, and also makes it a bit more obvious what these strings are meant to represent. Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
Diffstat (limited to 'tests/phpunit/includes')
-rw-r--r--tests/phpunit/includes/Output/OutputPageTest.php48
-rw-r--r--tests/phpunit/includes/ResourceLoader/SkinModuleTest.php20
-rw-r--r--tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php2
-rw-r--r--tests/phpunit/includes/debug/MWDebugTest.php6
-rw-r--r--tests/phpunit/includes/exception/MWExceptionTest.php4
-rw-r--r--tests/phpunit/includes/filerepo/ThumbnailEntryPointTest.php10
-rw-r--r--tests/phpunit/includes/jobqueue/JobTest.php2
-rw-r--r--tests/phpunit/includes/page/MovePageTest.php4
-rw-r--r--tests/phpunit/includes/page/PageSelectQueryBuilderTest.php5
-rw-r--r--tests/phpunit/includes/page/PageStoreTest.php8
-rw-r--r--tests/phpunit/includes/page/ParserOutputAccessTest.php15
-rw-r--r--tests/phpunit/includes/title/MediaWikiTitleCodecTest.php4
-rw-r--r--tests/phpunit/includes/title/NamespaceInfoTest.php45
-rw-r--r--tests/phpunit/includes/user/PasswordResetTest.php7
-rw-r--r--tests/phpunit/includes/user/UserGroupManagerTest.php84
15 files changed, 123 insertions, 141 deletions
diff --git a/tests/phpunit/includes/Output/OutputPageTest.php b/tests/phpunit/includes/Output/OutputPageTest.php
index a4a70e41d9a4..681ef0b381e1 100644
--- a/tests/phpunit/includes/Output/OutputPageTest.php
+++ b/tests/phpunit/includes/Output/OutputPageTest.php
@@ -100,11 +100,11 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
private function setupFeedLinks( $feed, $types ): OutputPage {
$outputPage = $this->newInstance( [
- 'AdvertisedFeedTypes' => $types,
- 'Feed' => $feed,
- 'OverrideSiteFeed' => false,
- 'Script' => '/w',
- 'Sitename' => false,
+ MainConfigNames::AdvertisedFeedTypes => $types,
+ MainConfigNames::Feed => $feed,
+ MainConfigNames::OverrideSiteFeed => false,
+ MainConfigNames::Script => '/w',
+ MainConfigNames::Sitename => false,
] );
$outputPage->setTitle( Title::makeTitle( NS_MAIN, 'Test' ) );
$this->overrideConfigValue( MainConfigNames::Script, '/w/index.php' );
@@ -175,25 +175,19 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
public static function provideGetHeadLinksArray() {
return [
[
- [
- 'EnableCanonicalServerLink' => true,
- ],
+ [ MainConfigNames::EnableCanonicalServerLink => true ],
'https://www.example.org/xyzzy/Hello',
true,
'/xyzzy/Hello'
],
[
- [
- 'EnableCanonicalServerLink' => true,
- ],
+ [ MainConfigNames::EnableCanonicalServerLink => true ],
'https://www.example.org/wikipage/My_test_page',
true,
null
],
[
- [
- 'EnableCanonicalServerLink' => true,
- ],
+ [ MainConfigNames::EnableCanonicalServerLink => true ],
'https://www.mediawiki.org/wiki/Manual:FauxRequest.php',
false,
null
@@ -225,7 +219,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
* Test the generation of hreflang Tags when site language has variants
*/
public function testGetLanguageVariantUrl() {
- $this->overrideConfigValue( 'LanguageCode', 'zh' );
+ $this->overrideConfigValue( MainConfigNames::LanguageCode, 'zh' );
$op = $this->newInstance();
$headLinks = $op->getHeadLinksArray();
@@ -248,8 +242,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
# Make sure $wgVariantArticlePath work
# We currently use MediaWiki internal language code as the primary variant URL parameter
$this->overrideConfigValues( [
- 'LanguageCode' => 'zh',
- 'VariantArticlePath' => '/$2/$1',
+ MainConfigNames::LanguageCode => 'zh',
+ MainConfigNames::VariantArticlePath => '/$2/$1',
] );
$op = $this->newInstance();
@@ -322,7 +316,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
'variant' => $urlVariant,
] );
$this->overrideConfigValues( [
- 'LanguageCode' => 'zh',
+ MainConfigNames::LanguageCode => 'zh',
'Request' => $req, # LanguageConverter is using global state...
] );
$op = $this->newInstance( [ MainConfigNames::EnableCanonicalServerLink => true ], $req );
@@ -654,10 +648,10 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
'If-Modified-Since not per spec but we accept it anyway because strtotime does' =>
[ $lastModified, "@$lastModified", true ],
'$wgCachePages = false' =>
- [ $lastModified, $lastModified, false, [ 'CachePages' => false ] ],
+ [ $lastModified, $lastModified, false, [ MainConfigNames::CachePages => false ] ],
'$wgCacheEpoch' =>
[ $lastModified, $lastModified, false,
- [ 'CacheEpoch' => wfTimestamp( TS_MW, $lastModified + 1 ) ] ],
+ [ MainConfigNames::CacheEpoch => wfTimestamp( TS_MW, $lastModified + 1 ) ] ],
'Recently-touched user' =>
[ $lastModified, $lastModified, false, [],
function ( OutputPage $op ) {
@@ -665,7 +659,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
} ],
'After CDN expiry' =>
[ $lastModified, $lastModified, false,
- [ 'UseCdn' => true, 'CdnMaxAge' => 3599 ] ],
+ [ MainConfigNames::UseCdn => true, MainConfigNames::CdnMaxAge => 3599 ] ],
'Hook allows cache use' =>
[ $lastModified + 1, $lastModified, true, [],
static function ( $op, $that ) {
@@ -1099,7 +1093,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
}
public function testSetSyndicated() {
- $op = $this->newInstance( [ 'Feed' => true ] );
+ $op = $this->newInstance( [ MainConfigNames::Feed => true ] );
$this->assertFalse( $op->isSyndicated() );
$op->setSyndicated();
@@ -1116,7 +1110,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
}
public function testFeedLinks() {
- $op = $this->newInstance( [ 'Feed' => true ] );
+ $op = $this->newInstance( [ MainConfigNames::Feed => true ] );
$this->assertSame( [], $op->getSyndicationLinks() );
$op->addFeedLink( 'not a supported format', 'abc' );
@@ -2469,8 +2463,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
$breakFrames, $preventClickjacking, $editPageFrameOptions, $expected
) {
$op = $this->newInstance( [
- 'BreakFrames' => $breakFrames,
- 'EditPageFrameOptions' => $editPageFrameOptions,
+ MainConfigNames::BreakFrames => $breakFrames,
+ MainConfigNames::EditPageFrameOptions => $editPageFrameOptions,
] );
$op->setPreventClickjacking( $preventClickjacking );
@@ -3015,7 +3009,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
$this->overrideConfigValue( MainConfigNames::UsePigLatinVariant, $options['variant'] ?? false );
$output = $this->newInstance( [
- 'UseCdn' => $options['useCdn'] ?? false,
+ MainConfigNames::UseCdn => $options['useCdn'] ?? false,
] );
$output->considerCacheSettingsFinal();
@@ -3204,7 +3198,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
] );
$this->setContentLang( $contLang );
$output = $this->newInstance(
- [ 'LanguageCode' => $contLang ],
+ [ MainConfigNames::LanguageCode => $contLang ],
new FauxRequest( [ 'uselang' => $userLang ] ),
'notitle'
);
diff --git a/tests/phpunit/includes/ResourceLoader/SkinModuleTest.php b/tests/phpunit/includes/ResourceLoader/SkinModuleTest.php
index 0aca4c8f248b..91ef312de007 100644
--- a/tests/phpunit/includes/ResourceLoader/SkinModuleTest.php
+++ b/tests/phpunit/includes/ResourceLoader/SkinModuleTest.php
@@ -405,7 +405,7 @@ class SkinModuleTest extends ResourceLoaderTestCase {
return [
[
[
- 'Logos' => [
+ MainConfigNames::Logos => [
'1x' => '/img/default.png',
'1.5x' => '/img/one-point-five.png',
'2x' => '/img/two-x.png',
@@ -420,16 +420,14 @@ class SkinModuleTest extends ResourceLoaderTestCase {
],
[
[
- 'Logos' => [
- '1x' => '/img/default.png',
- ],
+ MainConfigNames::Logos => [ '1x' => '/img/default.png' ],
],
'en',
'Link: </img/default.png>;rel=preload;as=image'
],
[
[
- 'Logos' => [
+ MainConfigNames::Logos => [
'1x' => '/img/default.png',
'2x' => '/img/two-x.png',
],
@@ -441,7 +439,7 @@ class SkinModuleTest extends ResourceLoaderTestCase {
],
[
[
- 'Logos' => [
+ MainConfigNames::Logos => [
'1x' => '/img/default.png',
'svg' => '/img/vector.svg',
],
@@ -452,18 +450,16 @@ class SkinModuleTest extends ResourceLoaderTestCase {
],
[
[
- 'BaseDirectory' => dirname( dirname( __DIR__ ) ) . '/data/media',
- 'Logos' => [
- '1x' => '/w/test.jpg',
- ],
- 'UploadPath' => '/w/images',
+ MainConfigNames::BaseDirectory => dirname( dirname( __DIR__ ) ) . '/data/media',
+ MainConfigNames::Logos => [ '1x' => '/w/test.jpg' ],
+ MainConfigNames::UploadPath => '/w/images',
],
'en',
'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
],
[
[
- 'Logos' => [
+ MainConfigNames::Logos => [
'1x' => '/img/default.png',
'1.5x' => '/img/one-point-five.png',
'2x' => '/img/two-x.png',
diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
index dce9a92fcfdd..87bf78cef05d 100644
--- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
+++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
@@ -1258,7 +1258,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase {
$services->getConnectionProvider(),
new ServiceOptions(
EditResultCache::CONSTRUCTOR_OPTIONS,
- [ 'RCMaxAge' => BagOStuff::TTL_MONTH ]
+ [ MainConfigNames::RCMaxAge => BagOStuff::TTL_MONTH ]
)
);
diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php
index 357e145449e7..9c24c9455d74 100644
--- a/tests/phpunit/includes/debug/MWDebugTest.php
+++ b/tests/phpunit/includes/debug/MWDebugTest.php
@@ -14,7 +14,7 @@ use Psr\Log\LoggerInterface;
class MWDebugTest extends MediaWikiIntegrationTestCase {
protected function setUp(): void {
- $this->setMwGlobals( 'wgDevelopmentWarnings', false );
+ $this->overrideConfigValue( MainConfigNames::DevelopmentWarnings, false );
parent::setUp();
/** Clear log before each test */
@@ -52,7 +52,7 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
}
public function testWarningDevelopment() {
- $this->setMwGlobals( 'wgDevelopmentWarnings', true );
+ $this->overrideConfigValue( MainConfigNames::DevelopmentWarnings, true );
$this->expectPHPError(
E_USER_NOTICE,
@@ -74,7 +74,7 @@ class MWDebugTest extends MediaWikiIntegrationTestCase {
*/
public function testMessagesFromErrorChannel() {
// Turn off to keep mw-error.log file empty in CI (and thus avoid build failure)
- $this->setMwGlobals( 'wgDebugLogGroups', [] );
+ $this->overrideConfigValue( MainConfigNames::DebugLogGroups, [] );
MWExceptionHandler::handleError( E_USER_DEPRECATED, 'Warning message' );
$this->assertEquals(
diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php
index 62cd3700777d..5c3564479dd7 100644
--- a/tests/phpunit/includes/exception/MWExceptionTest.php
+++ b/tests/phpunit/includes/exception/MWExceptionTest.php
@@ -1,5 +1,7 @@
<?php
+use MediaWiki\MainConfigNames;
+
/**
* @covers \MWException
* @author Antoine Musso
@@ -46,7 +48,7 @@ class MWExceptionTest extends MediaWikiIntegrationTestCase {
*/
public function testReport() {
// Turn off to keep mw-error.log file empty in CI (and thus avoid build failure)
- $this->setMwGlobals( 'wgDebugLogGroups', [] );
+ $this->overrideConfigValue( MainConfigNames::DebugLogGroups, [] );
global $wgOut;
$wgOut->disable();
diff --git a/tests/phpunit/includes/filerepo/ThumbnailEntryPointTest.php b/tests/phpunit/includes/filerepo/ThumbnailEntryPointTest.php
index 16d1b539df4e..7348f8c3d2a4 100644
--- a/tests/phpunit/includes/filerepo/ThumbnailEntryPointTest.php
+++ b/tests/phpunit/includes/filerepo/ThumbnailEntryPointTest.php
@@ -365,10 +365,7 @@ class ThumbnailEntryPointTest extends MediaWikiIntegrationTestCase {
$groupPermissions = $this->getConfVar( MainConfigNames::GroupPermissions );
$groupPermissions['*']['read'] = false;
- $this->overrideConfigValue(
- 'GroupPermissions',
- $groupPermissions
- );
+ $this->overrideConfigValue( MainConfigNames::GroupPermissions, $groupPermissions );
// Make the user have no rights
$authority = new SimpleAuthority(
@@ -406,10 +403,7 @@ class ThumbnailEntryPointTest extends MediaWikiIntegrationTestCase {
$groupPermissions = $this->getConfVar( MainConfigNames::GroupPermissions );
$groupPermissions['*']['read'] = false;
- $this->overrideConfigValue(
- 'GroupPermissions',
- $groupPermissions
- );
+ $this->overrideConfigValue( MainConfigNames::GroupPermissions, $groupPermissions );
// Make a user who is allowed to read
$authority = new SimpleAuthority(
diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php
index da78a8754935..ac7f30a8ca13 100644
--- a/tests/phpunit/includes/jobqueue/JobTest.php
+++ b/tests/phpunit/includes/jobqueue/JobTest.php
@@ -102,7 +102,7 @@ class JobTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideTestJobFactory
*/
public function testJobFactory( $handler, $expectedClass ) {
- $this->overrideConfigValue( 'JobClasses', [ 'testdummy' => $handler ] );
+ $this->overrideConfigValue( MainConfigNames::JobClasses, [ 'testdummy' => $handler ] );
$job = Job::factory( 'testdummy', Title::newMainPage(), [] );
$this->assertInstanceOf( $expectedClass, $job );
diff --git a/tests/phpunit/includes/page/MovePageTest.php b/tests/phpunit/includes/page/MovePageTest.php
index 895d0ee9bfe2..89a8960f4034 100644
--- a/tests/phpunit/includes/page/MovePageTest.php
+++ b/tests/phpunit/includes/page/MovePageTest.php
@@ -43,8 +43,8 @@ class MovePageTest extends MediaWikiIntegrationTestCase {
MovePage::CONSTRUCTOR_OPTIONS,
$params['options'] ?? [],
[
- 'CategoryCollation' => 'uppercase',
- 'MaximumMovedPages' => 100,
+ MainConfigNames::CategoryCollation => 'uppercase',
+ MainConfigNames::MaximumMovedPages => 100,
]
),
$mockProvider,
diff --git a/tests/phpunit/includes/page/PageSelectQueryBuilderTest.php b/tests/phpunit/includes/page/PageSelectQueryBuilderTest.php
index cbe914b1d404..f3e3f2e9eddf 100644
--- a/tests/phpunit/includes/page/PageSelectQueryBuilderTest.php
+++ b/tests/phpunit/includes/page/PageSelectQueryBuilderTest.php
@@ -3,6 +3,7 @@ namespace MediaWiki\Tests\Page;
use Exception;
use MediaWiki\Config\ServiceOptions;
+use MediaWiki\MainConfigNames;
use MediaWiki\Page\PageSelectQueryBuilder;
use MediaWiki\Page\PageStore;
use MediaWikiIntegrationTestCase;
@@ -31,8 +32,8 @@ class PageSelectQueryBuilderTest extends MediaWikiIntegrationTestCase {
$serviceOptions = new ServiceOptions(
PageStore::CONSTRUCTOR_OPTIONS,
[
- 'LanguageCode' => $services->getContentLanguage()->getCode(),
- 'PageLanguageUseDB' => true
+ MainConfigNames::LanguageCode => $services->getContentLanguage()->getCode(),
+ MainConfigNames::PageLanguageUseDB => true,
]
);
diff --git a/tests/phpunit/includes/page/PageStoreTest.php b/tests/phpunit/includes/page/PageStoreTest.php
index 2ba4d15bc1bc..61fe7cd5998d 100644
--- a/tests/phpunit/includes/page/PageStoreTest.php
+++ b/tests/phpunit/includes/page/PageStoreTest.php
@@ -53,8 +53,8 @@ class PageStoreTest extends MediaWikiIntegrationTestCase {
$serviceOptions = new ServiceOptions(
PageStore::CONSTRUCTOR_OPTIONS,
$options + [
- 'LanguageCode' => $services->getContentLanguage()->getCode(),
- 'PageLanguageUseDB' => true
+ MainConfigNames::LanguageCode => $services->getContentLanguage()->getCode(),
+ MainConfigNames::PageLanguageUseDB => true,
]
);
@@ -723,8 +723,8 @@ class PageStoreTest extends MediaWikiIntegrationTestCase {
$pageStore = $this->getPageStore(
[
- 'LanguageCode' => 'qxx',
- 'PageLanguageUseDB' => true
+ MainConfigNames::LanguageCode => 'qxx',
+ MainConfigNames::PageLanguageUseDB => true,
],
[ 'dbLoadBalancer' => $lb ]
);
diff --git a/tests/phpunit/includes/page/ParserOutputAccessTest.php b/tests/phpunit/includes/page/ParserOutputAccessTest.php
index d58dbbcb1474..325bddaa42bc 100644
--- a/tests/phpunit/includes/page/ParserOutputAccessTest.php
+++ b/tests/phpunit/includes/page/ParserOutputAccessTest.php
@@ -1,4 +1,5 @@
<?php
+
use MediaWiki\Json\JsonCodec;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Logger\Spi as LoggerSpi;
@@ -841,14 +842,12 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase {
* @param bool $fastStale
*/
private function setPoolCounterFactory( $status, $fastStale = false ) {
- $this->overrideConfigValues( [
- MainConfigNames::PoolCounterConf => [
- 'ArticleView' => [
- 'class' => MockPoolCounterFailing::class,
- 'fastStale' => $fastStale,
- 'mockAcquire' => $status,
- 'mockRelease' => Status::newGood( PoolCounter::RELEASED ),
- ],
+ $this->overrideConfigValue( MainConfigNames::PoolCounterConf, [
+ 'ArticleView' => [
+ 'class' => MockPoolCounterFailing::class,
+ 'fastStale' => $fastStale,
+ 'mockAcquire' => $status,
+ 'mockRelease' => Status::newGood( PoolCounter::RELEASED ),
],
] );
}
diff --git a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php
index de8701967e4d..4a1e239cd3d0 100644
--- a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php
+++ b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php
@@ -91,14 +91,14 @@ class MediaWikiTitleCodecTest extends MediaWikiIntegrationTestCase {
*/
private function getNamespaceInfo(): NamespaceInfo {
return $this->getDummyNamespaceInfo( [
- 'CanonicalNamespaceNames' => [
+ MainConfigNames::CanonicalNamespaceNames => [
NS_SPECIAL => 'Special',
NS_MAIN => '',
NS_TALK => 'Talk',
NS_USER => 'User',
NS_USER_TALK => 'User_talk',
],
- 'CapitalLinks' => true,
+ MainConfigNames::CapitalLinks => true,
] );
}
diff --git a/tests/phpunit/includes/title/NamespaceInfoTest.php b/tests/phpunit/includes/title/NamespaceInfoTest.php
index be3aad2f4a07..280ae3affc79 100644
--- a/tests/phpunit/includes/title/NamespaceInfoTest.php
+++ b/tests/phpunit/includes/title/NamespaceInfoTest.php
@@ -8,6 +8,7 @@
use MediaWiki\Config\ServiceOptions;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MainConfigNames;
use MediaWiki\Title\NamespaceInfo;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleValue;
@@ -23,25 +24,25 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
*/
private const DEFAULT_OPTIONS = [
- 'CanonicalNamespaceNames' => [
+ MainConfigNames::CanonicalNamespaceNames => [
NS_TALK => 'Talk',
NS_USER => 'User',
NS_USER_TALK => 'User_talk',
NS_SPECIAL => 'Special',
NS_MEDIA => 'Media',
],
- 'CapitalLinkOverrides' => [],
- 'CapitalLinks' => true,
- 'ContentNamespaces' => [ NS_MAIN ],
- 'ExtraNamespaces' => [],
- 'ExtraSignatureNamespaces' => [],
- 'NamespaceContentModels' => [],
- 'NamespacesWithSubpages' => [
+ MainConfigNames::CapitalLinkOverrides => [],
+ MainConfigNames::CapitalLinks => true,
+ MainConfigNames::ContentNamespaces => [ NS_MAIN ],
+ MainConfigNames::ExtraNamespaces => [],
+ MainConfigNames::ExtraSignatureNamespaces => [],
+ MainConfigNames::NamespaceContentModels => [],
+ MainConfigNames::NamespacesWithSubpages => [
NS_TALK => true,
NS_USER => true,
NS_USER_TALK => true,
],
- 'NonincludableNamespaces' => [],
+ MainConfigNames::NonincludableNamespaces => [],
];
/**
@@ -265,7 +266,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideIsContent
*/
public function testIsContent( $ns, $expected, $contentNamespaces = [ NS_MAIN ] ) {
- $obj = $this->newObj( [ 'ContentNamespaces' => $contentNamespaces ] );
+ $obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] );
$this->assertSame( $expected, $obj->isContent( $ns ) );
}
@@ -319,7 +320,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @param int $expected
*/
public function testWantSignatures_ExtraSignatureNamespaces( $index, $expected ) {
- $obj = $this->newObj( [ 'ExtraSignatureNamespaces' =>
+ $obj = $this->newObj( [ MainConfigNames::ExtraSignatureNamespaces =>
[ NS_MAIN, NS_USER, NS_SPECIAL, NS_MEDIA, 123456, -12345 ] ] );
$this->assertSame( $expected, $obj->wantSignatures( $index ) );
}
@@ -373,7 +374,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
*/
public function testHasSubpages( $ns, $expected, array $namespacesWithSubpages = null ) {
$obj = $this->newObj( $namespacesWithSubpages
- ? [ 'NamespacesWithSubpages' => $namespacesWithSubpages ]
+ ? [ MainConfigNames::NamespacesWithSubpages => $namespacesWithSubpages ]
: [] );
$this->assertSame( $expected, $obj->hasSubpages( $ns ) );
}
@@ -401,7 +402,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::getContentNamespaces
*/
public function testGetContentNamespaces( $contentNamespaces, array $expected ) {
- $obj = $this->newObj( [ 'ContentNamespaces' => $contentNamespaces ] );
+ $obj = $this->newObj( [ MainConfigNames::ContentNamespaces => $contentNamespaces ] );
$this->assertSame( $expected, $obj->getContentNamespaces() );
}
@@ -469,8 +470,8 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
$ns, $expected, $capitalLinks = true, array $capitalLinkOverrides = []
) {
$obj = $this->newObj( [
- 'CapitalLinks' => $capitalLinks,
- 'CapitalLinkOverrides' => $capitalLinkOverrides,
+ MainConfigNames::CapitalLinks => $capitalLinks,
+ MainConfigNames::CapitalLinkOverrides => $capitalLinkOverrides,
] );
$this->assertSame( $expected, $obj->isCapitalized( $ns ) );
}
@@ -526,7 +527,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::isNonincludable
*/
public function testIsNonincludable() {
- $obj = $this->newObj( [ 'NonincludableNamespaces' => [ NS_USER ] ] );
+ $obj = $this->newObj( [ MainConfigNames::NonincludableNamespaces => [ NS_USER ] ] );
$this->assertTrue( $obj->isNonincludable( NS_USER ) );
$this->assertFalse( $obj->isNonincludable( NS_TEMPLATE ) );
}
@@ -539,7 +540,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @param string $expected
*/
public function testGetNamespaceContentModel( $ns, $expected ) {
- $obj = $this->newObj( [ 'NamespaceContentModels' =>
+ $obj = $this->newObj( [ MainConfigNames::NamespaceContentModels =>
[ NS_USER => CONTENT_MODEL_WIKITEXT, 123 => CONTENT_MODEL_JSON, 1234 => 'abcdef' ],
] );
$this->assertSame( $expected, $obj->getNamespaceContentModel( $ns ) );
@@ -896,7 +897,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces
*/
public function testGetCanonicalNamespaces_NoCanonicalNamespaceNames() {
- $obj = $this->newObj( [ 'CanonicalNamespaceNames' => [] ] );
+ $obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );
$this->assertSame( [ NS_MAIN => '' ], $obj->getCanonicalNamespaces() );
}
@@ -905,7 +906,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::getCanonicalName
*/
public function testGetCanonicalName_NoCanonicalNamespaceNames() {
- $obj = $this->newObj( [ 'CanonicalNamespaceNames' => [] ] );
+ $obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );
$this->assertSame( '', $obj->getCanonicalName( NS_MAIN ) );
$this->assertFalse( $obj->getCanonicalName( NS_TALK ) );
@@ -915,7 +916,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::getCanonicalIndex
*/
public function testGetCanonicalIndex_NoCanonicalNamespaceNames() {
- $obj = $this->newObj( [ 'CanonicalNamespaceNames' => [] ] );
+ $obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );
$this->assertSame( NS_MAIN, $obj->getCanonicalIndex( '' ) );
$this->assertNull( $obj->getCanonicalIndex( 'talk' ) );
@@ -925,7 +926,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\Title\NamespaceInfo::getValidNamespaces
*/
public function testGetValidNamespaces_NoCanonicalNamespaceNames() {
- $obj = $this->newObj( [ 'CanonicalNamespaceNames' => [] ] );
+ $obj = $this->newObj( [ MainConfigNames::CanonicalNamespaceNames => [] ] );
$this->assertSame( [ NS_MAIN ], $obj->getValidNamespaces() );
}
@@ -1052,7 +1053,7 @@ class NamespaceInfoTest extends MediaWikiIntegrationTestCase {
* @return NamespaceInfo
*/
private function setupExtraNamespaces() {
- return $this->newObj( [ 'ExtraNamespaces' =>
+ return $this->newObj( [ MainConfigNames::ExtraNamespaces =>
[ NS_MAIN => 'No effect', NS_TALK => 'No effect', 1234567 => 'Extra' ]
] );
}
diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php
index 5c76d39af337..792661d09ddb 100644
--- a/tests/phpunit/includes/user/PasswordResetTest.php
+++ b/tests/phpunit/includes/user/PasswordResetTest.php
@@ -6,6 +6,7 @@ use MediaWiki\Block\CompositeBlock;
use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\SystemBlock;
use MediaWiki\Config\ServiceOptions;
+use MediaWiki\MainConfigNames;
use MediaWiki\Request\WebRequest;
use MediaWiki\Status\Status;
use MediaWiki\Tests\Unit\DummyServicesTrait;
@@ -511,9 +512,9 @@ class PasswordResetTest extends MediaWikiIntegrationTestCase {
private function makeConfig( $enableEmail, array $passwordResetRoutes, $emailForResets ) {
$hash = [
- 'AllowRequiringEmailForResets' => $emailForResets,
- 'EnableEmail' => $enableEmail,
- 'PasswordResetRoutes' => $passwordResetRoutes,
+ MainConfigNames::AllowRequiringEmailForResets => $emailForResets,
+ MainConfigNames::EnableEmail => $enableEmail,
+ MainConfigNames::PasswordResetRoutes => $passwordResetRoutes,
];
return new ServiceOptions( PasswordReset::CONSTRUCTOR_OPTIONS, $hash );
diff --git a/tests/phpunit/includes/user/UserGroupManagerTest.php b/tests/phpunit/includes/user/UserGroupManagerTest.php
index 98fb406b1647..dd624c2f39f8 100644
--- a/tests/phpunit/includes/user/UserGroupManagerTest.php
+++ b/tests/phpunit/includes/user/UserGroupManagerTest.php
@@ -73,23 +73,23 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
UserGroupManager::CONSTRUCTOR_OPTIONS,
$configOverrides,
[
- 'AddGroups' => [],
- 'AutoConfirmAge' => 0,
- 'AutoConfirmCount' => 0,
- 'Autopromote' => [
+ MainConfigNames::AddGroups => [],
+ MainConfigNames::AutoConfirmAge => 0,
+ MainConfigNames::AutoConfirmCount => 0,
+ MainConfigNames::Autopromote => [
'autoconfirmed' => [ APCOND_EDITCOUNT, 0 ]
],
- 'AutopromoteOnce' => [],
- 'GroupPermissions' => [
+ MainConfigNames::AutopromoteOnce => [],
+ MainConfigNames::GroupPermissions => [
self::GROUP => [
'runtest' => true,
]
],
- 'GroupsAddToSelf' => [],
- 'GroupsRemoveFromSelf' => [],
- 'ImplicitGroups' => [ '*', 'user', 'autoconfirmed' ],
- 'RemoveGroups' => [],
- 'RevokePermissions' => [],
+ MainConfigNames::GroupsAddToSelf => [],
+ MainConfigNames::GroupsRemoveFromSelf => [],
+ MainConfigNames::ImplicitGroups => [ '*', 'user', 'autoconfirmed' ],
+ MainConfigNames::RemoveGroups => [],
+ MainConfigNames::RevokePermissions => [],
],
$services->getMainConfig()
),
@@ -212,7 +212,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
$user = User::newFromName( 'UTUser1' );
$this->assertSame( [ '*' ], $manager->getUserImplicitGroups( $user ) );
- $manager = $this->getManager( [ 'Autopromote' => [
+ $manager = $this->getManager( [ MainConfigNames::Autopromote => [
'dummy' => APCOND_EMAILCONFIRMED
] ] );
$user = $this->getTestUser()->getUser();
@@ -544,14 +544,14 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
*/
public function testGetAllGroups() {
$manager = $this->getManager( [
- 'GroupPermissions' => [
+ MainConfigNames::GroupPermissions => [
__METHOD__ => [ 'test' => true ],
'implicit' => [ 'test' => true ]
],
- 'RevokePermissions' => [
+ MainConfigNames::RevokePermissions => [
'revoked' => [ 'test' => true ]
],
- 'ImplicitGroups' => [ 'implicit' ]
+ MainConfigNames::ImplicitGroups => [ 'implicit' ]
] );
$this->assertArrayEquals( [ __METHOD__, 'revoked' ], $manager->listAllGroups() );
}
@@ -560,9 +560,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\User\UserGroupManager::listAllImplicitGroups
*/
public function testGetAllImplicitGroups() {
- $manager = $this->getManager( [
- 'ImplicitGroups' => [ __METHOD__ ]
- ] );
+ $manager = $this->getManager( [ MainConfigNames::ImplicitGroups => [ __METHOD__ ] ] );
$this->assertArrayEquals( [ __METHOD__ ], $manager->listAllImplicitGroups() );
}
@@ -644,8 +642,8 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
array $expected
) {
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_EMAILCONFIRMED ] ],
- 'EmailAuthentication' => $emailAuthentication
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => [ APCOND_EMAILCONFIRMED ] ],
+ MainConfigNames::EmailAuthentication => $emailAuthentication
] );
$this->assertArrayEquals( $expected, $manager->getUserAutopromoteGroups( $user ) );
}
@@ -696,8 +694,8 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
}
$manager = $this->getManager(
[
- 'AutoConfirmCount' => 11,
- 'Autopromote' => [ 'test_autoconfirmed' => $requiredCond ]
+ MainConfigNames::AutoConfirmCount => 11,
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => $requiredCond ]
],
$userEditTrackerMock
);
@@ -735,8 +733,8 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
array $expected
) {
$manager = $this->getManager( [
- 'AutoConfirmAge' => 10000000,
- 'Autopromote' => [ 'test_autoconfirmed' => $requiredCondition ]
+ MainConfigNames::AutoConfirmAge => 10000000,
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => $requiredCondition ]
] );
$user = $this->createNoOpMock( User::class, [ 'getRegistration', 'isTemp', 'assertWiki' ] );
$user->method( 'assertWiki' )->willReturn( true );
@@ -776,7 +774,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
->with( $user )
->willReturn( $firstEditTs );
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => $requiredCondition ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => $requiredCondition ]
], $mockUserEditTracker );
$this->assertArrayEquals( $expected, $manager->getUserAutopromoteGroups( $user ) );
}
@@ -802,7 +800,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
) {
$user = $this->getTestUser( $userGroups )->getUser();
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => array_merge( [ APCOND_INGROUPS ], $requiredGroups ) ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => array_merge( [ APCOND_INGROUPS ], $requiredGroups ) ]
] );
$this->assertArrayEquals( $expected, $manager->getUserAutopromoteGroups( $user ) );
}
@@ -836,7 +834,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
array $expected
) {
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => $condition ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => $condition ]
] );
$requestMock = $this->createNoOpMock( WebRequest::class, [ 'getIP' ] );
$requestMock->expects( $this->once() )
@@ -854,9 +852,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\User\UserGroupManager::getUserAutopromoteGroups
*/
public function testGetUserAutopromoteGroupsHook() {
- $manager = $this->getManager( [
- 'Autopromote' => []
- ] );
+ $manager = $this->getManager( [ MainConfigNames::Autopromote => [] ] );
$user = $this->getTestUser()->getUser();
$this->setTemporaryHook(
'GetAutoPromoteGroups',
@@ -875,7 +871,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
*/
public function testGetUserAutopromoteComplexCondition() {
$manager = $this->getManager( [
- 'Autopromote' => [
+ MainConfigNames::Autopromote => [
'test_autoconfirmed' => [ '&',
[ APCOND_INGROUPS, 'group1' ],
[ '!', [ APCOND_INGROUPS, 'group2' ] ],
@@ -908,7 +904,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
*/
public function testGetUserAutopromoteBot() {
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_ISBOT ] ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => [ APCOND_ISBOT ] ]
] );
$notBot = $this->getTestUser()->getUser();
$this->assertSame( [], $manager->getUserAutopromoteGroups( $notBot ) );
@@ -923,7 +919,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
*/
public function testGetUserAutopromoteBlocked() {
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_BLOCKED ] ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => [ APCOND_BLOCKED ] ]
] );
$nonBlockedUser = $this->getTestUser()->getUser();
$this->assertSame( [], $manager->getUserAutopromoteGroups( $nonBlockedUser ) );
@@ -981,7 +977,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
*/
public function testGetUserAutopromoteInvalid() {
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => [ 999 ] ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => [ 999 ] ]
] );
$user = $this->getTestUser()->getUser();
$this->expectException( InvalidArgumentException::class );
@@ -1004,7 +1000,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
}
);
$manager = $this->getManager( [
- 'Autopromote' => [ 'test_autoconfirmed' => [ 999, 'ARGUMENT' ] ]
+ MainConfigNames::Autopromote => [ 'test_autoconfirmed' => [ 999, 'ARGUMENT' ] ]
] );
$this->assertArrayEquals( [ 'test_autoconfirmed' ], $manager->getUserAutopromoteGroups( $user ) );
}
@@ -1041,9 +1037,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
array $userGroups,
array $expected
) {
- $manager = $this->getManager( [
- 'AutopromoteOnce' => $config
- ] );
+ $manager = $this->getManager( [ MainConfigNames::AutopromoteOnce => $config ] );
$user = $this->getTestUser()->getUser();
$manager->addUserToMultipleGroups( $user, $userGroups );
foreach ( $formerGroups as $formerGroup ) {
@@ -1112,7 +1106,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
public function testAddUserToAutopromoteOnceGroupsSuccess() {
$user = $this->getTestUser()->getUser();
$manager = $this->getManager( [
- 'AutopromoteOnce' => [ 'EVENT' => [ 'autopromoteonce' => [ APCOND_EDITCOUNT, 0 ] ] ]
+ MainConfigNames::AutopromoteOnce => [ 'EVENT' => [ 'autopromoteonce' => [ APCOND_EDITCOUNT, 0 ] ] ]
] );
$this->assertNotContains( 'autopromoteonce', $manager->getUserGroups( $user ) );
$hookCalled = false;
@@ -1142,19 +1136,19 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
}
private const CHANGEABLE_GROUPS_TEST_CONFIG = [
- 'GroupPermissions' => [],
- 'AddGroups' => [
+ MainConfigNames::GroupPermissions => [],
+ MainConfigNames::AddGroups => [
'sysop' => [ 'rollback' ],
'bureaucrat' => [ 'sysop', 'bureaucrat' ],
],
- 'RemoveGroups' => [
+ MainConfigNames::RemoveGroups => [
'sysop' => [ 'rollback' ],
'bureaucrat' => [ 'sysop' ],
],
- 'GroupsAddToSelf' => [
+ MainConfigNames::GroupsAddToSelf => [
'sysop' => [ 'flood' ],
],
- 'GroupsRemoveFromSelf' => [
+ MainConfigNames::GroupsRemoveFromSelf => [
'flood' => [ 'flood' ],
],
];
@@ -1243,7 +1237,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
* @covers \MediaWiki\User\UserGroupManager::getUserPrivilegedGroups()
*/
public function testGetUserPrivilegedGroups() {
- $this->setMwGlobals( 'wgPrivilegedGroups', [ 'sysop', 'interface-admin', 'bar', 'baz' ] );
+ $this->overrideConfigValue( MainConfigNames::PrivilegedGroups, [ 'sysop', 'interface-admin', 'bar', 'baz' ] );
$makeHook = function ( $invocationCount, User $userToMatch, array $groupsToAdd ) {
return function ( $u, &$groups ) use ( $userToMatch, $invocationCount, $groupsToAdd ) {
$invocationCount();