1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Store\Tests; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use WMDE\Fundraising\Entities\MembershipApplication; |
9
|
|
|
use WMDE\Fundraising\Store\MembershipApplicationData; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @covers \WMDE\Fundraising\Entities\MembershipApplication |
13
|
|
|
* @covers \WMDE\Fundraising\Store\MembershipApplicationData |
14
|
|
|
* |
15
|
|
|
* @licence GNU GPL v2+ |
16
|
|
|
* @author Jeroen De Dauw < [email protected] > |
17
|
|
|
*/ |
18
|
|
|
class MembershipApplicationTest extends TestCase { |
19
|
|
|
|
20
|
|
|
public function testWhenSettingIdToAnInteger_getIdReturnsIt() { |
21
|
|
|
$application = new MembershipApplication(); |
22
|
|
|
$application->setId( 1337 ); |
23
|
|
|
|
24
|
|
|
$this->assertSame( 1337, $application->getId() ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testWhenSettingIdToNull_getIdReturnsNull() { |
28
|
|
|
$application = new MembershipApplication(); |
29
|
|
|
$application->setId( 1337 ); |
30
|
|
|
$application->setId( null ); |
31
|
|
|
|
32
|
|
|
$this->assertNull( $application->getId() ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testWhenIdIsNotSet_getIdReturnsNull() { |
36
|
|
|
$application = new MembershipApplication(); |
37
|
|
|
|
38
|
|
|
$this->assertNull( $application->getId() ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGivenNoData_getDataObjectReturnsObjectWithNullValues() { |
42
|
|
|
$application = new MembershipApplication(); |
43
|
|
|
|
44
|
|
|
$this->assertNull( $application->getDataObject()->getAccessToken() ); |
45
|
|
|
$this->assertNull( $application->getDataObject()->getUpdateToken() ); |
46
|
|
|
$this->assertNull( $application->getDataObject()->getPreservedStatus() ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testWhenProvidingData_setDataObjectSetsData() { |
50
|
|
|
$data = new MembershipApplicationData(); |
51
|
|
|
$data->setAccessToken( 'foo' ); |
52
|
|
|
$data->setUpdateToken( 'bar' ); |
53
|
|
|
$data->setPreservedStatus( 1337 ); |
54
|
|
|
|
55
|
|
|
$application = new MembershipApplication(); |
56
|
|
|
$application->setDataObject( $data ); |
57
|
|
|
|
58
|
|
|
$this->assertSame( |
59
|
|
|
[ |
60
|
|
|
'token' => 'foo', |
61
|
|
|
'utoken' => 'bar', |
62
|
|
|
'old_status' => 1337, |
63
|
|
|
], |
64
|
|
|
$application->getDecodedData() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testWhenProvidingNullData_setObjectDoesNotSetFields() { |
69
|
|
|
$application = new MembershipApplication(); |
70
|
|
|
$application->setDataObject( new MembershipApplicationData() ); |
71
|
|
|
|
72
|
|
|
$this->assertSame( |
73
|
|
|
[], |
74
|
|
|
$application->getDecodedData() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testWhenDataAlreadyExists_setDataObjectRetainsAndUpdatesData() { |
79
|
|
|
$application = new MembershipApplication(); |
80
|
|
|
$application->encodeAndSetData( [ |
81
|
|
|
'nyan' => 'cat', |
82
|
|
|
'token' => 'wee', |
83
|
|
|
'pink' => 'fluffy', |
84
|
|
|
] ); |
85
|
|
|
|
86
|
|
|
$data = new MembershipApplicationData(); |
87
|
|
|
$data->setAccessToken( 'foo' ); |
88
|
|
|
$data->setUpdateToken( 'bar' ); |
89
|
|
|
|
90
|
|
|
$application->setDataObject( $data ); |
91
|
|
|
|
92
|
|
|
$this->assertSame( |
93
|
|
|
[ |
94
|
|
|
'nyan' => 'cat', |
95
|
|
|
'token' => 'foo', |
96
|
|
|
'pink' => 'fluffy', |
97
|
|
|
'utoken' => 'bar', |
98
|
|
|
], |
99
|
|
|
$application->getDecodedData() |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testWhenModifyingTheDataObject_modificationsAreReflected() { |
104
|
|
|
$application = new MembershipApplication(); |
105
|
|
|
$application->encodeAndSetData( [ |
106
|
|
|
'nyan' => 'cat', |
107
|
|
|
'token' => 'wee', |
108
|
|
|
'pink' => 'fluffy', |
109
|
|
|
] ); |
110
|
|
|
|
111
|
|
|
$application->modifyDataObject( function( MembershipApplicationData $data ) { |
112
|
|
|
$data->setAccessToken( 'foo' ); |
113
|
|
|
$data->setUpdateToken( 'bar' ); |
114
|
|
|
} ); |
115
|
|
|
|
116
|
|
|
$this->assertSame( |
117
|
|
|
[ |
118
|
|
|
'nyan' => 'cat', |
119
|
|
|
'token' => 'foo', |
120
|
|
|
'pink' => 'fluffy', |
121
|
|
|
'utoken' => 'bar', |
122
|
|
|
], |
123
|
|
|
$application->getDecodedData() |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testStatusConstantsExist() { |
128
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_MODERATION ); |
129
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_ABORTED ); |
130
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_CANCELED ); |
131
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_CONFIRMED ); |
132
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_DELETED ); |
133
|
|
|
$this->assertNotNull( MembershipApplication::STATUS_NEUTRAL ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testGivenModerationStatus_needsModerationReturnsTrue() { |
137
|
|
|
$application = new MembershipApplication(); |
138
|
|
|
$application->setStatus( MembershipApplication::STATUS_MODERATION ); |
139
|
|
|
|
140
|
|
|
$this->assertTrue( $application->needsModeration() ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testGivenDefaultStatus_needsModerationReturnsFalse() { |
144
|
|
|
$application = new MembershipApplication(); |
145
|
|
|
|
146
|
|
|
$this->assertFalse( $application->needsModeration() ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testGivenModerationAndCancelledStatus_needsModerationReturnsTrue() { |
150
|
|
|
$application = new MembershipApplication(); |
151
|
|
|
$application->setStatus( |
152
|
|
|
MembershipApplication::STATUS_MODERATION + MembershipApplication::STATUS_CANCELED |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$this->assertTrue( $application->needsModeration() ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testGivenCancelledStatus_isCancelledReturnsTrue() { |
159
|
|
|
$application = new MembershipApplication(); |
160
|
|
|
$application->setStatus( MembershipApplication::STATUS_CANCELED ); |
161
|
|
|
|
162
|
|
|
$this->assertTrue( $application->isCancelled() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function testGivenDefaultStatus_isCancelledReturnsFalse() { |
166
|
|
|
$application = new MembershipApplication(); |
167
|
|
|
|
168
|
|
|
$this->assertFalse( $application->isCancelled() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testGivenModerationAndCancelledStatus_isCancelledReturnsTrue() { |
172
|
|
|
$application = new MembershipApplication(); |
173
|
|
|
$application->setStatus( |
174
|
|
|
MembershipApplication::STATUS_MODERATION + MembershipApplication::STATUS_CANCELED |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$this->assertTrue( $application->isCancelled() ); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function testGivenDeletedStatus_isDeletedReturnsTrue() { |
181
|
|
|
$application = new MembershipApplication(); |
182
|
|
|
$application->setStatus( MembershipApplication::STATUS_DELETED ); |
183
|
|
|
|
184
|
|
|
$this->assertTrue( $application->isDeleted() ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function testGivenDefaultStatus_isDeletedReturnsFalse() { |
188
|
|
|
$application = new MembershipApplication(); |
189
|
|
|
|
190
|
|
|
$this->assertFalse( $application->isCancelled() ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function testGivenModerationAndDeletedStatus_isDeletedReturnsTrue() { |
194
|
|
|
$application = new MembershipApplication(); |
195
|
|
|
$application->setStatus( |
196
|
|
|
MembershipApplication::STATUS_MODERATION + MembershipApplication::STATUS_DELETED |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
$this->assertTrue( $application->isDeleted() ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function testDefaultDonationReceiptValue_isNull(): void { |
203
|
|
|
$application = new MembershipApplication(); |
204
|
|
|
|
205
|
|
|
$this->assertNull( $application->getDonationReceipt() ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function testSetDonationReceiptValue_canBeRetrieved(): void { |
209
|
|
|
$application = new MembershipApplication(); |
210
|
|
|
$application->setDonationReceipt( false ); |
211
|
|
|
|
212
|
|
|
$this->assertFalse( $application->getDonationReceipt() ); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
} |
216
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.