1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii2VN |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yiiviet\tests\unit\payment; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class OnePayTest |
12
|
|
|
* |
13
|
|
|
* @author Vuong Minh <[email protected]> |
14
|
|
|
* @since 1.0 |
15
|
|
|
*/ |
16
|
|
|
class OnePayTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \yiiviet\payment\onepay\PaymentGateway |
21
|
|
|
*/ |
22
|
|
|
public $gateway; |
23
|
|
|
|
24
|
|
|
public static function gatewayId(): string |
25
|
|
|
{ |
26
|
|
|
return 'OP'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @expectedException \yii\base\InvalidConfigException |
31
|
|
|
* @expectedExceptionMessage cannot be blank |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function testPurchase() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
// Valid |
36
|
|
|
$responseData = $this->purchase([ |
37
|
|
|
'ReturnURL' => 'http://localhost/', |
38
|
|
|
'OrderInfo' => time(), |
39
|
|
|
'Amount' => 500000, |
40
|
|
|
'TicketNo' => '127.0.0.1', |
41
|
|
|
'AgainLink' => 'http://localhost/', |
42
|
|
|
'Title' => 'Hello World', |
43
|
|
|
'MerchTxnRef' => time() |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
$this->assertTrue($responseData->getIsOk()); |
47
|
|
|
$this->assertTrue(isset($responseData['redirect_url'])); |
48
|
|
|
|
49
|
|
|
// Throws |
50
|
|
|
$this->purchase([ |
51
|
|
|
'ReturnURL' => 'http://localhost/', |
52
|
|
|
'TicketNo' => '127.0.0.1', |
53
|
|
|
'AgainLink' => 'http://localhost/' |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @expectedException \yii\base\InvalidConfigException |
59
|
|
|
* @expectedExceptionMessage cannot be blank |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function testPurchaseInternational() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
// Valid |
64
|
|
|
$this->gateway->international = true; |
65
|
|
|
$responseData = $this->purchase([ |
66
|
|
|
'ReturnURL' => 'http://localhost/', |
67
|
|
|
'OrderInfo' => time(), |
68
|
|
|
'Amount' => 500000, |
69
|
|
|
'TicketNo' => '127.0.0.1', |
70
|
|
|
'AgainLink' => 'http://localhost/', |
71
|
|
|
'Title' => 'Hello World', |
72
|
|
|
'MerchTxnRef' => time() |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
$this->assertTrue($responseData->getIsOk()); |
76
|
|
|
$this->assertTrue(isset($responseData['redirect_url'])); |
77
|
|
|
|
78
|
|
|
// Throws |
79
|
|
|
$this->purchase([ |
80
|
|
|
'ReturnURL' => 'http://localhost/', |
81
|
|
|
'TicketNo' => '127.0.0.1', |
82
|
|
|
'AgainLink' => 'http://localhost/' |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @expectedException \yii\base\InvalidConfigException |
88
|
|
|
* @expectedExceptionMessage cannot be blank |
89
|
|
|
*/ |
90
|
|
|
public function testQueryDR() |
91
|
|
|
{ |
92
|
|
|
// Valid |
93
|
|
|
$responseData = $this->queryDR([ |
94
|
|
|
'MerchTxnRef' => 1 |
95
|
|
|
]); |
96
|
|
|
|
97
|
|
|
$this->assertTrue($responseData->getIsOk()); |
98
|
|
|
|
99
|
|
|
// Throws |
100
|
|
|
$this->queryDR([]); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @expectedException \yii\base\InvalidConfigException |
105
|
|
|
* @expectedExceptionMessage cannot be blank |
106
|
|
|
*/ |
107
|
|
|
public function testQueryDRInternational() |
108
|
|
|
{ |
109
|
|
|
// Valid |
110
|
|
|
$this->gateway->international = true; |
111
|
|
|
$responseData = $this->queryDR([ |
112
|
|
|
'MerchTxnRef' => 1 |
113
|
|
|
]); |
114
|
|
|
|
115
|
|
|
$this->assertTrue($responseData->getIsOk()); |
116
|
|
|
|
117
|
|
|
// Throws |
118
|
|
|
$this->queryDR([]); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testVerifyRequestPurchaseSuccess() |
122
|
|
|
{ |
123
|
|
|
$result = $this->verifyRequestPurchaseSuccess(); |
124
|
|
|
$this->assertFalse($result); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testVerifyRequestPurchaseInternationalSuccess() |
128
|
|
|
{ |
129
|
|
|
$this->gateway->international = true; |
130
|
|
|
$result = $this->verifyRequestPurchaseSuccess(); |
131
|
|
|
|
132
|
|
|
$this->assertFalse($result); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testVerifyRequestIPN() |
136
|
|
|
{ |
137
|
|
|
$result = $this->verifyRequestIPN(); |
138
|
|
|
|
139
|
|
|
$this->assertFalse($result); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testVerifyRequestIPNInternational() |
143
|
|
|
{ |
144
|
|
|
$this->gateway->international = true; |
145
|
|
|
$result = $this->verifyRequestIPN(); |
146
|
|
|
|
147
|
|
|
$this->assertFalse($result); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
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.