VerifyEmailFormTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace frontend\tests\unit\models;
  3. use common\fixtures\UserFixture;
  4. use frontend\models\VerifyEmailForm;
  5. class VerifyEmailFormTest 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 testVerifyWrongToken()
  21. {
  22. $this->tester->expectException('\yii\base\InvalidArgumentException', function() {
  23. new VerifyEmailForm('');
  24. });
  25. $this->tester->expectException('\yii\base\InvalidArgumentException', function() {
  26. new VerifyEmailForm('notexistingtoken_1391882543');
  27. });
  28. }
  29. public function testAlreadyActivatedToken()
  30. {
  31. $this->tester->expectException('\yii\base\InvalidArgumentException', function() {
  32. new VerifyEmailForm('already_used_token_1548675330');
  33. });
  34. }
  35. public function testVerifyCorrectToken()
  36. {
  37. $model = new VerifyEmailForm('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
  38. $user = $model->verifyEmail();
  39. expect($user)->isInstanceOf('common\models\User');
  40. expect($user->username)->equals('test.test');
  41. expect($user->email)->equals('test@mail.com');
  42. expect($user->status)->equals(\common\models\User::STATUS_ACTIVE);
  43. expect($user->validatePassword('Test1234'))->true();
  44. }
  45. }