personal_area_php/frontend/tests/unit/models/VerifyEmailFormTest.php
2024-04-24 18:02:58 +03:00

56 lines
1.5 KiB
PHP

<?php
namespace frontend\tests\unit\models;
use common\fixtures\UserFixture;
use frontend\models\VerifyEmailForm;
class VerifyEmailFormTest extends \Codeception\Test\Unit
{
/**
* @var \frontend\tests\UnitTester
*/
protected $tester;
public function _before()
{
$this->tester->haveFixtures([
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'user.php'
]
]);
}
public function testVerifyWrongToken()
{
$this->tester->expectThrowable('\yii\base\InvalidArgumentException', function() {
new VerifyEmailForm('');
});
$this->tester->expectThrowable('\yii\base\InvalidArgumentException', function() {
new VerifyEmailForm('notexistingtoken_1391882543');
});
}
public function testAlreadyActivatedToken()
{
$this->tester->expectThrowable('\yii\base\InvalidArgumentException', function() {
new VerifyEmailForm('already_used_token_1548675330');
});
}
public function testVerifyCorrectToken()
{
$model = new VerifyEmailForm('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
$user = $model->verifyEmail();
verify($user)->instanceOf('common\models\User');
verify($user->username)->equals('test.test');
verify($user->email)->equals('test@mail.com');
verify($user->status)->equals(\common\models\User::STATUS_ACTIVE);
verify($user->validatePassword('Test1234'))->true();
}
}