Commit 89c9a125 authored by Tobias Munk's avatar Tobias Munk

updated & fixed tests

parent bb2f45b4
......@@ -11,3 +11,4 @@ web/bundles
docker-compose.override.yml
tests/codeception/_output
tests/codeception/_support/_generated
......@@ -6,6 +6,7 @@ paths:
support: codeception/_support
envs: codeception/_envs
settings:
#shuffle: true
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
......@@ -14,11 +15,9 @@ extensions:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: codeception/_data/dump.sql
Yii2:
configFile: 'codeception/_config/codeception-module.php'
cleanup: false
config:
test_entry_url: http://web:80/index.php
coverage:
......
......@@ -9,7 +9,7 @@ require($rootPath.'/src/config/env.php');
# TODO: review run webserver in YII_ENV=prod for acceptance tests, yii2-localurls has redirect issues in YII_ENV=test, see https://github.com/codemix/yii2-localeurls/issues/62
if (php_sapi_name() == 'cli' && getenv('YII_ENV') !== 'test') {
echo "Error: YII_ENV must be set to 'test'\n";
exit;
exit(1);
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
......
<?php
use yii\db\Migration;
class m160720_000000_demo_data extends \dmstr\db\mysql\FileMigration
{
public $file = 'm161215_183747_app_0.8.2-1-ga18d13a_data.sql';
}
<?php
use yii\db\Migration;
class m160721_000000_users_and_auth extends \dmstr\db\mysql\FileMigration
{
}
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
TRUNCATE table `app_auth_assignment`;
TRUNCATE table `app_profile`;
TRUNCATE table `app_user`;
TRUNCATE table `app_social_account`;
INSERT INTO `app_user` (`id`, `username`, `email`, `password_hash`, `auth_key`, `confirmed_at`, `unconfirmed_email`, `blocked_at`, `registration_ip`, `created_at`, `updated_at`, `flags`)
VALUES
(1, 'admin', 'admin@h17n.de', '$2y$10$uN98TVi0OytDDgcpENV7IOWlWemn2TD/vij5hoN2QbZ/P8iGQkafy', 'ArSNskfLRoiDivKY98jaqgORDj597si4', 1463058272, NULL, NULL, NULL, 1463058272, 1475855889, 0),
(2, 'dev', 'dev@h17n.de', '$2y$10$8jo5HglYhJSgrl4iVVPSk.4pU3MOYSeyn1.jmtBgp0v3tRcQrtC1i', '33KED5Gw27sCnL3QyFe9svkaXL4pJUCx', 1463352048, NULL, NULL, '54.93.102.17', 1463349160, 1478617300, 0),
(3, 'editor', 'editor@h17n.de', '$2y$10$WzJWeCyCZi2n8w2nXIMbU.K7lJB8iMINcZIMutarHZ50qAGXsGIwy', 'HK7L1cW7VrpMGgvhHaQBnZGDu8zquCyM', 1467318745, NULL, NULL, '54.93.102.17', 1467318664, 1478617291, 0),
(4, 'preview', 'preview@h17n.de', '$2y$10$rfmrfvct3wD3akoVZY3l5OSidJ0xKMcoKeVlZZHfvT8fVZ4RYYj6m', 'WgWxMQCOMEyYgDDJ_mCBJcxvyL6h6SyI', 1467331347, NULL, NULL, '54.93.102.17', 1467331347, 1469693262, 0);
INSERT INTO `app_profile` (`user_id`, `name`, `public_email`, `gravatar_email`, `gravatar_id`, `location`, `website`, `bio`, `timezone`)
VALUES
(1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
(4, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
LOCK TABLES `app_auth_assignment` WRITE; TRUNCATE TABLE `app_auth_assignment`;
/*!40000 ALTER TABLE `app_auth_assignment` DISABLE KEYS */;
INSERT INTO `app_auth_assignment` VALUES ('Developer','2',1467315311),('Editor','3',1467318765),('Preview','4',1467331484);
/*!40000 ALTER TABLE `app_auth_assignment` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
......@@ -28,7 +28,7 @@ class E2eTester extends \Codeception\Actor
$this->fillField('input[name="login-form[login]"]', $username);
$this->fillField('input[name="login-form[password]"]', $password);
$this->click('#login-form button');
$this->waitForElementNotVisible('#login-form', 5);
$this->waitForElementNotVisible('#login-form', 10);
}
public function dontSeeHorizontalScrollbars(){
......
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Cli extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class E2e extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}
class_name: E2eTester
modules:
enabled:
#- \Helper\E2e
- \Helper\E2e
- WebDriver
- Asserts
config:
WebDriver:
browser: firefox
host: firefox
port: 4444
window_size: 1024x768
restart: true
url: http://web:80/
env:
firefox:
modules:
config:
WebDriver:
browser: firefox
port: 4444
host: firefox
# Can be configured as Docker selenium container
chrome:
modules:
config:
WebDriver:
browser: chrome
host: chrome
# Can be configured from modern.ie and selenium java standalone driver
ie:
modules:
config:
WebDriver:
browser: 'internet explorer'
host: 192.168.99.1
port: 14444
window_size: 1024x768
restart: true
url: http://192.168.99.1:32779/
<?php
// @group mandatory
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that access control works');
$routesWithAccessControl = [
'/backend',
'/backend/default/view-config',
'/prototype',
'/prototype/html',
'/prototype/less',
'/prototype/less/create',
'/settings',
'/settings/default/create',
'/translatemanager',
'/rbac',
'/user',
'/pages'
];
foreach ($routesWithAccessControl AS $route) {
$I->amOnPage($route);
$I->canSeeCurrentUrlMatches('|user/login|');
}
<?php
// @group mandatory
use tests\codeception\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that access control UI works');
$I->amOnPage('/');
$I->dontSeeLink('/de/backend', '.nav');
$I->dontSee('','.glyphicon.glyphicon-cog');
$I->login('admin', 'admin1');
$I->see('','.glyphicon.glyphicon-cog');
<?php
// @group mandatory
$I = new FunctionalTester($scenario);
$I->wantTo('Click backend links');
$I->amGoingTo('start in the backend');
$I->login('admin', 'admin1');
$url = '/backend';
$I->amOnPage($url);
$links = $I->grabMultiple('section.content a[href^="/"]', 'href');
foreach ($links as $i => $url) {
switch ($url) {
case '/debug':
case '/treemanager':
continue 2;
break;
}
$I->amGoingTo('check '.$url);
$I->amOnPage($url);
$I->cantSeeElement('.site-error');
$I->cantSeeElement('.alert-warning .alert');
}
<?php
// @group mandatory
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that error page works');
$I->amOnPage('/_this_page_does_not_exist_');
$I->seeResponseCodeIs(404);
$I->see('Not Found');
<?php
// @group mandatory
use tests\codeception\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that language urls work');
$I->expect('a 404 error for a non-existant language');
$I->amOnPage('/xx');
$I->canSeeResponseCodeIs(404);
$I->expect('a redirect if no language is set');
$I->amOnPage('/');
$I->canSeeResponseCodeIs(200);
$I->amOnPage('/de');
$I->canSeeResponseCodeIs(200);
$I->amOnPage('/en');
$I->canSeeResponseCodeIs(200);
// Note: extended redirect testing needs to be run in acceptance tests
......@@ -29,7 +29,9 @@ $I->seeResponseCodeIs(200);
$I->expectTo('see backend elements');
$I->see('admin');
$I->see('Backend','h1');
$I->see('ID','h3');
$I->seeLink('guide');
$I->seeLink('help');
$I->see('Widget Content','h4');
$I->see('Pages','h4');
$I->see('Application Settings','h4');
$I->see('Auto-detected modules', 'h3');
$I->see('filefly','a.btn-app');
$I->see('redirects','a.btn-app');
<?php
// @group mandatory
$rootPath = realpath(__DIR__.'/../../..');
$I = new FunctionalTester($scenario);
$I->wantTo('check application versioning');
$I->dontSeeFileFound('version', $rootPath);
$I->seeFileFound('version', $rootPath.'/src');
$I->openFile($rootPath.'/src/version');
$I->dontSeeInThisFile('dev');
$I->dontSeeInThisFile('dirty');
<?php
$config = require(dirname(__DIR__) . '/_config/test.php');
new yii\web\Application($config);
<?php
use yii\codeception\TestCase;
class ControllerTest extends TestCase
class ControllerTest extends \Codeception\Test\Unit
{
public $appConfig = '@tests/codeception/_config/test.php';
/**
* @group mandatory
*/
......@@ -16,7 +11,8 @@ class ControllerTest extends TestCase
$this->assertNotNull(Yii::$app);
}
public function testController(){
public function testController()
{
$this->assertNotFalse(Yii::$app->createController('site/index'));
}
}
<?php
namespace tests\codeception\unit\models;
use dektrium\user\models\User;
class UserTest extends \Codeception\Test\Unit
{
public function testUserLoginLogout()
{
$identity = User::findIdentity(1);
$this->assertTrue(\Yii::$app->user->login($identity, 0));
$this->assertTrue(\Yii::$app->user->logout());
}
public function testNonExistingUserModel()
{
$identity = User::findIdentity(99999);
$this->assertNull($identity);
}
}
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