fixing some tests

This commit is contained in:
Antonio Ramirez
2016-12-11 04:17:55 +01:00
parent d8e517a9d1
commit 0834ad6ca0
40 changed files with 1153 additions and 23 deletions

30
codeception.yml Normal file
View File

@ -0,0 +1,30 @@
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'tests/_app/config/test.php'
coverage:
enabled: true
include:
- ../lib/User/AuthClient/*
- ../controllers/*
- ../events/*
- ../filters/*
- ../helpers/*
- ../models/*
- ../traits/*
- ../views/*
- ../widgets/*
- ../Bootstrap.php
- ../Module.php
- ../Mailer.php
- ../Finder.php

View File

@ -16,7 +16,10 @@
"fabpot/php-cs-fixer": "^1.12", "fabpot/php-cs-fixer": "^1.12",
"phpmd/phpmd": "^2.4", "phpmd/phpmd": "^2.4",
"dektrium/yii2-user": "^0.9.9", "dektrium/yii2-user": "^0.9.9",
"dektrium/yii2-rbac": "^0.3.0" "dektrium/yii2-rbac": "^0.3.0",
"yiisoft/yii2-codeception": "^2.0.0",
"codeception/specify": "^0.4.3",
"codeception/verify": "^0.3.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

205
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "15f47ee84555dd06400d7388b738aae6", "hash": "6a535aefcdf64b58d80efc0402124dbc",
"content-hash": "7b85b85a725b61a678cfb1f7b17c6dc4", "content-hash": "718049b93fe83097e6e146cfb7dc8ddc",
"packages": [], "packages": [],
"packages-dev": [ "packages-dev": [
{ {
@ -290,6 +290,79 @@
], ],
"time": "2016-09-27 13:35:10" "time": "2016-09-27 13:35:10"
}, },
{
"name": "codeception/specify",
"version": "0.4.5",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Specify.git",
"reference": "5fb1d68a737f31155a0f7410cf47dea479b33415"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Specify/zipball/5fb1d68a737f31155a0f7410cf47dea479b33415",
"reference": "5fb1d68a737f31155a0f7410cf47dea479b33415",
"shasum": ""
},
"require": {
"myclabs/deep-copy": "~1.1",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-0": {
"Codeception\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert.php@mailican.com"
}
],
"description": "BDD code blocks for PHPUnit and Codeception",
"time": "2016-10-17 22:28:20"
},
{
"name": "codeception/verify",
"version": "0.3.2",
"source": {
"type": "git",
"url": "https://github.com/Codeception/Verify.git",
"reference": "b06d706261d1fee0cc312bacc5c1b7c506e5213a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/Verify/zipball/b06d706261d1fee0cc312bacc5c1b7c506e5213a",
"reference": "b06d706261d1fee0cc312bacc5c1b7c506e5213a",
"shasum": ""
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"files": [
"src/Codeception/function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert.php@mailican.com"
}
],
"description": "BDD assertion library for PHPUnit",
"time": "2016-08-29 22:49:25"
},
{ {
"name": "dektrium/yii2-rbac", "name": "dektrium/yii2-rbac",
"version": "0.3.0", "version": "0.3.0",
@ -605,6 +678,48 @@
], ],
"time": "2016-11-17 09:07:14" "time": "2016-11-17 09:07:14"
}, },
{
"name": "myclabs/deep-copy",
"version": "1.5.5",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/399c1f9781e222f6eb6cc238796f5200d1b7f108",
"reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"doctrine/collections": "1.*",
"phpunit/phpunit": "~4.1"
},
"type": "library",
"autoload": {
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"homepage": "https://github.com/myclabs/DeepCopy",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"time": "2016-10-31 17:19:45"
},
{ {
"name": "pdepend/pdepend", "name": "pdepend/pdepend",
"version": "2.3.2", "version": "2.3.2",
@ -893,12 +1008,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git", "url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "12a6329c24d08fb97bcf10128365757f845dc140" "reference": "968cd5302dba8d60ddb64489069953fae2ff1a92"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/12a6329c24d08fb97bcf10128365757f845dc140", "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/968cd5302dba8d60ddb64489069953fae2ff1a92",
"reference": "12a6329c24d08fb97bcf10128365757f845dc140", "reference": "968cd5302dba8d60ddb64489069953fae2ff1a92",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -938,7 +1053,7 @@
"mail", "mail",
"mailer" "mailer"
], ],
"time": "2016-11-24 01:01:52" "time": "2016-12-06 13:58:36"
}, },
{ {
"name": "symfony/config", "name": "symfony/config",
@ -946,12 +1061,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/config.git", "url": "https://github.com/symfony/config.git",
"reference": "dc43722df24b1320e22a0a525a74fed0eba61552" "reference": "c3539b8e8fbfbb44a1c5884473940ea0f1a08d0c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/config/zipball/dc43722df24b1320e22a0a525a74fed0eba61552", "url": "https://api.github.com/repos/symfony/config/zipball/c3539b8e8fbfbb44a1c5884473940ea0f1a08d0c",
"reference": "dc43722df24b1320e22a0a525a74fed0eba61552", "reference": "c3539b8e8fbfbb44a1c5884473940ea0f1a08d0c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -994,7 +1109,7 @@
], ],
"description": "Symfony Config Component", "description": "Symfony Config Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2016-11-29 11:12:53" "time": "2016-12-09 07:45:54"
}, },
{ {
"name": "symfony/console", "name": "symfony/console",
@ -1002,12 +1117,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/console.git", "url": "https://github.com/symfony/console.git",
"reference": "0eeddc19feb3bd91c443e676bd07c6ce5c30cfa3" "reference": "3c2380fcde1e7311afdc20836f4db460f0550427"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/console/zipball/0eeddc19feb3bd91c443e676bd07c6ce5c30cfa3", "url": "https://api.github.com/repos/symfony/console/zipball/3c2380fcde1e7311afdc20836f4db460f0550427",
"reference": "0eeddc19feb3bd91c443e676bd07c6ce5c30cfa3", "reference": "3c2380fcde1e7311afdc20836f4db460f0550427",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1057,7 +1172,7 @@
], ],
"description": "Symfony Console Component", "description": "Symfony Console Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2016-11-19 20:35:20" "time": "2016-12-08 15:31:48"
}, },
{ {
"name": "symfony/debug", "name": "symfony/debug",
@ -1122,12 +1237,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/dependency-injection.git", "url": "https://github.com/symfony/dependency-injection.git",
"reference": "3e613031d3e80beef18a015e544263a6dd58123f" "reference": "7fff820a0b1ffc3dc16ee132168cc7e0e65ba5c2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/dependency-injection/zipball/3e613031d3e80beef18a015e544263a6dd58123f", "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/7fff820a0b1ffc3dc16ee132168cc7e0e65ba5c2",
"reference": "3e613031d3e80beef18a015e544263a6dd58123f", "reference": "7fff820a0b1ffc3dc16ee132168cc7e0e65ba5c2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1177,7 +1292,7 @@
], ],
"description": "Symfony DependencyInjection Component", "description": "Symfony DependencyInjection Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2016-11-25 12:33:00" "time": "2016-12-08 15:31:48"
}, },
{ {
"name": "symfony/event-dispatcher", "name": "symfony/event-dispatcher",
@ -1500,12 +1615,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/yiisoft/yii2-framework.git", "url": "https://github.com/yiisoft/yii2-framework.git",
"reference": "f8202bb4eda46c2cb4664fee24723e6bf48f07e5" "reference": "39671fbb1308cc6feaa1c1091c6f4b8aca4f93f3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/f8202bb4eda46c2cb4664fee24723e6bf48f07e5", "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/39671fbb1308cc6feaa1c1091c6f4b8aca4f93f3",
"reference": "f8202bb4eda46c2cb4664fee24723e6bf48f07e5", "reference": "39671fbb1308cc6feaa1c1091c6f4b8aca4f93f3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1586,7 +1701,7 @@
"framework", "framework",
"yii2" "yii2"
], ],
"time": "2016-12-03 06:25:39" "time": "2016-12-10 18:26:22"
}, },
{ {
"name": "yiisoft/yii2-authclient", "name": "yiisoft/yii2-authclient",
@ -1687,6 +1802,52 @@
], ],
"time": "2016-08-09 21:17:28" "time": "2016-08-09 21:17:28"
}, },
{
"name": "yiisoft/yii2-codeception",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/yiisoft/yii2-codeception.git",
"reference": "76fdd689b7ec49c3c57db6137ae5ea536fa8f16d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/yii2-codeception/zipball/76fdd689b7ec49c3c57db6137ae5ea536fa8f16d",
"reference": "76fdd689b7ec49c3c57db6137ae5ea536fa8f16d",
"shasum": ""
},
"require": {
"yiisoft/yii2": ">=2.0.4"
},
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"yii\\codeception\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Mark Jebri",
"email": "mark.github@yandex.ru"
}
],
"description": "The Codeception integration for the Yii framework",
"keywords": [
"codeception",
"yii2"
],
"abandoned": "codeception/codeception",
"time": "2016-10-20 13:07:49"
},
{ {
"name": "yiisoft/yii2-composer", "name": "yiisoft/yii2-composer",
"version": "dev-master", "version": "dev-master",

View File

@ -0,0 +1,15 @@
<?php
return [
'id' => 'yii2-test-console',
'basePath' => dirname(__DIR__),
'aliases' => [
'@Da/User' => dirname(dirname(dirname(__DIR__))) . '/lib/User',
'@tests' => dirname(dirname(__DIR__)),
],
'components' => [
'log' => null,
'cache' => null,
'db' => require __DIR__ . '/db.php',
],
];

15
tests/_app/config/db.php Normal file
View File

@ -0,0 +1,15 @@
<?php
$db = [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=test',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
];
if (file_exists(__DIR__ . '/db.local.php')) {
$db = array_merge($db, require(__DIR__ . '/db.local.php'));
}
return $db;

View File

@ -0,0 +1,34 @@
<?php
return [
'id' => 'yii2-user-tests',
'basePath' => dirname(__DIR__),
'language' => 'en-US',
'aliases' => [
'@Da/User' => dirname(dirname(dirname(__DIR__))) . '/lib/User',
'@tests' => dirname(dirname(__DIR__)),
'@vendor' => VENDOR_DIR,
'@bower' => VENDOR_DIR . '/bower-asset',
],
'bootstrap' => ['Da\User\Bootstrap'],
'modules' => [
'user' => [
'class' => 'Da\User\Module',
'administrators' => ['user'],
],
],
'components' => [
'db' => require __DIR__ . '/db.php',
'mailer' => [
'useFileTransport' => true,
],
'urlManager' => [
'showScriptName' => true,
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
],
],
'params' => [],
];

View File

@ -0,0 +1,13 @@
<?php
namespace app\controllers;
use yii\web\Controller;
class SiteController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,10 @@
<?php
if (Yii::$app->user->getIsGuest()) {
echo \yii\helpers\Html::a('Login', ['/user/security/login']);
echo \yii\helpers\Html::a('Registration', ['/user/registration/register']);
} else {
echo \yii\helpers\Html::a('Logout', ['/user/security/logout']);
}
echo $content;

View File

@ -0,0 +1 @@
Index

12
tests/_app/yii.php Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env php
<?php
require dirname(__DIR__) . '/_bootstrap.php';
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
$config = require(__DIR__ . '/config/console.php');
$exitCode = (new yii\console\Application($config))->run();
exit($exitCode);

20
tests/_bootstrap.php Normal file
View File

@ -0,0 +1,20 @@
<?php
define('YII_ENV', 'test');
defined('YII_DEBUG') or define('YII_DEBUG', true);
// Search for autoload, since performance is irrelevant and usability isn't!
$dir = __DIR__ . '/../';
while (!file_exists($dir . '/vendor/autoload.php')) {
if ($dir == dirname($dir)) {
throw new \Exception('Failed to locate autoload.php');
}
$dir = dirname($dir);
}
$vendor = $dir . '/vendor';
define('VENDOR_DIR', $vendor);
require_once $vendor . '/autoload.php';
require $vendor . '/yiisoft/yii2/Yii.php';

View File

@ -0,0 +1,14 @@
<?php
namespace tests\_fixtures;
use yii\test\ActiveFixture;
class ProfileFixture extends ActiveFixture
{
public $modelClass = 'Da\User\Model\Profile';
public $depends = [
'tests\_fixtures\UserFixture'
];
}

View File

@ -0,0 +1,14 @@
<?php
namespace tests\_fixtures;
use yii\test\ActiveFixture;
class TokenFixture extends ActiveFixture
{
public $modelClass = 'Da\User\Model\Token';
public $depends = [
'tests\_fixtures\UserFixture'
];
}

View File

@ -0,0 +1,10 @@
<?php
namespace tests\_fixtures;
use yii\test\ActiveFixture;
class UserFixture extends ActiveFixture
{
public $modelClass = 'Da\User\Model\User';
}

View File

@ -0,0 +1,10 @@
<?php
$time = time();
return [
'user' => [
'user_id' => 1,
'name' => 'John Doe',
],
];

View File

@ -0,0 +1,32 @@
<?php
use Da\User\Model\Token;
$time = time();
return [
'confirmation' => [
'user_id' => 2,
'code' => 'NO2aCmBIjFQX624xmAc3VBu7Th3NJoa6',
'type' => Token::TYPE_CONFIRMATION,
'created_at' => $time,
],
'expired_confirmation' => [
'user_id' => 3,
'code' => 'qxYa315rqRgCOjYGk82GFHMEAV3T82AX',
'type' => Token::TYPE_CONFIRMATION,
'created_at' => $time - 86401,
],
'expired_recovery' => [
'user_id' => 5,
'code' => 'a5839d0e73b9c525942c2f59e88c1aaf',
'type' => Token::TYPE_RECOVERY,
'created_at' => $time - 21601,
],
'recovery' => [
'user_id' => 6,
'code' => '6f5d0dad53ef73e6ba6f01a441c0e602',
'type' => Token::TYPE_RECOVERY,
'created_at' => $time,
],
];

View File

@ -0,0 +1,59 @@
<?php
$time = time();
return [
'user' => [
'username' => 'user',
'email' => 'user@example.com',
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
'auth_key' => '39HU0m5lpjWtqstFVGFjj6lFb7UZDeRq',
'created_at' => $time,
'updated_at' => $time,
'confirmed_at' => $time,
],
'unconfirmed' => [
'username' => 'joe',
'email' => 'joe@example.com',
'password_hash' => '$2y$13$CIH1LSMPzU9xDCywt3QO8uovAu2axp8hwuXVa72oI.1G/USsGyMBS',
'auth_key' => 'mhh1A6KfqQLmHP-MiWN0WB0M90Q2u5OE',
'created_at' => $time,
'updated_at' => $time,
],
'unconfirmed_with_expired_token' => [
'username' => 'john',
'email' => 'john@example.com',
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
'auth_key' => 'h6OS9csJbZEOW59ZILmJxU6bCiqVno9A',
'created_at' => $time - 86401,
'updated_at' => $time - 86401,
],
'blocked' => [
'username' => 'steven',
'email' => 'steven@example.com',
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
'auth_key' => 'TnXTrtLdj-YJBlG2A6jFHJreKgbsLYCa',
'created_at' => $time,
'updated_at' => $time,
'blocked_at' => $time,
'confirmed_at' => $time,
],
'user_with_expired_recovery_token' => [
'username' => 'andrew',
'email' => 'andrew@example.com',
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
'auth_key' => 'qxYa315rqRgCOjYGk82GFHMEAV3T82AX',
'created_at' => $time - 21601,
'updated_at' => $time - 21601,
'confirmed_at' => $time - 21601,
],
'user_with_recovery_token' => [
'username' => 'alex',
'email' => 'alex@example.com',
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
'auth_key' => 'zQh1A65We0AmHPOMiWN0WB0M90Q24ziU',
'created_at' => $time,
'updated_at' => $time,
'confirmed_at' => $time,
],
];

2
tests/_output/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,16 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents admin page.
*
* @property \FunctionalTester $actor
*/
class AdminPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/admin/index';
}

