|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ShopPaymentTest extends FunctionalTest |
|
4
|
|
|
{ |
|
5
|
|
|
protected static $fixture_file = array( |
|
6
|
|
|
'silvershop/tests/fixtures/Pages.yml', |
|
7
|
|
|
'silvershop/tests/fixtures/shop.yml', |
|
8
|
|
|
); |
|
9
|
|
|
public static $disable_theme = true; |
|
10
|
|
|
|
|
11
|
|
|
public function setUpOnce() |
|
12
|
|
|
{ |
|
13
|
|
|
parent::setUpOnce(); |
|
14
|
|
|
// clear session |
|
15
|
|
|
ShoppingCart::singleton()->clear(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
ShopTest::setConfiguration(); |
|
22
|
|
|
|
|
23
|
|
|
//set supported gateways |
|
24
|
|
|
Payment::config()->allowed_gateways = array( |
|
25
|
|
|
'Dummy', //onsite |
|
26
|
|
|
'Manual', //manual |
|
27
|
|
|
'PaymentExpress_PxPay', //offsite |
|
28
|
|
|
'PaymentExpress_PxPost' //onsite |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
PaymentService::set_http_client($this->getHttpClient()); |
|
32
|
|
|
PaymentService::set_http_request($this->getHttpRequest()); |
|
33
|
|
|
|
|
34
|
|
|
//publish products |
|
35
|
|
|
$this->objFromFixture("Product", "socks")->publish('Stage', 'Live'); |
|
36
|
|
|
$this->objFromFixture("CheckoutPage", "checkout")->publish('Stage', 'Live'); |
|
37
|
|
|
$this->objFromFixture("CartPage", "cart")->publish('Stage', 'Live'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testManualPayment() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->markTestIncomplete("Process a manual payment"); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testOnsitePayment() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->markTestIncomplete("Process an onsite payment"); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testOffsitePayment() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->markTestIncomplete("Process an off-site payment"); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testOffsitePaymentWithGatewayCallback() |
|
56
|
|
|
{ |
|
57
|
|
|
//set up cart |
|
58
|
|
|
$cart = ShoppingCart::singleton() |
|
59
|
|
|
->setCurrent($this->objFromFixture("Order", "cart")) |
|
|
|
|
|
|
60
|
|
|
->current(); |
|
61
|
|
|
//collect checkout details |
|
62
|
|
|
$cart->update( |
|
63
|
|
|
array( |
|
64
|
|
|
'FirstName' => 'Foo', |
|
65
|
|
|
'Surname' => 'Bar', |
|
66
|
|
|
'Email' => '[email protected]', |
|
67
|
|
|
) |
|
68
|
|
|
); |
|
69
|
|
|
$cart->write(); |
|
70
|
|
|
//pay for order with external gateway |
|
71
|
|
|
$processor = OrderProcessor::create($cart); |
|
72
|
|
|
$this->setMockHttpResponse('paymentexpress/tests/Mock/PxPayPurchaseSuccess.txt'); |
|
73
|
|
|
$response = $processor->makePayment("PaymentExpress_PxPay", array()); |
|
74
|
|
|
//gateway responds (in a different session) |
|
75
|
|
|
$oldsession = $this->mainSession; |
|
76
|
|
|
$this->mainSession = new TestSession(); |
|
77
|
|
|
ShoppingCart::singleton()->clear(); |
|
78
|
|
|
$this->setMockHttpResponse('paymentexpress/tests/Mock/PxPayCompletePurchaseSuccess.txt'); |
|
79
|
|
|
$this->getHttpRequest()->query->replace(array('result' => 'abc123')); |
|
80
|
|
|
$identifier = $response->getPayment()->Identifier; |
|
81
|
|
|
$response = $this->get("paymentendpoint/$identifier/complete"); |
|
|
|
|
|
|
82
|
|
|
//reload cart as new order |
|
83
|
|
|
$order = Order::get()->byId($cart->ID); |
|
84
|
|
|
$this->assertFalse($order->isCart(), "order is no longer in cart"); |
|
|
|
|
|
|
85
|
|
|
$this->assertTrue($order->isPaid(), "order is paid"); |
|
|
|
|
|
|
86
|
|
|
//bring back client session |
|
87
|
|
|
$this->mainSession = $oldsession; |
|
88
|
|
|
$response = $this->get("paymentendpoint/$identifier/complete"); |
|
89
|
|
|
$this->assertNull(Session::get("shoppingcartid"), "cart session id should be removed"); |
|
|
|
|
|
|
90
|
|
|
$this->assertNotEquals(404, $response->getStatusCode(), "We shouldn't get page not found"); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
$this->markTestIncomplete("Should assert other things"); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
protected $payment; |
|
96
|
|
|
protected $httpClient; |
|
97
|
|
|
protected $httpRequest; |
|
98
|
|
|
|
|
99
|
|
|
protected function getHttpClient() |
|
100
|
|
|
{ |
|
101
|
|
|
if (null === $this->httpClient) { |
|
102
|
|
|
$this->httpClient = new Guzzle\Http\Client; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $this->httpClient; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getHttpRequest() |
|
109
|
|
|
{ |
|
110
|
|
|
if (null === $this->httpRequest) { |
|
111
|
|
|
$this->httpRequest = new Symfony\Component\HttpFoundation\Request; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $this->httpRequest; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
protected function setMockHttpResponse($paths) |
|
118
|
|
|
{ |
|
119
|
|
|
$testspath = BASE_PATH . '/vendor/omnipay'; |
|
120
|
|
|
$mock = new Guzzle\Plugin\Mock\MockPlugin(null, true); |
|
121
|
|
|
$this->getHttpClient()->getEventDispatcher()->removeSubscriber($mock); |
|
122
|
|
|
foreach ((array)$paths as $path) { |
|
123
|
|
|
$mock->addResponse($testspath . '/' . $path); |
|
124
|
|
|
} |
|
125
|
|
|
$this->getHttpClient()->getEventDispatcher()->addSubscriber($mock); |
|
126
|
|
|
|
|
127
|
|
|
return $mock; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.