3 namespace MediaWiki\Tests\Session
;
5 use MediaWiki\MainConfigNames
;
6 use MediaWiki\MediaWikiServices
;
7 use Wikimedia\ObjectCache\CachedBagOStuff
;
8 use Wikimedia\ObjectCache\HashBagOStuff
;
11 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
13 class TestBagOStuff
extends CachedBagOStuff
{
15 public function __construct() {
16 parent
::__construct( new HashBagOStuff
);
20 * @param string $id Session ID
21 * @param array $data Session data
23 public function setSessionData( $id, array $data ) {
24 $this->setSession( $id, [ 'data' => $data ] );
28 * @param string $id Session ID
29 * @param array $metadata Session metadata
31 public function setSessionMeta( $id, array $metadata ) {
32 $this->setSession( $id, [ 'metadata' => $metadata ] );
36 * @param string $id Session ID
37 * @param array $blob Session metadata and data
39 public function setSession( $id, array $blob ) {
44 $blob['metadata'] +
= [
48 'provider' => 'DummySessionProvider',
51 $this->setRawSession( $id, $blob );
55 * @param string $id Session ID
56 * @param array|mixed $blob Session metadata and data
58 public function setRawSession( $id, $blob ) {
59 $expiry = MediaWikiServices
::getInstance()->getMainConfig()->get( MainConfigNames
::ObjectCacheSessionExpiry
);
60 $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
64 * @param string $id Session ID
67 public function getSession( $id ) {
68 return $this->get( $this->makeKey( 'MWSession', $id ) );
72 * @param string $id Session ID
75 public function getSessionFromBackend( $id ) {
76 return $this->store
->get( $this->makeKey( 'MWSession', $id ) );
80 * @param string $id Session ID
82 public function deleteSession( $id ) {
83 $this->delete( $this->makeKey( 'MWSession', $id ) );
88 /** @deprecated class alias since 1.42 */
89 class_alias( TestBagOStuff
::class, 'MediaWiki\\Session\\TestBagOStuff' );