17 $config->set(
'CookiePrefix',
'wgCookiePrefix' );
20 'sessionCookieName' =>
$name,
21 'sessionCookieOptions' => [],
23 if ( $prefix !== null ) {
24 $params[
'sessionCookieOptions'][
'prefix'] = $prefix;
28 ->setConstructorArgs( [
$params ] )
29 ->getMockForAbstractClass();
31 $provider->setConfig(
$config );
39 ->getMockForAbstractClass();
41 $this->assertNull( $priv->sessionCookieName );
42 $this->assertSame( [], $priv->sessionCookieOptions );
45 ->setConstructorArgs( [ [
46 'sessionCookieName' =>
'Foo',
47 'sessionCookieOptions' => [
'Bar' ],
49 ->getMockForAbstractClass();
51 $this->assertSame(
'Foo', $priv->sessionCookieName );
52 $this->assertSame( [
'Bar' ], $priv->sessionCookieOptions );
56 ->setConstructorArgs( [ [
57 'sessionCookieName' =>
false,
59 ->getMockForAbstractClass();
60 $this->fail(
'Expected exception not thrown' );
63 'sessionCookieName must be a string',
70 ->setConstructorArgs( [ [
71 'sessionCookieOptions' =>
'x',
73 ->getMockForAbstractClass();
74 $this->fail(
'Expected exception not thrown' );
77 'sessionCookieOptions must be an array',
85 $this->assertFalse( $provider->persistsSessionID() );
86 $this->assertFalse( $provider->canChangeUser() );
89 $this->assertTrue( $provider->persistsSessionID() );
90 $this->assertFalse( $provider->canChangeUser() );
92 $msg = $provider->whyNoSession();
93 $this->assertInstanceOf(
'Message', $msg );
94 $this->assertSame(
'sessionprovider-nocookies', $msg->getKey() );
99 $this->assertSame( [], $provider->getVaryCookies() );
102 $this->assertSame( [
'wgCookiePrefixFoo' ], $provider->getVaryCookies() );
105 $this->assertSame( [
'BarFoo' ], $provider->getVaryCookies() );
108 $this->assertSame( [
'Foo' ], $provider->getVaryCookies() );
112 $this->
setMwGlobals(
'wgCookiePrefix',
'wgCookiePrefix' );
115 '' =>
'empty---------------------------',
116 'Foo' =>
'foo-----------------------------',
117 'wgCookiePrefixFoo' =>
'wgfoo---------------------------',
118 'BarFoo' =>
'foobar--------------------------',
124 $provider->getSessionIdFromCookie(
$request );
125 $this->fail(
'Expected exception not thrown' );
126 }
catch ( \BadMethodCallException $ex ) {
128 'MediaWiki\\Session\\ImmutableSessionProviderWithCookie::getSessionIdFromCookie ' .
129 'may not be called when $this->sessionCookieName === null',
136 'wgfoo---------------------------',
137 $provider->getSessionIdFromCookie(
$request )
142 'foobar--------------------------',
143 $provider->getSessionIdFromCookie(
$request )
148 'foo-----------------------------',
149 $provider->getSessionIdFromCookie(
$request )
153 $this->assertSame( null, $provider->getSessionIdFromCookie(
$request ) );
156 $this->assertSame( null, $provider->getSessionIdFromCookie(
$request ) );
160 $sentResponse = $this->getMock(
'FauxResponse', [
'headersSent',
'setCookie',
'header' ] );
161 $sentResponse->expects( $this->any() )->method(
'headersSent' )
162 ->will( $this->returnValue(
true ) );
163 $sentResponse->expects( $this->never() )->method(
'setCookie' );
164 $sentResponse->expects( $this->never() )->method(
'header' );
166 $sentRequest = $this->getMock(
'FauxRequest', [
'response' ] );
167 $sentRequest->expects( $this->any() )->method(
'response' )
168 ->will( $this->returnValue( $sentResponse ) );
179 'wgCookieExpiration' => 100,
180 'wgSecureLogin' =>
false,
184 $provider->setLogger(
new \Psr\Log\NullLogger() );
186 $priv->sessionCookieOptions = [
188 'path' =>
'CookiePath',
189 'domain' =>
'CookieDomain',
194 $sessionId =
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
196 $this->assertFalse(
$user->requiresHTTPS(),
'sanity check' );
201 'provider' => $provider,
208 new \Psr\Log\NullLogger(),
212 $backend->setRememberUser( $remember );
213 $backend->setForceHTTPS( $secure );
216 $priv->sessionCookieName = null;
218 $provider->persistSession( $backend,
$request );
219 $this->assertSame( [],
$request->response()->getCookies() );
222 $priv->sessionCookieName =
'session';
225 $provider->persistSession( $backend,
$request );
227 $cookie =
$request->response()->getCookieData(
'xsession' );
228 $this->assertInternalType(
'array', $cookie );
229 if ( isset( $cookie[
'expire'] ) && $cookie[
'expire'] > 0 ) {
231 $cookie[
'expire'] = round( $cookie[
'expire'] -
$time, -2 );
233 $this->assertEquals( [
234 'value' => $sessionId,
236 'path' =>
'CookiePath',
237 'domain' =>
'CookieDomain',
243 $cookie =
$request->response()->getCookieData(
'forceHTTPS' );
245 $this->assertInternalType(
'array', $cookie );
246 if ( isset( $cookie[
'expire'] ) && $cookie[
'expire'] > 0 ) {
248 $cookie[
'expire'] = round( $cookie[
'expire'] -
$time, -2 );
250 $this->assertEquals( [
253 'path' =>
'CookiePath',
254 'domain' =>
'CookieDomain',
260 $this->assertNull( $cookie );
265 $provider->persistSession( $backend,
$request );
266 $this->assertSame( [],
$request->response()->getCookies() );
280 $provider->setLogger(
new \Psr\Log\NullLogger() );
284 $priv->sessionCookieName = null;
286 $provider->unpersistSession(
$request );
287 $this->assertSame( null,
$request->response()->getCookie(
'session',
'' ) );
290 $priv->sessionCookieName =
'session';
292 $provider->unpersistSession(
$request );
293 $this->assertSame(
'',
$request->response()->getCookie(
'session',
'' ) );
297 $provider->unpersistSession( $request );
298 $this->assertSame( null, $request->response()->getCookie(
'session',
'' ) );
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
processing should stop and the error should be shown to the user * false
see documentation in includes Linker php for Linker::makeImageLink & $time
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
A logger that may be configured to either buffer logs or to print them to the output where PHPUnit wi...
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
error also a ContextSource you ll probably need to make sure the header is varied on $request
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
static newFromObject($object)
Return the same object, without access restrictions.
Allows to change the fields on the form that will be generated $name