VTCPayTest::testInvalidPurchase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
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 testInvalidVerifyIPN()
72
    {
73
        $_POST = [
74
            '_method' => 'POST',
75
            'data' => '100000|||1|1|1|1',
76
            'signature' => '643679f173526028e6bb26c2bc1256a420e5713b92fdb44cb4740f3c7c204145a'
77
        ];
78
79
        $this->assertFalse($this->gateway->verifyRequestIPN());
80
    }
81
82
    /**
83
     * @depends testInvalidVerifyIPN
84
     */
85
    public function testVerifyIPN()
86
    {
87
        $_POST = [
88
            '_method' => 'POST',
89
            'data' => '100000|||1|1|1|1',
90
            'signature' => '643679f173526028e6bb26c2bc1256a420e5713b92fdb44cb4740f3c7c204145'
91
        ];
92
93
        $data = $this->gateway->verifyRequestIPN();
94
        $this->assertInstanceOf('GatewayClients\DataInterface', $data);
95
        $this->assertTrue(isset($data['amount']));
96
    }
97
98
    public function testVerifyPurchaseSuccess()
99
    {
100
        $_GET = [
101
            'amount' => '100000',
102
            'status' => '1',
103
            'reference_number' => '1',
104
            'website_id' => '74132',
105
            'signature' => '1d31c0779f47e2bc3bfe40becf1fda0d7e881aeb90d8efb0341e258692cf896a'
106
        ];
107
108
        $this->assertFalse($this->gateway->verifyRequestPurchaseSuccess());
109
    }
110
}
111