|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace QuickPay\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use QuickPay\API\Client; |
|
6
|
|
|
use QuickPay\API\Request; |
|
7
|
|
|
use QuickPay\API\Response; |
|
8
|
|
|
|
|
9
|
|
|
class RequestTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
protected $request; |
|
12
|
|
|
|
|
13
|
|
|
public function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
$client = new Client(); |
|
16
|
|
|
$this->request = new Request($client); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testResponseInstance() |
|
20
|
|
|
{ |
|
21
|
|
|
$pingResponse = $this->request->get('/ping'); |
|
22
|
|
|
|
|
23
|
|
|
$this->assertTrue(($pingResponse instanceof Response)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testBadAuthentication() |
|
27
|
|
|
{ |
|
28
|
|
|
$client = new Client(':foo'); |
|
29
|
|
|
$request = new Request($client); |
|
30
|
|
|
|
|
31
|
|
|
$response = $request->get('/ping'); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals(401, $response->httpStatus()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testSuccessfulGetResponse() |
|
37
|
|
|
{ |
|
38
|
|
|
$pingResponse = $this->request->get('/ping'); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertTrue($pingResponse->isSuccess()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFailedGetResponse() |
|
44
|
|
|
{ |
|
45
|
|
|
$pingResponse = $this->request->get('/foobar'); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertFalse($pingResponse->isSuccess()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testSuccesfulPostResponse() |
|
51
|
|
|
{ |
|
52
|
|
|
$pingResponse = $this->request->post('/ping'); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertTrue($pingResponse->isSuccess()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testFailedPostResponse() |
|
58
|
|
|
{ |
|
59
|
|
|
$pingResponse = $this->request->post('/foobar'); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertFalse($pingResponse->isSuccess()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Test function added to make sure that issue gh-54 is fixed. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testBasket() |
|
68
|
|
|
{ |
|
69
|
|
|
$basket = []; |
|
70
|
|
|
$basket[0] = [ |
|
71
|
|
|
'qty' => 1, |
|
72
|
|
|
'item_no' => 2, |
|
73
|
|
|
'item_name' => 'Test 1', |
|
74
|
|
|
'item_price' => 100, |
|
75
|
|
|
'vat_rate' => 0.25, |
|
76
|
|
|
]; |
|
77
|
|
|
$basket[1] = [ |
|
78
|
|
|
'qty' => 1, |
|
79
|
|
|
'item_no' => 2, |
|
80
|
|
|
'item_name' => 'Test 2', |
|
81
|
|
|
'item_price' => 100, |
|
82
|
|
|
'vat_rate' => 0.25, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
$form = [ |
|
86
|
|
|
'currency' => 'DKK', |
|
87
|
|
|
'order_id' => 1, |
|
88
|
|
|
'basket' => $basket, |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
|
|
$query = $this->request->httpBuildQuery($form); |
|
92
|
|
|
|
|
93
|
|
|
$expected = 'currency=DKK&order_id=1&basket[][qty]=1&basket[][item_no]=2&basket[][item_name]=Test 1&basket[][item_price]=100&basket[][vat_rate]=0.25&basket[][qty]=1&basket[][item_no]=2&basket[][item_name]=Test 2&basket[][item_price]=100&basket[][vat_rate]=0.25'; |
|
94
|
|
|
|
|
95
|
|
|
$this->assertEquals(urldecode($query), $expected); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|