_bootstrap.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Here you can initialize variables via \Codeception\Util\Fixtures class
  4. * to store data in global array and use it in Cepts.
  5. *
  6. * ```php
  7. * // Here _bootstrap.php
  8. * \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
  9. * ```
  10. *
  11. * In Cept
  12. *
  13. * ```php
  14. * \Codeception\Util\Fixtures::get('user1');
  15. * ```
  16. */
  17. use backend\tests\AcceptanceTester;
  18. use yii\helpers\Url;
  19. function login(AcceptanceTester $I){
  20. static $cookie = null;
  21. static $cookieBackend = null;
  22. if ($cookieBackend == null || $cookie == null) {
  23. $I->amOnPage(Url::toRoute('/site/login'));
  24. $I->see('登录');
  25. $I->submitForm("button[name=login-button]", [
  26. 'LoginForm[username]' => "admin",
  27. 'LoginForm[password]' => 'password_0',
  28. 'LoginForm[captcha]' => 'testme',
  29. ]);
  30. $I->seeCookie('_csrf_backend');
  31. $cookie = $I->grabCookie("_csrf_backend");
  32. $I->seeCookie('BACKEND_FEEHICMS');
  33. $cookieBackend = $I->grabCookie("BACKEND_FEEHICMS");
  34. }
  35. $I->setCookie("_csrf_backend", $cookie);
  36. $I->setCookie("BACKEND_FEEHICMS", $cookieBackend);
  37. }