SignupFormTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace frontend\tests\unit\models;
  3. use common\fixtures\UserFixture;
  4. use frontend\models\SignupForm;
  5. class SignupFormTest extends \Codeception\Test\Unit
  6. {
  7. /**
  8. * @var \frontend\tests\UnitTester
  9. */
  10. protected $tester;
  11. public function _before()
  12. {
  13. $this->tester->haveFixtures([
  14. 'user' => [
  15. 'class' => UserFixture::className(),
  16. 'dataFile' => codecept_data_dir() . 'user.php'
  17. ]
  18. ]);
  19. }
  20. public function testCorrectSignup()
  21. {
  22. $model = new SignupForm([
  23. 'username' => 'some_username',
  24. 'email' => 'some_email@example.com',
  25. 'password' => 'some_password',
  26. ]);
  27. $user = $model->signup();
  28. expect($user)->isInstanceOf('common\models\User');
  29. expect($user->username)->equals('some_username');
  30. expect($user->email)->equals('some_email@example.com');
  31. expect($user->validatePassword('some_password'))->true();
  32. }
  33. public function testNotCorrectSignup()
  34. {
  35. $model = new SignupForm([
  36. 'username' => 'troy.becker',
  37. 'email' => 'nicolas.dianna@hotmail.com',
  38. 'password' => 'some_password',
  39. ]);
  40. expect_not($model->signup());
  41. expect_that($model->getErrors('username'));
  42. expect_that($model->getErrors('email'));
  43. expect($model->getFirstError('username'))
  44. ->equals('This username has already been taken.');
  45. expect($model->getFirstError('email'))
  46. ->equals('This email address has already been taken.');
  47. }
  48. }