Replace setMwGlobals by overrideConfigValue/overrideConfigValues

Change-Id: If63e84d8101f2169f684c4db822f7df907d2deec
This commit is contained in:
Fomafix 2024-07-22 10:30:27 +00:00
parent 90fdec4095
commit 07646e4a65
4 changed files with 22 additions and 32 deletions

View file

@ -12,9 +12,9 @@ use MediaWiki\Tests\Auth\AuthenticationRequestTestCase;
class CaptchaAuthenticationRequestTest extends AuthenticationRequestTestCase {
public function setUp(): void {
parent::setUp();
$this->setMwGlobals( [
'wgCaptchaClass' => SimpleCaptcha::class,
'wgCaptchaStorageClass' => CaptchaHashStore::class,
$this->overrideConfigValues( [
'CaptchaClass' => SimpleCaptcha::class,
'CaptchaStorageClass' => CaptchaHashStore::class,
] );
CaptchaStore::unsetInstanceForTests();
CaptchaStore::get()->clearAll();

View file

@ -24,11 +24,11 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
public function setUp(): void {
parent::setUp();
$this->setMwGlobals( [
'wgCaptchaClass' => SimpleCaptcha::class,
'wgCaptchaBadLoginAttempts' => 1,
'wgCaptchaBadLoginPerUserAttempts' => 1,
'wgCaptchaStorageClass' => CaptchaHashStore::class,
$this->overrideConfigValues( [
'CaptchaClass' => SimpleCaptcha::class,
'CaptchaBadLoginAttempts' => 1,
'CaptchaBadLoginPerUserAttempts' => 1,
'CaptchaStorageClass' => CaptchaHashStore::class,
] );
CaptchaStore::unsetInstanceForTests();
CaptchaStore::get()->clearAll();
@ -308,7 +308,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
$captchaTriggers = array_combine( $types, array_map( static function ( $type ) use ( $triggers ) {
return in_array( $type, $triggers, true );
}, $types ) );
$this->setMwGlobals( 'wgCaptchaTriggers', $captchaTriggers );
$this->overrideConfigValue( 'CaptchaTriggers', $captchaTriggers );
}
private function getProvider(): CaptchaPreAuthenticationProvider {

View file

@ -22,11 +22,7 @@ class QuestyCaptchaTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideGetCaptcha
*/
public function testGetCaptcha( $config, $expected ) {
# setMwGlobals() requires $wgCaptchaQuestion to be set
if ( !isset( $GLOBALS['wgCaptchaQuestions'] ) ) {
$GLOBALS['wgCaptchaQuestions'] = [];
}
$this->setMwGlobals( 'wgCaptchaQuestions', $config );
$this->overrideConfigValue( 'CaptchaQuestions', $config );
$qc = new QuestyCaptcha();
$this->assertEquals( $expected, $qc->getCaptcha() );

View file

@ -29,10 +29,8 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
*/
public function testTriggersCaptcha( $action, $expectedResult ) {
$captcha = new SimpleCaptcha();
$this->setMwGlobals( [
'wgCaptchaTriggers' => [
$this->overrideConfigValue( 'CaptchaTriggers', [
$action => $expectedResult,
]
] );
$this->assertEquals( $expectedResult, $captcha->triggersCaptcha( $action ) );
}
@ -53,11 +51,11 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
*/
public function testNamespaceTriggersOverwrite( $trigger, $expected ) {
$captcha = new SimpleCaptcha();
$this->setMwGlobals( [
'wgCaptchaTriggers' => [
$this->overrideConfigValues( [
'CaptchaTriggers' => [
$trigger => !$expected,
],
'wgCaptchaTriggersOnNamespace' => [
'CaptchaTriggersOnNamespace' => [
0 => [
$trigger => $expected,
],
@ -76,7 +74,7 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
private function setCaptchaTriggersAttribute( $trigger, $value ) {
// Avoid clobbering captcha triggers registered by other extensions
$this->setMwGlobals( 'wgCaptchaTriggers', $GLOBALS['wgCaptchaTriggers'] );
$this->overrideConfigValue( 'CaptchaTriggers', $GLOBALS['wgCaptchaTriggers'] );
$this->hold[] = ExtensionRegistry::getInstance()->setAttributeForTest(
'CaptchaTriggers', [ $trigger => $value ]
@ -103,7 +101,7 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideAttributeOverwritten
*/
public function testCaptchaTriggersAttributeGetsOverwritten( $trigger, $expected ) {
$this->setMwGlobals( 'wgCaptchaTriggers', [ $trigger => $expected ] );
$this->overrideConfigValue( 'CaptchaTriggers', [ $trigger => $expected ] );
$this->setCaptchaTriggersAttribute( $trigger, !$expected );
$captcha = new SimpleCaptcha();
$this->assertEquals( $expected, $captcha->triggersCaptcha( $trigger ) );
@ -172,8 +170,8 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
$this->setMwGlobals( [
'wgRequest' => $request,
'wgCaptchaWhitelistIP' => $IPWhitelist
] );
$this->overrideConfigValue( 'CaptchaWhitelistIP', $IPWhitelist );
$actual = $testObject->canSkipCaptcha( RequestContext::getMain()->getUser(), $config );
@ -189,10 +187,8 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
}
public function testTriggersCaptchaReturnsEarlyIfCaptchaSolved() {
$this->setMwGlobals( [
'wgCaptchaTriggers' => [
$this->overrideConfigValue( 'CaptchaTriggers', [
'edit' => true,
]
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */
@ -202,10 +198,8 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
}
public function testForceShowCaptcha() {
$this->setMwGlobals( [
'wgCaptchaTriggers' => [
$this->overrideConfigValue( 'CaptchaTriggers', [
'edit' => false,
]
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */