2016-01-21 02:44:29 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\_support\models\authentication;
|
2016-01-21 02:44:29 +05:30
|
|
|
|
2017-09-19 22:36:16 +05:30
|
|
|
use api\components\User\AuthenticationResult;
|
2016-05-14 05:17:17 +05:30
|
|
|
use api\models\authentication\ConfirmEmailForm;
|
2019-02-23 04:41:57 +05:30
|
|
|
use api\tests\unit\TestCase;
|
2016-01-21 02:44:29 +05:30
|
|
|
use common\models\Account;
|
2016-05-30 05:14:17 +05:30
|
|
|
use common\models\AccountSession;
|
2016-01-21 02:44:29 +05:30
|
|
|
use common\models\EmailActivation;
|
2019-02-21 01:28:52 +05:30
|
|
|
use common\tests\fixtures\EmailActivationFixture;
|
2016-01-21 02:44:29 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class ConfirmEmailFormTest extends TestCase {
|
2016-01-21 02:44:29 +05:30
|
|
|
|
2019-05-14 04:28:29 +05:30
|
|
|
public function _fixtures(): array {
|
2016-01-21 02:44:29 +05:30
|
|
|
return [
|
2016-05-16 04:03:19 +05:30
|
|
|
'emailActivations' => EmailActivationFixture::class,
|
2016-01-21 02:44:29 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function testConfirm() {
|
|
|
|
$fixture = $this->tester->grabFixture('emailActivations', 'freshRegistrationConfirmation');
|
|
|
|
$model = $this->createModel($fixture['key']);
|
|
|
|
$result = $model->confirm();
|
2017-09-19 22:36:16 +05:30
|
|
|
$this->assertInstanceOf(AuthenticationResult::class, $result);
|
2016-10-29 03:17:31 +05:30
|
|
|
$this->assertInstanceOf(AccountSession::class, $result->getSession(), 'session was generated');
|
|
|
|
$activationExists = EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists();
|
|
|
|
$this->assertFalse($activationExists, 'email activation key is not exist');
|
2016-12-04 22:26:49 +05:30
|
|
|
/** @var Account $account */
|
|
|
|
$account = Account::findOne($fixture['account_id']);
|
2019-02-26 04:56:02 +05:30
|
|
|
$this->assertSame(Account::STATUS_ACTIVE, $account->status, 'user status changed to active');
|
2016-10-29 03:17:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private function createModel($key) {
|
2016-01-21 02:44:29 +05:30
|
|
|
return new ConfirmEmailForm([
|
|
|
|
'key' => $key,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|