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