2016-05-11 01:55:04 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\AuthenticationRoute;
|
|
|
|
use api\tests\FunctionalTester;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
|
|
|
class ForgotPasswordCest {
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
/**
|
|
|
|
* @var AuthenticationRoute
|
|
|
|
*/
|
|
|
|
private $route;
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
public function _before(FunctionalTester $I) {
|
|
|
|
$this->route = new AuthenticationRoute($I);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWrongInput(FunctionalTester $I) {
|
|
|
|
$I->wantTo('see reaction on invalid input');
|
|
|
|
|
|
|
|
$this->route->forgotPassword();
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2017-01-24 02:20:13 +05:30
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_required',
|
|
|
|
],
|
2016-05-11 01:55:04 +05:30
|
|
|
]);
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('becauseimbatman!');
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'login' => 'error.login_not_exist',
|
|
|
|
],
|
|
|
|
]);
|
2016-05-11 01:55:04 +05:30
|
|
|
}
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
public function testForgotPasswordByEmail(FunctionalTester $I) {
|
|
|
|
$I->wantTo('create new password recover request by passing email');
|
|
|
|
$this->route->forgotPassword('admin@ely.by');
|
|
|
|
$this->assertSuccessResponse($I, false);
|
|
|
|
}
|
2016-05-11 01:55:04 +05:30
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
public function testForgotPasswordByUsername(FunctionalTester $I) {
|
|
|
|
$I->wantTo('create new password recover request by passing username');
|
|
|
|
$this->route->forgotPassword('Admin');
|
|
|
|
$this->assertSuccessResponse($I, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDataForFrequencyError(FunctionalTester $I) {
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->wantTo('get info about time to repeat recover password request');
|
2017-01-24 02:20:13 +05:30
|
|
|
$this->route->forgotPassword('Notch');
|
2016-05-11 01:55:04 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
2016-06-17 01:06:52 +05:30
|
|
|
'login' => 'error.recently_sent_message',
|
2016-05-11 01:55:04 +05:30
|
|
|
],
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
|
|
|
}
|
|
|
|
|
2017-01-24 02:20:13 +05:30
|
|
|
/**
|
|
|
|
* @param FunctionalTester $I
|
|
|
|
*/
|
|
|
|
private function assertSuccessResponse(FunctionalTester $I, bool $expectEmailMask = false): void {
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.canRepeatIn');
|
|
|
|
if ($expectEmailMask) {
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.emailMask');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 01:55:04 +05:30
|
|
|
}
|