1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiiviet/yii2-payment |
4
|
|
|
* @copyright Copyright (c) 2017 Yii Viet |
5
|
|
|
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php) |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yiiviet\tests\unit\payment; |
9
|
|
|
|
10
|
|
|
use Yii; |
11
|
|
|
|
12
|
|
|
use yii\base\Action; |
13
|
|
|
use yii\web\Controller; |
14
|
|
|
|
15
|
|
|
use yiiviet\payment\VerifyFilter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Lớp VerifyFilterTest |
19
|
|
|
* |
20
|
|
|
* @author Vuong Minh <[email protected]> |
21
|
|
|
* @since 1.0.2 |
22
|
|
|
*/ |
23
|
|
|
class VerifyFilterTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
public static function gatewayId(): string |
27
|
|
|
{ |
28
|
|
|
return 'VTC'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @expectedException \yii\base\InvalidConfigException |
33
|
|
|
* @expectedExceptionMessage `commands` property must be set! |
34
|
|
|
*/ |
35
|
|
|
public function testMissingCommand() |
36
|
|
|
{ |
37
|
|
|
return new VerifyFilter([ |
38
|
|
|
'gateway' => $this->gateway |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @expectedException \yii\base\InvalidConfigException |
44
|
|
|
* @expectedExceptionMessage `gateway` property must be set! |
45
|
|
|
*/ |
46
|
|
|
public function testMissingGateway() |
47
|
|
|
{ |
48
|
|
|
return new VerifyFilter([ |
49
|
|
|
'commands' => [ |
50
|
|
|
'ipn' => 'IPN' |
51
|
|
|
] |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @expectedException \yii\web\ForbiddenHttpException |
57
|
|
|
*/ |
58
|
|
|
public function testInvalid() |
59
|
|
|
{ |
60
|
|
|
$_POST = [ |
61
|
|
|
'_method' => 'POST', |
62
|
|
|
'data' => '100000|||1|1|1|1', |
63
|
|
|
'signature' => '643679f173526028e6bb26c2bc1256a420e5713b92fdb44cb4740f3c7c204145a' |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
return (new VerifyFilter([ |
67
|
|
|
'gateway' => $this->gateway, |
68
|
|
|
'commands' => [ |
69
|
|
|
'ipn' => 'IPN' |
70
|
|
|
] |
71
|
|
|
]))->beforeAction(new Action('ipn', new Controller('test', Yii::$app))); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @depends testMissingCommand |
76
|
|
|
* @depends testMissingGateway |
77
|
|
|
* @depends testInvalid |
78
|
|
|
*/ |
79
|
|
|
public function test() |
80
|
|
|
{ |
81
|
|
|
$_POST = [ |
82
|
|
|
'_method' => 'POST', |
83
|
|
|
'data' => '100000|||1|1|1|1', |
84
|
|
|
'signature' => '643679f173526028e6bb26c2bc1256a420e5713b92fdb44cb4740f3c7c204145' |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
$behavior = new VerifyFilter([ |
88
|
|
|
'gateway' => $this->gateway, |
89
|
|
|
'commands' => [ |
90
|
|
|
'ipn' => 'IPN' |
91
|
|
|
] |
92
|
|
|
]); |
93
|
|
|
|
94
|
|
|
$this->assertTrue($behavior->beforeAction(new Action('ipn', new Controller('test', Yii::$app)))); |
95
|
|
|
$this->assertInstanceOf('\GatewayClients\DataInterface', $behavior->getVerifiedData()); |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|