SignupFormTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }