ChangePasswordFormTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testVerifyOldPassword() 0 20 1
A testResetPassword() 0 8 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: zjw
5
 * Date: 2017/8/17
6
 * Time: 下午5:04
7
 */
8
9
namespace zacksleo\yii2\backend\tests;
10
11
use yii\base\InvalidParamException;
12
use zacksleo\yii2\backend\models\Admin;
13
use zacksleo\yii2\backend\models\forms\ChangePasswordForm;
14
use yii;
15
16
class ChangePasswordFormTest extends TestCase
17
{
18
    public function setUp()
19
    {
20
        parent::setUp();
21
        $admin = Admin::findOne(1);
22
        Yii::$app->user->setIdentity($admin);
23
    }
24
25
    public function testVerifyOldPassword()
26
    {
27
        $form = new ChangePasswordForm();
28
        $form->old_password = "1!an1u0";
29
        $form->new_password = "1ian1uo";
30
        $form->new_password_repeat = "1ian1uo1";
31
        $this->assertFalse($form->validate());
32
33
        $form->new_password_repeat = "1ian1uo";
34
        $this->assertTrue($form->validate());
35
        $form->verifyOldPassword('old_password', []);
36
37
        $form->validate();
38
        $this->assertTrue(empty($form->getErrors()));
39
40
        $form->old_password = "1ianlu0";
41
        $form->verifyOldPassword('old_password', []);
42
        $form->validate();
43
        $this->assertFalse(empty($form->getErrors()));
44
    }
45
46
    public function testResetPassword()
47
    {
48
        $form = new ChangePasswordForm();
49
        $form->new_password = "lianluo";
50
        $this->assertTrue($form->resetPassword());
51
        $form->new_password = "1!an1u0";
52
        $this->assertTrue($form->resetPassword());
53
    }
54
}
55