Completed
Push — master ( b35ad3...2671f8 )
by Vuong
04:19
created

VTCPayTest::testVerifyPurchaseSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
9
namespace yiiviet\tests\unit\payment;
10
11
/**
12
 * Lớp VTCPayTest
13
 *
14
 * @author Vuong Minh <[email protected]>
15
 * @since 1.0.2
16
 */
17
class VTCPayTest extends TestCase
18
{
19
20
    /**
21
     * @var \yiiviet\payment\vtcpay\PaymentGateway
22
     */
23
    public $gateway;
24
25
    public static function gatewayId(): string
26
    {
27
        return 'VTC';
28
    }
29
30
    /**
31
     * @throws \ReflectionException|\yii\base\InvalidConfigException|\yii\base\NotSupportedException
32
     * @expectedException \yii\base\NotSupportedException
33
     */
34
    public function testQueryDR()
35
    {
36
        $this->gateway->queryDR([]);
37
    }
38
39
    /**
40
     * @expectedException \yii\base\InvalidArgumentException
41
     */
42
    public function testQueryDRViaGatewayCollection()
43
    {
44
        $this->queryDR([]);
45
    }
46
47
    public function testPurchase()
48
    {
49
        /** @var \yiiviet\payment\vtcpay\ResponseData $responseData */
50
        $responseData = $this->gateway->purchase([
51
            'amount' => 100000,
52
            'reference_number' => 1
53
        ]);
54
55
        $this->assertTrue($responseData->getIsOk());
56
        $this->assertContains('signature=1d31c0779f47e2bc3bfe40becf1fda0d7e881aeb90d8efb0341e258692cf896a', $responseData->redirect_url);
57
    }
58
59
    /**
60
     * @throws \ReflectionException|\yii\base\InvalidConfigException
61
     * @expectedException \yii\base\InvalidConfigException
62
     * @depends testPurchase
63
     */
64
    public function testInvalidPurchase()
65
    {
66
        $this->gateway->purchase([
67
            'amount' => 10000
68
        ]);
69
    }
70
71
    public function testVerifyIPN()
72
    {
73
        $_POST = [
74
            '_method' => 'POST',
75
            'data' => '100000|VND|0963465816|1|74132',
76
            'signature' => '1d31c0779f47e2bc3bfe40becf1fda0d7e881aeb90d8efb0341e258692cf896a'
77
        ];
78
79
        $this->assertInstanceOf('GatewayClients\DataInterface', $this->gateway->verifyRequestIPN());
80
    }
81
82
    /**
83
     * @depends testVerifyIPN
84
     */
85
    public function testInvalidVerifyIPN()
86
    {
87
        $_POST = [
88
            '_method' => 'POST',
89
            'data' => '100000|VND|0963465816|1|74132',
90
            'signature' => '1d31c0779f47e2bc3bfe40becf1fda0d7e881aeb90d8efb0341e258692cf896aa'
91
        ];
92
93
        $this->assertFalse($this->gateway->verifyRequestIPN());
94
    }
95
96
    public function testVerifyPurchaseSuccess()
97
    {
98
        $_GET = [
99
            'amount' => '100000',
100
            'status' => '1',
101
            'reference_number' => '1',
102
            'website_id' => '74132',
103
            'signature' => '1d31c0779f47e2bc3bfe40becf1fda0d7e881aeb90d8efb0341e258692cf896a'
104
        ];
105
106
        $this->assertFalse($this->gateway->verifyRequestPurchaseSuccess());
107
    }
108
}
109