first commit
This commit is contained in:
10
frontend/tests/_bootstrap.php
Executable file
10
frontend/tests/_bootstrap.php
Executable 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';
|
25
frontend/tests/_data/login_data.php
Executable file
25
frontend/tests/_data/login_data.php
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'erau',
|
||||
'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',
|
||||
'updated_at' => '1392559490',
|
||||
'email' => 'sfriesen@jenkins.info',
|
||||
],
|
||||
[
|
||||
'username' => 'test.test',
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
// Test1234
|
||||
'password_hash' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
'email' => 'test@mail.com',
|
||||
'status' => '9',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
];
|
45
frontend/tests/_data/user.php
Executable file
45
frontend/tests/_data/user.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'username' => 'okirlin',
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
],
|
||||
[
|
||||
'username' => 'troy.becker',
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
[
|
||||
'username' => 'test.test',
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
//Test1234
|
||||
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
|
||||
'email' => 'test@mail.com',
|
||||
'status' => '9',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
[
|
||||
'username' => 'test2.test',
|
||||
'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
Executable file
2
frontend/tests/_output/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
frontend/tests/_support/.gitignore
vendored
Executable file
1
frontend/tests/_support/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
_generated
|
34
frontend/tests/_support/FunctionalTester.php
Executable file
34
frontend/tests/_support/FunctionalTester.php
Executable 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
Executable file
26
frontend/tests/_support/UnitTester.php
Executable 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
Executable file
9
frontend/tests/acceptance.suite.yml.example
Executable 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
Executable file
21
frontend/tests/acceptance/HomeCest.php
Executable 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
Executable file
16
frontend/tests/acceptance/_bootstrap.php
Executable 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
Executable file
7
frontend/tests/functional.suite.yml
Executable file
@ -0,0 +1,7 @@
|
||||
suite_namespace: frontend\tests\functional
|
||||
actor: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- Asserts
|
14
frontend/tests/functional/AboutCest.php
Executable file
14
frontend/tests/functional/AboutCest.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class AboutCest
|
||||
{
|
||||
public function checkAbout(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/about');
|
||||
$I->see('About', 'h1');
|
||||
}
|
||||
}
|
60
frontend/tests/functional/ContactCest.php
Executable file
60
frontend/tests/functional/ContactCest.php
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
/* @var $scenario \Codeception\Scenario */
|
||||
|
||||
class ContactCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/contact');
|
||||
}
|
||||
|
||||
public function checkContact(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Contact', 'h1');
|
||||
}
|
||||
|
||||
public function checkContactSubmitNoData(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', []);
|
||||
$I->see('Contact', 'h1');
|
||||
$I->seeValidationError('Name cannot be blank');
|
||||
$I->seeValidationError('Email cannot be blank');
|
||||
$I->seeValidationError('Subject cannot be blank');
|
||||
$I->seeValidationError('Body cannot be blank');
|
||||
$I->seeValidationError('The verification code is incorrect');
|
||||
}
|
||||
|
||||
public function checkContactSubmitNotCorrectEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', [
|
||||
'ContactForm[name]' => 'tester',
|
||||
'ContactForm[email]' => 'tester.email',
|
||||
'ContactForm[subject]' => 'test subject',
|
||||
'ContactForm[body]' => 'test content',
|
||||
'ContactForm[verifyCode]' => 'testme',
|
||||
]);
|
||||
$I->seeValidationError('Email is not a valid email address.');
|
||||
$I->dontSeeValidationError('Name cannot be blank');
|
||||
$I->dontSeeValidationError('Subject cannot be blank');
|
||||
$I->dontSeeValidationError('Body cannot be blank');
|
||||
$I->dontSeeValidationError('The verification code is incorrect');
|
||||
}
|
||||
|
||||
public function checkContactSubmitCorrectData(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#contact-form', [
|
||||
'ContactForm[name]' => 'tester',
|
||||
'ContactForm[email]' => 'tester@example.com',
|
||||
'ContactForm[subject]' => 'test subject',
|
||||
'ContactForm[body]' => 'test content',
|
||||
'ContactForm[verifyCode]' => 'testme',
|
||||
]);
|
||||
$I->seeEmailIsSent();
|
||||
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
|
||||
}
|
||||
}
|
17
frontend/tests/functional/HomeCest.php
Executable file
17
frontend/tests/functional/HomeCest.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkOpen(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute(\Yii::$app->homeUrl);
|
||||
$I->see('My Application');
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
66
frontend/tests/functional/LoginCest.php
Executable file
66
frontend/tests/functional/LoginCest.php
Executable file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
class LoginCest
|
||||
{
|
||||
/**
|
||||
* 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[username]' => $login,
|
||||
'LoginForm[password]' => $password,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmpty(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('', ''));
|
||||
$I->seeValidationError('Username 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 username or password.');
|
||||
}
|
||||
|
||||
public function checkInactiveAccount(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('test.test', 'Test1234'));
|
||||
$I->seeValidationError('Incorrect username or password');
|
||||
}
|
||||
|
||||
public function checkValidLogin(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('erau', 'password_0'));
|
||||
$I->see('Logout (erau)', 'form button[type=submit]');
|
||||
$I->dontSeeLink('Login');
|
||||
$I->dontSeeLink('Signup');
|
||||
}
|
||||
}
|
83
frontend/tests/functional/ResendVerificationEmailCest.php
Executable file
83
frontend/tests/functional/ResendVerificationEmailCest.php
Executable file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
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 checkEmptyField(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams(''));
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkWrongEmailFormat(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('abcd.com'));
|
||||
$I->seeValidationError('Email is not a valid email address.');
|
||||
}
|
||||
|
||||
public function checkWrongEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('wrong@email.com'));
|
||||
$I->seeValidationError('There is no user with this email address.');
|
||||
}
|
||||
|
||||
public function checkAlreadyVerifiedEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test2@mail.com'));
|
||||
$I->seeValidationError('There is no user with this email address.');
|
||||
}
|
||||
|
||||
public function checkSendSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test@mail.com'));
|
||||
$I->canSeeEmailIsSent();
|
||||
$I->seeRecord('common\models\User', [
|
||||
'email' => 'test@mail.com',
|
||||
'username' => 'test.test',
|
||||
'status' => \common\models\User::STATUS_INACTIVE
|
||||
]);
|
||||
$I->see('Check your email for further instructions.');
|
||||
}
|
||||
}
|
59
frontend/tests/functional/SignupCest.php
Executable file
59
frontend/tests/functional/SignupCest.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?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('Username 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[username]' => 'tester',
|
||||
'SignupForm[email]' => 'ttttt',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]
|
||||
);
|
||||
$I->dontSee('Username 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[username]' => 'tester',
|
||||
'SignupForm[email]' => 'tester.email@example.com',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]);
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'username' => 'tester',
|
||||
'email' => 'tester.email@example.com',
|
||||
'status' => \common\models\User::STATUS_INACTIVE
|
||||
]);
|
||||
|
||||
$I->seeEmailIsSent();
|
||||
$I->see('Thank you for registration. Please check your inbox for verification email.');
|
||||
}
|
||||
}
|
68
frontend/tests/functional/VerifyEmailCest.php
Executable file
68
frontend/tests/functional/VerifyEmailCest.php
Executable file
@ -0,0 +1,68 @@
|
||||
<?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 checkAlreadyActivatedToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => 'already_used_token_1548675330']);
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Wrong verify email token.');
|
||||
}
|
||||
|
||||
public function checkSuccessVerification(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330']);
|
||||
$I->canSee('Your email has been confirmed!');
|
||||
$I->canSee('Congratulations!', 'h1');
|
||||
$I->see('Logout (test.test)', 'form button[type=submit]');
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'username' => 'test.test',
|
||||
'email' => 'test@mail.com',
|
||||
'status' => \common\models\User::STATUS_ACTIVE
|
||||
]);
|
||||
}
|
||||
}
|
16
frontend/tests/functional/_bootstrap.php
Executable file
16
frontend/tests/functional/_bootstrap.php
Executable 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
Executable file
7
frontend/tests/unit.suite.yml
Executable 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
Executable file
16
frontend/tests/unit/_bootstrap.php
Executable 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');
|
||||
* ```
|
||||
*/
|
35
frontend/tests/unit/models/ContactFormTest.php
Executable file
35
frontend/tests/unit/models/ContactFormTest.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use frontend\models\ContactForm;
|
||||
use yii\mail\MessageInterface;
|
||||
|
||||
class ContactFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
public function testSendEmail()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
|
||||
$model->attributes = [
|
||||
'name' => 'Tester',
|
||||
'email' => 'tester@example.com',
|
||||
'subject' => 'very important letter subject',
|
||||
'body' => 'body of current message',
|
||||
];
|
||||
|
||||
verify($model->sendEmail('admin@example.com'))->notEmpty();
|
||||
|
||||
// using Yii2 module actions to check email was sent
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
/** @var MessageInterface $emailMessage */
|
||||
$emailMessage = $this->tester->grabLastSentEmail();
|
||||
verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
|
||||
verify($emailMessage->getTo())->arrayHasKey('admin@example.com');
|
||||
verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com');
|
||||
verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com');
|
||||
verify($emailMessage->getSubject())->equals('very important letter subject');
|
||||
verify($emailMessage->toString())->stringContainsString('body of current message');
|
||||
}
|
||||
}
|
59
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Executable file
59
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?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())->false();
|
||||
}
|
||||
|
||||
public function testNotSendEmailsToInactiveUser()
|
||||
{
|
||||
$user = $this->tester->grabFixture('user', 1);
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $user['email'];
|
||||
verify($model->sendEmail())->false();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
$emailMessage = $this->tester->grabLastSentEmail();
|
||||
verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
|
||||
verify($emailMessage->getTo())->arrayHasKey($model->email);
|
||||
verify($emailMessage->getFrom())->arrayHasKey(Yii::$app->params['supportEmail']);
|
||||
}
|
||||
}
|
85
frontend/tests/unit/models/ResendVerificationEmailFormTest.php
Executable file
85
frontend/tests/unit/models/ResendVerificationEmailFormTest.php
Executable file
@ -0,0 +1,85 @@
|
||||
<?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())->false();
|
||||
verify($model->hasErrors())->true();
|
||||
verify($model->getFirstError('email'))->equals('There is no user with this email address.');
|
||||
}
|
||||
|
||||
public function testSuccessfullyResend()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
$model->attributes = [
|
||||
'email' => 'test@mail.com'
|
||||
];
|
||||
|
||||
verify($model->validate())->true();
|
||||
verify($model->hasErrors())->false();
|
||||
|
||||
verify($model->sendEmail())->true();
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
$mail = $this->tester->grabLastSentEmail();
|
||||
|
||||
verify($mail)->instanceOf('yii\mail\MessageInterface');
|
||||
verify($mail->getTo())->arrayHasKey('test@mail.com');
|
||||
verify($mail->getFrom())->arrayHasKey(\Yii::$app->params['supportEmail']);
|
||||
verify($mail->getSubject())->equals('Account registration at ' . \Yii::$app->name);
|
||||
verify($mail->toString())->stringContainsString('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
|
||||
}
|
||||
}
|
44
frontend/tests/unit/models/ResetPasswordFormTest.php
Executable file
44
frontend/tests/unit/models/ResetPasswordFormTest.php
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\models\ResetPasswordForm;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
72
frontend/tests/unit/models/SignupFormTest.php
Executable file
72
frontend/tests/unit/models/SignupFormTest.php
Executable file
@ -0,0 +1,72 @@
|
||||
<?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([
|
||||
'username' => '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', [
|
||||
'username' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'status' => \common\models\User::STATUS_INACTIVE
|
||||
]);
|
||||
|
||||
$this->tester->seeEmailIsSent();
|
||||
|
||||
$mail = $this->tester->grabLastSentEmail();
|
||||
|
||||
verify($mail)->instanceOf('yii\mail\MessageInterface');
|
||||
verify($mail->getTo())->arrayHasKey('some_email@example.com');
|
||||
verify($mail->getFrom())->arrayHasKey(\Yii::$app->params['supportEmail']);
|
||||
verify($mail->getSubject())->equals('Account registration at ' . \Yii::$app->name);
|
||||
verify($mail->toString())->stringContainsString($user->verification_token);
|
||||
}
|
||||
|
||||
public function testNotCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'username' => 'troy.becker',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
verify($model->signup())->empty();
|
||||
verify($model->getErrors('username'))->notEmpty();
|
||||
verify($model->getErrors('email'))->notEmpty();
|
||||
|
||||
verify($model->getFirstError('username'))
|
||||
->equals('This username has already been taken.');
|
||||
verify($model->getFirstError('email'))
|
||||
->equals('This email address has already been taken.');
|
||||
}
|
||||
}
|
55
frontend/tests/unit/models/VerifyEmailFormTest.php
Executable file
55
frontend/tests/unit/models/VerifyEmailFormTest.php
Executable file
@ -0,0 +1,55 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user