X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/session/TestBagOStuff.php diff --git a/tests/phpunit/includes/session/TestBagOStuff.php b/tests/phpunit/includes/session/TestBagOStuff.php new file mode 100644 index 00000000..fd02a2e9 --- /dev/null +++ b/tests/phpunit/includes/session/TestBagOStuff.php @@ -0,0 +1,90 @@ +setSession( $id, [ 'data' => $data ], $expiry, $user ); + } + + /** + * @param string $id Session ID + * @param array $metadata Session metadata + * @param int $expiry Expiry + */ + public function setSessionMeta( $id, array $metadata, $expiry = 0 ) { + $this->setSession( $id, [ 'metadata' => $metadata ], $expiry ); + } + + /** + * @param string $id Session ID + * @param array $blob Session metadata and data + * @param int $expiry Expiry + * @param User $user User for metadata + */ + public function setSession( $id, array $blob, $expiry = 0, User $user = null ) { + $blob += [ + 'data' => [], + 'metadata' => [], + ]; + $blob['metadata'] += [ + 'userId' => $user ? $user->getId() : 0, + 'userName' => $user ? $user->getName() : null, + 'userToken' => $user ? $user->getToken( true ) : null, + 'provider' => 'DummySessionProvider', + ]; + + $this->setRawSession( $id, $blob, $expiry, $user ); + } + + /** + * @param string $id Session ID + * @param array|mixed $blob Session metadata and data + * @param int $expiry Expiry + */ + public function setRawSession( $id, $blob, $expiry = 0 ) { + if ( $expiry <= 0 ) { + $expiry = \RequestContext::getMain()->getConfig()->get( 'ObjectCacheSessionExpiry' ); + } + + $this->set( $this->makeKey( 'MWSession', $id ), $blob, $expiry ); + } + + /** + * @param string $id Session ID + * @return mixed + */ + public function getSession( $id ) { + return $this->get( $this->makeKey( 'MWSession', $id ) ); + } + + /** + * @param string $id Session ID + * @return mixed + */ + public function getSessionFromBackend( $id ) { + return $this->backend->get( $this->makeKey( 'MWSession', $id ) ); + } + + /** + * @param string $id Session ID + */ + public function deleteSession( $id ) { + $this->delete( $this->makeKey( 'MWSession', $id ) ); + } + +}