fixing some tests
This commit is contained in:
15
tests/_app/config/console.php
Normal file
15
tests/_app/config/console.php
Normal 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
15
tests/_app/config/db.php
Normal 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;
|
||||
34
tests/_app/config/test.php
Normal file
34
tests/_app/config/test.php
Normal 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' => [],
|
||||
];
|
||||
13
tests/_app/controllers/SiteController.php
Normal file
13
tests/_app/controllers/SiteController.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
||||
10
tests/_app/views/layouts/main.php
Normal file
10
tests/_app/views/layouts/main.php
Normal 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;
|
||||
1
tests/_app/views/site/index.php
Normal file
1
tests/_app/views/site/index.php
Normal file
@ -0,0 +1 @@
|
||||
Index
|
||||
12
tests/_app/yii.php
Normal file
12
tests/_app/yii.php
Normal 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
20
tests/_bootstrap.php
Normal 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';
|
||||
14
tests/_fixtures/ProfileFixture.php
Normal file
14
tests/_fixtures/ProfileFixture.php
Normal 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'
|
||||
];
|
||||
}
|
||||
14
tests/_fixtures/TokenFixture.php
Normal file
14
tests/_fixtures/TokenFixture.php
Normal 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'
|
||||
];
|
||||
}
|
||||
10
tests/_fixtures/UserFixture.php
Normal file
10
tests/_fixtures/UserFixture.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace tests\_fixtures;
|
||||
|
||||
use yii\test\ActiveFixture;
|
||||
|
||||
class UserFixture extends ActiveFixture
|
||||
{
|
||||
public $modelClass = 'Da\User\Model\User';
|
||||
}
|
||||
10
tests/_fixtures/data/profile.php
Normal file
10
tests/_fixtures/data/profile.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
$time = time();
|
||||
|
||||
return [
|
||||
'user' => [
|
||||
'user_id' => 1,
|
||||
'name' => 'John Doe',
|
||||
],
|
||||
];
|
||||
32
tests/_fixtures/data/token.php
Normal file
32
tests/_fixtures/data/token.php
Normal 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,
|
||||
],
|
||||
];
|
||||
59
tests/_fixtures/data/user.php
Normal file
59
tests/_fixtures/data/user.php
Normal 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
2
tests/_output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
16
tests/_pages/AdminPage.php
Normal file
16
tests/_pages/AdminPage.php
Normal 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';
|
||||
}
|
||||
29
tests/_pages/CreatePage.php
Normal file
29
tests/_pages/CreatePage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
27
tests/_pages/LoginPage.php
Normal file
27
tests/_pages/LoginPage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
25
tests/_pages/RecoveryPage.php
Normal file
25
tests/_pages/RecoveryPage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
31
tests/_pages/RegistrationPage.php
Normal file
31
tests/_pages/RegistrationPage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
25
tests/_pages/ResendPage.php
Normal file
25
tests/_pages/ResendPage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
31
tests/_pages/SettingsPage.php
Normal file
31
tests/_pages/SettingsPage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
29
tests/_pages/UpdatePage.php
Normal file
29
tests/_pages/UpdatePage.php
Normal 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');
|
||||
}
|
||||
}
|
||||
26
tests/_support/FunctionalTester.php
Normal file
26
tests/_support/FunctionalTester.php
Normal 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
|
||||
*/
|
||||
}
|
||||
26
tests/_support/UnitTester.php
Normal file
26
tests/_support/UnitTester.php
Normal 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
|
||||
*/
|
||||
}
|
||||
6
tests/functional.suite.yml
Normal file
6
tests/functional.suite.yml
Normal file
@ -0,0 +1,6 @@
|
||||
class_name: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- Asserts
|
||||
23
tests/functional/ConfirmationCept.php
Normal file
23
tests/functional/ConfirmationCept.php
Normal 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');
|
||||
32
tests/functional/CreateCept.php
Normal file
32
tests/functional/CreateCept.php
Normal 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');
|
||||
41
tests/functional/LoginCept.php
Normal file
41
tests/functional/LoginCept.php
Normal 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');
|
||||
56
tests/functional/RecoveryCept.php
Normal file
56
tests/functional/RecoveryCept.php
Normal 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');
|
||||
104
tests/functional/RegistrationCest.php
Normal file
104
tests/functional/RegistrationCest.php
Normal 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())));
|
||||
}
|
||||
}
|
||||
29
tests/functional/ResendCept.php
Normal file
29
tests/functional/ResendCept.php
Normal 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.');
|
||||
86
tests/functional/SettingsCept.php
Normal file
86
tests/functional/SettingsCept.php
Normal 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');
|
||||
26
tests/functional/UpdateCept.php
Normal file
26
tests/functional/UpdateCept.php
Normal 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');
|
||||
1
tests/functional/_bootstrap.php
Normal file
1
tests/functional/_bootstrap.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
||||
5
tests/unit.suite.yml
Normal file
5
tests/unit.suite.yml
Normal file
@ -0,0 +1,5 @@
|
||||
class_name: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- Yii2
|
||||
1
tests/unit/_bootstrap.php
Normal file
1
tests/unit/_bootstrap.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
||||
Reference in New Issue
Block a user