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;
protected $request;
/** @var Config */
protected $config;
- /** @var \\Psr\\Log\\LoggerInterface */
+ /** @var LoggerInterface */
protected $logger;
protected $preauthMocks = [];
if ( $canChangeUser !== null ) {
$methods[] = 'canChangeUser';
}
- $provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( $methods )
->getMock();
$provider->expects( $this->any() )->method( '__toString' )
$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 );
$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 );
$blockOptions = [
'address' => 'UTBlockee',
'user' => $user->getID(),
+ 'by' => $this->getTestSysop()->getUser()->getId(),
'reason' => __METHOD__,
'expiry' => time() + 100500,
'createAccount' => true,
$blockOptions = [
'address' => '127.0.0.0/24',
+ 'by' => $this->getTestSysop()->getUser()->getId(),
'reason' => __METHOD__,
'expiry' => time() + 100500,
'createAccount' => true,
->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 );
// 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' ) );
$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() );
// 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' ) ) );
$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' ) ) );
// 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 ) {
$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 );