1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Swiss Payment Slip |
4
|
|
|
* |
5
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
6
|
|
|
* @copyright 2012-2016 Some nice Swiss guys |
7
|
|
|
* @author Marc Würth [email protected] |
8
|
|
|
* @author Manuel Reinhard <[email protected]> |
9
|
|
|
* @author Peter Siska <[email protected]> |
10
|
|
|
* @link https://github.com/ravage84/SwissPaymentSlip/ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace SwissPaymentSlip\SwissPaymentSlip\Tests; |
14
|
|
|
|
15
|
|
|
use SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip; |
16
|
|
|
use SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlipData; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Tests for the RedPaymentSlip class |
20
|
|
|
* |
21
|
|
|
* @coversDefaultClass SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip |
22
|
|
|
*/ |
23
|
|
|
class RedPaymentSlipTest extends PaymentSlipTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* The object under test |
27
|
|
|
* |
28
|
|
|
* @var RedPaymentSlip |
29
|
|
|
*/ |
30
|
|
|
protected $paymentSlip; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Setup a slip to test and some default and set attributes to test |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$slipData = new RedPaymentSlipData(); |
40
|
|
|
$this->paymentSlip = new RedPaymentSlip($slipData); |
41
|
|
|
|
42
|
|
|
$attributes = array(); |
43
|
|
|
$attributes['PosX'] = 0; |
44
|
|
|
$attributes['PosY'] = 0; |
45
|
|
|
$attributes['Width'] = 0; |
46
|
|
|
$attributes['Height'] = 0; |
47
|
|
|
$attributes['Background'] = 'transparent'; |
48
|
|
|
$attributes['FontFamily'] = 'Helvetica'; |
49
|
|
|
$attributes['FontSize'] = '10'; |
50
|
|
|
$attributes['FontColor'] = '#000'; |
51
|
|
|
$attributes['LineHeight'] = 4; |
52
|
|
|
$attributes['TextAlign'] = 'L'; |
53
|
|
|
|
54
|
|
|
$this->defaultAttributes = $attributes; |
55
|
|
|
|
56
|
|
|
$attributes = array(); |
57
|
|
|
$attributes['PosX'] = 123; |
58
|
|
|
$attributes['PosY'] = 456; |
59
|
|
|
$attributes['Width'] = 987; |
60
|
|
|
$attributes['Height'] = 654; |
61
|
|
|
$attributes['Background'] = '#123456'; |
62
|
|
|
$attributes['FontFamily'] = 'Courier'; |
63
|
|
|
$attributes['FontSize'] = '1'; |
64
|
|
|
$attributes['FontColor'] = '#654321'; |
65
|
|
|
$attributes['LineHeight'] = '15'; |
66
|
|
|
$attributes['TextAlign'] = 'C'; |
67
|
|
|
|
68
|
|
|
$this->setAttributes = $attributes; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Tests the getPaymentSlipData method |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
* @covers ::getPaymentSlipData |
76
|
|
|
*/ |
77
|
|
|
public function testGetPaymentSlipDataIsInstanceOf() |
78
|
|
|
{ |
79
|
|
|
$this->assertInstanceOf( |
80
|
|
|
'SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlipData', |
81
|
|
|
$this->paymentSlip->getPaymentSlipData() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Tests the default background |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
* @covers ::setDefaults |
90
|
|
|
*/ |
91
|
|
|
public function testSlipBackgroundDefaultValues() |
92
|
|
|
{ |
93
|
|
|
$this->assertEquals('ezs_red.gif', basename($this->paymentSlip->getSlipBackground())); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Tests the default attributes of the payment reason element |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
* @covers ::setDefaults |
101
|
|
|
* @todo Implement once the defaults are set properly in RedPaymentSlip::setDefaults() |
102
|
|
|
*/ |
103
|
|
|
public function testPaymentReasonAttrDefaultValues() |
104
|
|
|
{ |
105
|
|
|
$this->markTestIncomplete( |
106
|
|
|
'This test has not been implemented yet.' |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Tests the default attributes of the left IBAN element |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
* @covers ::setDefaults |
115
|
|
|
* @todo Implement once the defaults are set properly in RedPaymentSlip::setDefaults() |
116
|
|
|
*/ |
117
|
|
|
public function testIbanLeftAttrDefaultValues() |
118
|
|
|
{ |
119
|
|
|
$this->markTestIncomplete( |
120
|
|
|
'This test has not been implemented yet.' |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Tests the default attributes of the right IBAN element |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
* @covers ::setDefaults |
129
|
|
|
* @todo Implement once the defaults are set properly in RedPaymentSlip::setDefaults() |
130
|
|
|
*/ |
131
|
|
|
public function testIbanRightAttrDefaultValues() |
132
|
|
|
{ |
133
|
|
|
$this->markTestIncomplete( |
134
|
|
|
'This test has not been implemented yet.' |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Tests the setPaymentReasonAttr method |
140
|
|
|
* |
141
|
|
|
* @return void |
142
|
|
|
* @covers ::setPaymentReasonAttr |
143
|
|
|
* @covers ::setAttributes |
144
|
|
|
* @covers ::getPaymentReasonAttr |
145
|
|
|
*/ |
146
|
|
|
public function testSetPaymentReasonAttr() |
147
|
|
|
{ |
148
|
|
|
$returned = $this->paymentSlip->setPaymentReasonAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C'); |
149
|
|
|
$this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip', $returned); |
150
|
|
|
$this->assertEquals($this->setAttributes, $this->paymentSlip->getPaymentReasonAttr()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Tests the setIbanLeftAttr method |
155
|
|
|
* |
156
|
|
|
* @return void |
157
|
|
|
* @covers ::setIbanLeftAttr |
158
|
|
|
* @covers ::setAttributes |
159
|
|
|
* @covers ::getIbanLeftAttr |
160
|
|
|
*/ |
161
|
|
|
public function testSetIbanLeftAttr() |
162
|
|
|
{ |
163
|
|
|
$returned = $this->paymentSlip->setIbanLeftAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C'); |
164
|
|
|
$this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip', $returned); |
165
|
|
|
$this->assertEquals($this->setAttributes, $this->paymentSlip->getIbanLeftAttr()); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Tests the setIbanRightAttr method |
170
|
|
|
* |
171
|
|
|
* @return void |
172
|
|
|
* @covers ::setIbanRightAttr |
173
|
|
|
* @covers ::setAttributes |
174
|
|
|
* @covers ::getIbanRightAttr |
175
|
|
|
*/ |
176
|
|
|
public function testSetIbanRightAttr() |
177
|
|
|
{ |
178
|
|
|
$returned = $this->paymentSlip->setIbanRightAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C'); |
179
|
|
|
$this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip', $returned); |
180
|
|
|
$this->assertEquals($this->setAttributes, $this->paymentSlip->getIbanRightAttr()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Tests the setDisplayIban method |
185
|
|
|
* |
186
|
|
|
* @return void |
187
|
|
|
* @covers ::setDisplayIban |
188
|
|
|
* @covers ::getDisplayIban |
189
|
|
|
* @covers ::isBool |
190
|
|
|
*/ |
191
|
|
View Code Duplication |
public function testSetDisplayIban() |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
// Test the default value |
194
|
|
|
$this->assertTrue($this->paymentSlip->getDisplayIban()); |
195
|
|
|
|
196
|
|
|
// Disable the feature, also assert returned instance |
197
|
|
|
$returned = $this->paymentSlip->setDisplayIban(false); |
198
|
|
|
$this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip', $returned); |
199
|
|
|
$this->assertFalse($this->paymentSlip->getDisplayIban()); |
200
|
|
|
|
201
|
|
|
// Re-enable the feature |
202
|
|
|
$this->paymentSlip->setDisplayIban(); |
203
|
|
|
$this->assertTrue($this->paymentSlip->getDisplayIban()); |
204
|
|
|
|
205
|
|
|
// Check if the data is disabled |
206
|
|
|
$this->paymentSlip->getPaymentSlipData()->setWithIban(false); |
207
|
|
|
$this->assertFalse($this->paymentSlip->getDisplayIban()); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Tests the setDisplayIban method with an invalid parameter |
212
|
|
|
* |
213
|
|
|
* @return void |
214
|
|
|
* @expectedException \InvalidArgumentException |
215
|
|
|
* @expectedExceptionMessage $displayIban is not a boolean. |
216
|
|
|
* @covers ::setDisplayIban |
217
|
|
|
* @covers ::isBool |
218
|
|
|
*/ |
219
|
|
|
public function testSetDisplayIbanInvalidParameter() |
220
|
|
|
{ |
221
|
|
|
$this->paymentSlip->setDisplayIban('true'); |
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Tests the setDisplayPaymentReason method |
226
|
|
|
* |
227
|
|
|
* @return void |
228
|
|
|
* @covers ::setDisplayPaymentReason |
229
|
|
|
* @covers ::getDisplayPaymentReason |
230
|
|
|
* @covers ::isBool |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function testSetDisplayPaymentReason() |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
// Test the default value |
235
|
|
|
$this->assertTrue($this->paymentSlip->getDisplayPaymentReason()); |
236
|
|
|
|
237
|
|
|
// Disable the feature, also assert returned instance |
238
|
|
|
$returned = $this->paymentSlip->setDisplayPaymentReason(false); |
239
|
|
|
$this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip', $returned); |
240
|
|
|
$this->assertFalse($this->paymentSlip->getDisplayPaymentReason()); |
241
|
|
|
|
242
|
|
|
// Re-enable the feature |
243
|
|
|
$this->paymentSlip->setDisplayPaymentReason(); |
244
|
|
|
$this->assertTrue($this->paymentSlip->getDisplayPaymentReason()); |
245
|
|
|
|
246
|
|
|
// Check if the data is disabled |
247
|
|
|
$this->paymentSlip->getPaymentSlipData()->setWithPaymentReason(false); |
248
|
|
|
$this->assertFalse($this->paymentSlip->getDisplayPaymentReason()); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Tests the setDisplayPaymentReason method with an invalid parameter |
253
|
|
|
* |
254
|
|
|
* @return void |
255
|
|
|
* @expectedException \InvalidArgumentException |
256
|
|
|
* @expectedExceptionMessage $displayPaymentReason is not a boolean. |
257
|
|
|
* @covers ::setDisplayPaymentReason |
258
|
|
|
* @covers ::isBool |
259
|
|
|
*/ |
260
|
|
|
public function testSetDisplayPaymentReasonInvalidParameter() |
261
|
|
|
{ |
262
|
|
|
$this->paymentSlip->setDisplayPaymentReason('true'); |
|
|
|
|
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Tests the getAllElements method |
267
|
|
|
* |
268
|
|
|
* @return void |
269
|
|
|
* @covers ::getAllElements |
270
|
|
|
*/ |
271
|
|
View Code Duplication |
public function testGetAllElements() |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$elements = $this->paymentSlip->getAllElements(); |
274
|
|
|
|
275
|
|
|
$expectedElements = array( |
276
|
|
|
'bankLeft', |
277
|
|
|
'bankRight', |
278
|
|
|
'recipientLeft', |
279
|
|
|
'recipientRight', |
280
|
|
|
'accountLeft', |
281
|
|
|
'accountRight', |
282
|
|
|
'amountFrancsLeft', |
283
|
|
|
'amountFrancsRight', |
284
|
|
|
'amountCentsLeft', |
285
|
|
|
'amountCentsRight', |
286
|
|
|
'payerLeft', |
287
|
|
|
'payerRight', |
288
|
|
|
'IbanLeft', |
289
|
|
|
'IbanRight', |
290
|
|
|
'paymentReason', |
291
|
|
|
); |
292
|
|
|
|
293
|
|
|
$this->assertElementsArray($expectedElements, $elements); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Tests the getAllElements method when no elements are shown |
298
|
|
|
* |
299
|
|
|
* @return void |
300
|
|
|
* @covers ::getAllElements |
301
|
|
|
*/ |
302
|
|
View Code Duplication |
public function testGetAllElementsNoElementsShown() |
|
|
|
|
303
|
|
|
{ |
304
|
|
|
$this->paymentSlip->setDisplayAccount(false); |
305
|
|
|
$this->paymentSlip->setDisplayAmount(false); |
306
|
|
|
$this->paymentSlip->setDisplayBank(false); |
307
|
|
|
$this->paymentSlip->setDisplayPayer(false); |
308
|
|
|
$this->paymentSlip->setDisplayRecipient(false); |
309
|
|
|
$this->paymentSlip->setDisplayIban(false); |
310
|
|
|
$this->paymentSlip->setDisplayPaymentReason(false); |
311
|
|
|
|
312
|
|
|
$elements = $this->paymentSlip->getAllElements(); |
313
|
|
|
|
314
|
|
|
$expectedElements = array(); |
315
|
|
|
|
316
|
|
|
$this->assertElementsArray($expectedElements, $elements); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Tests the getAllElements method when all data is disabled |
321
|
|
|
* |
322
|
|
|
* @return void |
323
|
|
|
* @covers ::getAllElements |
324
|
|
|
*/ |
325
|
|
View Code Duplication |
public function testGetAllElementsDisabledData() |
|
|
|
|
326
|
|
|
{ |
327
|
|
|
$paymentSlipData = $this->paymentSlip->getPaymentSlipData(); |
328
|
|
|
$paymentSlipData->setWithAccountNumber(false); |
329
|
|
|
$paymentSlipData->setWithAmount(false); |
330
|
|
|
$paymentSlipData->setWithBank(false); |
331
|
|
|
$paymentSlipData->setWithPayer(false); |
332
|
|
|
$paymentSlipData->setWithRecipient(false); |
333
|
|
|
$paymentSlipData->setWithPaymentReason(false); |
334
|
|
|
$paymentSlipData->setWithIban(false); |
335
|
|
|
|
336
|
|
|
$elements = $this->paymentSlip->getAllElements(); |
337
|
|
|
|
338
|
|
|
$expectedElements = array(); |
339
|
|
|
|
340
|
|
|
$this->assertElementsArray($expectedElements, $elements); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
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.