Initial commit

This commit is contained in:
Chris Smith
2025-02-19 14:51:16 +01:00
commit d82a6cad96
198 changed files with 13819 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace frontend\tests\unit\models;
use Yii;
use frontend\models\PasswordResetRequestForm;
use common\fixtures\UserFixture as UserFixture;
use common\models\User;
class PasswordResetRequestFormTest 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 testSendMessageWithWrongEmailAddress()
{
$model = new PasswordResetRequestForm();
$model->email = 'not-existing-email@example.com';
verify($model->sendEmail())->true();
}
public function testNotSendEmailsToInactiveUser()
{
$user = $this->tester->grabFixture('user', 1);
$model = new PasswordResetRequestForm();
$model->email = $user['email'];
// this is true because we do not want to display messages such as "email does not exist"
verify($model->sendEmail())->true();
}
public function testSendEmailSuccessfully()
{
$userFixture = $this->tester->grabFixture('user', 0);
$model = new PasswordResetRequestForm();
$model->email = $userFixture['email'];
$user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
verify($model->sendEmail())->notEmpty();
verify($user->password_reset_token)->notEmpty();
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace frontend\tests\unit\models;
use Codeception\Test\Unit;
use common\fixtures\UserFixture;
use frontend\models\ResendVerificationEmailForm;
class ResendVerificationEmailFormTest extends 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 testWrongEmailAddress()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'aaa@bbb.cc'
];
verify($model->validate())->false();
verify($model->hasErrors())->true();
verify($model->getFirstError('email'))->equals('There is no user with this email address.');
}
public function testEmptyEmailAddress()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => ''
];
verify($model->validate())->false();
verify($model->hasErrors())->true();
verify($model->getFirstError('email'))->equals('Email cannot be blank.');
}
public function testResendToActiveUser()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'test2@mail.com'
];
verify($model->validate())->true();
}
public function testSuccessfullyResend()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'test@mail.com'
];
verify($model->validate())->true();
verify($model->hasErrors())->false();
verify($model->sendEmail())->true();
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace frontend\tests\unit\models;
use common\fixtures\UserFixture;
use frontend\models\ResetPasswordForm;
use InvalidArgumentException;
class ResetPasswordFormTest 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 testResetWrongToken()
{
$this->tester->expectThrowable('yii\base\InvalidArgumentException', function() {
new ResetPasswordForm('');
});
$this->tester->expectThrowable('yii\base\InvalidArgumentException', function() {
new ResetPasswordForm('notexistingtoken_1391882543');
});
}
public function testResetCorrectToken()
{
$user = $this->tester->grabFixture('user', 0);
$form = new ResetPasswordForm($user['password_reset_token']);
verify($form->resetPassword())->notEmpty();
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace frontend\tests\unit\models;
use common\fixtures\UserFixture;
use frontend\models\SignupForm;
class SignupFormTest 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 testCorrectSignup()
{
$model = new SignupForm([
'first_name' => 'some_username',
'email' => 'some_email@example.com',
'password' => 'some_password',
]);
$user = $model->signup();
verify($user)->notEmpty();
/** @var \common\models\User $user */
$user = $this->tester->grabRecord('common\models\User', [
'first_name' => 'some_username',
'email' => 'some_email@example.com',
'status' => \common\models\User::STATUS_UNVERIFIED
]);
}
public function testEmailAlreadySignedUp()
{
$model = new SignupForm([
'first_name' => 'troy.becker',
'email' => 'nicolas.dianna@hotmail.com',
'password' => 'some_password',
]);
verify($model->signup())->empty();
verify($model->getErrors('first_name'))->empty();
verify($model->getErrors('email'))->notEmpty();
verify($model->getFirstError('email'))
->equals('This email address has already been taken.');
}
}

View File

@@ -0,0 +1,48 @@
<?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 testVerifyCorrectToken()
{
$model = new VerifyEmailForm('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
$user = $model->verifyEmail();
verify($user)->instanceOf('common\models\User');
verify($user->first_name)->equals('test.test');
verify($user->email)->equals('test@mail.com');
verify($user->status)->equals(\common\models\User::STATUS_VERIFIED);
verify($user->validatePassword('Test1234'))->true();
}
}