Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / phpunit / includes / session / TestBagOStuff.php
blob759eca62ea9953f54be5935599dc285ce4b3e62d
1 <?php
3 namespace MediaWiki\Session;
5 /**
6 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
7 */
8 class TestBagOStuff extends \CachedBagOStuff {
10 public function __construct() {
11 parent::__construct( new \HashBagOStuff );
14 /**
15 * @param string $id Session ID
16 * @param array $data Session data
17 * @param int $expiry Expiry
18 * @param User $user User for metadata
20 public function setSessionData( $id, array $data, $expiry = 0, User $user = null ) {
21 $this->setSession( $id, [ 'data' => $data ], $expiry, $user );
24 /**
25 * @param string $id Session ID
26 * @param array $metadata Session metadata
27 * @param int $expiry Expiry
29 public function setSessionMeta( $id, array $metadata, $expiry = 0 ) {
30 $this->setSession( $id, [ 'metadata' => $metadata ], $expiry );
33 /**
34 * @param string $id Session ID
35 * @param array $blob Session metadata and data
36 * @param int $expiry Expiry
37 * @param User $user User for metadata
39 public function setSession( $id, array $blob, $expiry = 0, User $user = null ) {
40 $blob += [
41 'data' => [],
42 'metadata' => [],
44 $blob['metadata'] += [
45 'userId' => $user ? $user->getId() : 0,
46 'userName' => $user ? $user->getName() : null,
47 'userToken' => $user ? $user->getToken( true ) : null,
48 'provider' => 'DummySessionProvider',
51 $this->setRawSession( $id, $blob, $expiry, $user );
54 /**
55 * @param string $id Session ID
56 * @param array|mixed $blob Session metadata and data
57 * @param int $expiry Expiry
59 public function setRawSession( $id, $blob, $expiry = 0 ) {
60 if ( $expiry <= 0 ) {
61 $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
64 $this->set( wfMemcKey( 'MWSession', $id ), $blob, $expiry );
67 /**
68 * @param string $id Session ID
69 * @return mixed
71 public function getSession( $id ) {
72 return $this->get( wfMemcKey( 'MWSession', $id ) );
75 /**
76 * @param string $id Session ID
77 * @return mixed
79 public function getSessionFromBackend( $id ) {
80 return $this->backend->get( wfMemcKey( 'MWSession', $id ) );
83 /**
84 * @param string $id Session ID
86 public function deleteSession( $id ) {
87 $this->delete( wfMemcKey( 'MWSession', $id ) );