|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class UserConfirmationStepTest extends PipelineTest { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
protected static $fixture_file = 'PipelineTest.yml'; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Makes the dummy confirmation step |
|
9
|
|
|
* |
|
10
|
|
|
* @return UserConfirmationStep |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
public function getDummyConfirmationStep() { |
|
|
|
|
|
|
13
|
|
|
// Load data into step and pipeline |
|
14
|
|
|
$data = $this->getPipelineConfig(); |
|
15
|
|
|
$confirmStep = $this->objFromFixture('UserConfirmationStep', 'testconfirm'); |
|
16
|
|
|
$pipeline = $confirmStep->Pipeline(); |
|
17
|
|
|
$pipeline->Config = serialize($data); |
|
18
|
|
|
$pipeline->write(); |
|
19
|
|
|
$confirmStep->Config = serialize($pipeline->getConfigSetting('Steps', 'RequestConfirmationStep')); |
|
20
|
|
|
$confirmStep->write(); |
|
21
|
|
|
|
|
22
|
|
|
return $confirmStep; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Test that timeout expiry works |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testTimeout() { |
|
29
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
30
|
|
|
|
|
31
|
|
|
// Assert dependencies are injected |
|
32
|
|
|
$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
|
|
|
|
|
|
33
|
|
|
$step->start(); |
|
34
|
|
|
|
|
35
|
|
|
// Assert not error at startup |
|
36
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
|
|
37
|
|
|
$this->assertHasLog('Starting TestConfirmStep...'); |
|
38
|
|
|
|
|
39
|
|
|
// Go to two weeks into the future |
|
40
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+2 weeks'))); |
|
41
|
|
|
|
|
42
|
|
|
// Retry step |
|
43
|
|
|
$this->clearLog(); |
|
44
|
|
|
$step->start(); |
|
45
|
|
|
$this->assertEquals('Failed', $step->Status); |
|
|
|
|
|
|
46
|
|
|
$this->assertTrue($step->isTimedOut()); |
|
|
|
|
|
|
47
|
|
|
$this->assertSentMessage( |
|
48
|
|
|
'Deployment approval for testproject/uat has timed out due to no response', |
|
49
|
|
|
'[email protected]' |
|
50
|
|
|
); |
|
51
|
|
|
$this->assertSentMessage( |
|
52
|
|
|
'Deployment approval for testproject/uat has timed out due to no response', |
|
53
|
|
|
'[email protected]' |
|
54
|
|
|
); |
|
55
|
|
|
$this->assertHasLog( |
|
56
|
|
|
"TestConfirmStep took longer than 604800 seconds (7 days) to be approved and has timed out" |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testSendConfirm() { |
|
61
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
62
|
|
|
|
|
63
|
|
|
// Assert dependencies are injected |
|
64
|
|
|
$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
|
|
|
|
|
|
65
|
|
|
$step->start(); |
|
66
|
|
|
|
|
67
|
|
|
// Assert not error at startup |
|
68
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
|
|
69
|
|
|
$this->assertEquals('None', $step->Approval); |
|
|
|
|
|
|
70
|
|
|
$this->assertHasLog('Starting TestConfirmStep...'); |
|
71
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
72
|
|
|
$link = Director::absoluteURL('naut/project/testproject/environment/uat'); |
|
73
|
|
|
$this->assertSentMessage( |
|
74
|
|
|
"You requested approval for deployment of testproject/uat. Cancel? {$link}", |
|
75
|
|
|
'[email protected]' |
|
76
|
|
|
); |
|
77
|
|
|
$this->assertSentMessage( |
|
78
|
|
|
"Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
|
79
|
|
|
'[email protected]' |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Test delayed notification |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testSendDelay() { |
|
87
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
88
|
|
|
|
|
89
|
|
|
// Assert dependencies are injected |
|
90
|
|
|
$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
|
|
|
|
|
|
91
|
|
|
$step->start(); |
|
92
|
|
|
|
|
93
|
|
|
// Assert not error at startup |
|
94
|
|
|
$this->assertEquals('Started', $step->Status); |
|
|
|
|
|
|
95
|
|
|
$this->assertHasLog('Starting TestConfirmStep...'); |
|
96
|
|
|
|
|
97
|
|
|
// Check only recipient and first admin has been notified |
|
98
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
99
|
|
|
$link = Director::absoluteURL('naut/project/testproject/environment/uat'); |
|
100
|
|
|
$this->assertSentMessage( |
|
101
|
|
|
"You requested approval for deployment of testproject/uat. Cancel? {$link}", |
|
102
|
|
|
'[email protected]' |
|
103
|
|
|
); |
|
104
|
|
|
$this->assertSentMessage( |
|
105
|
|
|
"Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
|
106
|
|
|
'[email protected]' |
|
107
|
|
|
); |
|
108
|
|
|
$this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
// Advance 1 hour and ensure no other notifications have been sent |
|
111
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+1 hour'))); |
|
112
|
|
|
$this->clearLog(); |
|
113
|
|
|
$step->start(); |
|
114
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
115
|
|
|
$this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
// Advance 3 hours (2 more) and ensure the next notification is sent out |
|
118
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+3 hour'))); |
|
119
|
|
|
$this->clearLog(); |
|
120
|
|
|
$step->start(); |
|
121
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
122
|
|
|
$this->assertSentMessage( |
|
123
|
|
|
"Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
|
124
|
|
|
'[email protected]' |
|
125
|
|
|
); |
|
126
|
|
|
$this->assertSentMessage( |
|
127
|
|
|
"Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
|
128
|
|
|
'[email protected]' |
|
129
|
|
|
); |
|
130
|
|
|
$this->assertEquals(2, count(PipelineTest_RecordingMessageSender::get_messages())); |
|
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
// Go to 5 hours (another 2) and ensure the final notification is sent |
|
133
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+5 hour'))); |
|
134
|
|
|
$this->clearLog(); |
|
135
|
|
|
$step->start(); |
|
136
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
137
|
|
|
$this->assertSentMessage( |
|
138
|
|
|
"Deployment for testproject/uat requested by Marley, Bob. Approve? {$link}", |
|
139
|
|
|
'[email protected]' |
|
140
|
|
|
); |
|
141
|
|
|
$this->assertEquals(1, count(PipelineTest_RecordingMessageSender::get_messages())); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
// Go to 24 hours and ensure no notifications are sent |
|
144
|
|
|
SS_Datetime::set_mock_now(date('Y-m-d H:i:s', strtotime('+24 hour'))); |
|
145
|
|
|
$this->clearLog(); |
|
146
|
|
|
$step->start(); |
|
147
|
|
|
$this->assertFalse($step->isTimedOut()); |
|
|
|
|
|
|
148
|
|
|
$this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages()); |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function testRejection() { |
|
152
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
153
|
|
|
|
|
154
|
|
|
// Assert dependencies are injected |
|
155
|
|
|
$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
|
|
|
|
|
|
156
|
|
|
$step->start(); |
|
157
|
|
|
$this->logInWithPermission('ADMIN'); |
|
158
|
|
|
$step->reject(); |
|
159
|
|
|
|
|
160
|
|
|
// Assert not error at startup |
|
161
|
|
|
$this->assertEquals('Failed', $step->Status); |
|
|
|
|
|
|
162
|
|
|
$this->assertEquals('Rejected', $step->Approval); |
|
|
|
|
|
|
163
|
|
|
$this->assertHasLog('TestConfirmStep has been rejected'); |
|
164
|
|
|
$this->assertNotSentMessage('Deployment for testproject/uat has failed', '[email protected]'); |
|
165
|
|
|
$this->assertNotSentMessage('Deployment for testproject/uat has failed', '[email protected]'); |
|
166
|
|
|
$this->assertNotSentMessage('Deployment for testproject/uat has failed', '[email protected]'); |
|
167
|
|
|
$this->assertSentMessage('Deployment for testproject/uat has been rejected', '[email protected]'); |
|
168
|
|
|
$this->assertSentMessage('Deployment for testproject/uat has been rejected', '[email protected]'); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
View Code Duplication |
public function testApproval() { |
|
|
|
|
|
|
172
|
|
|
$step = $this->getDummyConfirmationStep(); |
|
173
|
|
|
|
|
174
|
|
|
// Assert dependencies are injected |
|
175
|
|
|
$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService); |
|
|
|
|
|
|
176
|
|
|
$step->start(); |
|
177
|
|
|
$this->logInWithPermission('ADMIN'); |
|
178
|
|
|
$step->approve(); |
|
179
|
|
|
|
|
180
|
|
|
// Assert not error at startup |
|
181
|
|
|
$this->assertEquals('Finished', $step->Status); |
|
|
|
|
|
|
182
|
|
|
$this->assertEquals('Approved', $step->Approval); |
|
|
|
|
|
|
183
|
|
|
$this->assertHasLog('TestConfirmStep has been approved'); |
|
184
|
|
|
$this->assertSentMessage('Deployment for testproject/uat has been approved', '[email protected]'); |
|
185
|
|
|
$this->assertSentMessage('Deployment for testproject/uat has been approved', '[email protected]'); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.