コード例 #1
0
 public function testLogout()
 {
     $this->cookieService->expects($this->once())->method('read')->with($this->request, $this->response)->will($this->returnValue(new SerieToken(1, 'abc', 'def')));
     $this->rememberMeService->expects($this->once())->method('removeSerie')->with(1, 'abc');
     $this->cookieService->expects($this->once())->method('writeNull')->with($this->response);
     $this->listener->logout(new AdapterChainEvent());
 }
コード例 #2
0
 public function testWriteSerie()
 {
     $serie = new SerieToken(3, 'abc', 'def');
     $serie->setExpiresAt(new \DateTime('+1 year'));
     $response = new Response();
     $this->service->writeSerie($response, $serie);
     $this->assertTrue($response->getHeaders()->has('SetCookie'));
     $cookie = $response->getHeaders()->get('SetCookie')->current();
     $this->assertInstanceOf('Zend\\Http\\Header\\SetCookie', $cookie);
     $this->assertEquals('JwPersistentUser', $cookie->getName());
     $this->assertEquals('3:abc:def', $cookie->getValue());
     $this->assertDateTimeEquals(new \DateTime('+1 year'), new \DateTime($cookie->getExpires()));
     $this->assertEquals('/', $cookie->getPath());
 }
 public function testValidLogin()
 {
     $request = new Request();
     $response = new Response();
     $serieTokenInCookie = new SerieToken(1, 'abc', 'def');
     $newSerie = new SerieToken(1, 'abc', 'ghi');
     // Assume valid user
     $this->userMapper->expects($this->once())->method('findById')->will($this->returnValue($this->getMock('ZfcUser\\Entity\\UserInterface')));
     // Request contains cookie
     $this->cookieService->expects($this->once())->method('read')->with($request, $response)->will($this->returnValue($serieTokenInCookie));
     // Response contains updated cookie
     $this->cookieService->expects($this->once())->method('writeSerie')->with($response, $newSerie);
     $newSerie->setExpiresAt(new \DateTime('+3 days'));
     $this->rememberMeService->expects($this->once())->method('getNextInSerie')->with($serieTokenInCookie)->will($this->returnValue($newSerie));
     $this->authService->expects($this->once())->method('authenticate');
     $eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface');
     $this->service->setEventManager($eventManager);
     $eventManager->expects($this->once())->method('trigger')->with('login', $this->service, ['token' => $newSerie]);
     $this->service->loginFrom($request, $response);
 }
コード例 #4
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $service = new CookieService();
     $service->setModuleOptions($serviceLocator->get('JwPersistentUser\\ModuleOptions'));
     return $service;
 }