Blame view

tests/codeception/frontend/unit/models/SignupFormTest.php 1.48 KB
b0f143c3   Yarik   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
  <?php
  
  namespace tests\codeception\frontend\unit\models;
  
  use tests\codeception\frontend\unit\DbTestCase;
  use tests\codeception\common\fixtures\UserFixture;
  use Codeception\Specify;
  use frontend\models\SignupForm;
  
  class SignupFormTest extends DbTestCase
  {
  
      use Specify;
  
      public function testCorrectSignup()
      {
          $model = new SignupForm([
              'username' => 'some_username',
              'email' => 'some_email@example.com',
              'password' => 'some_password',
          ]);
  
          $user = $model->signup();
  
          $this->assertInstanceOf('common\models\User', $user, 'user should be valid');
  
          expect('username should be correct', $user->username)->equals('some_username');
          expect('email should be correct', $user->email)->equals('some_email@example.com');
          expect('password should be correct', $user->validatePassword('some_password'))->true();
      }
  
      public function testNotCorrectSignup()
      {
          $model = new SignupForm([
              'username' => 'troy.becker',
              'email' => 'nicolas.dianna@hotmail.com',
              'password' => 'some_password',
          ]);
  
          expect('username and email are in use, user should not be created', $model->signup())->null();
      }
  
      public function fixtures()
      {
          return [
              'user' => [
                  'class' => UserFixture::className(),
                  'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',
              ],
          ];
      }
  }