namespace MediaWiki\Session;
+use Config;
use MediaWikiTestCase;
use User;
use Wikimedia\TestingAccessWrapper;
class SessionBackendTest extends MediaWikiTestCase {
const SESSIONID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
+ /** @var SessionManager */
protected $manager;
+
+ /** @var Config */
protected $config;
+
+ /** @var SessionProvider */
protected $provider;
+
+ /** @var TestBagOStuff */
protected $store;
protected $onSessionMetadataCalled = false;
* Returns a non-persistent backend that thinks it has at least one session active
* @param User|null $user
* @param string $id
+ * @return SessionBackend
*/
protected function getBackend( User $user = null, $id = null ) {
if ( !$this->config ) {
$this->assertSame( self::SESSIONID, $backend->getId() );
$this->assertSame( $id, $backend->getSessionId() );
$this->assertSame( $this->provider, $backend->getProvider() );
- $this->assertInstanceOf( 'User', $backend->getUser() );
+ $this->assertInstanceOf( User::class, $backend->getUser() );
$this->assertSame( 'UTSysop', $backend->getUser()->getName() );
$this->assertSame( $info->wasPersisted(), $backend->isPersistent() );
$this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() );
$this->assertSame( $info->forceHTTPS(), $backend->shouldForceHTTPS() );
$expire = time() + 100;
- $this->store->setSessionMeta( self::SESSIONID, [ 'expires' => $expire ], 2 );
+ $this->store->setSessionMeta( self::SESSIONID, [ 'expires' => $expire ] );
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, [
'provider' => $this->provider,
$this->assertSame( self::SESSIONID, $backend->getId() );
$this->assertSame( $id, $backend->getSessionId() );
$this->assertSame( $this->provider, $backend->getProvider() );
- $this->assertInstanceOf( 'User', $backend->getUser() );
+ $this->assertInstanceOf( User::class, $backend->getUser() );
$this->assertTrue( $backend->getUser()->isAnon() );
$this->assertSame( $info->wasPersisted(), $backend->isPersistent() );
$this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() );
public function testResetId() {
$id = session_id();
- $builder = $this->getMockBuilder( 'DummySessionProvider' )
+ $builder = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistsSessionId', 'sessionIdWasReset' ] );
$this->provider = $builder->getMock();
}
public function testPersist() {
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistSession' ] )->getMock();
$this->provider->expects( $this->once() )->method( 'persistSession' );
$backend = $this->getBackend();
}
public function testUnpersist() {
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'unpersistSession' ] )->getMock();
$this->provider->expects( $this->once() )->method( 'unpersistSession' );
$backend = $this->getBackend();
$backend->unpersist();
$this->assertFalse( $backend->isPersistent() );
$this->assertFalse( $this->store->getSession( self::SESSIONID ) );
- $this->assertNotFalse( $wrap->store->get( wfMemcKey( 'MWSession', self::SESSIONID ) ) );
+ $this->assertNotFalse(
+ $wrap->store->get( $wrap->store->makeKey( 'MWSession', self::SESSIONID ) )
+ );
}
public function testRememberUser() {
public function testSetUser() {
$user = static::getTestSysop()->getUser();
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'canChangeUser' ] )->getMock();
$this->provider->expects( $this->any() )->method( 'canChangeUser' )
->will( $this->returnValue( false ) );
->setMethods( [ 'onSessionMetadata' ] )->getMock();
$neverHook->expects( $this->never() )->method( 'onSessionMetadata' );
- $builder = $this->getMockBuilder( 'DummySessionProvider' )
+ $builder = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistSession', 'unpersistSession' ] );
$neverProvider = $builder->getMock();
$testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ];
// Not persistent
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistSession' ] )->getMock();
$this->provider->expects( $this->never() )->method( 'persistSession' );
$this->onSessionMetadataCalled = false;
$this->assertNotEquals( 0, $wrap->expires );
// Persistent
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistSession' ] )->getMock();
$this->provider->expects( $this->atLeastOnce() )->method( 'persistSession' );
$this->onSessionMetadataCalled = false;
$this->assertNotEquals( 0, $wrap->expires );
// Not persistent, not expiring
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'persistSession' ] )->getMock();
$this->provider->expects( $this->never() )->method( 'persistSession' );
$this->onSessionMetadataCalled = false;
}
public function testGetAllowedUserRights() {
- $this->provider = $this->getMockBuilder( 'DummySessionProvider' )
+ $this->provider = $this->getMockBuilder( \DummySessionProvider::class )
->setMethods( [ 'getAllowedUserRights' ] )
->getMock();
$this->provider->expects( $this->any() )->method( 'getAllowedUserRights' )