first commit
This commit is contained in:
13
frontend/tests/functional/AboutCest.php
Normal file
13
frontend/tests/functional/AboutCest.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class AboutCest
|
||||
{
|
||||
public function checkAbout(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/about');
|
||||
$I->see('About', 'h1');
|
||||
}
|
||||
}
|
59
frontend/tests/functional/ContactCest.php
Normal file
59
frontend/tests/functional/ContactCest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
/* @var $scenario \Codeception\Scenario */
|
||||
|
||||
class ContactCest
|
||||
{
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnPage(['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
Normal file
17
frontend/tests/functional/HomeCest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkOpen(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnPage(\Yii::$app->homeUrl);
|
||||
$I->see('My Application');
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
60
frontend/tests/functional/LoginCest.php
Normal file
60
frontend/tests/functional/LoginCest.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?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::className(),
|
||||
'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 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');
|
||||
}
|
||||
}
|
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('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.', '.help-block');
|
||||
$I->dontSee('Password cannot be blank.', '.help-block');
|
||||
$I->see('Email is not a valid email address.', '.help-block');
|
||||
}
|
||||
|
||||
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',
|
||||
]);
|
||||
|
||||
$I->see('Logout (tester)', 'form button[type=submit]');
|
||||
}
|
||||
}
|
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');
|
||||
* ```
|
||||
*/
|
Reference in New Issue
Block a user