Completed
Pull Request — master (#513)
by Helpful
04:05
created

UserConfirmationStepTest::testApproval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %
Metric Value
dl 16
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
class UserConfirmationStepTest extends PipelineTest {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
33
		$step->start();
34
35
		// Assert not error at startup
36
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
46
		$this->assertTrue($step->isTimedOut());
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
65
		$step->start();
66
67
		// Assert not error at startup
68
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
69
		$this->assertEquals('None', $step->Approval);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
70
		$this->assertHasLog('Starting TestConfirmStep...');
71
		$this->assertFalse($step->isTimedOut());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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);
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
91
		$step->start();
92
93
		// Assert not error at startup
94
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
95
		$this->assertHasLog('Starting TestConfirmStep...');
96
97
		// Check only recipient and first admin has been notified
98
		$this->assertFalse($step->isTimedOut());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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()));
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
115
		$this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages());
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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()));
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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()));
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
148
		$this->assertEmpty(PipelineTest_RecordingMessageSender::get_messages());
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
149
	}
150
151
	public function testRejection() {
152
		$step = $this->getDummyConfirmationStep();
153
154
		// Assert dependencies are injected
155
		$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService);
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
156
		$step->start();
157
		$this->logInWithPermission('ADMIN');
158
		$step->reject();
159
160
		// Assert not error at startup
161
		$this->assertEquals('Failed', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
162
		$this->assertEquals('Rejected', $step->Approval);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
		$step = $this->getDummyConfirmationStep();
173
174
		// Assert dependencies are injected
175
		$this->assertTrue($step->getMessagingService() instanceof ConfirmationMessagingService);
1 ignored issue
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
176
		$step->start();
177
		$this->logInWithPermission('ADMIN');
178
		$step->approve();
179
180
		// Assert not error at startup
181
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
182
		$this->assertEquals('Approved', $step->Approval);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<UserConfirmationStepTest>.

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.

Loading history...
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