2016-01-21 02:44:29 +05:30
|
|
|
<?php
|
2016-05-14 05:17:17 +05:30
|
|
|
namespace tests\codeception\api\models\authentication;
|
2016-01-21 02:44:29 +05:30
|
|
|
|
2016-05-30 05:14:17 +05:30
|
|
|
use api\components\User\LoginResult;
|
2016-05-14 05:17:17 +05:30
|
|
|
use api\models\authentication\ConfirmEmailForm;
|
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;
|
2016-10-29 03:17:31 +05:30
|
|
|
use tests\codeception\api\unit\TestCase;
|
2016-01-21 02:44:29 +05:30
|
|
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
class ConfirmEmailFormTest extends TestCase {
|
2016-01-21 02:44:29 +05:30
|
|
|
|
2016-10-29 03:17:31 +05:30
|
|
|
public function _fixtures() {
|
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();
|
|
|
|
$this->assertInstanceOf(LoginResult::class, $result);
|
|
|
|
$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');
|
|
|
|
/** @var Account $user */
|
|
|
|
$user = Account::findOne($fixture['account_id']);
|
|
|
|
$this->assertEquals(Account::STATUS_ACTIVE, $user->status, 'user status changed to active');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createModel($key) {
|
2016-01-21 02:44:29 +05:30
|
|
|
return new ConfirmEmailForm([
|
|
|
|
'key' => $key,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|