Add 3D filetype for STL files
[lhc/web/wiklou.git] / tests / phpunit / includes / session / TestBagOStuff.php
1 <?php
2
3 namespace MediaWiki\Session;
4
5 /**
6 * BagOStuff with utility functions for MediaWiki\\Session\\* testing
7 */
8 class TestBagOStuff extends \CachedBagOStuff {
9
10 public function __construct() {
11 parent::__construct( new \HashBagOStuff );
12 }
13
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
19 */
20 public function setSessionData( $id, array $data, $expiry = 0, User $user = null ) {
21 $this->setSession( $id, [ 'data' => $data ], $expiry, $user );
22 }
23
24 /**
25 * @param string $id Session ID
26 * @param array $metadata Session metadata
27 * @param int $expiry Expiry
28 */
29 public function setSessionMeta( $id, array $metadata, $expiry = 0 ) {
30 $this->setSession( $id, [ 'metadata' => $metadata ], $expiry );
31 }
32
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
38 */
39 public function setSession( $id, array $blob, $expiry = 0, User $user = null ) {
40 $blob += [
41 'data' => [],
42 'metadata' => [],
43 ];
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',
49 ];
50
51 $this->setRawSession( $id, $blob, $expiry, $user );
52 }
53
54 /**
55 * @param string $id Session ID
56 * @param array|mixed $blob Session metadata and data
57 * @param int $expiry Expiry
58 */
59 public function setRawSession( $id, $blob, $expiry = 0 ) {
60 if ( $expiry <= 0 ) {
61 $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' );
62 }
63
64 $this->set( wfMemcKey( 'MWSession', $id ), $blob, $expiry );
65 }
66
67 /**
68 * @param string $id Session ID
69 * @return mixed
70 */
71 public function getSession( $id ) {
72 return $this->get( wfMemcKey( 'MWSession', $id ) );
73 }
74
75 /**
76 * @param string $id Session ID
77 * @return mixed
78 */
79 public function getSessionFromBackend( $id ) {
80 return $this->backend->get( wfMemcKey( 'MWSession', $id ) );
81 }
82
83 /**
84 * @param string $id Session ID
85 */
86 public function deleteSession( $id ) {
87 $this->delete( wfMemcKey( 'MWSession', $id ) );
88 }
89
90 }