<?php
+use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
use Wikimedia\ScopedCallback;
use Wikimedia\TestingAccessWrapper;
$this->testUser = $this->getMutableTestUser();
$this->testUserName = $this->testUser->getUser()->getName();
- $mock1 = $this->getMockForAbstractClass( 'CentralIdLookup' );
+ $mock1 = $this->getMockForAbstractClass( CentralIdLookup::class );
$mock1->expects( $this->any() )->method( 'isAttached' )
->will( $this->returnValue( true ) );
$mock1->expects( $this->any() )->method( 'lookupUserNames' )
->will( $this->returnValue( [ $this->testUserName => 42, 'UTDummy' => 43, 'UTInvalid' => 0 ] ) );
$mock1->expects( $this->never() )->method( 'lookupCentralIds' );
- $mock2 = $this->getMockForAbstractClass( 'CentralIdLookup' );
+ $mock2 = $this->getMockForAbstractClass( CentralIdLookup::class );
$mock2->expects( $this->any() )->method( 'isAttached' )
->will( $this->returnValue( false ) );
$mock2->expects( $this->any() )->method( 'lookupUserNames' )
}
public function addDBData() {
- $passwordFactory = new \PasswordFactory();
- $passwordFactory->init( \RequestContext::getMain()->getConfig() );
+ $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
$passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
$dbw = wfGetDB( DB_MASTER );
public function testBasics() {
$user = $this->testUser->getUser();
$bp = BotPassword::newFromUser( $user, 'BotPassword' );
- $this->assertInstanceOf( 'BotPassword', $bp );
+ $this->assertInstanceOf( BotPassword::class, $bp );
$this->assertTrue( $bp->isSaved() );
$this->assertSame( 42, $bp->getUserCentralId() );
$this->assertSame( 'BotPassword', $bp->getAppId() );
'user' => $user,
'appId' => 'DoesNotExist'
] );
- $this->assertInstanceOf( 'BotPassword', $bp );
+ $this->assertInstanceOf( BotPassword::class, $bp );
$this->assertFalse( $bp->isSaved() );
$this->assertSame( 42, $bp->getUserCentralId() );
$this->assertSame( 'DoesNotExist', $bp->getAppId() );
'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
'grants' => [ 'test' ],
] );
- $this->assertInstanceOf( 'BotPassword', $bp );
+ $this->assertInstanceOf( BotPassword::class, $bp );
$this->assertFalse( $bp->isSaved() );
$this->assertSame( 43, $bp->getUserCentralId() );
$this->assertSame( 'DoesNotExist2', $bp->getAppId() );
'centralId' => 45,
'appId' => 'DoesNotExist'
] );
- $this->assertInstanceOf( 'BotPassword', $bp );
+ $this->assertInstanceOf( BotPassword::class, $bp );
$this->assertFalse( $bp->isSaved() );
$this->assertSame( 45, $bp->getUserCentralId() );
$this->assertSame( 'DoesNotExist', $bp->getAppId() );
'user' => $user,
'appId' => 'BotPassword'
] );
- $this->assertInstanceOf( 'BotPassword', $bp );
+ $this->assertInstanceOf( BotPassword::class, $bp );
$this->assertFalse( $bp->isSaved() );
$this->assertNull( BotPassword::newUnsaved( [
$bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
$password = $bp->getPassword();
- $this->assertInstanceOf( 'Password', $password );
+ $this->assertInstanceOf( Password::class, $password );
$this->assertTrue( $password->equals( 'foobaz' ) );
$bp->centralId = 44;
$password = $bp->getPassword();
- $this->assertInstanceOf( 'InvalidPassword', $password );
+ $this->assertInstanceOf( InvalidPassword::class, $password );
$bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
$dbw = wfGetDB( DB_MASTER );
__METHOD__
);
$password = $bp->getPassword();
- $this->assertInstanceOf( 'InvalidPassword', $password );
+ $this->assertInstanceOf( InvalidPassword::class, $password );
}
public function testInvalidateAllPasswordsForUser() {
$bp1 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
$bp2 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 43, 'BotPassword' ) );
- $this->assertNotInstanceOf( 'InvalidPassword', $bp1->getPassword(), 'sanity check' );
- $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword(), 'sanity check' );
+ $this->assertNotInstanceOf( InvalidPassword::class, $bp1->getPassword(), 'sanity check' );
+ $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword(), 'sanity check' );
BotPassword::invalidateAllPasswordsForUser( $this->testUserName );
- $this->assertInstanceOf( 'InvalidPassword', $bp1->getPassword() );
- $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword() );
+ $this->assertInstanceOf( InvalidPassword::class, $bp1->getPassword() );
+ $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword() );
$bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
- $this->assertInstanceOf( 'InvalidPassword', $bp->getPassword() );
+ $this->assertInstanceOf( InvalidPassword::class, $bp->getPassword() );
}
public function testRemoveAllPasswordsForUser() {
);
// Failed restriction
- $request = $this->getMockBuilder( 'FauxRequest' )
+ $request = $this->getMockBuilder( FauxRequest::class )
->setMethods( [ 'getIP' ] )
->getMock();
$request->expects( $this->any() )->method( 'getIP' )
'sanity check'
);
$status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
- $this->assertInstanceOf( 'Status', $status );
+ $this->assertInstanceOf( Status::class, $status );
$this->assertTrue( $status->isGood() );
$session = $status->getValue();
$this->assertInstanceOf( MediaWiki\Session\Session::class, $session );
* @param string|null $password
*/
public function testSave( $password ) {
- $passwordFactory = new \PasswordFactory();
- $passwordFactory->init( \RequestContext::getMain()->getConfig() );
+ $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory();
$bp = BotPassword::newUnsaved( [
'centralId' => 42,
$this->assertFalse( $bp->save( 'update', $passwordHash ) );
$this->assertTrue( $bp->save( 'insert', $passwordHash ) );
$bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
- $this->assertInstanceOf( 'BotPassword', $bp2 );
+ $this->assertInstanceOf( BotPassword::class, $bp2 );
$this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
$this->assertEquals( $bp->getAppId(), $bp2->getAppId() );
$this->assertEquals( $bp->getToken(), $bp2->getToken() );
$this->assertEquals( $bp->getGrants(), $bp2->getGrants() );
$pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
if ( $password === null ) {
- $this->assertInstanceOf( 'InvalidPassword', $pw );
+ $this->assertInstanceOf( InvalidPassword::class, $pw );
} else {
$this->assertTrue( $pw->equals( $password ) );
}
$this->assertTrue( $bp->save( 'update' ) );
$this->assertNotEquals( $token, $bp->getToken() );
$bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
- $this->assertInstanceOf( 'BotPassword', $bp2 );
+ $this->assertInstanceOf( BotPassword::class, $bp2 );
$this->assertEquals( $bp->getToken(), $bp2->getToken() );
$pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
if ( $password === null ) {
- $this->assertInstanceOf( 'InvalidPassword', $pw );
+ $this->assertInstanceOf( InvalidPassword::class, $pw );
} else {
$this->assertTrue( $pw->equals( $password ) );
}