2016-05-12 01:13:19 +03:00
|
|
|
<?php
|
2019-02-20 22:58:52 +03:00
|
|
|
namespace api\tests\_support\models\authentication;
|
2016-05-12 01:13:19 +03:00
|
|
|
|
2017-09-19 20:06:16 +03:00
|
|
|
use api\components\User\AuthenticationResult;
|
2016-05-14 02:47:17 +03:00
|
|
|
use api\models\authentication\RecoverPasswordForm;
|
2019-02-23 02:11:57 +03:00
|
|
|
use api\tests\unit\TestCase;
|
2016-05-12 01:13:19 +03:00
|
|
|
use common\models\Account;
|
|
|
|
use common\models\EmailActivation;
|
2019-02-20 22:58:52 +03:00
|
|
|
use common\tests\fixtures\EmailActivationFixture;
|
2016-05-12 01:13:19 +03:00
|
|
|
|
2016-10-29 00:47:31 +03:00
|
|
|
class RecoverPasswordFormTest extends TestCase {
|
2016-05-12 01:13:19 +03:00
|
|
|
|
2019-05-14 01:58:29 +03:00
|
|
|
public function _fixtures(): array {
|
2016-05-12 01:13:19 +03:00
|
|
|
return [
|
2016-05-16 01:33:19 +03:00
|
|
|
'emailActivations' => EmailActivationFixture::class,
|
2016-05-12 01:13:19 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecoverPassword() {
|
2016-10-29 00:47:31 +03:00
|
|
|
$fixture = $this->tester->grabFixture('emailActivations', 'freshPasswordRecovery');
|
|
|
|
$model = new RecoverPasswordForm([
|
|
|
|
'key' => $fixture['key'],
|
|
|
|
'newPassword' => '12345678',
|
|
|
|
'newRePassword' => '12345678',
|
|
|
|
]);
|
|
|
|
$result = $model->recoverPassword();
|
2017-09-19 20:06:16 +03:00
|
|
|
$this->assertInstanceOf(AuthenticationResult::class, $result);
|
2016-10-29 00:47:31 +03:00
|
|
|
$this->assertNull($result->getSession(), 'session was not generated');
|
|
|
|
$this->assertFalse(EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists());
|
|
|
|
/** @var Account $account */
|
|
|
|
$account = Account::findOne($fixture['account_id']);
|
|
|
|
$this->assertTrue($account->validatePassword('12345678'));
|
2016-05-12 01:13:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|