Completed
Push — master ( 20b8ce...b87dd6 )
by Alexey
05:19
created

testSendEmailSuccessfully()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
namespace frontend\tests\unit\models;
3
4
use Yii;
5
use modules\users\models\PasswordResetRequestForm;
6
use common\fixtures\User as UserFixture;
7
use modules\users\models\User;
8
9
/**
10
 * Class PasswordResetRequestFormTest
11
 * @package frontend\tests\unit\models
12
 */
13
class PasswordResetRequestFormTest extends \Codeception\Test\Unit
14
{
15
    /**
16
     * @var \frontend\tests\UnitTester
17
     */
18
    protected $tester;
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function _before()
24
    {
25
        $this->tester->haveFixtures([
26
            'user' => [
27
                'class' => UserFixture::className(),
28
                'dataFile' => codecept_data_dir() . 'user.php'
29
            ]
30
        ]);
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function testSendMessageWithWrongEmailAddress()
37
    {
38
        $model = new PasswordResetRequestForm();
39
        $model->email = '[email protected]';
40
        expect_not($model->sendEmail());
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function testNotSendEmailsToInactiveUser()
47
    {
48
        $user = $this->tester->grabFixture('user', 1);
49
        $model = new PasswordResetRequestForm();
50
        $model->email = $user['email'];
51
        expect_not($model->sendEmail());
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function testSendEmailSuccessfully()
58
    {
59
        $userFixture = $this->tester->grabFixture('user', 2);
60
        
61
        $model = new PasswordResetRequestForm();
62
        $model->email = $userFixture['email'];
63
        $user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
64
65
        expect_that($model->sendEmail());
66
        expect_that($user->password_reset_token);
67
68
        $emailMessage = $this->tester->grabLastSentEmail();
69
        expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
70
        expect($emailMessage->getTo())->hasKey($model->email);
71
        expect($emailMessage->getFrom())->hasKey(Yii::$app->params['supportEmail']);
72
    }
73
}
74