SignupCest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace frontend\tests\functional;
  3. use frontend\tests\FunctionalTester;
  4. class SignupCest
  5. {
  6. protected $formId = '#form-signup';
  7. public function _before(FunctionalTester $I)
  8. {
  9. $I->amOnRoute('site/signup');
  10. }
  11. public function signupWithEmptyFields(FunctionalTester $I)
  12. {
  13. $I->see('注册', 'h1');
  14. $I->submitForm($this->formId, []);
  15. $I->seeValidationError('用户名不能为空');
  16. $I->seeValidationError('邮箱不能为空');
  17. $I->seeValidationError('密码不能为空');
  18. }
  19. public function signupWithWrongEmail(FunctionalTester $I)
  20. {
  21. $I->submitForm(
  22. $this->formId, [
  23. 'SignupForm[username]' => 'tester',
  24. 'SignupForm[email]' => 'ttttt',
  25. 'SignupForm[password]' => 'tester_password',
  26. ]
  27. );
  28. $I->dontSee('Username cannot be blank.', '.help-block');
  29. $I->dontSee('Password cannot be blank.', '.help-block');
  30. $I->see('邮箱不是有效的邮箱地址。', '.help-block');
  31. }
  32. public function signupSuccessfully(FunctionalTester $I)
  33. {
  34. $I->submitForm($this->formId, [
  35. 'SignupForm[username]' => 'tester',
  36. 'SignupForm[email]' => 'tester.email@example.com',
  37. 'SignupForm[password]' => 'tester_password',
  38. ]);
  39. $I->seeRecord('common\models\User', [
  40. 'username' => 'tester',
  41. 'email' => 'tester.email@example.com',
  42. ]);
  43. $I->see('退出登录');
  44. }
  45. }