aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
diff options
context:
space:
mode:
authorDaimona Eaytoy <daimona.wiki@gmail.com>2023-08-15 21:52:00 +0200
committerDaimona Eaytoy <daimona.wiki@gmail.com>2023-08-16 00:34:30 +0000
commit2668b94a5a9457d0c15f5140bf9d4add4b85262c (patch)
treec7c9e92af377c198b6a7e87a472bf25966fc1a14 /tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
parentc0728d032a665390a4f9ef4ce98f3a1f01b38b7d (diff)
downloadmediawikicore-2668b94a5a9457d0c15f5140bf9d4add4b85262c.tar.gz
mediawikicore-2668b94a5a9457d0c15f5140bf9d4add4b85262c.zip
Do not use UTSysop directly in auth tests
These tests are all making two assumptions: - That the sysop test account exists - That its name is UTSysop Both assumptions happen to be true right now, but the first one will no longer be after change I30861742. The second one will probably remain true for a while, but still, tests shouldn't rely on this implementation detail when possible. If a test needs an exiting test user, it should call getTestUser / getTestSysop. Use mocks or different usernames where the user actually doesn't matter, e.g. in non-Database tests where UTSysop already doesn't exist. Bug: T342428 Change-Id: Ie77e72f5a5ee6a2ef4ec9dceaa9044bb690f68b2
Diffstat (limited to 'tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php')
-rw-r--r--tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
index 9dda44d93417..37e7869f8591 100644
--- a/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
@@ -4,6 +4,7 @@ namespace MediaWiki\Auth;
use MediaWiki\Tests\Unit\Auth\AuthenticationProviderTestTrait;
use MediaWiki\Tests\Unit\DummyServicesTrait;
+use User;
/**
* @group AuthManager
@@ -14,7 +15,7 @@ class AbstractPrimaryAuthenticationProviderTest extends \MediaWikiIntegrationTes
use AuthenticationProviderTestTrait;
public function testAbstractPrimaryAuthenticationProvider() {
- $user = \User::newFromName( 'UTSysop' );
+ $user = $this->createMock( User::class );
$provider = $this->getMockForAbstractClass( AbstractPrimaryAuthenticationProvider::class );
@@ -66,20 +67,21 @@ class AbstractPrimaryAuthenticationProviderTest extends \MediaWikiIntegrationTes
for ( $i = 0; $i < 3; $i++ ) {
$reqs[$i] = $this->createMock( AuthenticationRequest::class );
}
+ $username = 'TestProviderRevokeAccessForUser';
$provider = $this->getMockForAbstractClass( AbstractPrimaryAuthenticationProvider::class );
$provider->expects( $this->once() )->method( 'getAuthenticationRequests' )
->with(
$this->identicalTo( AuthManager::ACTION_REMOVE ),
- $this->identicalTo( [ 'username' => 'UTSysop' ] )
+ $this->identicalTo( [ 'username' => $username ] )
)
->willReturn( $reqs );
$provider->expects( $this->exactly( 3 ) )->method( 'providerChangeAuthenticationData' )
- ->willReturnCallback( function ( $req ) {
- $this->assertSame( 'UTSysop', $req->username );
+ ->willReturnCallback( function ( $req ) use ( $username ) {
+ $this->assertSame( $username, $req->username );
} );
- $provider->providerRevokeAccessForUser( 'UTSysop' );
+ $provider->providerRevokeAccessForUser( $username );
foreach ( $reqs as $i => $req ) {
$this->assertNotNull( $req->username, "#$i" );