|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Marlon Ogone package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Marlon BVBA <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ogone\Tests\Ecommerce; |
|
13
|
|
|
|
|
14
|
|
|
use Ogone\PaymentResponse; |
|
15
|
|
|
use Ogone\Tests\ShaComposer\FakeShaComposer; |
|
16
|
|
|
use Ogone\Ecommerce\EcommercePaymentResponse; |
|
17
|
|
|
use InvalidArgumentException; |
|
18
|
|
|
|
|
19
|
|
|
class EcommercePaymentResponseTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @test */ |
|
22
|
|
|
public function CanBeVerified() |
|
23
|
|
|
{ |
|
24
|
|
|
$aRequest = $this->provideRequest(); |
|
25
|
|
|
|
|
26
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
27
|
|
|
$this->assertTrue($paymentResponse->isValid(new FakeShaComposer)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** @test */ |
|
31
|
|
|
public function CanBeConvertedToArray() |
|
32
|
|
|
{ |
|
33
|
|
|
$aRequest = $this->provideRequest(); |
|
34
|
|
|
|
|
35
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
36
|
|
|
$paymentResponse->isValid(new FakeShaComposer); |
|
37
|
|
|
$array = $paymentResponse->toArray(); |
|
38
|
|
|
$this->assertArrayHasKey('ORDERID', $array); |
|
39
|
|
|
$this->assertArrayHasKey('STATUS', $array); |
|
40
|
|
|
$this->assertArrayHasKey('AMOUNT', $array); |
|
41
|
|
|
$this->assertArrayHasKey('SHASIGN', $array); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @test |
|
47
|
|
|
* @expectedException InvalidArgumentException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function CannotExistWithoutShaSign() |
|
50
|
|
|
{ |
|
51
|
|
|
$paymentResponse = new EcommercePaymentResponse(array()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** @test */ |
|
55
|
|
View Code Duplication |
public function ParametersCanBeRetrieved() |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$aRequest = $this->provideRequest(); |
|
58
|
|
|
|
|
59
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
60
|
|
|
$this->assertEquals($aRequest['orderID'], $paymentResponse->getParam('orderid')); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
* @expectedException InvalidArgumentException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function RequestIsFilteredFromNonOgoneParameters() |
|
68
|
|
|
{ |
|
69
|
|
|
$aRequest = $this->provideRequest(); |
|
70
|
|
|
|
|
71
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
72
|
|
|
$paymentResponse->getParam('unknown_param'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** @test */ |
|
76
|
|
|
public function ChecksStatus() |
|
77
|
|
|
{ |
|
78
|
|
|
$aRequest = $this->provideRequest(); |
|
79
|
|
|
|
|
80
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
81
|
|
|
$this->assertTrue($paymentResponse->isSuccessful()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** @test */ |
|
85
|
|
|
public function AmountIsConvertedToCent() |
|
86
|
|
|
{ |
|
87
|
|
|
$aRequest = $this->provideRequest(); |
|
88
|
|
|
|
|
89
|
|
|
$paymentResponse = new EcommercePaymentResponse($aRequest); |
|
90
|
|
|
$this->assertEquals(100, $paymentResponse->getParam('amount')); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function provideFloats() |
|
94
|
|
|
{ |
|
95
|
|
|
return array( |
|
96
|
|
|
array('17.89', 1789), |
|
97
|
|
|
array('65.35', 6535), |
|
98
|
|
|
array('12.99', 1299), |
|
99
|
|
|
array('1.0', 100) |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @test |
|
105
|
|
|
* @expectedException InvalidArgumentException |
|
106
|
|
|
*/ |
|
107
|
|
|
public function InvalidForInvalidCurrency() |
|
108
|
|
|
{ |
|
109
|
|
|
$paymentResponse = new EcommercePaymentResponse(array('amount' => 'NaN', 'shasign' => '123')); |
|
110
|
|
|
$paymentResponse->getParam('amount'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @test |
|
115
|
|
|
* @dataProvider provideFloats |
|
116
|
|
|
*/ |
|
117
|
|
|
public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
|
118
|
|
|
{ |
|
119
|
|
|
$paymentResponse = new EcommercePaymentResponse(array('amount' => $string, 'shasign' => '123')); |
|
120
|
|
|
$this->assertEquals($integer, $paymentResponse->getParam('amount')); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Helper method to setup a request array |
|
125
|
|
|
*/ |
|
126
|
|
|
private function provideRequest() |
|
127
|
|
|
{ |
|
128
|
|
|
return array( |
|
129
|
|
|
'orderID' => '123', |
|
130
|
|
|
'SHASIGN' => FakeShaComposer::FAKESHASTRING, |
|
131
|
|
|
'UNKNOWN_PARAM' => false, /* unkown parameter, should be filtered out */ |
|
132
|
|
|
'status' => PaymentResponse::STATUS_AUTHORISED, |
|
133
|
|
|
'amount' => 1, |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.