選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

54 行
1.5KB

  1. <?php
  2. namespace tests\codeception\frontend\unit\models;
  3. use tests\codeception\frontend\unit\DbTestCase;
  4. use tests\codeception\common\fixtures\UserFixture;
  5. use Codeception\Specify;
  6. use frontend\models\SignupForm;
  7. class SignupFormTest extends DbTestCase
  8. {
  9. use Specify;
  10. public function testCorrectSignup()
  11. {
  12. $model = new SignupForm([
  13. 'username' => 'some_username',
  14. 'email' => 'some_email@example.com',
  15. 'password' => 'some_password',
  16. ]);
  17. $user = $model->signup();
  18. $this->assertInstanceOf('common\models\User', $user, 'user should be valid');
  19. expect('username should be correct', $user->username)->equals('some_username');
  20. expect('email should be correct', $user->email)->equals('some_email@example.com');
  21. expect('password should be correct', $user->validatePassword('some_password'))->true();
  22. }
  23. public function testNotCorrectSignup()
  24. {
  25. $model = new SignupForm([
  26. 'username' => 'troy.becker',
  27. 'email' => 'nicolas.dianna@hotmail.com',
  28. 'password' => 'some_password',
  29. ]);
  30. expect('username and email are in use, user should not be created', $model->signup())->null();
  31. }
  32. public function fixtures()
  33. {
  34. return [
  35. 'user' => [
  36. 'class' => UserFixture::className(),
  37. 'dataFile' => '@tests/codeception/frontend/unit/fixtures/data/models/user.php',
  38. ],
  39. ];
  40. }
  41. }