Exemplo n.º 1
0
 /**
  * @covers ZfcUser\Authentication\Adapter\AdapterChain::resetAdapters
  */
 public function testResetAdapters()
 {
     $listeners = array();
     for ($i = 1; $i <= 3; $i++) {
         $storage = $this->getMock('ZfcUser\\Authentication\\Storage\\Db');
         $storage->expects($this->once())->method('clear');
         $adapter = $this->getMock('ZfcUser\\Authentication\\Adapter\\AbstractAdapter');
         $adapter->expects($this->once())->method('getStorage')->will($this->returnValue($storage));
         $callback = $this->getMockBuilder('Zend\\Stdlib\\CallbackHandler')->disableOriginalConstructor()->getMock();
         $callback->expects($this->once())->method('getCallback')->will($this->returnValue(array($adapter)));
         $listeners[] = $callback;
     }
     $this->eventManager->expects($this->once())->method('getListeners')->with($this->equalTo('authenticate'))->will($this->returnValue($listeners));
     $result = $this->adapterChain->resetAdapters();
     $this->assertInstanceOf('ZfcUser\\Authentication\\Adapter\\AdapterChain', $result);
 }
 /**
  * Delegate checking of user credentials to ZfcUser's onboard adapter chain
  *
  * @param  string  $username
  * @param  string  $password
  * @return boolean
  */
 public function checkUserCredentials($username, $password)
 {
     $request = new \Zend\Http\Request();
     $request->getPost()->set('identity', $username);
     $request->getPost()->set('credential', $password);
     $adapterResult = $this->authAdapter->prepareForAuthentication($request);
     if ($adapterResult instanceof \Zend\Stdlib\ResponseInterface) {
         return false;
     }
     $authResult = $this->auth->authenticate($this->authAdapter);
     if (!$authResult->isValid()) {
         $this->authAdapter->resetAdapters();
         return false;
     }
     return true;
 }