fix test configuration
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace Da\User;
|
||||
|
||||
use Da\User\Helper\ClassMapHelper;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Validator\TimeZoneValidator;
|
||||
use Yii;
|
||||
use yii\authclient\Collection;
|
||||
@ -23,7 +24,7 @@ class Bootstrap implements BootstrapInterface
|
||||
|
||||
if ($app->hasModule('user') && $app->getModule('user') instanceof Module) {
|
||||
$map = $this->buildClassMap($app->getModule('user')->classMap);
|
||||
$this->initContainer($map);
|
||||
$this->initContainer($app,$map);
|
||||
$this->initTranslations($app);
|
||||
$this->initMailServiceConfiguration($app, $app->getModule('user'));
|
||||
|
||||
@ -41,9 +42,10 @@ class Bootstrap implements BootstrapInterface
|
||||
/**
|
||||
* Initialize container with module classes
|
||||
*
|
||||
* @param \yii\base\Application $app
|
||||
* @param array $map the previously built class map list
|
||||
*/
|
||||
protected function initContainer($map)
|
||||
protected function initContainer($app, $map)
|
||||
{
|
||||
$di = Yii::$container;
|
||||
try {
|
||||
@ -99,9 +101,12 @@ try{
|
||||
$name = (substr($class, strrpos($class, '\\') + 1));
|
||||
$modelClassMap[$class] = $model;
|
||||
if (in_array($name, ['User', 'Profile', 'Token', 'SocialNetworkAccount'])) {
|
||||
$di->set("Da\\User\\Query\\{$name}Query", function() use ($model) {
|
||||
$di->set(
|
||||
"Da\\User\\Query\\{$name}Query",
|
||||
function () use ($model) {
|
||||
return $model::find();
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
$di->setSingleton(ClassMapHelper::class, ClassMapHelper::class, [$modelClassMap]);
|
||||
@ -109,14 +114,15 @@ try{
|
||||
// search class
|
||||
$di->set(Search\UserSearch::class, [$di->get(Query\UserQuery::class)]);
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
if ($app instanceof WebApplication) {
|
||||
|
||||
// override Yii
|
||||
$di->set(
|
||||
'yii\web\User',
|
||||
[
|
||||
'enableAutoLogin' => true,
|
||||
'loginUrl' => ['/user/auth/login'],
|
||||
'identityClass' => $di->get(ClassMapHelper::class)->get('User')
|
||||
'identityClass' => $di->get(ClassMapHelper::class)->get(User::class)
|
||||
]
|
||||
);
|
||||
}
|
||||
@ -213,6 +219,7 @@ try{
|
||||
protected function initControllerNamespace(WebApplication $app)
|
||||
{
|
||||
$app->getModule('user')->controllerNamespace = 'Da\User\Controller';
|
||||
$app->getModule('user')->setViewPath('@Da/User/resources/views');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,7 +236,7 @@ try{
|
||||
$defaults = [
|
||||
// --- models
|
||||
'User' => 'Da\User\Model\User',
|
||||
'Account' => 'Da\User\Model\Account',
|
||||
'SocialNetworkAccount' => 'Da\User\Model\SocialNetworkAccount',
|
||||
'Profile' => 'Da\User\Model\Profile',
|
||||
'Token' => 'Da\User\Model\Token',
|
||||
// --- search
|
||||
@ -245,7 +252,7 @@ try{
|
||||
$routes = [
|
||||
'Da\User\Model' => [
|
||||
'User',
|
||||
'Account',
|
||||
'SocialNetworkAccount',
|
||||
'Profile',
|
||||
'Token'
|
||||
],
|
||||
@ -286,7 +293,7 @@ try{
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
throw new Exception('Unknown configuration class name');
|
||||
throw new Exception("Unknown configuration class name '{$name}'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class AdminController extends Controller
|
||||
* @param UserQuery $userQuery
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($id, Module $module, UserQuery $userQuery, array $config)
|
||||
public function __construct($id, Module $module, UserQuery $userQuery, array $config = [])
|
||||
{
|
||||
$this->userQuery = $userQuery;
|
||||
parent::__construct($id, $module, $config);
|
||||
|
||||
@ -20,7 +20,7 @@ class ProfileController extends Controller
|
||||
* @param ProfileQuery $profileQuery
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($id, Module $module, ProfileQuery $profileQuery, array $config)
|
||||
public function __construct($id, Module $module, ProfileQuery $profileQuery, array $config = [])
|
||||
{
|
||||
$this->profileQuery = $profileQuery;
|
||||
parent::__construct($id, $module, $config);
|
||||
|
||||
@ -34,7 +34,7 @@ class RecoveryController extends Controller
|
||||
* @param TokenQuery $tokenQuery
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct($id, Module $module, UserQuery $userQuery, TokenQuery $tokenQuery, array $config)
|
||||
public function __construct($id, Module $module, UserQuery $userQuery, TokenQuery $tokenQuery, array $config = [])
|
||||
{
|
||||
$this->userQuery = $userQuery;
|
||||
$this->tokenQuery = $tokenQuery;
|
||||
@ -90,7 +90,7 @@ class RecoveryController extends Controller
|
||||
$this->trigger(FormEvent::EVENT_AFTER_REQUEST, $event);
|
||||
|
||||
return $this->render(
|
||||
'/user/shared/message',
|
||||
'/shared/message',
|
||||
[
|
||||
'title' => Yii::t('user', 'Recovery message sent'),
|
||||
'module' => $this->module,
|
||||
@ -130,7 +130,7 @@ class RecoveryController extends Controller
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'/user/shared/message',
|
||||
'/shared/message',
|
||||
[
|
||||
'title' => Yii::t('user', 'Invalid or expired link'),
|
||||
'module' => $this->module,
|
||||
@ -149,7 +149,7 @@ class RecoveryController extends Controller
|
||||
$this->trigger(ResetPasswordEvent::EVENT_AFTER_RESET, $event);
|
||||
|
||||
return $this->render(
|
||||
'/user/shared/message',
|
||||
'/shared/message',
|
||||
[
|
||||
'title' => Yii::t('user', 'Password has been changed'),
|
||||
'module' => $this->module,
|
||||
|
||||
@ -47,7 +47,7 @@ class RegistrationController extends Controller
|
||||
Module $module,
|
||||
UserQuery $userQuery,
|
||||
SocialNetworkAccountQuery $socialNetworkAccountQuery,
|
||||
array $config
|
||||
array $config = []
|
||||
) {
|
||||
|
||||
$this->userQuery = $userQuery;
|
||||
@ -106,7 +106,7 @@ class RegistrationController extends Controller
|
||||
'Your account has been created and a message with further instructions has been sent to your email'
|
||||
)
|
||||
);
|
||||
return $this->render('/user/shared/message', [
|
||||
return $this->render('/shared/message', [
|
||||
'title' => Yii::t('user', 'Your account has been created')
|
||||
]);
|
||||
}
|
||||
@ -186,7 +186,7 @@ class RegistrationController extends Controller
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'/user/shared/message',
|
||||
'/shared/message',
|
||||
[
|
||||
'title' => Yii::t('user', 'Account confirmation'),
|
||||
'module' => $this->module,
|
||||
|
||||
@ -36,7 +36,7 @@ class SecurityController extends Controller
|
||||
$id,
|
||||
Module $module,
|
||||
SocialNetworkAccountQuery $socialNetworkAccountQuery,
|
||||
array $config
|
||||
array $config = []
|
||||
) {
|
||||
$this->socialNetworkAccountQuery = $socialNetworkAccountQuery;
|
||||
parent::__construct($id, $module, $config);
|
||||
|
||||
@ -54,7 +54,7 @@ class SettingsController extends Controller
|
||||
ProfileQuery $profileQuery,
|
||||
UserQuery $userQuery,
|
||||
SocialNetworkAccountQuery $socialNetworkAccountQuery,
|
||||
array $config
|
||||
array $config = []
|
||||
) {
|
||||
$this->profileQuery = $profileQuery;
|
||||
$this->userQuery = $userQuery;
|
||||
|
||||
@ -33,7 +33,7 @@ class RegistrationForm extends Model
|
||||
public function rules()
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getClassMap()->get('User');
|
||||
$user = $this->getClassMap()->get(User::class);
|
||||
|
||||
return [
|
||||
// username rules
|
||||
|
||||
@ -138,7 +138,7 @@ class Profile extends ActiveRecord
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne($this->getClassMap()->get('User'), ['id' => 'user_id']);
|
||||
return $this->hasOne($this->getClassMap()->get(User::class), ['id' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -96,7 +96,7 @@ class SocialNetworkAccount extends ActiveRecord
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne($this->getClassMap()->get('User'), ['id' => 'user_id']);
|
||||
return $this->hasOne($this->getClassMap()->get(User::class), ['id' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -74,7 +74,7 @@ class Token extends ActiveRecord
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->hasOne($this->getClassMap()->get('User'), ['id' => 'user_id']);
|
||||
return $this->hasOne($this->getClassMap()->get(User::class), ['id' => 'user_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -238,7 +238,7 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
*/
|
||||
public function getProfile()
|
||||
{
|
||||
return $this->hasOne($this->getClassMap()->get('Profile'), ['user_id' => 'id']);
|
||||
return $this->hasOne($this->getClassMap()->get(Profile::class), ['user_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -14,6 +14,10 @@ class Module extends \yii\base\Module
|
||||
* @var bool whether to force email confirmation to.
|
||||
*/
|
||||
public $enableEmailConfirmation = true;
|
||||
/**
|
||||
* @var bool whether to display flash messages or not
|
||||
*/
|
||||
public $enableFlashMessages = true;
|
||||
/**
|
||||
* @var bool whether to generate passwords automatically and remove the password field from the registration form.
|
||||
*/
|
||||
@ -88,4 +92,6 @@ class Module extends \yii\base\Module
|
||||
'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
|
||||
'settings/<action:\w+>' => 'settings/<action>'
|
||||
];
|
||||
|
||||
public $viewPath = '@Da/User/resources/views';
|
||||
}
|
||||
|
||||
@ -18,13 +18,13 @@ class AccountConfirmationService implements ServiceInterface
|
||||
public function __construct(
|
||||
$code,
|
||||
User $model,
|
||||
TokenQuery $tokenQuery,
|
||||
UserConfirmationService $userConfirmationService
|
||||
UserConfirmationService $userConfirmationService,
|
||||
TokenQuery $tokenQuery
|
||||
) {
|
||||
$this->code = $code;
|
||||
$this->model = $model;
|
||||
$this->tokenQuery = $tokenQuery;
|
||||
$this->userConfirmationService = $userConfirmationService;
|
||||
$this->tokenQuery = $tokenQuery;
|
||||
}
|
||||
|
||||
public function run()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use AssignmentsWidget;
|
||||
use Da\User\Widget\AssignmentsWidget;
|
||||
|
||||
/**
|
||||
* @var yii\web\View $this
|
||||
@ -20,6 +20,6 @@ use AssignmentsWidget;
|
||||
]
|
||||
) ?>
|
||||
|
||||
<?= Assignments::widget(['userId' => $user->id]) ?>
|
||||
<?= AssignmentsWidget::widget(['userId' => $user->id]) ?>
|
||||
|
||||
<?php $this->endContent() ?>
|
||||
|
||||
@ -1,18 +1,9 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Dektrium project.
|
||||
*
|
||||
* (c) Dektrium project <http://github.com/dektrium>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE.md
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use yii\bootstrap\Alert;
|
||||
|
||||
/**
|
||||
* @var dektrium\user\Module $module
|
||||
* @var \Da\User\Module $module
|
||||
*/
|
||||
?>
|
||||
|
||||
|
||||
@ -10,6 +10,6 @@ $this->title = $title;
|
||||
|
||||
?>
|
||||
|
||||
<?= $this->render('/_alert', [
|
||||
<?= $this->render('_alert', [
|
||||
'module' => $module,
|
||||
]);
|
||||
|
||||
2
tests/_app/assets/.gitignore
vendored
Normal file
2
tests/_app/assets/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@ -18,6 +18,9 @@ return [
|
||||
],
|
||||
],
|
||||
'components' => [
|
||||
'assetManager' => [
|
||||
'basePath' => __DIR__ . '/../assets'
|
||||
],
|
||||
'db' => require __DIR__ . '/db.php',
|
||||
'mailer' => [
|
||||
'useFileTransport' => true,
|
||||
|
||||
@ -4,6 +4,7 @@ $time = time();
|
||||
|
||||
return [
|
||||
'user' => [
|
||||
'id' => 1,
|
||||
'username' => 'user',
|
||||
'email' => 'user@example.com',
|
||||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
|
||||
@ -13,6 +14,7 @@ return [
|
||||
'confirmed_at' => $time,
|
||||
],
|
||||
'unconfirmed' => [
|
||||
'id' => 2,
|
||||
'username' => 'joe',
|
||||
'email' => 'joe@example.com',
|
||||
'password_hash' => '$2y$13$CIH1LSMPzU9xDCywt3QO8uovAu2axp8hwuXVa72oI.1G/USsGyMBS',
|
||||
@ -21,6 +23,7 @@ return [
|
||||
'updated_at' => $time,
|
||||
],
|
||||
'unconfirmed_with_expired_token' => [
|
||||
'id' => 3,
|
||||
'username' => 'john',
|
||||
'email' => 'john@example.com',
|
||||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
|
||||
@ -29,6 +32,7 @@ return [
|
||||
'updated_at' => $time - 86401,
|
||||
],
|
||||
'blocked' => [
|
||||
'id' => 4,
|
||||
'username' => 'steven',
|
||||
'email' => 'steven@example.com',
|
||||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
|
||||
@ -39,6 +43,7 @@ return [
|
||||
'confirmed_at' => $time,
|
||||
],
|
||||
'user_with_expired_recovery_token' => [
|
||||
'id' => 5,
|
||||
'username' => 'andrew',
|
||||
'email' => 'andrew@example.com',
|
||||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
|
||||
@ -48,6 +53,7 @@ return [
|
||||
'confirmed_at' => $time - 21601,
|
||||
],
|
||||
'user_with_recovery_token' => [
|
||||
'id' => 6,
|
||||
'username' => 'alex',
|
||||
'email' => 'alex@example.com',
|
||||
'password_hash' => '$2y$13$qY.ImaYBppt66qez6B31QO92jc5DYVRzo5NxM1ivItkW74WsSG6Ui',
|
||||
|
||||
Reference in New Issue
Block a user