View File

@ -0,0 +1,29 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents admin create page.
*
* @property \FunctionalTester $actor
*/
class CreatePage extends BasePage
{
/** @inheritdoc */
public $route = '/user/admin/create';
/**
* @param $username
* @param $email
* @param $password
*/
public function create($username, $email, $password)
{
$this->actor->fillField('#user-username', $username);
$this->actor->fillField('#user-email', $email);
$this->actor->fillField('#user-password', $password);
$this->actor->click('Save');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents login page.
*
* @property \FunctionalTester $actor
*/
class LoginPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/security/login';
/**
* @param $login
* @param $password
*/
public function login($login, $password)
{
$this->actor->fillField('#login-form-login', $login);
$this->actor->fillField('#login-form-password', $password);
$this->actor->click('Sign in');
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents resend page.
*
* @property \FunctionalTester $actor
*/
class RecoveryPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/recovery/request';
/**
* @param $email
*/
public function recover($email)
{
$this->actor->fillField('#recovery-form-email', $email);
$this->actor->click('Continue');
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents registration page.
*
* @property \FunctionalTester $actor
*/
class RegistrationPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/registration/register';
/**
* @param $username
* @param $email
* @param $password
*/
public function register($email, $username = null, $password = null)
{
$this->actor->fillField('#register-form-email', $email);
$this->actor->fillField('#register-form-username', $username);
if ($password !== null) {
$this->actor->fillField('#register-form-password', $password);
}
$this->actor->click('Sign up');
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents resend page.
*
* @property \FunctionalTester $actor
*/
class ResendPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/registration/resend';
/**
* @param $email
*/
public function resend($email)
{
$this->actor->fillField('#resend-form-email', $email);
$this->actor->click('Continue');
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents email settings page.
*
* @property \FunctionalTester $actor
*/
class SettingsPage extends BasePage
{
/** @inheritdoc */
public $route = '/user/settings/account';
/**
* @param $email
* @param $username
* @param null $password
* @param $currentPassword
*/
public function update($email, $username, $currentPassword, $password = null)
{
$this->actor->fillField('#settings-form-email', $email);
$this->actor->fillField('#settings-form-username', $username);
$this->actor->fillField('#settings-form-new_password', $password);
$this->actor->fillField('#settings-form-current_password', $currentPassword);
$this->actor->click('Save');
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace tests\_pages;
use yii\codeception\BasePage;
/**
* Represents admin update page.
*
* @property \FunctionalTester $actor
*/
class UpdatePage extends BasePage
{
/** @inheritdoc */
public $route = '/user/admin/update';
/**
* @param $username
* @param $email
* @param $password
*/
public function update($username, $email, $password = null)
{
$this->actor->fillField('#user-username', $username);
$this->actor->fillField('#user-email', $email);
$this->actor->fillField('#user-password', $password);
$this->actor->click('Update');
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($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;
/**
* Define custom actions here
*/
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($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
*/
}

View File

@ -0,0 +1,6 @@
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- Asserts

View File

@ -0,0 +1,23 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\TokenFixture;
use yii\helpers\Url;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that confirmation works');
$I->haveFixtures(['token' => TokenFixture::className()]);
$I->amGoingTo('check that error is showed when token expired');
$token = $I->grabFixture('token', 'expired_confirmation');
$I->amOnPage(Url::toRoute(['/user/registration/confirm', 'id' => $token->user_id, 'code' => $token->code]));
$I->see('The confirmation link is invalid or expired. Please try requesting a new one.');
$I->amGoingTo('check that user get confirmed');
$token = $I->grabFixture('token', 'confirmation');
$I->amOnPage(Url::toRoute(['/user/registration/confirm', 'id' => $token->user_id, 'code' => $token->code]));
$I->see('Thank you, registration is now complete.');
$I->see('Logout');

View File

@ -0,0 +1,32 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\UserFixture;
use tests\_pages\CreatePage;
use tests\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that user creation works');
$I->haveFixtures(['user' => UserFixture::className()]);
$loginPage = LoginPage::openBy($I);
$user = $I->grabFixture('user', 'user');
$loginPage->login($user->email, 'qwerty');
$page = CreatePage::openBy($I);
$I->amGoingTo('try to create user with empty fields');
$page->create('', '', '');
$I->expectTo('see validations errors');
$I->see('Username cannot be blank.');
$I->see('Email cannot be blank.');
$page->create('foobar', 'foobar@example.com', 'foobar');
$I->see('User has been created');
Yii::$app->user->logout();
LoginPage::openBy($I)->login('foobar@example.com', 'foobar');
$I->see('Logout');

View File

@ -0,0 +1,41 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\UserFixture;
use tests\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that login works');
$I->haveFixtures(['user' => UserFixture::className()]);
$page = LoginPage::openBy($I);
$I->amGoingTo('try to login with empty credentials');
$page->login('', '');
$I->expectTo('see validations errors');
$I->see('Login cannot be blank.');
$I->see('Password cannot be blank.');
$I->amGoingTo('try to login with unconfirmed account');
$user = $I->grabFixture('user', 'unconfirmed');
$page->login($user->email, 'qwerty');
$I->see('You need to confirm your email address');
$I->amGoingTo('try to login with blocked account');
$user = $I->grabFixture('user', 'blocked');
$page->login($user->email, 'qwerty');
$I->see('Your account has been blocked');
$I->amGoingTo('try to login with wrong credentials');
$user = $I->grabFixture('user', 'user');
$page->login($user->email, 'wrong');
$I->expectTo('see validations errors');
$I->see('Invalid login or password');
$I->amGoingTo('try to login with correct credentials');
$page->login($user->email, 'qwerty');
$I->dontSee('Login');
$I->see('Logout');

View File

@ -0,0 +1,56 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\TokenFixture;
use tests\_fixtures\UserFixture;
use tests\_pages\RecoveryPage;
use tests\_pages\LoginPage;
use yii\helpers\Html;
use yii\helpers\Url;
use Da\User\Model\User;
use Da\User\Model\Token;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that password recovery works');
$I->haveFixtures(['user' => UserFixture::className(), 'token' => TokenFixture::className()]);
$I->amGoingTo('try to request recovery token for unconfirmed account');
$page = RecoveryPage::openBy($I);
$user = $I->grabFixture('user', 'unconfirmed');
$page->recover($user->email);
$I->see('An email has been sent with instructions for resetting your password');
$I->amGoingTo('try to request recovery token');
$page = RecoveryPage::openBy($I);
$user = $I->grabFixture('user', 'user');
$page->recover($user->email);
$I->see('An email has been sent with instructions for resetting your password');
$user = $I->grabRecord(User::className(), ['email' => $user->email]);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
/** @var yii\swiftmailer\Message $message */
$message = $I->grabLastSentEmail();
$I->assertArrayHasKey($user->email, $message->getTo());
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
$I->amGoingTo('reset password with invalid token');
$user = $I->grabFixture('user', 'user_with_expired_recovery_token');
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
$I->see('Recovery link is invalid or expired. Please try requesting a new one.');
$I->amGoingTo('reset password');
$user = $I->grabFixture('user', 'user_with_recovery_token');
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_RECOVERY]);
$I->amOnPage(Url::toRoute(['/user/recovery/reset', 'id' => $user->id, 'code' => $token->code]));
$I->fillField('#recovery-form-password', 'newpass');
$I->click('Finish');
$I->see('Your password has been changed successfully.');
$page = LoginPage::openBy($I);
$page->login($user->email, 'qwerty');
$I->see('Invalid login or password');
$page->login($user->email, 'newpass');
$I->dontSee('Invalid login or password');

View File

@ -0,0 +1,104 @@
<?php
use Da\User\Model\Token;
use Da\User\Model\User;
use Da\User\Module;
use tests\_fixtures\UserFixture;
use tests\_pages\LoginPage;
use tests\_pages\RegistrationPage;
use yii\helpers\Html;
class RegistrationCest
{
public function _before(FunctionalTester $I)
{
$I->haveFixtures(['user' => UserFixture::className()]);
}
public function _after(FunctionalTester $I)
{
\Yii::$container->set(Module::className(), [
'enableConfirmation' => true,
'enableGeneratingPassword' => false,
]);
}
/**
* Tests registration with email, username and password without any confirmation.
* @param FunctionalTester $I
*/
public function testRegistration(FunctionalTester $I)
{
\Yii::$container->set(Module::className(), [
'enableConfirmation' => false,
'enableGeneratingPassword' => false,
]);
$page = RegistrationPage::openBy($I);
$I->amGoingTo('try to register with empty credentials');
$page->register('', '', '');
$I->see('Username cannot be blank');
$I->see('Email cannot be blank');
$I->see('Password cannot be blank');
$I->amGoingTo('try to register with already used email and username');
$user = $I->grabFixture('user', 'user');
$page->register($user->email, $user->username, 'qwerty');
$I->see(Html::encode('This username has already been taken'));
$I->see(Html::encode('This email address has already been taken'));
$page->register('tester@example.com', 'tester', 'tester');
$I->see('Your account has been created and a message with further instructions has been sent to your email');
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
$I->assertTrue($user->isConfirmed);
$page = LoginPage::openBy($I);
$page->login('tester', 'tester');
$I->see('Logout');
}
/**
* Tests registration when confirmation message is sent.
* @param FunctionalTester $I
*/
public function testRegistrationWithConfirmation(FunctionalTester $I)
{
\Yii::$container->set(Module::className(), [
'enableConfirmation' => true,
]);
$page = RegistrationPage::openBy($I);
$page->register('tester@example.com', 'tester', 'tester');
$I->see('Your account has been created and a message with further instructions has been sent to your email');
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRMATION]);
/** @var yii\swiftmailer\Message $message */
$message = $I->grabLastSentEmail();
$I->assertArrayHasKey($user->email, $message->getTo());
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
$I->assertFalse($user->isConfirmed);
}
/**
* Tests registration when password is generated automatically and sent to user.
* @param FunctionalTester $I
*/
public function testRegistrationWithoutPassword(FunctionalTester $I)
{
\Yii::$container->set(Module::className(), [
'enableConfirmation' => false,
'enableGeneratingPassword' => true,
]);
$page = RegistrationPage::openBy($I);
$page->register('tester@example.com', 'tester');
$I->see('Your account has been created and a message with further instructions has been sent to your email');
$user = $I->grabRecord(User::className(), ['email' => 'tester@example.com']);
$I->assertEquals('tester', $user->username);
/** @var yii\swiftmailer\Message $message */
$message = $I->grabLastSentEmail();
$I->assertArrayHasKey($user->email, $message->getTo());
$I->assertContains('We have generated a password for you', utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\UserFixture;
use tests\_pages\ResendPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that resending of confirmation tokens works');
$I->haveFixtures(['user' => UserFixture::className()]);
$I->amGoingTo('try to resend token to non-existent user');
$page = ResendPage::openBy($I);
$page->resend('foo@example.com');
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
$I->amGoingTo('try to resend token to already confirmed user');
$page = ResendPage::openBy($I);
$user = $I->grabFixture('user', 'user');
$page->resend($user->email);
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');
$I->amGoingTo('try to resend token to unconfirmed user');
$page = ResendPage::openBy($I);
$user = $I->grabFixture('user', 'unconfirmed');
$page->resend($user->email);
$I->see('A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.');

View File

@ -0,0 +1,86 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use Da\User\Model\Token;
use Da\User\Model\User;
use tests\_fixtures\ProfileFixture;
use tests\_fixtures\UserFixture;
use tests\_pages\LoginPage;
use tests\_pages\SettingsPage;
use yii\helpers\Html;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that account settings page work');
$I->haveFixtures(['user' => UserFixture::className(), 'profile' => ProfileFixture::className()]);
$page = LoginPage::openBy($I);
$user = $I->grabFixture('user', 'user');
$page->login($user->username, 'qwerty');
$page = SettingsPage::openBy($I);
$I->amGoingTo('check that current password is required and must be valid');
$page->update($user->email, $user->username, 'wrong');
$I->see('Current password is not valid');
$I->amGoingTo('check that email is changing properly');
$page->update('new_user@example.com', $user->username, 'qwerty');
$I->seeRecord(User::className(), ['email' => $user->email, 'unconfirmed_email' => 'new_user@example.com']);
$I->see('A confirmation message has been sent to your new email address');
$user = $I->grabRecord(User::className(), ['id' => $user->id]);
$token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_CONFIRM_NEW_EMAIL]);
/** @var yii\swiftmailer\Message $message */
$message = $I->grabLastSentEmail();
$I->assertArrayHasKey($user->unconfirmed_email, $message->getTo());
$I->assertContains(Html::encode($token->getUrl()), utf8_encode(quoted_printable_decode($message->getSwiftMessage()->toString())));
Yii::$app->user->logout();
$I->amGoingTo('log in using new email address before clicking the confirmation link');
$page = LoginPage::openBy($I);
$page->login('new_user@example.com', 'qwerty');
$I->see('Invalid login or password');
$I->amGoingTo('log in using new email address after clicking the confirmation link');
$user->attemptEmailChange($token->code);
$page->login('new_user@example.com', 'qwerty');
$I->see('Logout');
$I->seeRecord(User::className(), [
'id' => 1,
'email' => 'new_user@example.com',
'unconfirmed_email' => null,
]);
$I->amGoingTo('reset email changing process');
$page = SettingsPage::openBy($I);
$page->update('user@example.com', $user->username, 'qwerty');
$I->see('A confirmation message has been sent to your new email address');
$I->seeRecord(User::className(), [
'id' => 1,
'email' => 'new_user@example.com',
'unconfirmed_email' => 'user@example.com',
]);
$page->update('new_user@example.com', $user->username, 'qwerty');
$I->see('Your account details have been updated');
$I->seeRecord(User::className(), [
'id' => 1,
'email' => 'new_user@example.com',
'unconfirmed_email' => null,
]);
$I->amGoingTo('change username and password');
$page->update('new_user@example.com', 'nickname', 'qwerty', '123654');
$I->see('Your account details have been updated');
$I->seeRecord(User::className(), [
'username' => 'nickname',
'email' => 'new_user@example.com',
]);
Yii::$app->user->logout();
$I->amGoingTo('login with new credentials');
$page = LoginPage::openBy($I);
$page->login('nickname', '123654');
$I->see('Logout');

View File

@ -0,0 +1,26 @@
<?php
/**
* @var Codeception\Scenario $scenario
*/
use tests\_fixtures\UserFixture;
use tests\_pages\UpdatePage;
use tests\_pages\LoginPage;
$I = new FunctionalTester($scenario);
$I->wantTo('ensure that user update works');
$I->haveFixtures(['user' => UserFixture::className()]);
$loginPage = LoginPage::openBy($I);
$user = $I->grabFixture('user', 'user');
$loginPage->login($user->email, 'qwerty');
$page = UpdatePage::openBy($I, ['id' => $user->id]);
$page->update('user', 'updated_user@example.com', 'new_pass');
$I->see('Account details have been updated');
Yii::$app->user->logout();
LoginPage::openBy($I)->login('updated_user@example.com', 'new_pass');
$I->see('Logout');

View File

@ -0,0 +1 @@
<?php

5
tests/unit.suite.yml Normal file
View File

@ -0,0 +1,5 @@
class_name: UnitTester
modules:
enabled:
- Asserts
- Yii2

View File

@ -0,0 +1 @@
<?php