Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / includes / session / TestBagOStuff.php
1 <?php
2
3 namespace MediaWiki\Session;
4
5 use CachedBagOStuff;
6 use HashBagOStuff;
7 use RequestContext;
8
9 /**
10 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
11 */
12 class TestBagOStuff extends CachedBagOStuff {
13
14 public function __construct() {
15 parent::__construct( new HashBagOStuff );
16 }
17
18 /**
19 * @param string $id Session ID
20 * @param array $data Session data
21 */
22 public function setSessionData( $id, array $data ) {
23 $this->setSession( $id, [ 'data' => $data ] );
24 }
25
26 /**
27 * @param string $id Session ID
28 * @param array $metadata Session metadata
29 */
30 public function setSessionMeta( $id, array $metadata ) {
31 $this->setSession( $id, [ 'metadata' => $metadata ] );
32 }
33
34 /**
35 * @param string $id Session ID
36 * @param array $blob Session metadata and data
37 */
38 public function setSession( $id, array $blob ) {
39 $blob += [
40 'data' => [],
41 'metadata' => [],
42 ];
43 $blob['metadata'] += [
44 'userId' => 0,
45 'userName' => null,
46 'userToken' => null,
47 'provider' => 'DummySessionProvider',
48 ];
49
50 $this->setRawSession( $id, $blob );
51 }
52
53 /**
54 * @param string $id Session ID
55 * @param array|mixed $blob Session metadata and data
56 */
57 public function setRawSession( $id, $blob ) {
58 $expiry = RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
59 $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry );
60 }
61
62 /**
63 * @param string $id Session ID
64 * @return mixed
65 */
66 public function getSession( $id ) {
67 return $this->get( $this->makeKey( 'MWSession', $id ) );
68 }
69
70 /**
71 * @param string $id Session ID
72 * @return mixed
73 */
74 public function getSessionFromBackend( $id ) {
75 return $this->backend->get( $this->makeKey( 'MWSession', $id ) );
76 }
77
78 /**
79 * @param string $id Session ID
80 */
81 public function deleteSession( $id ) {
82 $this->delete( $this->makeKey( 'MWSession', $id ) );
83 }
84
85 }