Merge "Fix confusing usages of TestingAccessWrapper"

This commit is contained in:
jenkins-bot 2024-09-17 23:27:24 +00:00 committed by Gerrit Code Review
commit 31c26eaa77
2 changed files with 14 additions and 11 deletions

View file

@ -36,8 +36,10 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
public function tearDown(): void {
parent::tearDown();
/** @var Hooks $req */
$req = TestingAccessWrapper::newFromClass( Hooks::class );
// make sure $wgCaptcha resets between tests
TestingAccessWrapper::newFromClass( Hooks::class )->instanceCreated = false;
$req->instanceCreated = false;
}
/**
@ -102,10 +104,12 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
[ 'username' => 'Foo' ] );
$this->assertCount( 1, $reqs );
$this->assertInstanceOf( CaptchaAuthenticationRequest::class, $reqs[0] );
/** @var CaptchaAuthenticationRequest $req */
$req = $reqs[0];
$this->assertInstanceOf( CaptchaAuthenticationRequest::class, $req );
$id = $reqs[0]->captchaId;
$data = TestingAccessWrapper::newFromObject( $reqs[0] )->captchaData;
$id = $req->captchaId;
$data = $req->captchaData;
$this->assertEquals( $captcha->retrieveCaptcha( $id ), $data + [ 'index' => $id ] );
}
@ -241,6 +245,7 @@ class CaptchaPreAuthenticationProviderTest extends MediaWikiIntegrationTestCase
);
$provider = new CaptchaPreAuthenticationProvider();
$this->initProvider( $provider, null, null, $this->getServiceContainer()->getAuthManager() );
/** @var CaptchaPreAuthenticationProvider $providerAccess */
$providerAccess = TestingAccessWrapper::newFromObject( $provider );
$disablePingLimiter = false;

View file

@ -170,10 +170,10 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
'edit' => true,
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */
/** @var SimpleCaptcha $wrapper */
$wrapper = TestingAccessWrapper::newFromObject( $testObject );
$wrapper->captchaSolved = true;
$this->assertFalse( $wrapper->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered if already solved' );
$this->assertFalse( $testObject->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered if already solved' );
}
public function testForceShowCaptcha() {
@ -181,12 +181,10 @@ class CaptchaTest extends MediaWikiIntegrationTestCase {
'edit' => false,
] );
$testObject = new SimpleCaptcha();
/** @var SimpleCaptcha|TestingAccessWrapper $wrapper */
$wrapper = TestingAccessWrapper::newFromObject( $testObject );
$this->assertFalse(
$wrapper->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered by edit action in this configuration'
$testObject->triggersCaptcha( 'edit' ), 'CAPTCHA is not triggered by edit action in this configuration'
);
$wrapper->setForceShowCaptcha( true );
$this->assertTrue( $wrapper->triggersCaptcha( 'edit' ), 'Force showing a CAPTCHA if flag is set' );
$testObject->setForceShowCaptcha( true );
$this->assertTrue( $testObject->triggersCaptcha( 'edit' ), 'Force showing a CAPTCHA if flag is set' );
}
}