|
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\Tests\ShaComposer\FakeShaComposer; |
|
15
|
|
|
use Ogone\Ecommerce\EcommercePaymentRequest; |
|
16
|
|
|
use Ogone\Tests\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
class EcommercePaymentRequestTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** @test */ |
|
21
|
|
|
public function IsValidWhenRequiredFieldsAreFilledIn() |
|
22
|
|
|
{ |
|
23
|
|
|
$paymentRequest = $this->provideMinimalPaymentRequest(); |
|
24
|
|
|
$paymentRequest->validate(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** @test */ |
|
28
|
|
|
public function IsValidWhenAllFieldsAreFilledIn() |
|
29
|
|
|
{ |
|
30
|
|
|
$paymentRequest = $this->provideCompletePaymentRequest(); |
|
31
|
|
|
$paymentRequest->validate(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @test |
|
36
|
|
|
* @expectedException \RuntimeException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function IsInvalidWhenFieldsAreMissing() |
|
39
|
|
|
{ |
|
40
|
|
|
$paymentRequest = new EcommercePaymentRequest(new FakeShaComposer); |
|
41
|
|
|
$paymentRequest->validate(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** @test */ |
|
45
|
|
|
public function UnimportantParamsUseMagicSetters() |
|
46
|
|
|
{ |
|
47
|
|
|
$paymentRequest = new EcommercePaymentRequest(new FakeShaComposer); |
|
48
|
|
|
$paymentRequest->setBgcolor('FFFFFF'); |
|
|
|
|
|
|
49
|
|
|
$this->assertEquals('FFFFFF', $paymentRequest->getBgcolor()); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @test |
|
54
|
|
|
* @dataProvider provideBadParameters |
|
55
|
|
|
* @expectedException \InvalidArgumentException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function BadParametersCauseExceptions($method, $value) |
|
58
|
|
|
{ |
|
59
|
|
|
$paymentRequest = new EcommercePaymentRequest(new FakeShaComposer); |
|
60
|
|
|
$paymentRequest->$method($value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
* @expectedException \BadMethodCallException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function UnknownMethodFails() |
|
68
|
|
|
{ |
|
69
|
|
|
$paymentRequest = new EcommercePaymentRequest(new FakeShaComposer); |
|
70
|
|
|
$paymentRequest->getFoobar(); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function provideBadParameters() |
|
74
|
|
|
{ |
|
75
|
|
|
$longString = str_repeat('longstring', 100); |
|
76
|
|
|
$notAUri = 'http://not a uri'; |
|
77
|
|
|
$longUri = "http://www.example.com/$longString"; |
|
78
|
|
|
|
|
79
|
|
|
return array( |
|
80
|
|
|
array('setAccepturl', $notAUri), |
|
81
|
|
|
array('setAmount', 10.50), |
|
82
|
|
|
array('setAmount', -1), |
|
83
|
|
|
array('setAmount', 1000000000000000), |
|
84
|
|
|
array('setBrand', 'Oxfam'), |
|
85
|
|
|
array('setCancelurl', $notAUri), |
|
86
|
|
|
array('setCancelurl', $longUri), |
|
87
|
|
|
array('setCurrency', 'Belgische Frank'), |
|
88
|
|
|
//array('setCustomername', ''), |
|
|
|
|
|
|
89
|
|
|
array('setDeclineurl', $notAUri), |
|
90
|
|
|
array('setDynamicTemplateUri', $notAUri), |
|
91
|
|
|
array('setEmail', 'foo @ bar'), |
|
92
|
|
|
array('setEmail', "[email protected]"), |
|
93
|
|
|
array('setExceptionurl', $notAUri), |
|
94
|
|
|
//array('setFeedbackMessage', ''), |
|
|
|
|
|
|
95
|
|
|
//array('setFeedbackParams', ''), |
|
|
|
|
|
|
96
|
|
|
array('setLanguage', 'West-Vlaams'), |
|
97
|
|
|
array('setOgoneUri', $notAUri), |
|
98
|
|
|
array('setOrderDescription', $longString), |
|
99
|
|
|
array('setOrderid', "Weird çh@®a©†€rs"), |
|
100
|
|
|
array('setOrderid', $longString), |
|
101
|
|
|
array('setOwnerAddress', $longString), |
|
102
|
|
|
array('setOwnercountry', 'Benidorm'), |
|
103
|
|
|
array('setOwnerPhone', $longString), |
|
104
|
|
|
array('setOwnerTown', $longString), |
|
105
|
|
|
array('setOwnerZip', $longString), |
|
106
|
|
|
array('setParamvar', $longString), |
|
107
|
|
|
array('setPaymentMethod', 'Digital'), |
|
108
|
|
|
array('setPspid', $longString), |
|
109
|
|
|
array('setOperation', 'UNKNOWN_OPERATION'), |
|
110
|
|
|
array('setOperation', EcommercePaymentRequest::OPERATION_REFUND), |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** @return EcommercePaymentRequest */ |
|
115
|
|
|
private function provideCompletePaymentRequest() |
|
116
|
|
|
{ |
|
117
|
|
|
$paymentRequest = $this->provideMinimalPaymentRequest(); |
|
118
|
|
|
|
|
119
|
|
|
$paymentRequest->setAccepturl('http://example.com/accept'); |
|
120
|
|
|
$paymentRequest->setDeclineurl('http://example.com/decline'); |
|
121
|
|
|
$paymentRequest->setExceptionurl('http://example.com/exception'); |
|
122
|
|
|
$paymentRequest->setCancelurl('http://example.com/cancel'); |
|
123
|
|
|
$paymentRequest->setBackurl('http://example.com/back'); |
|
124
|
|
|
$paymentRequest->setDynamicTemplateUri('http://example.com/template'); |
|
125
|
|
|
|
|
126
|
|
|
$paymentRequest->setCurrency('EUR'); |
|
127
|
|
|
$paymentRequest->setLanguage('nl_BE'); |
|
128
|
|
|
$paymentRequest->setPaymentMethod('CreditCard'); |
|
129
|
|
|
$paymentRequest->setBrand('VISA'); |
|
130
|
|
|
|
|
131
|
|
|
$paymentRequest->setFeedbackMessage("Thanks for ordering"); |
|
132
|
|
|
$paymentRequest->setFeedbackParams(array('amountOfProducts' => '5', 'usedCoupon' => 1)); |
|
133
|
|
|
$paymentRequest->setParamvar('aParamVar'); |
|
134
|
|
|
$paymentRequest->setOrderDescription("Four horses and a carriage"); |
|
135
|
|
|
|
|
136
|
|
|
$paymentRequest->setOwnerPhone('123456789'); |
|
137
|
|
|
|
|
138
|
|
|
$paymentRequest->setOperation(EcommercePaymentRequest::OPERATION_REQUEST_DIRECT_SALE); |
|
139
|
|
|
|
|
140
|
|
|
return $paymentRequest; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: