当前位置: 首页>>代码示例>>PHP>>正文


PHP WebRequest::getSession方法代码示例

本文整理汇总了PHP中WebRequest::getSession方法的典型用法代码示例。如果您正苦于以下问题:PHP WebRequest::getSession方法的具体用法?PHP WebRequest::getSession怎么用?PHP WebRequest::getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebRequest的用法示例。


在下文中一共展示了WebRequest::getSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAccountLink

 /**
  * @dataProvider provideAccountLink
  * @param StatusValue $preTest
  * @param array $primaryResponses
  * @param array $managerResponses
  */
 public function testAccountLink(StatusValue $preTest, array $primaryResponses, array $managerResponses)
 {
     $user = \User::newFromName('UTSysop');
     $this->initializeManager();
     // Set up lots of mocks...
     $req = $this->getMockForAbstractClass(AuthenticationRequest::class);
     $req->primary = $primaryResponses;
     $mocks = [];
     foreach (['pre', 'primary'] as $key) {
         $class = ucfirst($key) . 'AuthenticationProvider';
         $mocks[$key] = $this->getMockForAbstractClass("MediaWiki\\Auth\\{$class}", [], "Mock{$class}");
         $mocks[$key]->expects($this->any())->method('getUniqueId')->will($this->returnValue($key));
         for ($i = 2; $i <= 3; $i++) {
             $mocks[$key . $i] = $this->getMockForAbstractClass("MediaWiki\\Auth\\{$class}", [], "Mock{$class}");
             $mocks[$key . $i]->expects($this->any())->method('getUniqueId')->will($this->returnValue($key . $i));
         }
     }
     $mocks['pre']->expects($this->any())->method('testForAccountLink')->will($this->returnCallback(function ($u) use($user, $preTest) {
         $this->assertSame($user->getId(), $u->getId());
         $this->assertSame($user->getName(), $u->getName());
         return $preTest;
     }));
     $mocks['pre2']->expects($this->atMost(1))->method('testForAccountLink')->will($this->returnValue(StatusValue::newGood()));
     $mocks['primary']->expects($this->any())->method('accountCreationType')->will($this->returnValue(PrimaryAuthenticationProvider::TYPE_LINK));
     $ct = count($req->primary);
     $callback = $this->returnCallback(function ($u, $reqs) use($user, $req) {
         $this->assertSame($user->getId(), $u->getId());
         $this->assertSame($user->getName(), $u->getName());
         $foundReq = false;
         foreach ($reqs as $r) {
             $this->assertSame($user->getName(), $r->username);
             $foundReq = $foundReq || get_class($r) === get_class($req);
         }
         $this->assertTrue($foundReq, '$reqs contains $req');
         return array_shift($req->primary);
     });
     $mocks['primary']->expects($this->exactly(min(1, $ct)))->method('beginPrimaryAccountLink')->will($callback);
     $mocks['primary']->expects($this->exactly(max(0, $ct - 1)))->method('continuePrimaryAccountLink')->will($callback);
     $abstain = AuthenticationResponse::newAbstain();
     $mocks['primary2']->expects($this->any())->method('accountCreationType')->will($this->returnValue(PrimaryAuthenticationProvider::TYPE_LINK));
     $mocks['primary2']->expects($this->atMost(1))->method('beginPrimaryAccountLink')->will($this->returnValue($abstain));
     $mocks['primary2']->expects($this->never())->method('continuePrimaryAccountLink');
     $mocks['primary3']->expects($this->any())->method('accountCreationType')->will($this->returnValue(PrimaryAuthenticationProvider::TYPE_CREATE));
     $mocks['primary3']->expects($this->never())->method('beginPrimaryAccountLink');
     $mocks['primary3']->expects($this->never())->method('continuePrimaryAccountLink');
     $this->preauthMocks = [$mocks['pre'], $mocks['pre2']];
     $this->primaryauthMocks = [$mocks['primary3'], $mocks['primary2'], $mocks['primary']];
     $this->logger = new \TestLogger(true, function ($message, $level) {
         return $level === LogLevel::DEBUG ? null : $message;
     });
     $this->initializeManager(true);
     $constraint = \PHPUnit_Framework_Assert::logicalOr($this->equalTo(AuthenticationResponse::PASS), $this->equalTo(AuthenticationResponse::FAIL));
     $providers = array_merge($this->preauthMocks, $this->primaryauthMocks);
     foreach ($providers as $p) {
         $p->postCalled = false;
         $p->expects($this->atMost(1))->method('postAccountLink')->willReturnCallback(function ($user, $response) use($constraint, $p) {
             $this->assertInstanceOf('User', $user);
             $this->assertSame('UTSysop', $user->getName());
             $this->assertInstanceOf(AuthenticationResponse::class, $response);
             $this->assertThat($response->status, $constraint);
             $p->postCalled = $response->status;
         });
     }
     $first = true;
     $created = false;
     $expectLog = [];
     foreach ($managerResponses as $i => $response) {
         if ($response instanceof AuthenticationResponse && $response->status === AuthenticationResponse::PASS) {
             $expectLog[] = [LogLevel::INFO, 'Account linked to {user} by primary'];
         }
         $ex = null;
         try {
             if ($first) {
                 $ret = $this->manager->beginAccountLink($user, [$req], 'http://localhost/');
             } else {
                 $ret = $this->manager->continueAccountLink([$req]);
             }
             if ($response instanceof \Exception) {
                 $this->fail('Expected exception not thrown', "Response {$i}");
             }
         } catch (\Exception $ex) {
             if (!$response instanceof \Exception) {
                 throw $ex;
             }
             $this->assertEquals($response->getMessage(), $ex->getMessage(), "Response {$i}, exception");
             $this->assertNull($this->request->getSession()->getSecret('AuthManager::accountLinkState'), "Response {$i}, exception, session state");
             return;
         }
         $this->assertSame('http://localhost/', $req->returnToUrl);
         $ret->message = $this->message($ret->message);
         $this->assertEquals($response, $ret, "Response {$i}, response");
         if ($response->status === AuthenticationResponse::PASS || $response->status === AuthenticationResponse::FAIL) {
             $this->assertNull($this->request->getSession()->getSecret('AuthManager::accountLinkState'), "Response {$i}, session state");
             foreach ($providers as $p) {
//.........这里部分代码省略.........
开发者ID:claudinec,项目名称:galan-wiki,代码行数:101,代码来源:AuthManagerTest.php

示例2: loadDefaults

 /**
  * Set cached properties to default.
  *
  * @note This no longer clears uncached lazy-initialised properties;
  *       the constructor does that instead.
  *
  * @param string|bool $name
  */
 public function loadDefaults($name = false)
 {
     $this->mId = 0;
     $this->mName = $name;
     $this->mRealName = '';
     $this->mEmail = '';
     $this->mOptionOverrides = null;
     $this->mOptionsLoaded = false;
     $loggedOut = $this->mRequest ? $this->mRequest->getSession()->getLoggedOutTimestamp() : 0;
     if ($loggedOut !== 0) {
         $this->mTouched = wfTimestamp(TS_MW, $loggedOut);
     } else {
         $this->mTouched = '1';
         # Allow any pages to be cached
     }
     $this->mToken = null;
     // Don't run cryptographic functions till we need a token
     $this->mEmailAuthenticated = null;
     $this->mEmailToken = '';
     $this->mEmailTokenExpires = null;
     $this->mRegistration = wfTimestamp(TS_MW);
     $this->mGroups = array();
     Hooks::run('UserLoadDefaults', array($this, $name));
 }
开发者ID:paladox,项目名称:2,代码行数:32,代码来源:User.php


注:本文中的WebRequest::getSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。