NganLuongTest::testPurchase32()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
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
use Yii;
12
13
/**
14
 * Class NganLuongTest
15
 *
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0
18
 */
19
class NganLuongTest extends TestCase
20
{
21
22
    const TOKEN = '58914-68d8693f31a5c6299813c4d26bb643c2';
23
24
    /**
25
     * @var \yiiviet\payment\nganluong\PaymentGateway
26
     */
27
    public $gateway;
28
29
30
    public static function gatewayId(): string
31
    {
32
        return 'NL';
33
    }
34
35
    /**
36
     * @expectedException \yii\base\InvalidConfigException
37
     * @expectedExceptionMessage cannot be blank
38
     */
39
    public function testPurchase()
40
    {
41
        // Valid
42
        $responseData = $this->purchase([
43
            'bank_code' => 'VCB',
44
            'buyer_fullname' => 'vxm',
45
            'buyer_email' => '[email protected]',
46
            'buyer_mobile' => '0909113911',
47
            'total_amount' => 10000000,
48
            'order_code' => microtime(),
49
            'return_url' => 'http://localhost'
50
        ]);
51
52
        $this->assertTrue($responseData->getIsOk());
53
        $this->assertTrue(isset($responseData['checkout_url']));
54
55
        // Throws
56
        $this->purchase([]);
57
58
    }
59
60
    /**
61
     * @expectedException \yii\base\InvalidConfigException
62
     * @expectedExceptionMessage cannot be blank
63
     */
64
    public function testQueryDR()
65
    {
66
        // Valid
67
        $responseData = $this->queryDR([
68
            'token' => self::TOKEN
69
        ]);
70
71
        $this->assertEquals('81', $responseData->error_code);
72
        $this->assertFalse($responseData->getIsOk());
73
74
        // Throws
75
        $this->queryDR([]);
76
    }
77
78
    /**
79
     * @expectedException \yii\base\InvalidConfigException
80
     * @expectedExceptionMessage cannot be blank
81
     */
82
    public function testAuthenticate()
83
    {
84
        // Valid
85
        $this->gateway->setVersion('3.2');
86
        $responseData = $this->gateway->authenticate([
87
            'token' => self::TOKEN,
88
            'otp' => '123321',
89
            'auth_url' => 'http://localhost'
90
        ]);
91
        $this->assertFalse($responseData->getIsOk());
92
93
        // Throws
94
        $this->gateway->authenticate([
95
            'token' => self::TOKEN,
96
            'otp' => '123321'
97
        ]);
98
    }
99
100
    public function testVerifyRequestPurchaseSuccess()
101
    {
102
        $_GET = [];
103
        $result = $this->verifyRequestPurchaseSuccess();
104
        $this->assertFalse($result);
105
    }
106
107
    /**
108
     * @expectedException \yii\base\InvalidConfigException
109
     * @expectedExceptionMessage cannot be blank
110
     */
111
    public function testPurchase32()
112
    {
113
        // Valid
114
        $this->gateway->setVersion('3.2');
115
        $responseData = $this->purchase([
116
            'bank_code' => 'VCB',
117
            'buyer_fullname' => 'vxm',
118
            'buyer_email' => '[email protected]',
119
            'buyer_mobile' => '0909113911',
120
            'total_amount' => 10000000,
121
            'order_code' => microtime(),
122
            'card_number' => '123123123',
123
            'card_fullname' => 'vxm',
124
            'card_month' => '01',
125
            'card_year' => '2012'
126
        ]);
127
128
        $this->assertFalse($responseData->getIsOk());
129
130
        // Throws
131
        $this->purchase([
132
            'bank_code' => 'VCB',
133
            'buyer_fullname' => 'vxm',
134
            'buyer_email' => '[email protected]',
135
            'buyer_mobile' => '0909113911',
136
            'total_amount' => 10000000,
137
            'order_code' => microtime()
138
        ]);
139
    }
140
}
141