|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ConfirmationTokenChainTest extends SapphireTest { |
|
4
|
|
|
|
|
5
|
|
|
protected function getTokenRequiringReload($requiresReload = true, $extraMethods = array()) { |
|
6
|
|
|
$methods = array_merge(array('reloadRequired'), $extraMethods); |
|
7
|
|
|
$mock = $this->getMockBuilder('ParameterConfirmationToken') |
|
8
|
|
|
->disableOriginalConstructor() |
|
9
|
|
|
->setMethods($methods) |
|
10
|
|
|
->getMock(); |
|
11
|
|
|
|
|
12
|
|
|
$mock->expects($this->any()) |
|
13
|
|
|
->method('reloadRequired') |
|
14
|
|
|
->will($this->returnValue($requiresReload)); |
|
15
|
|
|
|
|
16
|
|
|
return $mock; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testFilteredTokens() { |
|
20
|
|
|
$chain = new ConfirmationTokenChain(); |
|
21
|
|
|
$chain->pushToken($tokenRequiringReload = $this->getTokenRequiringReload()); |
|
22
|
|
|
$chain->pushToken($tokenNotRequiringReload = $this->getTokenRequiringReload(false)); |
|
23
|
|
|
|
|
24
|
|
|
$reflectionMethod = new ReflectionMethod('ConfirmationTokenChain', 'filteredTokens'); |
|
25
|
|
|
$reflectionMethod->setAccessible(true); |
|
26
|
|
|
$tokens = $reflectionMethod->invoke($chain); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertContains($tokenRequiringReload, $tokens, 'Token requiring a reload was not returned'); |
|
29
|
|
|
$this->assertNotContains($tokenNotRequiringReload, $tokens, 'Token not requiring a reload was returned'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testSuppressionRequired() { |
|
33
|
|
|
$chain = new ConfirmationTokenChain(); |
|
34
|
|
|
$chain->pushToken($this->getTokenRequiringReload(false)); |
|
35
|
|
|
$this->assertFalse($chain->suppressionRequired(), 'Suppression incorrectly marked as required'); |
|
36
|
|
|
|
|
37
|
|
|
$chain = new ConfirmationTokenChain(); |
|
38
|
|
|
$chain->pushToken($this->getTokenRequiringReload()); |
|
39
|
|
|
$this->assertTrue($chain->suppressionRequired(), 'Suppression not marked as required'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testSuppressTokens() { |
|
43
|
|
|
$mockToken = $this->getTokenRequiringReload(true, array('suppress')); |
|
44
|
|
|
$mockToken->expects($this->once()) |
|
45
|
|
|
->method('suppress'); |
|
46
|
|
|
|
|
47
|
|
|
$chain = new ConfirmationTokenChain(); |
|
48
|
|
|
$chain->pushToken($mockToken); |
|
49
|
|
|
$chain->suppressTokens(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testReloadRequired() { |
|
53
|
|
|
$mockToken = $this->getTokenRequiringReload(true); |
|
54
|
|
|
$secondMockToken = $this->getTokenRequiringReload(false); |
|
55
|
|
|
|
|
56
|
|
|
$chain = new ConfirmationTokenChain(); |
|
57
|
|
|
$chain->pushToken($mockToken); |
|
58
|
|
|
$chain->pushToken($secondMockToken); |
|
59
|
|
|
$this->assertTrue($chain->reloadRequired()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testParams() { |
|
63
|
|
|
$mockToken = $this->getTokenRequiringReload(true, array('params')); |
|
64
|
|
|
$mockToken->expects($this->once()) |
|
65
|
|
|
->method('params') |
|
66
|
|
|
->with($this->isTrue()) |
|
67
|
|
|
->will($this->returnValue(array('mockTokenParam' => '1'))); |
|
68
|
|
|
$secondMockToken = $this->getTokenRequiringReload(true, array('params')); |
|
69
|
|
|
$secondMockToken->expects($this->once()) |
|
70
|
|
|
->method('params') |
|
71
|
|
|
->with($this->isTrue()) |
|
72
|
|
|
->will($this->returnValue(array('secondMockTokenParam' => '2'))); |
|
73
|
|
|
|
|
74
|
|
|
$chain = new ConfirmationTokenChain(); |
|
75
|
|
|
$chain->pushToken($mockToken); |
|
76
|
|
|
$chain->pushToken($secondMockToken); |
|
77
|
|
|
$this->assertEquals(array('mockTokenParam' => '1', 'secondMockTokenParam' => '2'), $chain->params(true)); |
|
78
|
|
|
|
|
79
|
|
|
$mockToken = $this->getTokenRequiringReload(true, array('params')); |
|
80
|
|
|
$mockToken->expects($this->once()) |
|
81
|
|
|
->method('params') |
|
82
|
|
|
->with($this->isFalse()) |
|
83
|
|
|
->will($this->returnValue(array('mockTokenParam' => '1'))); |
|
84
|
|
|
|
|
85
|
|
|
$chain = new ConfirmationTokenChain(); |
|
86
|
|
|
$chain->pushToken($mockToken); |
|
87
|
|
|
$this->assertEquals(array('mockTokenParam' => '1'), $chain->params(false)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testGetRedirectUrlBase() { |
|
91
|
|
|
$mockUrlToken = $this->getMockBuilder('URLConfirmationToken') |
|
92
|
|
|
->disableOriginalConstructor() |
|
93
|
|
|
->setMethods(array('reloadRequired', 'getRedirectUrlBase')) |
|
94
|
|
|
->getMock(); |
|
95
|
|
|
$mockUrlToken->expects($this->any()) |
|
96
|
|
|
->method('reloadRequired') |
|
97
|
|
|
->will($this->returnValue(true)); |
|
98
|
|
|
$mockUrlToken->expects($this->any()) |
|
99
|
|
|
->method('getRedirectUrlBase') |
|
100
|
|
|
->will($this->returnValue('url-base')); |
|
101
|
|
|
|
|
102
|
|
|
$mockParameterToken = $this->getMockBuilder('ParameterConfirmationToken') |
|
103
|
|
|
->disableOriginalConstructor() |
|
104
|
|
|
->setMethods(array('reloadRequired', 'getRedirectUrlBase')) |
|
105
|
|
|
->getMock(); |
|
106
|
|
|
$mockParameterToken->expects($this->any()) |
|
107
|
|
|
->method('reloadRequired') |
|
108
|
|
|
->will($this->returnValue(true)); |
|
109
|
|
|
$mockParameterToken->expects($this->any()) |
|
110
|
|
|
->method('getRedirectUrlBase') |
|
111
|
|
|
->will($this->returnValue('parameter-base')); |
|
112
|
|
|
|
|
113
|
|
|
$chain = new ConfirmationTokenChain(); |
|
114
|
|
|
$chain->pushToken($mockParameterToken); |
|
115
|
|
|
$chain->pushToken($mockUrlToken); |
|
116
|
|
|
$this->assertEquals('url-base', $chain->getRedirectUrlBase(), 'URLConfirmationToken url base should take priority'); |
|
117
|
|
|
|
|
118
|
|
|
// Push them in reverse order to check priority still correct |
|
119
|
|
|
$chain = new ConfirmationTokenChain(); |
|
120
|
|
|
$chain->pushToken($mockUrlToken); |
|
121
|
|
|
$chain->pushToken($mockParameterToken); |
|
122
|
|
|
$this->assertEquals('url-base', $chain->getRedirectUrlBase(), 'URLConfirmationToken url base should take priority'); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function testGetRedirectUrlParams() { |
|
126
|
|
|
$mockToken = $this->getTokenRequiringReload(true, array('getRedirectUrlParams')); |
|
127
|
|
|
$mockToken->expects($this->once()) |
|
128
|
|
|
->method('getRedirectUrlParams') |
|
129
|
|
|
->will($this->returnValue(array('mockTokenParam' => '1'))); |
|
130
|
|
|
|
|
131
|
|
|
$secondMockToken = $this->getTokenRequiringReload(true, array('getRedirectUrlParams')); |
|
132
|
|
|
$secondMockToken->expects($this->once()) |
|
133
|
|
|
->method('getRedirectUrlParams') |
|
134
|
|
|
->will($this->returnValue(array('secondMockTokenParam' => '2'))); |
|
135
|
|
|
|
|
136
|
|
|
$chain = new ConfirmationTokenChain(); |
|
137
|
|
|
$chain->pushToken($mockToken); |
|
138
|
|
|
$chain->pushToken($secondMockToken); |
|
139
|
|
|
$this->assertEquals(array('mockTokenParam' => '1', 'secondMockTokenParam' => '2'), $chain->getRedirectUrlParams()); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|