1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* @author Nicolas Clavaud <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Ogone\Tests\DirectLink; |
7
|
|
|
|
8
|
|
|
use Ogone\DirectLink\DirectLinkQueryResponse; |
9
|
|
|
|
10
|
|
View Code Duplication |
class DirectLinkQueryResponseTest extends \PHPUnit_Framework_TestCase |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @test |
15
|
|
|
* @expectedException InvalidArgumentException |
16
|
|
|
*/ |
17
|
|
|
public function CantExistWithoutXmlFile() |
18
|
|
|
{ |
19
|
|
|
$queryResponse = new DirectLinkQueryResponse(''); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** @test */ |
23
|
|
|
public function ParametersCanBeRetrieved() |
24
|
|
|
{ |
25
|
|
|
$xml = $this->provideXML(); |
26
|
|
|
|
27
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
28
|
|
|
$this->assertEquals('5', $queryResponse->getParam('orderid')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
* @expectedException InvalidArgumentException |
34
|
|
|
*/ |
35
|
|
|
public function RequestIsFilteredFromNonOgoneParameters() |
36
|
|
|
{ |
37
|
|
|
$xml = $this->provideXML(); |
38
|
|
|
|
39
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
40
|
|
|
$queryResponse->getParam('unknown_param'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
* @expectedException InvalidArgumentException |
46
|
|
|
*/ |
47
|
|
|
public function ChecksInvalidXml() |
48
|
|
|
{ |
49
|
|
|
$xml = $this->provideInvalidXML(); |
50
|
|
|
|
51
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @test */ |
55
|
|
|
public function ChecksStatus() |
56
|
|
|
{ |
57
|
|
|
$xml = $this->provideXML(); |
58
|
|
|
|
59
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
60
|
|
|
$this->assertTrue($queryResponse->isSuccessful()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** @test */ |
64
|
|
|
public function AmountIsConvertedToCent() |
65
|
|
|
{ |
66
|
|
|
$xml = $this->provideXML(); |
67
|
|
|
|
68
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
69
|
|
|
$this->assertEquals(450, $queryResponse->getParam('amount')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function provideFloats() |
73
|
|
|
{ |
74
|
|
|
return array( |
75
|
|
|
array('17.89', 1789), |
76
|
|
|
array('65.35', 6535), |
77
|
|
|
array('12.99', 1299), |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
* @dataProvider provideFloats |
84
|
|
|
*/ |
85
|
|
|
public function CorrectlyConvertsFloatAmountsToInteger($string, $integer) |
86
|
|
|
{ |
87
|
|
|
$xml = $this->provideXML($string); |
88
|
|
|
|
89
|
|
|
$queryResponse = new DirectLinkQueryResponse($xml); |
90
|
|
|
$this->assertEquals($integer, $queryResponse->getParam('amount')); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Helper method to setup an xml-string |
95
|
|
|
*/ |
96
|
|
|
private function provideXML($amount = null) |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
$xml = '<?xml version="1.0"?> |
100
|
|
|
<ncresponse |
101
|
|
|
orderID="5" |
102
|
|
|
PAYID="33146134" |
103
|
|
|
PAYIDSUB="" |
104
|
|
|
NCSTATUS="0" |
105
|
|
|
NCERROR="0" |
106
|
|
|
NCERRORPLUS="!" |
107
|
|
|
ACCEPTANCE="test123" |
108
|
|
|
STATUS="91" |
109
|
|
|
ECI="7" |
110
|
|
|
AMOUNT="'.(($amount) ? $amount : '4.5').'" |
111
|
|
|
CURRENCY="GBP" |
112
|
|
|
PM="CreditCard" |
113
|
|
|
BRAND="VISA" |
114
|
|
|
CARDNO="XXXXXXXXXXXX1111" |
115
|
|
|
IP="127.0.0.1"> |
116
|
|
|
</ncresponse>'; |
117
|
|
|
|
118
|
|
|
return $xml; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Helper method to setup an invalid xml-string |
123
|
|
|
*/ |
124
|
|
|
private function provideInvalidXML() |
125
|
|
|
{ |
126
|
|
|
$xml = '<?xml version="1.0"?> |
127
|
|
|
<ncresponse |
128
|
|
|
</ncresponse>'; |
129
|
|
|
|
130
|
|
|
return $xml; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
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.