Completed
Push — master ( e7a8c5...00b793 )
by Vuong
01:27
created

QrCodeWidgetTest::testValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-mfa
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\mfa;
9
10
use Yii;
11
12
use vxm\mfa\QrCodeWidget;
13
14
/**
15
 * Class QrCodeWidgetTest
16
 *
17
 * @author Vuong Minh <[email protected]>
18
 * @since 1.0.0
19
 */
20
class QrCodeWidgetTest extends TestCase
21
{
22
23
    public function testInvalidCall()
24
    {
25
        try {
26
            QrCodeWidget::widget();
27
        } catch (\Throwable $throwable) {
28
            $this->assertTrue($throwable instanceof \yii\base\InvalidCallException);
29
        }
30
    }
31
32
    /**
33
     * @depends testInvalidCall
34
     */
35
    public function testMissingLabel()
36
    {
37
        $identity = Identity::findIdentity('user1');
38
        Yii::$app->user->login($identity);
39
        Yii::$app->user->switchIdentityLoggedIn();
40
41
        try {
42
            QrCodeWidget::widget();
43
        } catch (\Throwable $throwable) {
44
            $this->assertTrue($throwable instanceof \Assert\InvalidArgumentException);
45
        }
46
    }
47
48
    /**
49
     * @depends testMissingLabel
50
     */
51
    public function testValid()
52
    {
53
        $identity = Identity::findIdentity('user1');
54
        Yii::$app->user->login($identity);
55
        Yii::$app->user->switchIdentityLoggedIn();
56
57
        $result = QrCodeWidget::widget([
58
            'label' => 'vxm',
59
            'image' => 'https://abc.com',
60
            'issuer' => 'Test'
61
        ]);
62
        $this->assertNotEmpty($result);
63
    }
64
65
}
66