You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SignupFormTest.php 1.5KB

8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }