Issues (50)

tests/OrangePaymentSlipTest.php (10 issues)

Labels
Severity
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\OrangePaymentSlip;
16
use SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlipData;
17
18
/**
19
 * Tests for the OrangePaymentSlip class
20
 *
21
 * @coversDefaultClass SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip
22
 */
23
class OrangePaymentSlipTest extends PaymentSlipTestCase
24
{
25
    /**
26
     * The object under test
27
     *
28
     * @var OrangePaymentSlip
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 OrangePaymentSlipData();
40
        $this->paymentSlip = new OrangePaymentSlip($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\OrangePaymentSlipData',
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_orange.gif', basename($this->paymentSlip->getSlipBackground()));
94
    }
95
96
    /**
97
     * Tests the default attributes of the left reference number element
98
     *
99
     * @return void
100
     * @covers ::setDefaults
101
     */
102
    public function testReferenceNumberLeftAttrDefaultValues()
103
    {
104
        $attributes = $this->paymentSlip->getReferenceNumberLeftAttr();
105
106
        $expectedAttributes = $this->defaultAttributes;
107
108
        $expectedAttributes['PosX'] = 3;
109
        $expectedAttributes['PosY'] = 60;
110
        $expectedAttributes['Width'] = 50;
111
        $expectedAttributes['Height'] = 4;
112
        $expectedAttributes['FontSize'] = 8;
113
114
        $this->assertEquals($expectedAttributes, $attributes);
115
    }
116
117
    /**
118
     * Tests the default attributes of the right reference number element
119
     *
120
     * @return void
121
     * @covers ::setDefaults
122
     */
123
    public function testReferenceNumberRightAttrDefaultValues()
124
    {
125
        $attributes = $this->paymentSlip->getReferenceNumberRightAttr();
126
127
        $expectedAttributes = $this->defaultAttributes;
128
129
        $expectedAttributes['PosX'] = 125;
130
        $expectedAttributes['PosY'] = 33.5;
131
        $expectedAttributes['Width'] = 80;
132
        $expectedAttributes['Height'] = 4;
133
        $expectedAttributes['TextAlign'] = 'R';
134
135
        $this->assertEquals($expectedAttributes, $attributes);
136
    }
137
138
    /**
139
     * Tests the default attributes of the code line element
140
     *
141
     * @return void
142
     * @covers ::setDefaults
143
     */
144
    public function testCodeLineAttrDefaultValues()
145
    {
146
        $attributes = $this->paymentSlip->getCodeLineAttr();
147
148
        $expectedAttributes = $this->defaultAttributes;
149
150
        $expectedAttributes['PosX'] = 64;
151
        $expectedAttributes['PosY'] = 85;
152
        $expectedAttributes['Width'] = 140;
153
        $expectedAttributes['Height'] = 4;
154
        $expectedAttributes['FontFamily'] = 'OCRB10';
155
        $expectedAttributes['TextAlign'] = 'R';
156
157
        $this->assertEquals($expectedAttributes, $attributes);
158
    }
159
160
    /**
161
     * Tests the setReferenceNumberLeftAttr method
162
     *
163
     * @return void
164
     * @covers ::setReferenceNumberLeftAttr
165
     * @covers ::setAttributes
166
     * @covers ::getReferenceNumberLeftAttr
167
     */
168
    public function testSetReferenceNumberLeftAttr()
169
    {
170
        $returned = $this->paymentSlip->setReferenceNumberLeftAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C');
0 ignored issues
show
'15' of type string is incompatible with the type double|null expected by parameter $lineHeight of SwissPaymentSlip\SwissPa...ferenceNumberLeftAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $returned = $this->paymentSlip->setReferenceNumberLeftAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', /** @scrutinizer ignore-type */ '15', 'C');
Loading history...
'1' of type string is incompatible with the type double|null expected by parameter $fontSize of SwissPaymentSlip\SwissPa...ferenceNumberLeftAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

170
        $returned = $this->paymentSlip->setReferenceNumberLeftAttr(123, 456, 987, 654, '#123456', 'Courier', /** @scrutinizer ignore-type */ '1', '#654321', '15', 'C');
Loading history...
171
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
172
        $this->assertEquals($this->setAttributes, $this->paymentSlip->getReferenceNumberLeftAttr());
173
    }
174
175
    /**
176
     * Tests the setReferenceNumberRightAttr method
177
     *
178
     * @return void
179
     * @covers ::setReferenceNumberRightAttr
180
     * @covers ::setAttributes
181
     * @covers ::getReferenceNumberRightAttr
182
     */
183
    public function testSetReferenceNumberRightAttr()
184
    {
185
        $returned = $this->paymentSlip->setReferenceNumberRightAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C');
0 ignored issues
show
'1' of type string is incompatible with the type double|null expected by parameter $fontSize of SwissPaymentSlip\SwissPa...erenceNumberRightAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

185
        $returned = $this->paymentSlip->setReferenceNumberRightAttr(123, 456, 987, 654, '#123456', 'Courier', /** @scrutinizer ignore-type */ '1', '#654321', '15', 'C');
Loading history...
'15' of type string is incompatible with the type double|null expected by parameter $lineHeight of SwissPaymentSlip\SwissPa...erenceNumberRightAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

185
        $returned = $this->paymentSlip->setReferenceNumberRightAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', /** @scrutinizer ignore-type */ '15', 'C');
Loading history...
186
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
187
        $this->assertEquals($this->setAttributes, $this->paymentSlip->getReferenceNumberRightAttr());
188
    }
189
190
    /**
191
     * Tests the setCodeLineAttr method
192
     *
193
     * @return void
194
     * @covers ::setCodeLineAttr
195
     * @covers ::setAttributes
196
     * @covers ::getCodeLineAttr
197
     */
198
    public function testSetCodeLineAttr()
199
    {
200
        $returned = $this->paymentSlip->setCodeLineAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', '15', 'C');
0 ignored issues
show
'1' of type string is incompatible with the type double|null expected by parameter $fontSize of SwissPaymentSlip\SwissPa...Slip::setCodeLineAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

200
        $returned = $this->paymentSlip->setCodeLineAttr(123, 456, 987, 654, '#123456', 'Courier', /** @scrutinizer ignore-type */ '1', '#654321', '15', 'C');
Loading history...
'15' of type string is incompatible with the type double|null expected by parameter $lineHeight of SwissPaymentSlip\SwissPa...Slip::setCodeLineAttr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

200
        $returned = $this->paymentSlip->setCodeLineAttr(123, 456, 987, 654, '#123456', 'Courier', '1', '#654321', /** @scrutinizer ignore-type */ '15', 'C');
Loading history...
201
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
202
        $this->assertEquals($this->setAttributes, $this->paymentSlip->getCodeLineAttr());
203
    }
204
205
    /**
206
     * Tests the setDisplayReferenceNr method
207
     *
208
     * @return void
209
     * @covers ::setDisplayReferenceNr
210
     * @covers ::getDisplayReferenceNr
211
     * @covers ::isBool
212
     */
213
    public function testSetDisplayReferenceNr()
214
    {
215
        // Test the default value
216
        $this->assertTrue($this->paymentSlip->getDisplayReferenceNr());
217
218
        // Disable the feature, also assert returned instance
219
        $returned = $this->paymentSlip->setDisplayReferenceNr(false);
220
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
221
        $this->assertFalse($this->paymentSlip->getDisplayReferenceNr());
222
223
        // Re-enable the feature
224
        $this->paymentSlip->setDisplayReferenceNr();
225
        $this->assertTrue($this->paymentSlip->getDisplayReferenceNr());
226
227
        // Check if the data is disabled
228
        $this->paymentSlip->getPaymentSlipData()->setWithReferenceNumber(false);
229
        $this->assertFalse($this->paymentSlip->getDisplayReferenceNr());
230
    }
231
232
    /**
233
     * Tests the setDisplayReferenceNr method with an invalid parameter
234
     *
235
     * @return void
236
     * @expectedException \InvalidArgumentException
237
     * @expectedExceptionMessage $displayReferenceNr is not a boolean.
238
     * @covers ::setDisplayReferenceNr
239
     * @covers ::isBool
240
     */
241
    public function testSetDisplayReferenceNrInvalidParameter()
242
    {
243
        $this->paymentSlip->setDisplayReferenceNr('true');
0 ignored issues
show
'true' of type string is incompatible with the type boolean expected by parameter $displayReferenceNr of SwissPaymentSlip\SwissPa...setDisplayReferenceNr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

243
        $this->paymentSlip->setDisplayReferenceNr(/** @scrutinizer ignore-type */ 'true');
Loading history...
244
    }
245
246
    /**
247
     * Tests the setDisplayCodeLine method
248
     *
249
     * @return void
250
     * @covers ::setDisplayCodeLine
251
     * @covers ::getDisplayCodeLine
252
     * @covers ::isBool
253
     */
254
    public function testSetDisplayCodeLine()
255
    {
256
        // Test the default value
257
        $this->assertTrue($this->paymentSlip->getDisplayCodeLine());
258
259
        // Disable feature, also check for returned instance
260
        $returned = $this->paymentSlip->setDisplayCodeLine(false);
261
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
262
        $this->assertFalse($this->paymentSlip->getDisplayCodeLine());
263
264
        // Re-enable the feature
265
        $this->paymentSlip->setDisplayCodeLine();
266
        $this->assertTrue($this->paymentSlip->getDisplayCodeLine());
267
268
        // Check if the data is disabled
269
        $this->paymentSlip->getPaymentSlipData()->setWithAccountNumber(true);
270
        $this->paymentSlip->getPaymentSlipData()->setWithReferenceNumber(false);
271
        $this->assertFalse($this->paymentSlip->getDisplayCodeLine());
272
273
        // Check if the data is disabled
274
        $this->paymentSlip->getPaymentSlipData()->setWithAccountNumber(false);
275
        $this->paymentSlip->getPaymentSlipData()->setWithReferenceNumber(true);
276
        $this->assertFalse($this->paymentSlip->getDisplayCodeLine());
277
    }
278
279
    /**
280
     * Tests the setDisplayCodeLine method with an invalid parameter
281
     *
282
     * @return void
283
     * @expectedException \InvalidArgumentException
284
     * @expectedExceptionMessage $displayCodeLine is not a boolean.
285
     * @covers ::setDisplayCodeLine
286
     * @covers ::isBool
287
     */
288
    public function testSetDisplayCodeLineInvalidParameter()
289
    {
290
        $this->paymentSlip->setDisplayCodeLine('true');
0 ignored issues
show
'true' of type string is incompatible with the type boolean expected by parameter $displayCodeLine of SwissPaymentSlip\SwissPa...p::setDisplayCodeLine(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

290
        $this->paymentSlip->setDisplayCodeLine(/** @scrutinizer ignore-type */ 'true');
Loading history...
291
    }
292
293
    /**
294
     * Tests the setReferenceNrFormatted method
295
     *
296
     * @return void
297
     * @covers ::setReferenceNrFormatted
298
     * @covers ::getReferenceNrFormatted
299
     * @covers ::isBool
300
     */
301
    public function testSetReferenceNrFormatted()
302
    {
303
        // Test the default value
304
        $this->assertTrue($this->paymentSlip->getReferenceNrFormatted());
305
306
        // Disable feature, also check for returned instance
307
        $returned = $this->paymentSlip->setReferenceNrFormatted(false);
308
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
309
        $this->assertFalse($this->paymentSlip->getReferenceNrFormatted());
310
311
        // Re-enable the feature
312
        $this->paymentSlip->setReferenceNrFormatted(true);
313
        $this->assertTrue($this->paymentSlip->getReferenceNrFormatted());
314
    }
315
316
    /**
317
     * Tests the setReferenceNrFormatted method with an invalid parameter
318
     *
319
     * @return void
320
     * @expectedException \InvalidArgumentException
321
     * @expectedExceptionMessage $referenceNrFormatted is not a boolean.
322
     * @covers ::setReferenceNrFormatted
323
     * @covers ::isBool
324
     */
325
    public function testSetReferenceNrFormattedInvalidParameter()
326
    {
327
        $this->paymentSlip->setReferenceNrFormatted('true');
0 ignored issues
show
'true' of type string is incompatible with the type boolean expected by parameter $referenceNrFormatted of SwissPaymentSlip\SwissPa...tReferenceNrFormatted(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

327
        $this->paymentSlip->setReferenceNrFormatted(/** @scrutinizer ignore-type */ 'true');
Loading history...
328
    }
329
330
    /**
331
     * Tests the setReferenceNrFillZeros method
332
     *
333
     * @return void
334
     * @covers ::setReferenceNrFillZeros
335
     * @covers ::getReferenceNrFillZeros
336
     * @covers ::isBool
337
     */
338
    public function testSetReferenceNrFillZeros()
339
    {
340
        // Test the default value
341
        $this->assertTrue($this->paymentSlip->getReferenceNrFillZeros());
342
343
        // Disable feature, also check for returned instance
344
        $returned = $this->paymentSlip->setReferenceNrFillZeros(false);
345
        $this->assertInstanceOf('SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip', $returned);
346
        $this->assertFalse($this->paymentSlip->getReferenceNrFillZeros());
347
348
        // Re-enable the feature
349
        $this->paymentSlip->setReferenceNrFillZeros(true);
350
        $this->assertTrue($this->paymentSlip->getReferenceNrFillZeros());
351
    }
352
353
    /**
354
     * Tests the setReferenceNrFillZeros method with an invalid parameter
355
     *
356
     * @return void
357
     * @expectedException \InvalidArgumentException
358
     * @expectedExceptionMessage $referenceNrFillZeros is not a boolean.
359
     * @covers ::setReferenceNrFillZeros
360
     * @covers ::isBool
361
     */
362
    public function testSetReferenceNrFillZerosInvalidParameter()
363
    {
364
        $this->paymentSlip->setReferenceNrFillZeros('true');
0 ignored issues
show
'true' of type string is incompatible with the type boolean expected by parameter $referenceNrFillZeros of SwissPaymentSlip\SwissPa...tReferenceNrFillZeros(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

364
        $this->paymentSlip->setReferenceNrFillZeros(/** @scrutinizer ignore-type */ 'true');
Loading history...
365
    }
366
367
    /**
368
     * Tests the getAllElements method
369
     *
370
     * @return void
371
     * @covers ::getAllElements
372
     */
373
    public function testGetAllElements()
374
    {
375
        $elements = $this->paymentSlip->getAllElements();
376
377
        $expectedElements = array(
378
            'bankLeft',
379
            'bankRight',
380
            'recipientLeft',
381
            'recipientRight',
382
            'accountLeft',
383
            'accountRight',
384
            'amountFrancsLeft',
385
            'amountFrancsRight',
386
            'amountCentsLeft',
387
            'amountCentsRight',
388
            'referenceNumberLeft',
389
            'referenceNumberRight',
390
            'payerLeft',
391
            'payerRight',
392
            'codeLine'
393
        );
394
395
        $this->assertElementsArray($expectedElements, $elements);
396
    }
397
398
    /**
399
     * Tests the getAllElements method when no elements are shown
400
     *
401
     * @return void
402
     * @covers ::getAllElements
403
     */
404
    public function testGetAllElementsNoElementsShown()
405
    {
406
        $this->paymentSlip->setDisplayAccount(false);
407
        $this->paymentSlip->setDisplayAmount(false);
408
        $this->paymentSlip->setDisplayBank(false);
409
        $this->paymentSlip->setDisplayPayer(false);
410
        $this->paymentSlip->setDisplayRecipient(false);
411
        $this->paymentSlip->setDisplayCodeLine(false);
412
        $this->paymentSlip->setDisplayReferenceNr(false);
413
414
        $elements = $this->paymentSlip->getAllElements();
415
416
        $expectedElements = array();
417
418
        $this->assertElementsArray($expectedElements, $elements);
419
    }
420
421
    /**
422
     * Tests the getAllElements method when all data is disabled
423
     *
424
     * @return void
425
     * @covers ::getAllElements
426
     */
427
    public function testGetAllElementsDisabledData()
428
    {
429
        $paymentSlipData = $this->paymentSlip->getPaymentSlipData();
430
        $paymentSlipData->setWithAccountNumber(false);
431
        $paymentSlipData->setWithAmount(false);
432
        $paymentSlipData->setWithBank(false);
433
        $paymentSlipData->setWithPayer(false);
434
        $paymentSlipData->setWithRecipient(false);
435
        $paymentSlipData->setWithReferenceNumber(false);
436
        $paymentSlipData->setWithBankingCustomerId(false);
437
438
        $elements = $this->paymentSlip->getAllElements();
439
440
        $expectedElements = array();
441
442
        $this->assertElementsArray($expectedElements, $elements);
443
    }
444
}
445