mirror of
https://github.com/elyby/accounts.git
synced 2024-12-05 21:19:04 +05:30
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
namespace api\tests\functional\accounts;
|
|
|
|
use api\tests\_pages\AccountsRoute;
|
|
use api\tests\functional\_steps\OauthSteps;
|
|
use api\tests\FunctionalTester;
|
|
use common\models\Account;
|
|
|
|
class ChangeUsernameCest {
|
|
|
|
/**
|
|
* @var AccountsRoute
|
|
*/
|
|
private $route;
|
|
|
|
public function _before(FunctionalTester $I) {
|
|
$this->route = new AccountsRoute($I);
|
|
}
|
|
|
|
public function _after() {
|
|
/** @var Account $account */
|
|
$account = Account::findOne(1);
|
|
$account->username = 'Admin';
|
|
$account->save();
|
|
}
|
|
|
|
public function testChangeUsername(FunctionalTester $I) {
|
|
$I->wantTo('change my nickname');
|
|
$id = $I->amAuthenticated();
|
|
|
|
$this->route->changeUsername($id, 'password_0', 'bruce_wayne');
|
|
$this->assertSuccessResponse($I);
|
|
}
|
|
|
|
public function testChangeUsernameNotAvailable(FunctionalTester $I) {
|
|
$I->wantTo('see, that nickname "in use" is not available');
|
|
$id = $I->amAuthenticated();
|
|
|
|
$this->route->changeUsername($id, 'password_0', 'Jon');
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseIsJson();
|
|
$I->canSeeResponseContainsJson([
|
|
'success' => false,
|
|
'errors' => [
|
|
'username' => 'error.username_not_available',
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function testChangeUsernameInternal(OauthSteps $I) {
|
|
$accessToken = $I->getAccessTokenByClientCredentialsGrant(['change_account_username', 'escape_identity_verification']);
|
|
$I->amBearerAuthenticated($accessToken);
|
|
|
|
$this->route->changeUsername(1, null, 'im_batman');
|
|
$this->assertSuccessResponse($I);
|
|
}
|
|
|
|
/**
|
|
* @param FunctionalTester $I
|
|
*/
|
|
private function assertSuccessResponse(FunctionalTester $I): void {
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseIsJson();
|
|
$I->canSeeResponseContainsJson([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
|
|
}
|