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