Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / session / TestBagOStuff.php
blobbe9f5a6512b5f3f8a7605d63c54b49366a450a9f
1 <?php
3 namespace MediaWiki\Tests\Session;
5 use MediaWiki\MainConfigNames;
6 use MediaWiki\MediaWikiServices;
7 use Wikimedia\ObjectCache\CachedBagOStuff;
8 use Wikimedia\ObjectCache\HashBagOStuff;
10 /**
11 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
13 class TestBagOStuff extends CachedBagOStuff {
15 public function __construct() {
16 parent::__construct( new HashBagOStuff );
19 /**
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 ] );
27 /**
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 ] );
35 /**
36 * @param string $id Session ID
37 * @param array $blob Session metadata and data
39 public function setSession( $id, array $blob ) {
40 $blob += [
41 'data' => [],
42 'metadata' => [],
44 $blob['metadata'] += [
45 'userId' => 0,
46 'userName' => null,
47 'userToken' => null,
48 'provider' => 'DummySessionProvider',
51 $this->setRawSession( $id, $blob );
54 /**
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 );
63 /**
64 * @param string $id Session ID
65 * @return mixed
67 public function getSession( $id ) {
68 return $this->get( $this->makeKey( 'MWSession', $id ) );
71 /**
72 * @param string $id Session ID
73 * @return mixed
75 public function getSessionFromBackend( $id ) {
76 return $this->store->get( $this->makeKey( 'MWSession', $id ) );
79 /**
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' );