X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fauth%2FAuthManagerTest.php;h=211eba00b7adeb4a26cc290146df010f2845b8e7;hp=a8405992fe8dd65f1c61e4436aeb5d3471c22ca5;hb=27c61fb1e94da9114314468fd00bcf129ec064b6;hpb=6c9a2923fe1ee3a65cb027be5e781772f2b12fbd diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index a8405992fe..211eba00b7 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -2,10 +2,13 @@ namespace MediaWiki\Auth; +use Config; use MediaWiki\Session\SessionInfo; use MediaWiki\Session\UserInfo; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use StatusValue; +use WebRequest; use Wikimedia\ScopedCallback; use Wikimedia\TestingAccessWrapper; @@ -19,7 +22,7 @@ class AuthManagerTest extends \MediaWikiTestCase { protected $request; /** @var Config */ protected $config; - /** @var \\Psr\\Log\\LoggerInterface */ + /** @var LoggerInterface */ protected $logger; protected $preauthMocks = []; @@ -149,7 +152,7 @@ class AuthManagerTest extends \MediaWikiTestCase { if ( $canChangeUser !== null ) { $methods[] = 'canChangeUser'; } - $provider = $this->getMockBuilder( 'DummySessionProvider' ) + $provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( $methods ) ->getMock(); $provider->expects( $this->any() )->method( '__toString' ) @@ -968,7 +971,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $p->expects( $this->atMost( 1 ) )->method( 'postAuthentication' ) ->willReturnCallback( function ( $user, $response ) use ( $constraint, $p ) { if ( $user !== null ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( 'UTSysop', $user->getName() ); } $this->assertInstanceOf( AuthenticationResponse::class, $response ); @@ -1408,7 +1411,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $readOnlyMode = \MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode(); $readOnlyMode->setReason( 'Because' ); $this->assertEquals( - \Status::newFatal( 'readonlytext', 'Because' ), + \Status::newFatal( wfMessage( 'readonlytext', 'Because' ) ), $this->manager->checkAccountCreatePermissions( new \User ) ); $readOnlyMode->setReason( false ); @@ -1433,6 +1436,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $blockOptions = [ 'address' => 'UTBlockee', 'user' => $user->getID(), + 'by' => $this->getTestSysop()->getUser()->getId(), 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true, @@ -1445,6 +1449,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $blockOptions = [ 'address' => '127.0.0.0/24', + 'by' => $this->getTestSysop()->getUser()->getId(), 'reason' => __METHOD__, 'expiry' => time() + 100500, 'createAccount' => true, @@ -1998,7 +2003,7 @@ class AuthManagerTest extends \MediaWikiTestCase { ->willReturnCallback( function ( $user, $creator, $response ) use ( $constraint, $p, $username ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); $this->assertSame( 'UTSysop', $creator->getName() ); $this->assertInstanceOf( AuthenticationResponse::class, $response ); @@ -2262,7 +2267,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Set up lots of mocks... $mock = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\PrimaryAuthenticationProvider", [] + \MediaWiki\Auth\PrimaryAuthenticationProvider::class, [] ); $mock->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( 'primary' ) ); @@ -2478,7 +2483,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $this->hook( 'LocalUserCreated', $this->never() ); $ret = $this->manager->autoCreateUser( $user, AuthManager::AUTOCREATE_SOURCE_SESSION, true ); $this->unhook( 'LocalUserCreated' ); - $this->assertEquals( \Status::newFatal( 'readonlytext', 'Because' ), $ret ); + $this->assertEquals( \Status::newFatal( wfMessage( 'readonlytext', 'Because' ) ), $ret ); $this->assertEquals( 0, $user->getId() ); $this->assertNotEquals( $username, $user->getName() ); $this->assertEquals( 0, $session->getUser()->getId() ); @@ -2668,7 +2673,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnValue( \Status::newFatal( 'because' ) ) ); @@ -2690,7 +2695,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) ); $this->assertFalse( $cache->get( $backoffKey ), 'sanity check' ); $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->throwException( new \Exception( 'Excepted' ) ) ); @@ -2714,7 +2719,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails because the user already exists. $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnCallback( function () use ( $username, &$user ) { @@ -3474,7 +3479,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $p->postCalled = false; $p->expects( $this->atMost( 1 ) )->method( 'postAccountLink' ) ->willReturnCallback( function ( $user, $response ) use ( $constraint, $p ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( 'UTSysop', $user->getName() ); $this->assertInstanceOf( AuthenticationResponse::class, $response ); $this->assertThat( $response->status, $constraint );