mirror of
https://github.com/elyby/accounts.git
synced 2024-10-30 15:33:21 +05:30
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
namespace tests\codeception\api\functional;
|
|
|
|
use common\models\Account;
|
|
use tests\codeception\api\_pages\AccountsRoute;
|
|
use tests\codeception\api\_pages\AuthenticationRoute;
|
|
use tests\codeception\api\functional\_steps\OauthSteps;
|
|
use tests\codeception\api\FunctionalTester;
|
|
|
|
class AccountsChangePasswordCest {
|
|
|
|
/**
|
|
* @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->setPassword('password_0');
|
|
$account->save();
|
|
}
|
|
|
|
public function testChangePassword(FunctionalTester $I) {
|
|
$I->wantTo('change my password');
|
|
$id = $I->amAuthenticated();
|
|
|
|
$this->route->changePassword($id, 'password_0', 'new-password', 'new-password');
|
|
$this->assertSuccessResponse($I);
|
|
|
|
$I->notLoggedIn();
|
|
|
|
$loginRoute = new AuthenticationRoute($I);
|
|
$loginRoute->login('Admin', 'new-password');
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseContainsJson([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
|
|
public function testChangePasswordInternal(OauthSteps $I) {
|
|
$accessToken = $I->getAccessTokenByClientCredentialsGrant(['change_account_password', 'escape_identity_verification']);
|
|
$I->amBearerAuthenticated($accessToken);
|
|
|
|
$this->route->changePassword(1, null, 'new-password-1', 'new-password-1');
|
|
$this->assertSuccessResponse($I);
|
|
}
|
|
|
|
private function assertSuccessResponse(FunctionalTester $I): void {
|
|
$I->canSeeResponseCodeIs(200);
|
|
$I->canSeeResponseIsJson();
|
|
$I->canSeeResponseContainsJson([
|
|
'success' => true,
|
|
]);
|
|
}
|
|
|
|
}
|