Skip to content

Commit a5a2481

Browse files
committed
Added acceptance tests for the basic app.
1 parent 6c5dfc0 commit a5a2481

28 files changed

+1677
-14
lines changed

apps/basic/codeception.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
paths:
2+
tests: tests
3+
log: tests/_log
4+
data: tests/_data
5+
helpers: tests/_helpers
6+
settings:
7+
bootstrap: _bootstrap.php
8+
suite_class: \PHPUnit_Framework_TestSuite
9+
colors: true
10+
memory_limit: 1024M
11+
log: true
12+
modules:
13+
config:
14+
Db:
15+
dsn: ''
16+
user: ''
17+
password: ''
18+
dump: tests/_data/dump.sql

apps/basic/config/web-test.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$config = require(__DIR__ . '/web.php');
4+
5+
// ... customize $config for the "test" environment here...
6+
7+
return $config;

apps/basic/config/main.php apps/basic/config/web.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
2-
$params = require(__DIR__ . '/params.php');
2+
33
return array(
44
'id' => 'bootstrap',
55
'basePath' => dirname(__DIR__),
66
'preload' => array('log'),
7-
'modules' => array(
8-
// 'debug' => array(
9-
// 'class' => 'yii\debug\Module',
10-
// )
11-
),
127
'components' => array(
138
'cache' => array(
149
'class' => 'yii\caching\FileCache',
@@ -27,11 +22,8 @@
2722
'class' => 'yii\logging\FileTarget',
2823
'levels' => array('error', 'warning'),
2924
),
30-
// array(
31-
// 'class' => 'yii\logging\DebugTarget',
32-
// )
3325
),
3426
),
3527
),
36-
'params' => $params,
28+
'params' => require(__DIR__ . '/params.php'),
3729
);

apps/basic/controllers/SiteController.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function actions()
1414
return array(
1515
'captcha' => array(
1616
'class' => 'yii\web\CaptchaAction',
17+
'fixedVerifyCode' => YII_ENV === 'test' ? 'testme' : null,
1718
),
1819
);
1920
}

apps/basic/tests/_data/dump.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Replace this file with actual dump of your database */
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for CodeGuy
5+
6+
class CodeHelper extends \Codeception\Module
7+
{
8+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for TestGuy
5+
6+
class TestHelper extends \Codeception\Module
7+
{
8+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Codeception\Module;
3+
4+
// here you can define custom functions for WebGuy
5+
6+
class WebHelper extends \Codeception\Module
7+
{
8+
}

apps/basic/tests/_log/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Codeception Test Suite Configuration
2+
3+
# suite for acceptance tests.
4+
# perform tests in browser using the Selenium-like tools.
5+
# powered by Mink (http://mink.behat.org).
6+
# (tip: that's what your customer will see).
7+
# (tip: test your ajax and javascript by one of Mink drivers).
8+
9+
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
10+
11+
class_name: WebGuy
12+
modules:
13+
enabled:
14+
- PhpBrowser
15+
- WebHelper
16+
config:
17+
PhpBrowser:
18+
url: 'http://localhost/index-test.php'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
$I = new WebGuy($scenario);
3+
$I->wantTo('ensure that about works');
4+
$I->amOnPage('?r=site/about');
5+
$I->see('About', 'h1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
$I = new WebGuy($scenario);
3+
$I->wantTo('ensure that contact works');
4+
$I->amOnPage('?r=site/contact');
5+
$I->see('Contact', 'h1');
6+
7+
$I->submitForm('#contact-form', array());
8+
$I->see('Contact', 'h1');
9+
$I->see('Name cannot be blank');
10+
$I->see('Email cannot be blank');
11+
$I->see('Subject cannot be blank');
12+
$I->see('Body cannot be blank');
13+
$I->see('The verification code is incorrect');
14+
15+
$I->submitForm('#contact-form', array(
16+
'ContactForm[name]' => 'tester',
17+
'ContactForm[email]' => 'tester.email',
18+
'ContactForm[subject]' => 'test subject',
19+
'ContactForm[body]' => 'test content',
20+
'ContactForm[verifyCode]' => 'testme',
21+
));
22+
$I->dontSee('Name cannot be blank', '.help-inline');
23+
$I->see('Email is not a valid email address.');
24+
$I->dontSee('Subject cannot be blank', '.help-inline');
25+
$I->dontSee('Body cannot be blank', '.help-inline');
26+
$I->dontSee('The verification code is incorrect', '.help-inline');
27+
28+
$I->submitForm('#contact-form', array(
29+
'ContactForm[name]' => 'tester',
30+
'ContactForm[email]' => '[email protected]',
31+
'ContactForm[subject]' => 'test subject',
32+
'ContactForm[body]' => 'test content',
33+
'ContactForm[verifyCode]' => 'testme',
34+
));
35+
$I->dontSeeElement('#contact-form');
36+
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
$I = new WebGuy($scenario);
3+
$I->wantTo('ensure that home page works');
4+
$I->amOnPage('');
5+
$I->see('My Company');
6+
$I->seeLink('About');
7+
$I->click('About');
8+
$I->see('This is the About page.');
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$I = new WebGuy($scenario);
3+
$I->wantTo('ensure that login works');
4+
$I->amOnPage('?r=site/login');
5+
$I->see('Login', 'h1');
6+
7+
$I->submitForm('#login-form', array());
8+
$I->dontSee('Logout (admin)');
9+
$I->see('Username cannot be blank');
10+
$I->see('Password cannot be blank');
11+
12+
$I->submitForm('#login-form', array(
13+
'LoginForm[username]' => 'admin',
14+
'LoginForm[password]' => 'wrong',
15+
));
16+
$I->dontSee('Logout (admin)');
17+
$I->see('Incorrect username or password');
18+
19+
$I->submitForm('#login-form', array(
20+
'LoginForm[username]' => 'admin',
21+
'LoginForm[password]' => 'admin',
22+
));
23+
$I->see('Logout (admin)');

0 commit comments

Comments
 (0)