Commit 5698a10c by Qiang Xue

Added functional tests for the basic app.

parent 7f1b8c10
......@@ -8,4 +8,8 @@
class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper]
enabled: [Filesystem, TestHelper, Yii2]
config:
Yii2:
entryScript: 'www/index-test.php'
url: 'http://localhost/'
<?php
$I = new TestGuy($scenario);
$I->wantTo('ensure that contact works');
$I->amOnPage('?r=site/contact');
$I->see('Contact', 'h1');
$I->submitForm('#contact-form', array());
$I->see('Contact', 'h1');
$I->see('Name cannot be blank');
$I->see('Email cannot be blank');
$I->see('Subject cannot be blank');
$I->see('Body cannot be blank');
$I->see('The verification code is incorrect');
$I->submitForm('#contact-form', array(
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester.email',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
$I->dontSee('Name cannot be blank', '.help-inline');
$I->see('Email is not a valid email address.');
$I->dontSee('Subject cannot be blank', '.help-inline');
$I->dontSee('Body cannot be blank', '.help-inline');
$I->dontSee('The verification code is incorrect', '.help-inline');
$I->submitForm('#contact-form', array(
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester@example.com',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
));
$I->dontSeeElement('#contact-form');
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
<?php
$I = new TestGuy($scenario);
$I->wantTo('ensure that home page works');
$I->amOnPage('');
$I->see('My Company');
$I->seeLink('About');
$I->click('About');
$I->see('This is the About page.');
<?php
$I = new TestGuy($scenario);
$I->wantTo('ensure that login works');
$I->amOnPage('?r=site/login');
$I->see('Login', 'h1');
$I->submitForm('#login-form', array());
$I->dontSee('Logout (admin)');
$I->see('Username cannot be blank');
$I->see('Password cannot be blank');
$I->submitForm('#login-form', array(
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'wrong',
));
$I->dontSee('Logout (admin)');
$I->see('Incorrect username or password');
$I->submitForm('#login-form', array(
'LoginForm[username]' => 'admin',
'LoginForm[password]' => 'admin',
));
$I->see('Logout (admin)');
......@@ -8,8 +8,8 @@ defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
require(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php');
require_once(__DIR__ . '/../vendor/autoload.php');
$config = require(__DIR__ . '/../config/web-test.php');
......
......@@ -82,7 +82,7 @@ class ErrorHandler extends Component
*/
protected function renderException($exception)
{
if (Yii::$app instanceof \yii\console\Application) {
if (Yii::$app instanceof \yii\console\Application || YII_ENV === 'test') {
echo Yii::$app->renderException($exception);
return;
}
......
......@@ -416,7 +416,9 @@ class User extends Component
public function switchIdentity($identity, $duration = 0)
{
$session = Yii::$app->getSession();
$session->regenerateID(true);
if (YII_ENV !== 'test') {
$session->regenerateID(true);
}
$this->setIdentity($identity);
$session->remove($this->idVar);
$session->remove($this->authTimeoutVar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment