mirror of
https://github.com/elyby/accounts.git
synced 2024-12-26 23:20:18 +05:30
bdc96d82c1
Добавлен механизм сохранения сессий и refresh_token
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
namespace tests\codeception\api;
|
|
|
|
use Codeception\Actor;
|
|
use InvalidArgumentException;
|
|
use tests\codeception\api\_pages\AuthenticationRoute;
|
|
|
|
/**
|
|
* Inherited Methods
|
|
* @method void wantToTest($text)
|
|
* @method void wantTo($text)
|
|
* @method void execute($callable)
|
|
* @method void expectTo($prediction)
|
|
* @method void expect($prediction)
|
|
* @method void amGoingTo($argumentation)
|
|
* @method void am($role)
|
|
* @method void lookForwardTo($achieveValue)
|
|
* @method void comment($description)
|
|
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
|
*
|
|
* @SuppressWarnings(PHPMD)
|
|
*/
|
|
class FunctionalTester extends Actor {
|
|
use _generated\FunctionalTesterActions;
|
|
|
|
public function loggedInAsActiveAccount($login = null, $password = null) {
|
|
$route = new AuthenticationRoute($this);
|
|
if ($login === null) {
|
|
$route->login('Admin', 'password_0');
|
|
} elseif ($login !== null && $password !== null) {
|
|
$route->login($login, $password);
|
|
} else {
|
|
throw new InvalidArgumentException('login and password should be presented both.');
|
|
}
|
|
|
|
$this->canSeeResponseIsJson();
|
|
$this->canSeeAuthCredentials(false);
|
|
$jwt = $this->grabDataFromResponseByJsonPath('$.access_token')[0];
|
|
$this->amBearerAuthenticated($jwt);
|
|
}
|
|
|
|
public function notLoggedIn() {
|
|
$this->haveHttpHeader('Authorization', null);
|
|
}
|
|
|
|
public function canSeeAuthCredentials($expectRefresh = false) {
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
if ($expectRefresh) {
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
} else {
|
|
$this->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
}
|
|
}
|
|
|
|
}
|