2016-05-10 17:37:32 +05:30
|
|
|
<?php
|
|
|
|
namespace tests\codeception\api;
|
|
|
|
|
2017-01-08 17:25:28 +05:30
|
|
|
use api\components\User\LoginResult;
|
|
|
|
use api\models\authentication\LoginForm;
|
2016-05-16 13:51:12 +05:30
|
|
|
use Codeception\Actor;
|
|
|
|
use InvalidArgumentException;
|
2016-05-10 17:37:32 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2016-05-16 13:51:12 +05:30
|
|
|
class FunctionalTester extends Actor {
|
2016-05-10 17:37:32 +05:30
|
|
|
use _generated\FunctionalTesterActions;
|
|
|
|
|
2016-05-16 13:51:12 +05:30
|
|
|
public function loggedInAsActiveAccount($login = null, $password = null) {
|
2017-01-08 17:25:28 +05:30
|
|
|
$form = new LoginForm();
|
|
|
|
if ($login === null && $password === null) {
|
|
|
|
$form->login = 'Admin';
|
|
|
|
$form->password = 'password_0';
|
2016-05-16 13:51:12 +05:30
|
|
|
} elseif ($login !== null && $password !== null) {
|
2017-01-08 17:25:28 +05:30
|
|
|
$form->login = $login;
|
|
|
|
$form->password = $password;
|
2016-05-16 13:51:12 +05:30
|
|
|
} else {
|
|
|
|
throw new InvalidArgumentException('login and password should be presented both.');
|
|
|
|
}
|
|
|
|
|
2017-01-08 17:25:28 +05:30
|
|
|
$result = $form->login();
|
|
|
|
$this->assertInstanceOf(LoginResult::class, $result);
|
|
|
|
if ($result !== false) {
|
|
|
|
$this->amBearerAuthenticated($result->getJwt());
|
|
|
|
}
|
2016-05-10 17:37:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function notLoggedIn() {
|
|
|
|
$this->haveHttpHeader('Authorization', null);
|
|
|
|
}
|
|
|
|
|
2016-05-30 05:14:17 +05:30
|
|
|
public function canSeeAuthCredentials($expectRefresh = false) {
|
|
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
|
|
if ($expectRefresh) {
|
|
|
|
$this->canSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
|
|
} else {
|
|
|
|
$this->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-10 17:37:32 +05:30
|
|
|
}
|