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\PaymentSlipData; |
||
16 | |||
17 | /** |
||
18 | * Tests for the PaymentSlipData class |
||
19 | * |
||
20 | * @coversDefaultClass SwissPaymentSlip\SwissPaymentSlip\PaymentSlipData |
||
21 | */ |
||
22 | class PaymentSlipDataTest extends \PHPUnit_Framework_TestCase |
||
23 | { |
||
24 | /** |
||
25 | * The object under test |
||
26 | * |
||
27 | * @var PaymentSlipData |
||
28 | */ |
||
29 | protected $slipData; |
||
30 | |||
31 | /** |
||
32 | * Setup the object under test |
||
33 | * |
||
34 | * @return void |
||
35 | */ |
||
36 | protected function setUp() |
||
37 | { |
||
38 | $this->slipData = new TestablePaymentSlipData(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Tests the getWithBank and setWithBank methods |
||
43 | * |
||
44 | * @return void |
||
45 | * @covers ::setWithBank |
||
46 | * @covers ::getWithBank |
||
47 | * @covers ::isBool |
||
48 | * @covers ::setBankData |
||
49 | * @covers ::setBankName |
||
50 | * @covers ::setBankCity |
||
51 | * @covers ::getBankName |
||
52 | * @covers ::getBankCity |
||
53 | */ |
||
54 | public function testSetWithBank() |
||
55 | { |
||
56 | // Test default values |
||
57 | $this->assertEquals('', $this->slipData->getBankName()); |
||
58 | $this->assertEquals('', $this->slipData->getBankCity()); |
||
59 | $this->assertTrue($this->slipData->getWithBank()); |
||
60 | |||
61 | // Set data when enabled, also check for returned instance, also check for returned instance |
||
62 | $returned = $this->slipData->setBankData('Seldwyla Bank', '8001 Zürich'); |
||
63 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
64 | $this->assertEquals('Seldwyla Bank', $this->slipData->getBankName()); |
||
65 | $this->assertEquals('8001 Zürich', $this->slipData->getBankCity()); |
||
66 | |||
67 | // Disable feature, also check for returned instance |
||
68 | $returned = $this->slipData->setWithBank(false); |
||
69 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
70 | $this->assertFalse($this->slipData->getWithBank()); |
||
71 | |||
72 | // Re-enable feature, using no parameter |
||
73 | $this->slipData->setWithBank(); |
||
74 | $this->assertTrue($this->slipData->getWithBank()); |
||
75 | $this->assertEquals('', $this->slipData->getBankName()); |
||
76 | $this->assertEquals('', $this->slipData->getBankCity()); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Tests the setBankName method when disabled |
||
81 | * |
||
82 | * @return void |
||
83 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
84 | * @expectedExceptionMessage You are accessing the disabled bank name. You need to re-enable it first. |
||
85 | * @covers ::setBankName |
||
86 | */ |
||
87 | public function testSetBankNameWhenDisabled() |
||
88 | { |
||
89 | $this->slipData->setWithBank(false); |
||
90 | $this->slipData->setBankName(''); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Tests the getBankName method when disabled |
||
95 | * |
||
96 | * @return void |
||
97 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
98 | * @expectedExceptionMessage You are accessing the disabled bank name. You need to re-enable it first. |
||
99 | * @covers ::getBankName |
||
100 | */ |
||
101 | public function testGetBankNameWhenDisabled() |
||
102 | { |
||
103 | $this->slipData->setWithBank(false); |
||
104 | $this->slipData->getBankName(); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Tests the setBankCity method when disabled |
||
109 | * |
||
110 | * @return void |
||
111 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
112 | * @expectedExceptionMessage You are accessing the disabled bank city. You need to re-enable it first. |
||
113 | * @covers ::setBankCity |
||
114 | */ |
||
115 | public function testSetBankCityWhenDisabled() |
||
116 | { |
||
117 | $this->slipData->setWithBank(false); |
||
118 | $this->slipData->setBankCity(''); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Tests the getBankCity method when disabled |
||
123 | * |
||
124 | * @return void |
||
125 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
126 | * @expectedExceptionMessage You are accessing the disabled bank city. You need to re-enable it first. |
||
127 | * @covers ::getBankCity |
||
128 | */ |
||
129 | public function testGetBankCityWhenDisabled() |
||
130 | { |
||
131 | $this->slipData->setWithBank(false); |
||
132 | $this->slipData->getBankCity(); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Tests the setWithBank method with an invalid parameter |
||
137 | * |
||
138 | * @return void |
||
139 | * @expectedException \InvalidArgumentException |
||
140 | * @expectedExceptionMessage $withBank is not a boolean. |
||
141 | * @covers ::setWithBank |
||
142 | * @covers ::isBool |
||
143 | */ |
||
144 | public function testSetWithBankInvalidParameter() |
||
145 | { |
||
146 | $this->slipData->setWithBank(1); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Tests the getWithAccountNumber and setWithAccountNumber methods |
||
151 | * |
||
152 | * @return void |
||
153 | * @covers ::setWithAccountNumber |
||
154 | * @covers ::getWithAccountNumber |
||
155 | * @covers ::isBool |
||
156 | * @covers ::setAccountNumber |
||
157 | * @covers ::getAccountNumber |
||
158 | */ |
||
159 | public function testSetWithAccountNumber() |
||
160 | { |
||
161 | // Test default values |
||
162 | $this->assertEquals('', $this->slipData->getAccountNumber()); |
||
163 | $this->assertTrue($this->slipData->getWithAccountNumber()); |
||
164 | |||
165 | // Set data when enabled, also check for returned instance |
||
166 | $returned = $this->slipData->setAccountNumber('01-2345-6'); |
||
167 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
168 | $this->assertEquals('01-2345-6', $this->slipData->getAccountNumber()); |
||
169 | |||
170 | // Disable feature, also check for returned instance |
||
171 | $returned = $this->slipData->setWithAccountNumber(false); |
||
172 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
173 | |||
174 | // Re-enable feature, using no parameter |
||
175 | $this->slipData->setWithAccountNumber(); |
||
176 | $this->assertTrue($this->slipData->getWithAccountNumber()); |
||
177 | $this->assertEquals('', $this->slipData->getAccountNumber()); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Tests the setAccountNumber method when disabled |
||
182 | * |
||
183 | * @return void |
||
184 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
185 | * @expectedExceptionMessage You are accessing the disabled account number. You need to re-enable it first. |
||
186 | * @covers ::setAccountNumber |
||
187 | */ |
||
188 | public function testSetAccountNumberWhenDisabled() |
||
189 | { |
||
190 | $this->slipData->setWithAccountNumber(false); |
||
191 | $this->slipData->setAccountNumber(''); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Tests the getAccountNumber method when disabled |
||
196 | * |
||
197 | * @return void |
||
198 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
199 | * @expectedExceptionMessage You are accessing the disabled account number. You need to re-enable it first. |
||
200 | * @covers ::getAccountNumber |
||
201 | */ |
||
202 | public function testGetAccountNumberWhenDisabled() |
||
203 | { |
||
204 | $this->slipData->setWithAccountNumber(false); |
||
205 | $this->slipData->getAccountNumber(); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Tests the setAccountNumber method with an invalid parameter |
||
210 | * |
||
211 | * @return void |
||
212 | * @expectedException \InvalidArgumentException |
||
213 | * @expectedExceptionMessage $withAccountNumber is not a boolean. |
||
214 | * @covers ::setWithAccountNumber |
||
215 | * @covers ::isBool |
||
216 | */ |
||
217 | public function testSetWithAccountNumberInvalidParameter() |
||
218 | { |
||
219 | $this->slipData->setWithAccountNumber(1); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Tests the getWithRecipient and setWithRecipient methods |
||
224 | * |
||
225 | * @return void |
||
226 | * @covers ::setWithRecipient |
||
227 | * @covers ::getWithRecipient |
||
228 | * @covers ::isBool |
||
229 | * @covers ::setRecipientData |
||
230 | * @covers ::setRecipientLine1 |
||
231 | * @covers ::setRecipientLine2 |
||
232 | * @covers ::setRecipientLine3 |
||
233 | * @covers ::setRecipientLine4 |
||
234 | * @covers ::getRecipientLine1 |
||
235 | * @covers ::getRecipientLine2 |
||
236 | * @covers ::getRecipientLine3 |
||
237 | * @covers ::getRecipientLine4 |
||
238 | */ |
||
239 | public function testSetWithRecipient() |
||
240 | { |
||
241 | // Test default values |
||
242 | $this->assertEquals('', $this->slipData->getRecipientLine1()); |
||
243 | $this->assertEquals('', $this->slipData->getRecipientLine2()); |
||
244 | $this->assertEquals('', $this->slipData->getRecipientLine3()); |
||
245 | $this->assertEquals('', $this->slipData->getRecipientLine4()); |
||
246 | $this->assertTrue($this->slipData->getWithRecipient()); |
||
247 | |||
248 | // Set data when enabled, also check for returned instance |
||
249 | $returned = $this->slipData->setRecipientData('AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD'); |
||
250 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
251 | $this->assertEquals('AAAAAAAAAA', $this->slipData->getRecipientLine1()); |
||
252 | $this->assertEquals('BBBBBBBBBB', $this->slipData->getRecipientLine2()); |
||
253 | $this->assertEquals('CCCCCCCCCC', $this->slipData->getRecipientLine3()); |
||
254 | $this->assertEquals('DDDDDDDDDD', $this->slipData->getRecipientLine4()); |
||
255 | |||
256 | // Disable feature, also check for returned instance |
||
257 | $returned = $this->slipData->setWithRecipient(false); |
||
258 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
259 | $this->assertFalse($this->slipData->getWithRecipient()); |
||
260 | |||
261 | // Re-enable feature, using no parameter |
||
262 | $this->slipData->setWithRecipient(); |
||
263 | $this->assertTrue($this->slipData->getWithRecipient()); |
||
264 | $this->assertEquals('', $this->slipData->getRecipientLine1()); |
||
265 | $this->assertEquals('', $this->slipData->getRecipientLine2()); |
||
266 | $this->assertEquals('', $this->slipData->getRecipientLine3()); |
||
267 | $this->assertEquals('', $this->slipData->getRecipientLine4()); |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * Tests the setRecipientLine1 method when disabled |
||
272 | * |
||
273 | * @return void |
||
274 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
275 | * @expectedExceptionMessage You are accessing the disabled recipient line 1. You need to re-enable it first. |
||
276 | * @covers ::setRecipientLine1 |
||
277 | */ |
||
278 | public function testSetRecipientLine1WhenDisabled() |
||
279 | { |
||
280 | $this->slipData->setWithRecipient(false); |
||
281 | $this->slipData->setRecipientLine1(''); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Tests the getRecipientLine1 method when disabled |
||
286 | * |
||
287 | * @return void |
||
288 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
289 | * @expectedExceptionMessage You are accessing the disabled recipient line 1. You need to re-enable it first. |
||
290 | * @covers ::getRecipientLine1 |
||
291 | */ |
||
292 | public function testGetRecipientLine1WhenDisabled() |
||
293 | { |
||
294 | $this->slipData->setWithRecipient(false); |
||
295 | $this->slipData->getRecipientLine1(); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Tests the setRecipientLine2 method when disabled |
||
300 | * |
||
301 | * @return void |
||
302 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
303 | * @expectedExceptionMessage You are accessing the disabled recipient line 2. You need to re-enable it first. |
||
304 | * @covers ::setRecipientLine2 |
||
305 | */ |
||
306 | public function testSetRecipientLine2WhenDisabled() |
||
307 | { |
||
308 | $this->slipData->setWithRecipient(false); |
||
309 | $this->slipData->setRecipientLine2(''); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Tests the getRecipientLine2 method when disabled |
||
314 | * |
||
315 | * @return void |
||
316 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
317 | * @expectedExceptionMessage You are accessing the disabled recipient line 2. You need to re-enable it first. |
||
318 | * @covers ::getRecipientLine2 |
||
319 | */ |
||
320 | public function testGetRecipientLine2WhenDisabled() |
||
321 | { |
||
322 | $this->slipData->setWithRecipient(false); |
||
323 | $this->slipData->getRecipientLine2(); |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Tests the setRecipientLine3 method when disabled |
||
328 | * |
||
329 | * @return void |
||
330 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
331 | * @expectedExceptionMessage You are accessing the disabled recipient line 3. You need to re-enable it first. |
||
332 | * @covers ::setRecipientLine3 |
||
333 | */ |
||
334 | public function testSetRecipientLine3WhenDisabled() |
||
335 | { |
||
336 | $this->slipData->setWithRecipient(false); |
||
337 | $this->slipData->setRecipientLine3(''); |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Tests the getRecipientLine3 method when disabled |
||
342 | * |
||
343 | * @return void |
||
344 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
345 | * @expectedExceptionMessage You are accessing the disabled recipient line 3. You need to re-enable it first. |
||
346 | * @covers ::getRecipientLine3 |
||
347 | */ |
||
348 | public function testGetRecipientLine3WhenDisabled() |
||
349 | { |
||
350 | $this->slipData->setWithRecipient(false); |
||
351 | $this->slipData->getRecipientLine3(); |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * Tests the getRecipientLine4 method when disabled |
||
356 | * |
||
357 | * @return void |
||
358 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
359 | * @expectedExceptionMessage You are accessing the disabled recipient line 4. You need to re-enable it first. |
||
360 | * @covers ::getRecipientLine4 |
||
361 | */ |
||
362 | public function testGetRecipientLine4WhenDisabled() |
||
363 | { |
||
364 | $this->slipData->setWithRecipient(false); |
||
365 | $this->slipData->getRecipientLine4(); |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Tests the setRecipientLine4 method when disabled |
||
370 | * |
||
371 | * @return void |
||
372 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
373 | * @expectedExceptionMessage You are accessing the disabled recipient line 4. You need to re-enable it first. |
||
374 | * @covers ::setRecipientLine4 |
||
375 | */ |
||
376 | public function testSetRecipientLine4WhenDisabled() |
||
377 | { |
||
378 | $this->slipData->setWithRecipient(false); |
||
379 | $this->slipData->setRecipientLine4(''); |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * Tests the setWithRecipient method with an invalid parameter |
||
384 | * |
||
385 | * @return void |
||
386 | * @expectedException \InvalidArgumentException |
||
387 | * @expectedExceptionMessage $withRecipient is not a boolean. |
||
388 | * @covers ::setWithRecipient |
||
389 | * @covers ::isBool |
||
390 | */ |
||
391 | public function testSetWithRecipientInvalidParameter() |
||
392 | { |
||
393 | $this->slipData->setWithRecipient(1); |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * Tests the getWithAmount and setWithAmount methods |
||
398 | * |
||
399 | * @return void |
||
400 | * @covers ::setWithAmount |
||
401 | * @covers ::getWithAmount |
||
402 | * @covers ::isBool |
||
403 | * @covers ::setAmount |
||
404 | * @covers ::getAmount |
||
405 | */ |
||
406 | public function testSetWithAmount() |
||
407 | { |
||
408 | // Test default values |
||
409 | $this->assertEquals(0.0, $this->slipData->getAmount()); |
||
410 | $this->assertTrue($this->slipData->getWithAmount()); |
||
411 | |||
412 | // Set data when enabled, also check for returned instance |
||
413 | $returned = $this->slipData->setAmount(1234567.89); |
||
414 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
415 | $this->assertEquals(1234567.89, $this->slipData->getAmount()); |
||
416 | |||
417 | // Disable feature, also check for returned instance |
||
418 | $returned = $this->slipData->setWithAmount(false); |
||
419 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
420 | $this->assertFalse($this->slipData->getWithAmount()); |
||
421 | |||
422 | // Re-enable feature, using no parameter |
||
423 | $this->slipData->setWithAmount(); |
||
424 | $this->assertTrue($this->slipData->getWithAmount()); |
||
425 | $this->assertEquals(0.0, $this->slipData->getAmount()); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Tests the setAmount method when disabled |
||
430 | * |
||
431 | * @return void |
||
432 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
433 | * @expectedExceptionMessage You are accessing the disabled amount. You need to re-enable it first. |
||
434 | * @covers ::setAmount |
||
435 | */ |
||
436 | public function testSetAmountWhenDisabled() |
||
437 | { |
||
438 | $this->slipData->setWithAmount(false); |
||
439 | $this->slipData->setAmount(''); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
440 | } |
||
441 | |||
442 | /** |
||
443 | * Tests the getAmount method when disabled |
||
444 | * |
||
445 | * @return void |
||
446 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
447 | * @expectedExceptionMessage You are accessing the disabled amount. You need to re-enable it first. |
||
448 | * @covers ::getAmount |
||
449 | */ |
||
450 | public function testGetAmountWhenDisabled() |
||
451 | { |
||
452 | $this->slipData->setWithAmount(false); |
||
453 | $this->slipData->getAmount(); |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * Tests the setWithAmount method with an invalid parameter |
||
458 | * |
||
459 | * @return void |
||
460 | * @expectedException \InvalidArgumentException |
||
461 | * @expectedExceptionMessage $withAmount is not a boolean. |
||
462 | * @covers ::setWithAmount |
||
463 | * @covers ::isBool |
||
464 | */ |
||
465 | public function testSetWithAmountInvalidParameter() |
||
466 | { |
||
467 | $this->slipData->setWithAmount(1); |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Tests the getWithPayer and setWithPayer methods |
||
472 | * |
||
473 | * @return void |
||
474 | * @covers ::setWithPayer |
||
475 | * @covers ::getWithPayer |
||
476 | * @covers ::isBool |
||
477 | * @covers ::setPayerData |
||
478 | * @covers ::setPayerLine1 |
||
479 | * @covers ::setPayerLine2 |
||
480 | * @covers ::setPayerLine3 |
||
481 | * @covers ::setPayerLine4 |
||
482 | * @covers ::getPayerLine1 |
||
483 | * @covers ::getPayerLine2 |
||
484 | * @covers ::getPayerLine3 |
||
485 | * @covers ::getPayerLine4 |
||
486 | */ |
||
487 | public function testSetWithPayer() |
||
488 | { |
||
489 | // Test default values |
||
490 | $this->assertEquals('', $this->slipData->getPayerLine1()); |
||
491 | $this->assertEquals('', $this->slipData->getPayerLine2()); |
||
492 | $this->assertEquals('', $this->slipData->getPayerLine3()); |
||
493 | $this->assertEquals('', $this->slipData->getPayerLine4()); |
||
494 | $this->assertTrue($this->slipData->getWithPayer()); |
||
495 | |||
496 | // Set data when enabled, also check for returned instance |
||
497 | $returned = $this->slipData->setPayerData('AAAAAAAAAA', 'BBBBBBBBBB', 'CCCCCCCCCC', 'DDDDDDDDDD'); |
||
498 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
499 | $this->assertEquals('AAAAAAAAAA', $this->slipData->getPayerLine1()); |
||
500 | $this->assertEquals('BBBBBBBBBB', $this->slipData->getPayerLine2()); |
||
501 | $this->assertEquals('CCCCCCCCCC', $this->slipData->getPayerLine3()); |
||
502 | $this->assertEquals('DDDDDDDDDD', $this->slipData->getPayerLine4()); |
||
503 | |||
504 | // Disable feature, also check for returned instance |
||
505 | $returned = $this->slipData->setWithPayer(false); |
||
506 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
507 | $this->assertFalse($this->slipData->getWithPayer()); |
||
508 | |||
509 | // Re-enable feature, using no parameter |
||
510 | $this->slipData->setWithPayer(); |
||
511 | $this->assertTrue($this->slipData->getWithPayer()); |
||
512 | $this->assertEquals('', $this->slipData->getPayerLine1()); |
||
513 | $this->assertEquals('', $this->slipData->getPayerLine2()); |
||
514 | $this->assertEquals('', $this->slipData->getPayerLine3()); |
||
515 | $this->assertEquals('', $this->slipData->getPayerLine4()); |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Tests the setPayerLine1 method when disabled |
||
520 | * |
||
521 | * @return void |
||
522 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
523 | * @expectedExceptionMessage You are accessing the disabled payer line 1. You need to re-enable it first. |
||
524 | * @covers ::setPayerLine1 |
||
525 | */ |
||
526 | public function testSetPayerLine1WhenDisabled() |
||
527 | { |
||
528 | $this->slipData->setWithPayer(false); |
||
529 | $this->slipData->setPayerLine1(''); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Tests the getPayerLine1 method when disabled |
||
534 | * |
||
535 | * @return void |
||
536 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
537 | * @expectedExceptionMessage You are accessing the disabled payer line 1. You need to re-enable it first. |
||
538 | * @covers ::getPayerLine1 |
||
539 | */ |
||
540 | public function testGetPayerLine1WhenDisabled() |
||
541 | { |
||
542 | $this->slipData->setWithPayer(false); |
||
543 | $this->slipData->getPayerLine1(); |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * Tests the setPayerLine2 method when disabled |
||
548 | * |
||
549 | * @return void |
||
550 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
551 | * @expectedExceptionMessage You are accessing the disabled payer line 2. You need to re-enable it first. |
||
552 | * @covers ::setPayerLine2 |
||
553 | */ |
||
554 | public function testSetPayerLine2WhenDisabled() |
||
555 | { |
||
556 | $this->slipData->setWithPayer(false); |
||
557 | $this->slipData->setPayerLine2(''); |
||
558 | } |
||
559 | |||
560 | /** |
||
561 | * Tests the getPayerLine2 method when disabled |
||
562 | * |
||
563 | * @return void |
||
564 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
565 | * @expectedExceptionMessage You are accessing the disabled payer line 2. You need to re-enable it first. |
||
566 | * @covers ::getPayerLine2 |
||
567 | */ |
||
568 | public function testGetPayerLine2WhenDisabled() |
||
569 | { |
||
570 | $this->slipData->setWithPayer(false); |
||
571 | $this->slipData->getPayerLine2(); |
||
572 | } |
||
573 | |||
574 | /** |
||
575 | * Tests the setPayerLine3 method when disabled |
||
576 | * |
||
577 | * @return void |
||
578 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
579 | * @expectedExceptionMessage You are accessing the disabled payer line 3. You need to re-enable it first. |
||
580 | * @covers ::setPayerLine3 |
||
581 | */ |
||
582 | public function testSetPayerLine3WhenDisabled() |
||
583 | { |
||
584 | $this->slipData->setWithPayer(false); |
||
585 | $this->slipData->setPayerLine3(''); |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * Tests the getPayerLine3 method when disabled |
||
590 | * |
||
591 | * @return void |
||
592 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
593 | * @expectedExceptionMessage You are accessing the disabled payer line 3. You need to re-enable it first. |
||
594 | * @covers ::getPayerLine3 |
||
595 | */ |
||
596 | public function testGetPayerLine3WhenDisabled() |
||
597 | { |
||
598 | $this->slipData->setWithPayer(false); |
||
599 | $this->slipData->getPayerLine3(); |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * Tests the setPayerLine4 method when disabled |
||
604 | * |
||
605 | * @return void |
||
606 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
607 | * @expectedExceptionMessage You are accessing the disabled payer line 4. You need to re-enable it first. |
||
608 | * @covers ::setPayerLine4 |
||
609 | */ |
||
610 | public function testSetPayerLine4WhenDisabled() |
||
611 | { |
||
612 | $this->slipData->setWithPayer(false); |
||
613 | $this->slipData->setPayerLine4(''); |
||
614 | } |
||
615 | |||
616 | /** |
||
617 | * Tests the getPayerLine4 method when disabled |
||
618 | * |
||
619 | * @return void |
||
620 | * @expectedException \SwissPaymentSlip\SwissPaymentSlip\Exception\DisabledDataException |
||
621 | * @expectedExceptionMessage You are accessing the disabled payer line 4. You need to re-enable it first. |
||
622 | * @covers ::getPayerLine4 |
||
623 | */ |
||
624 | public function testGetPayerLine4WhenDisabled() |
||
625 | { |
||
626 | $this->slipData->setWithPayer(false); |
||
627 | $this->slipData->getPayerLine4(); |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | * Tests the setWithPayer method with an invalid parameter |
||
632 | * |
||
633 | * @return void |
||
634 | * @expectedException \InvalidArgumentException |
||
635 | * @expectedExceptionMessage $withPayer is not a boolean. |
||
636 | * @covers ::setWithPayer |
||
637 | * @covers ::isBool |
||
638 | */ |
||
639 | public function testSetWithPayerInvalidParameter() |
||
640 | { |
||
641 | $this->slipData->setWithPayer(1); |
||
642 | } |
||
643 | |||
644 | /** |
||
645 | * Tests the getAmountFrancs method |
||
646 | * |
||
647 | * @return void |
||
648 | * @covers ::getAmountFrancs |
||
649 | */ |
||
650 | public function testGetAmountFrancs() |
||
651 | { |
||
652 | // Test default value |
||
653 | $this->assertEquals(0, $this->slipData->getAmountFrancs()); |
||
654 | |||
655 | // Test with set value |
||
656 | $this->slipData->setAmount(1234567.89); |
||
657 | $this->assertEquals(1234567, $this->slipData->getAmountFrancs()); |
||
658 | } |
||
659 | |||
660 | /** |
||
661 | * Tests the getAmountCents method |
||
662 | * |
||
663 | * @return void |
||
664 | * @covers ::getAmountCents |
||
665 | */ |
||
666 | public function testGetAmountCents() |
||
667 | { |
||
668 | // Test default value |
||
669 | $this->assertEquals(0, $this->slipData->getAmountFrancs()); |
||
670 | |||
671 | // Test with set value |
||
672 | $this->slipData->setAmount(1234567.89); |
||
673 | $this->assertEquals(89, $this->slipData->getAmountCents()); |
||
674 | |||
675 | // Test with set value on amount with 0 after decimal point |
||
676 | $this->slipData->setAmount(1234567.05); |
||
677 | $this->assertEquals(05, $this->slipData->getAmountCents()); |
||
678 | |||
679 | // Test with set value on amount with 0 two positions after decimal point |
||
680 | // To show that it's still working as intended |
||
681 | $this->slipData->setAmount(1234567.50); |
||
682 | $this->assertEquals(50, $this->slipData->getAmountCents()); |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * Tests the setNotForPayment method |
||
687 | * |
||
688 | * @return void |
||
689 | * @covers ::setNotForPayment |
||
690 | * @covers ::getNotForPayment |
||
691 | * @covers ::getAmountFrancs |
||
692 | * @covers ::getAmountCents |
||
693 | */ |
||
694 | public function testSetNotForPayment() |
||
695 | { |
||
696 | // Test default values |
||
697 | $this->assertFalse($this->slipData->getNotForPayment()); |
||
698 | |||
699 | $this->assertEquals('', $this->slipData->getBankName()); |
||
700 | $this->assertEquals('', $this->slipData->getBankCity()); |
||
701 | |||
702 | $this->assertEquals('', $this->slipData->getRecipientLine1()); |
||
703 | $this->assertEquals('', $this->slipData->getRecipientLine2()); |
||
704 | $this->assertEquals('', $this->slipData->getRecipientLine3()); |
||
705 | $this->assertEquals('', $this->slipData->getRecipientLine4()); |
||
706 | |||
707 | $this->assertEquals('', $this->slipData->getAccountNumber()); |
||
708 | |||
709 | $this->assertEquals(0.0, $this->slipData->getAmount()); |
||
710 | $this->assertEquals(0, $this->slipData->getAmountFrancs()); |
||
711 | $this->assertEquals(0, $this->slipData->getAmountCents()); |
||
712 | |||
713 | $this->assertEquals('', $this->slipData->getPayerLine1()); |
||
714 | $this->assertEquals('', $this->slipData->getPayerLine2()); |
||
715 | $this->assertEquals('', $this->slipData->getPayerLine3()); |
||
716 | $this->assertEquals('', $this->slipData->getPayerLine4()); |
||
717 | |||
718 | $returned = $this->slipData->setNotForPayment(true); |
||
719 | $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\Tests\TestablePaymentSlipData', $returned); |
||
720 | $this->assertTrue($this->slipData->getNotForPayment()); |
||
721 | |||
722 | $this->assertEquals('XXXXXX', $this->slipData->getBankName()); |
||
723 | $this->assertEquals('XXXXXX', $this->slipData->getBankCity()); |
||
724 | |||
725 | $this->assertEquals('XXXXXX', $this->slipData->getRecipientLine1()); |
||
726 | $this->assertEquals('XXXXXX', $this->slipData->getRecipientLine2()); |
||
727 | $this->assertEquals('XXXXXX', $this->slipData->getRecipientLine3()); |
||
728 | $this->assertEquals('XXXXXX', $this->slipData->getRecipientLine4()); |
||
729 | |||
730 | $this->assertEquals('XXXXXX', $this->slipData->getAccountNumber()); |
||
731 | |||
732 | $this->assertEquals('XXXXXXXX.XX', $this->slipData->getAmount()); |
||
733 | $this->assertEquals('XXXXXXXX', $this->slipData->getAmountFrancs()); |
||
734 | $this->assertEquals('XX', $this->slipData->getAmountCents()); |
||
735 | |||
736 | $this->assertEquals('XXXXXX', $this->slipData->getPayerLine1()); |
||
737 | $this->assertEquals('XXXXXX', $this->slipData->getPayerLine2()); |
||
738 | $this->assertEquals('XXXXXX', $this->slipData->getPayerLine3()); |
||
739 | $this->assertEquals('XXXXXX', $this->slipData->getPayerLine4()); |
||
740 | } |
||
741 | |||
742 | /** |
||
743 | * Tests the setNotForPayment method when fields are disabled |
||
744 | * |
||
745 | * @return void |
||
746 | * @covers ::setNotForPayment |
||
747 | */ |
||
748 | public function testSetNotForPaymentDisabledFields() |
||
749 | { |
||
750 | $this->slipData->setWithAccountNumber(false); |
||
751 | $this->slipData->setWithAmount(false); |
||
752 | $this->slipData->setWithBank(false); |
||
753 | $this->slipData->setWithPayer(false); |
||
754 | $this->slipData->setWithRecipient(false); |
||
755 | |||
756 | $this->slipData->setNotForPayment(true); |
||
757 | } |
||
758 | } |
||
759 |