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 Codeception\Specify;
|
|
|
|
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;
|
|
|
|
use tests\codeception\api\unit\DbTestCase;
|
|
|
|
use tests\codeception\common\fixtures\EmailActivationFixture;
|
|
|
|
use Yii;
|
|
|
|
|
|
|
|
/**
|
2016-05-14 05:17:17 +05:30
|
|
|
* @property EmailActivationFixture $emailActivations
|
2016-01-21 02:44:29 +05:30
|
|
|
*/
|
|
|
|
class ConfirmEmailFormTest extends DbTestCase {
|
|
|
|
use Specify;
|
|
|
|
|
|
|
|
public function fixtures() {
|
|
|
|
return [
|
2016-05-16 04:03:19 +05:30
|
|
|
'emailActivations' => EmailActivationFixture::class,
|
2016-01-21 02:44:29 +05:30
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createModel($key) {
|
|
|
|
return new ConfirmEmailForm([
|
|
|
|
'key' => $key,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-03-21 02:03:09 +05:30
|
|
|
public function testConfirm() {
|
2016-05-11 01:10:06 +05:30
|
|
|
$fixture = $this->emailActivations['freshRegistrationConfirmation'];
|
2016-01-21 02:44:29 +05:30
|
|
|
$model = $this->createModel($fixture['key']);
|
|
|
|
$this->specify('expect true result', function() use ($model, $fixture) {
|
2016-05-30 05:14:17 +05:30
|
|
|
$result = $model->confirm();
|
|
|
|
expect($result)->isInstanceOf(LoginResult::class);
|
|
|
|
expect('session was generated', $result->getSession())->isInstanceOf(AccountSession::class);
|
2016-03-21 02:03:09 +05:30
|
|
|
$activationExists = EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists();
|
|
|
|
expect('email activation key is not exist', $activationExists)->false();
|
2016-01-21 02:44:29 +05:30
|
|
|
/** @var Account $user */
|
|
|
|
$user = Account::findOne($fixture['account_id']);
|
|
|
|
expect('user status changed to active', $user->status)->equals(Account::STATUS_ACTIVE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|