mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 06:44:59 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,46 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Test;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\GroupCenter;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use LogicException;
|
||||
|
||||
/**
|
||||
* A trait to prepare user with permission. May be used
|
||||
* A trait to prepare user with permission. May be used
|
||||
* within tests.
|
||||
*
|
||||
*
|
||||
* **Usage : ** You must set up trait with `setUpTrait` before use
|
||||
* and use tearDownTrait after usage.
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
trait PrepareUserTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* prepare a user with correct permissions
|
||||
*
|
||||
* prepare a user with correct permissions.
|
||||
*
|
||||
* Example of permissions:
|
||||
* ```
|
||||
* array(
|
||||
@@ -52,38 +40,36 @@ trait PrepareUserTrait
|
||||
* )
|
||||
* )
|
||||
* ```
|
||||
* Scope must be an int. Scope created have this int as id, and the
|
||||
* Scope must be an int. Scope created have this int as id, and the
|
||||
* int converted to string as name.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param array $permissions an array of permissions, with key 'center' for the center and key 'attrs' for an array of ['role' => (string), 'scope' => (int)]
|
||||
*
|
||||
* @throws LogicException if the trait is not set up
|
||||
*
|
||||
* @return User
|
||||
* @throws \LogicException if the trait is not set up
|
||||
*/
|
||||
protected function prepareUser(array $permissions)
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
$groupCenter = (new GroupCenter())
|
||||
->setCenter($permission['center']);
|
||||
->setCenter($permission['center']);
|
||||
$permissionGroup = new PermissionsGroup();
|
||||
|
||||
|
||||
foreach ($permission['permissionsGroup'] as $pg) {
|
||||
|
||||
$roleScope = (new RoleScope())
|
||||
->setRole($pg['role'])
|
||||
->setScope($pg['scope']);
|
||||
;
|
||||
->setRole($pg['role'])
|
||||
->setScope($pg['scope']);
|
||||
|
||||
$permissionGroup->addRoleScope($roleScope);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$groupCenter->setPermissionsGroup($permissionGroup);
|
||||
$user->addGroupCenter($groupCenter);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user