Initial commit
This commit is contained in:
10
frontend/tests/_bootstrap.php
Normal file
10
frontend/tests/_bootstrap.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
|
||||
|
||||
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
|
||||
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
|
||||
require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php';
|
||||
require_once __DIR__ . '/../config/bootstrap.php';
|
||||
26
frontend/tests/_data/login_data.php
Normal file
26
frontend/tests/_data/login_data.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
|
||||
// password_0
|
||||
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
|
||||
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
|
||||
'created_at' => '1392559490',
|
||||
'status' => '1',
|
||||
'updated_at' => '1392559490',
|
||||
'email' => 'sfriesen@jenkins.info',
|
||||
'first_name' => 'sfriesen',
|
||||
],
|
||||
[
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
// Test1234
|
||||
'password_hash' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
'email' => 'test@mail.com',
|
||||
'first_name' => 'test',
|
||||
'status' => '9',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
];
|
||||
46
frontend/tests/_data/user.php
Normal file
46
frontend/tests/_data/user.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'first_name' => 'mister dude',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'first_name' => 'already taken',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
[
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
//Test1234
|
||||
'first_name' => 'test.test',
|
||||
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
|
||||
'email' => 'test@mail.com',
|
||||
'status' => 10,
|
||||
'sales_agent_id' => 0,
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
[
|
||||
'auth_key' => '4XXdVqi3rDpa_a6JH6zqVreFxUPcUPvJ',
|
||||
//Test1234
|
||||
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
|
||||
'email' => 'test2@mail.com',
|
||||
'status' => '10',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => 'already_used_token_1548675330',
|
||||
],
|
||||
];
|
||||
2
frontend/tests/_output/.gitignore
vendored
Normal file
2
frontend/tests/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
1
frontend/tests/_support/.gitignore
vendored
Normal file
1
frontend/tests/_support/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_generated
|
||||
34
frontend/tests/_support/FunctionalTester.php
Normal file
34
frontend/tests/_support/FunctionalTester.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class FunctionalTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\FunctionalTesterActions;
|
||||
|
||||
|
||||
public function seeValidationError($message)
|
||||
{
|
||||
$this->see($message, '.invalid-feedback');
|
||||
}
|
||||
|
||||
public function dontSeeValidationError($message)
|
||||
{
|
||||
$this->dontSee($message, '.invalid-feedback');
|
||||
}
|
||||
}
|
||||
26
frontend/tests/_support/UnitTester.php
Normal file
26
frontend/tests/_support/UnitTester.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
9
frontend/tests/acceptance.suite.yml.example
Normal file
9
frontend/tests/acceptance.suite.yml.example
Normal file
@@ -0,0 +1,9 @@
|
||||
suite_namespace: frontend\tests\acceptance
|
||||
actor: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- WebDriver:
|
||||
url: http://localhost:8080
|
||||
browser: firefox
|
||||
- Yii2:
|
||||
part: init
|
||||
21
frontend/tests/acceptance/HomeCest.php
Normal file
21
frontend/tests/acceptance/HomeCest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\acceptance;
|
||||
|
||||
use frontend\tests\AcceptanceTester;
|
||||
use yii\helpers\Url;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkHome(AcceptanceTester $I)
|
||||
{
|
||||
$I->amOnRoute(Url::toRoute('/site/index'));
|
||||
$I->see('My Application');
|
||||
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->wait(2); // wait for page to be opened
|
||||
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
||||
16
frontend/tests/acceptance/_bootstrap.php
Normal file
16
frontend/tests/acceptance/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cepts.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cept
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
7
frontend/tests/functional.suite.yml
Normal file
7
frontend/tests/functional.suite.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
suite_namespace: frontend\tests\functional
|
||||
actor: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- Asserts
|
||||
67
frontend/tests/functional/LoginCest.php
Normal file
67
frontend/tests/functional/LoginCest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
class LoginCest
|
||||
{
|
||||
protected $formId = '#login-form';
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'login_data.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/login');
|
||||
}
|
||||
|
||||
protected function formParams($login, $password)
|
||||
{
|
||||
return [
|
||||
'LoginForm[email]' => $login,
|
||||
'LoginForm[password]' => $password,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmpty(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('', ''));
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkWrongPassword(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('admin', 'wrong'));
|
||||
$I->seeValidationError('Incorrect email or password.');
|
||||
}
|
||||
|
||||
public function checkInactiveAccount(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test@mail.com', 'Test1234'));
|
||||
$I->seeValidationError('Incorrect email or password');
|
||||
}
|
||||
|
||||
public function checkValidLogin(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('sfriesen@jenkins.info', 'password_0'));
|
||||
$I->see('Logout (sfriesen@jenkins.info)', 'form button[type=submit]');
|
||||
$I->dontSeeLink('Login');
|
||||
$I->dontSeeLink('Signup');
|
||||
}
|
||||
}
|
||||
53
frontend/tests/functional/ResendVerificationEmailCest.php
Normal file
53
frontend/tests/functional/ResendVerificationEmailCest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
class ResendVerificationEmailCest
|
||||
{
|
||||
protected $formId = '#resend-verification-email-form';
|
||||
|
||||
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/resend-verification-email');
|
||||
}
|
||||
|
||||
protected function formParams($email)
|
||||
{
|
||||
return [
|
||||
'ResendVerificationEmailForm[email]' => $email
|
||||
];
|
||||
}
|
||||
|
||||
public function checkPage(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Resend verification email', 'h1');
|
||||
$I->see('Please fill out your email. A verification email will be sent there.');
|
||||
}
|
||||
|
||||
public function checkSendSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test@mail.com'));
|
||||
$I->see('Check your email for further instructions.');
|
||||
}
|
||||
}
|
||||
57
frontend/tests/functional/SignupCest.php
Normal file
57
frontend/tests/functional/SignupCest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class SignupCest
|
||||
{
|
||||
protected $formId = '#form-signup';
|
||||
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/signup');
|
||||
}
|
||||
|
||||
public function signupWithEmptyFields(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Signup', 'h1');
|
||||
$I->see('Please fill out the following fields to signup:');
|
||||
$I->submitForm($this->formId, []);
|
||||
$I->seeValidationError('First Name cannot be blank.');
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function signupWithWrongEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm(
|
||||
$this->formId, [
|
||||
'SignupForm[first_name]' => 'tester',
|
||||
'SignupForm[email]' => 'ttttt',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]
|
||||
);
|
||||
$I->dontSee('First Name cannot be blank.', '.invalid-feedback');
|
||||
$I->dontSee('Password cannot be blank.', '.invalid-feedback');
|
||||
$I->see('Email is not a valid email address.', '.invalid-feedback');
|
||||
}
|
||||
|
||||
public function signupSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, [
|
||||
'SignupForm[first_name]' => 'tester',
|
||||
'SignupForm[email]' => 'tester.email@example.com',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]);
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'first_name' => 'tester',
|
||||
'email' => 'tester.email@example.com',
|
||||
'status' => \common\models\User::STATUS_UNVERIFIED
|
||||
]);
|
||||
|
||||
$I->see('Thank you for registration. Please check your email for further instructions');
|
||||
}
|
||||
}
|
||||
59
frontend/tests/functional/VerifyEmailCest.php
Normal file
59
frontend/tests/functional/VerifyEmailCest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class VerifyEmailCest
|
||||
{
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmptyToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => '']);
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Verify email token cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkInvalidToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => 'wrong_token']);
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Wrong verify email token.');
|
||||
}
|
||||
|
||||
public function checkNoToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email');
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Missing required parameters: token');
|
||||
}
|
||||
|
||||
public function checkSuccessVerification(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330']);
|
||||
$I->canSee('Your email has been confirmed! Upon our approval you will receive a welcome email.');
|
||||
$I->canSee('Sales Agent Portal', 'h1');
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'email' => 'test@mail.com',
|
||||
'status' => \common\models\User::STATUS_VERIFIED
|
||||
]);
|
||||
}
|
||||
}
|
||||
16
frontend/tests/functional/_bootstrap.php
Normal file
16
frontend/tests/functional/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
7
frontend/tests/unit.suite.yml
Normal file
7
frontend/tests/unit.suite.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
suite_namespace: frontend\tests\unit
|
||||
actor: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: [orm, email, fixtures]
|
||||
- Asserts
|
||||
16
frontend/tests/unit/_bootstrap.php
Normal file
16
frontend/tests/unit/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Tests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Tests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
55
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Normal file
55
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
45
frontend/tests/unit/models/ResetPasswordFormTest.php
Normal file
45
frontend/tests/unit/models/ResetPasswordFormTest.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
60
frontend/tests/unit/models/SignupFormTest.php
Normal file
60
frontend/tests/unit/models/SignupFormTest.php
Normal 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.');
|
||||
}
|
||||
}
|
||||
48
frontend/tests/unit/models/VerifyEmailFormTest.php
Normal file
48
frontend/tests/unit/models/VerifyEmailFormTest.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user