VerifyEmailCest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace frontend\tests\functional;
  3. use common\fixtures\UserFixture;
  4. use frontend\tests\FunctionalTester;
  5. class VerifyEmailCest
  6. {
  7. /**
  8. * Load fixtures before db transaction begin
  9. * Called in _before()
  10. * @see \Codeception\Module\Yii2::_before()
  11. * @see \Codeception\Module\Yii2::loadFixtures()
  12. * @return array
  13. */
  14. public function _fixtures()
  15. {
  16. return [
  17. 'user' => [
  18. 'class' => UserFixture::className(),
  19. 'dataFile' => codecept_data_dir() . 'user.php',
  20. ],
  21. ];
  22. }
  23. public function checkEmptyToken(FunctionalTester $I)
  24. {
  25. $I->amOnRoute('site/verify-email', ['token' => '']);
  26. $I->canSee('Bad Request', 'h1');
  27. $I->canSee('Verify email token cannot be blank.');
  28. }
  29. public function checkInvalidToken(FunctionalTester $I)
  30. {
  31. $I->amOnRoute('site/verify-email', ['token' => 'wrong_token']);
  32. $I->canSee('Bad Request', 'h1');
  33. $I->canSee('Wrong verify email token.');
  34. }
  35. public function checkNoToken(FunctionalTester $I)
  36. {
  37. $I->amOnRoute('site/verify-email');
  38. $I->canSee('Bad Request', 'h1');
  39. $I->canSee('Missing required parameters: token');
  40. }
  41. public function checkAlreadyActivatedToken(FunctionalTester $I)
  42. {
  43. $I->amOnRoute('site/verify-email', ['token' => 'already_used_token_1548675330']);
  44. $I->canSee('Bad Request', 'h1');
  45. $I->canSee('Wrong verify email token.');
  46. }
  47. public function checkSuccessVerification(FunctionalTester $I)
  48. {
  49. $I->amOnRoute('site/verify-email', ['token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330']);
  50. $I->canSee('Your email has been confirmed!');
  51. $I->canSee('Congratulations!', 'h1');
  52. $I->see('Logout (test.test)', 'form button[type=submit]');
  53. $I->seeRecord('common\models\User', [
  54. 'username' => 'test.test',
  55. 'email' => 'test@mail.com',
  56. 'status' => \common\models\User::STATUS_ACTIVE
  57. ]);
  58. }
  59. }