|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JwPersistentUserTest\Service; |
|
4
|
|
|
|
|
5
|
|
|
use JwPersistentUser\Test\TestCase; |
|
6
|
|
|
use JwPersistentUser\Model\SerieToken; |
|
7
|
|
|
use JwPersistentUser\Service\CookieService; |
|
8
|
|
|
use JwPersistentUser\Service\RememberMeService; |
|
9
|
|
|
use JwPersistentUser\Service\CookieAuthenticationService; |
|
10
|
|
|
|
|
11
|
|
|
use Zend\Http\Request; |
|
12
|
|
|
use Zend\Http\Response; |
|
13
|
|
|
use Zend\Authentication\AuthenticationServiceInterface; |
|
14
|
|
|
|
|
15
|
|
|
use ZfcUser\Mapper\User as ZfcUserMapper; |
|
16
|
|
|
|
|
17
|
|
|
class CookieAuthenticationServiceTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var CookieAuthenticationService |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $service; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var RememberMeService |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $rememberMeService; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var AuthenticationServiceInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $authService; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var CookieService |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $cookieService; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ZfcUserMapper |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $userMapper; |
|
43
|
|
|
|
|
44
|
|
|
public function setUp() |
|
45
|
|
|
{ |
|
46
|
|
|
parent::setUp(); |
|
47
|
|
|
|
|
48
|
|
|
$sl = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); |
|
49
|
|
|
|
|
50
|
|
|
$this->service = new CookieAuthenticationService($sl); |
|
51
|
|
|
|
|
52
|
|
|
$this->authService = $this->getMock('Zend\Authentication\AuthenticationServiceInterface'); |
|
53
|
|
|
$this->service->setAuthService($this->authService); |
|
54
|
|
|
|
|
55
|
|
|
$this->rememberMeService = $this->getMock('JwPersistentUser\Service\RememberMeService'); |
|
56
|
|
|
$this->service->setRememberMeService($this->rememberMeService); |
|
57
|
|
|
|
|
58
|
|
|
$this->cookieService = $this->getMock('JwPersistentUser\Service\CookieService'); |
|
59
|
|
|
$this->service->setCookieService($this->cookieService); |
|
60
|
|
|
|
|
61
|
|
|
$this->userMapper = $this->getMock('ZfcUser\Mapper\User'); |
|
62
|
|
|
$this->service->setUserMapper($this->userMapper); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testValidLogin() |
|
66
|
|
|
{ |
|
67
|
|
|
$request = new Request; |
|
68
|
|
|
$response = new Response; |
|
69
|
|
|
|
|
70
|
|
|
$serieTokenInCookie = new SerieToken(1, 'abc', 'def'); |
|
71
|
|
|
$newSerie = new SerieToken(1, 'abc', 'ghi'); |
|
72
|
|
|
|
|
73
|
|
|
// Assume valid user |
|
74
|
|
|
$this->userMapper->expects($this->once()) |
|
|
|
|
|
|
75
|
|
|
->method('findById') |
|
76
|
|
|
->will($this->returnValue($this->getMock('ZfcUser\Entity\UserInterface'))); |
|
77
|
|
|
|
|
78
|
|
|
// Request contains cookie |
|
79
|
|
|
$this->cookieService->expects($this->once()) |
|
|
|
|
|
|
80
|
|
|
->method('read') |
|
81
|
|
|
->with($request, $response) |
|
82
|
|
|
->will($this->returnValue($serieTokenInCookie)); |
|
83
|
|
|
|
|
84
|
|
|
// Response contains updated cookie |
|
85
|
|
|
$this->cookieService->expects($this->once()) |
|
|
|
|
|
|
86
|
|
|
->method('writeSerie') |
|
87
|
|
|
->with($response, $newSerie); |
|
88
|
|
|
|
|
89
|
|
|
$newSerie->setExpiresAt(new \DateTime('+3 days')); |
|
90
|
|
|
$this->rememberMeService->expects($this->once()) |
|
|
|
|
|
|
91
|
|
|
->method('getNextInSerie') |
|
92
|
|
|
->with($serieTokenInCookie) |
|
93
|
|
|
->will($this->returnValue($newSerie)); |
|
94
|
|
|
|
|
95
|
|
|
$this->authService->expects($this->once()) |
|
|
|
|
|
|
96
|
|
|
->method('authenticate'); |
|
97
|
|
|
|
|
98
|
|
|
$eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); |
|
99
|
|
|
$this->service->setEventManager($eventManager); |
|
100
|
|
|
$eventManager->expects($this->once()) |
|
101
|
|
|
->method('trigger') |
|
102
|
|
|
->with('login', $this->service, ['token' => $newSerie]); |
|
103
|
|
|
|
|
104
|
|
|
$this->service->loginFrom($request, $response); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.