2016-08-06 19:06:24 +05:30
|
|
|
<?php
|
2019-09-18 04:44:05 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\tests\functional\dev\applications;
|
2016-08-06 19:06:24 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\IdentityInfoRoute;
|
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
|
|
use api\tests\FunctionalTester;
|
2016-08-06 19:06:24 +05:30
|
|
|
|
|
|
|
class IdentityInfoCest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var IdentityInfoRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
|
|
|
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new IdentityInfoRoute($I);
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
public function testGetErrorIfNoAccessToken(OauthSteps $I) {
|
|
|
|
$I->wantToTest('behavior when this endpoint called without Authorization header');
|
|
|
|
$this->route->info();
|
|
|
|
$I->canSeeResponseCodeIs(401);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'name' => 'Unauthorized',
|
|
|
|
'status' => 401,
|
|
|
|
'message' => 'Your request was made with invalid credentials.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-08-06 19:06:24 +05:30
|
|
|
public function testGetErrorIfNotEnoughPerms(OauthSteps $I) {
|
2019-02-21 01:28:52 +05:30
|
|
|
$I->wantToTest('behavior when this endpoint called with token, that have not enough scopes');
|
2016-08-06 19:06:24 +05:30
|
|
|
$accessToken = $I->getAccessToken();
|
|
|
|
$I->amBearerAuthenticated($accessToken);
|
|
|
|
$this->route->info();
|
|
|
|
$I->canSeeResponseCodeIs(403);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'name' => 'Forbidden',
|
|
|
|
'status' => 403,
|
2019-02-21 01:28:52 +05:30
|
|
|
'message' => 'You are not allowed to perform this action.',
|
2016-08-06 19:06:24 +05:30
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInfo(OauthSteps $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$accessToken = $I->getAccessToken(['account_info']);
|
2016-08-06 19:06:24 +05:30
|
|
|
$I->amBearerAuthenticated($accessToken);
|
|
|
|
$this->route->info();
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'id' => 1,
|
|
|
|
'uuid' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
|
|
|
'username' => 'Admin',
|
|
|
|
'registeredAt' => 1451775316,
|
|
|
|
'profileLink' => 'http://ely.by/u1',
|
|
|
|
'preferredLanguage' => 'en',
|
|
|
|
]);
|
|
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.email');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInfoWithEmail(OauthSteps $I) {
|
2017-09-19 22:36:16 +05:30
|
|
|
$accessToken = $I->getAccessToken(['account_info', 'account_email']);
|
2016-08-06 19:06:24 +05:30
|
|
|
$I->amBearerAuthenticated($accessToken);
|
|
|
|
$this->route->info();
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'id' => 1,
|
|
|
|
'uuid' => 'df936908-b2e1-544d-96f8-2977ec213022',
|
|
|
|
'username' => 'Admin',
|
|
|
|
'registeredAt' => 1451775316,
|
|
|
|
'profileLink' => 'http://ely.by/u1',
|
|
|
|
'preferredLanguage' => 'en',
|
|
|
|
'email' => 'admin@ely.by',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|