Blame view

frontend/tests/unit/models/PasswordResetRequestFormTest.php 2.03 KB
950817c6   Alex Savenko   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  <?php
      
      namespace frontend\tests\unit\models;
      
      use Yii;
      use frontend\models\PasswordResetRequestForm;
      use common\fixtures\User as UserFixture;
      use common\models\User;
      
      class PasswordResetRequestFormTest extends \Codeception\Test\Unit
      {
          /**
           * @var \frontend\tests\UnitTester
           */
          protected $tester;
          
          public function _before()
          {
              $this->tester->haveFixtures(
                  [
                      'user' => [
                          'class'    => UserFixture::className(),
                          'dataFile' => codecept_data_dir() . 'user.php',
                      ],
                  ]
              );
          }
          
          public function testSendMessageWithWrongEmailAddress()
          {
              $model = new PasswordResetRequestForm();
              $model->email = 'not-existing-email@example.com';
              expect_not($model->sendEmail());
          }
          
          public function testNotSendEmailsToInactiveUser()
          {
              $user = $this->tester->grabFixture('user', 1);
              $model = new PasswordResetRequestForm();
              $model->email = $user[ 'email' ];
              expect_not($model->sendEmail());
          }
          
          public function testSendEmailSuccessfully()
          {
              $userFixture = $this->tester->grabFixture('user', 0);
              
              $model = new PasswordResetRequestForm();
              $model->email = $userFixture[ 'email' ];
              $user = User::findOne([ 'password_reset_token' => $userFixture[ 'password_reset_token' ] ]);
              
              expect_that($model->sendEmail());
              expect_that($user->password_reset_token);
              
              $emailMessage = $this->tester->grabLastSentEmail();
              expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
              expect($emailMessage->getTo())->hasKey($model->email);
              expect($emailMessage->getFrom())->hasKey(Yii::$app->params[ 'supportEmail' ]);
          }
      }