diff --git a/tests/phpunit/CaptchaAuthenticationRequestTest.php b/tests/phpunit/CaptchaAuthenticationRequestTest.php index 392bf695b..aceb1470e 100644 --- a/tests/phpunit/CaptchaAuthenticationRequestTest.php +++ b/tests/phpunit/CaptchaAuthenticationRequestTest.php @@ -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(); diff --git a/tests/phpunit/CaptchaPreAuthenticationProviderTest.php b/tests/phpunit/CaptchaPreAuthenticationProviderTest.php index ca8b490ac..c6cbf0823 100644 --- a/tests/phpunit/CaptchaPreAuthenticationProviderTest.php +++ b/tests/phpunit/CaptchaPreAuthenticationProviderTest.php @@ -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 { diff --git a/tests/phpunit/QuestyCaptchaTest.php b/tests/phpunit/QuestyCaptchaTest.php index 335771543..4deb9009a 100644 --- a/tests/phpunit/QuestyCaptchaTest.php +++ b/tests/phpunit/QuestyCaptchaTest.php @@ -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() ); diff --git a/tests/phpunit/SimpleCaptcha/CaptchaTest.php b/tests/phpunit/SimpleCaptcha/CaptchaTest.php index 06783abfd..e392dfaeb 100644 --- a/tests/phpunit/SimpleCaptcha/CaptchaTest.php +++ b/tests/phpunit/SimpleCaptcha/CaptchaTest.php @@ -29,10 +29,8 @@ class CaptchaTest extends MediaWikiIntegrationTestCase { */ public function testTriggersCaptcha( $action, $expectedResult ) { $captcha = new SimpleCaptcha(); - $this->setMwGlobals( [ - 'wgCaptchaTriggers' => [ - $action => $expectedResult, - ] + $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' => [ - 'edit' => true, - ] + $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' => [ - 'edit' => false, - ] + $this->overrideConfigValue( 'CaptchaTriggers', [ + 'edit' => false, ] ); $testObject = new SimpleCaptcha(); /** @var SimpleCaptcha|TestingAccessWrapper $wrapper */