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 { class CaptchaAuthenticationRequestTest extends AuthenticationRequestTestCase {
public function setUp(): void { public function setUp(): void {
parent::setUp(); parent::setUp();
$this->setMwGlobals( [ $this->overrideConfigValues( [
'wgCaptchaClass' => SimpleCaptcha::class, 'CaptchaClass' => SimpleCaptcha::class,
'wgCaptchaStorageClass' => CaptchaHashStore::class, 'CaptchaStorageClass' => CaptchaHashStore::class,
] ); ] );
CaptchaStore::unsetInstanceForTests(); CaptchaStore::unsetInstanceForTests();
CaptchaStore::get()->clearAll(); CaptchaStore::get()->clearAll();

View file

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

View file

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

View file

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