mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix: AuthorizationHelperTest: remove deprecated and deprecation of PrepareScopeTrait
This commit is contained in:
parent
dba1d0548e
commit
5f6e506300
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A trait to prepare center.
|
|
||||||
*
|
|
||||||
* **Usage :** You must set up trait with `setUpTrait` before use
|
|
||||||
* and use tearDownTrait after usage.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
trait PrepareCircleTrait
|
|
||||||
{
|
|
||||||
private $circleProphet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* prepare a mocked center, with and id and name given.
|
|
||||||
*
|
|
||||||
* @param int $id
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return \Chill\MainBundle\Entity\Center
|
|
||||||
*/
|
|
||||||
protected function prepareCircle($id, $name)
|
|
||||||
{
|
|
||||||
if (null === $this->circleProphet) {
|
|
||||||
$this->circleProphet = new \Prophecy\Prophet();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope = $this->circleProphet->prophesize();
|
|
||||||
$scope->willExtend('\\' . \Chill\MainBundle\Entity\Scope::class);
|
|
||||||
$scope->getId()->willReturn($id);
|
|
||||||
$scope->getName()->willReturn($name);
|
|
||||||
|
|
||||||
return $scope->reveal();
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,6 +11,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\MainBundle\Test;
|
namespace Chill\MainBundle\Test;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Scope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A trait to prepare center.
|
* A trait to prepare center.
|
||||||
*
|
*
|
||||||
@ -18,25 +20,24 @@ namespace Chill\MainBundle\Test;
|
|||||||
* and use tearDownTrait after usage.
|
* and use tearDownTrait after usage.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*
|
|
||||||
* @deprecated use PrepareCircleTrait instead
|
|
||||||
*/
|
*/
|
||||||
trait PrepareScopeTrait
|
trait PrepareScopeTrait
|
||||||
{
|
{
|
||||||
use PrepareCircleTrait;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* prepare a mocked center, with and id and name given.
|
* prepare a mocked scope, with and id and name given.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* The name will be present in both lang `fr` and `en`.
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return \Chill\MainBundle\Entity\Center
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
protected function prepareScope($id, $name)
|
protected function prepareScope(int $id, string $name): Scope
|
||||||
{
|
{
|
||||||
return $this->prepareCircle($id, $name);
|
$scope = new Scope();
|
||||||
|
// set the name
|
||||||
|
$scope->setName(['fr' => $name, 'en' => $name]);
|
||||||
|
$reflection = new \ReflectionClass($scope);
|
||||||
|
$idProperty = $reflection->getProperty('id');
|
||||||
|
$idProperty->setAccessible(true);
|
||||||
|
$idProperty->setValue($scope, $id);
|
||||||
|
|
||||||
|
return $scope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,12 @@ use Chill\MainBundle\Entity\HasScopeInterface;
|
|||||||
use Chill\MainBundle\Entity\HasScopesInterface;
|
use Chill\MainBundle\Entity\HasScopesInterface;
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Chill\MainBundle\Test\PrepareCenterTrait;
|
use Chill\MainBundle\Test\PrepareCenterTrait;
|
||||||
use Chill\MainBundle\Test\PrepareScopeTrait;
|
use Chill\MainBundle\Test\PrepareScopeTrait;
|
||||||
use Chill\MainBundle\Test\PrepareUserTrait;
|
use Chill\MainBundle\Test\PrepareUserTrait;
|
||||||
use Chill\MainBundle\Test\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
|
||||||
use function array_map;
|
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,24 +197,6 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFindUsersReaching()
|
|
||||||
{
|
|
||||||
$centerA = self::$kernel->getContainer()
|
|
||||||
->get('doctrine.orm.entity_manager')
|
|
||||||
->getRepository(Center::class)
|
|
||||||
->findOneByName('Center A');
|
|
||||||
|
|
||||||
$users = $this->getAuthorizationHelper()
|
|
||||||
->findUsersReaching(
|
|
||||||
'CHILL_PERSON_SEE',
|
|
||||||
$centerA
|
|
||||||
);
|
|
||||||
|
|
||||||
$usernames = array_map(static fn (User $u) => $u->getUsername(), $users);
|
|
||||||
|
|
||||||
$this->assertContains('center a_social', $usernames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetParentRoles()
|
public function testGetParentRoles()
|
||||||
{
|
{
|
||||||
$parentRoles = $this->getAuthorizationHelper()
|
$parentRoles = $this->getAuthorizationHelper()
|
||||||
@ -272,7 +253,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
@ -338,7 +319,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement(HasCentersInterface::class);
|
$entity->willImplement(HasCentersInterface::class);
|
||||||
$entity->willImplement(HasScopesInterface::class);
|
$entity->willImplement(HasScopesInterface::class);
|
||||||
$entity->getCenters()->willReturn([$centerA, $centerB]);
|
$entity->getCenters()->willReturn([$centerA, $centerB]);
|
||||||
@ -360,7 +341,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement(HasCentersInterface::class);
|
$entity->willImplement(HasCentersInterface::class);
|
||||||
$entity->getCenters()->willReturn([$center, $centerB]);
|
$entity->getCenters()->willReturn([$center, $centerB]);
|
||||||
|
|
||||||
@ -379,7 +360,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
|
|
||||||
@ -403,7 +384,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
|
|
||||||
@ -427,7 +408,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
||||||
$entity->getCenter()->willReturn($centerB);
|
$entity->getCenter()->willReturn($centerB);
|
||||||
@ -448,7 +429,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
|
|
||||||
@ -467,7 +448,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasScopeInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
@ -499,7 +480,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
$entity->willImplement('\\' . \Chill\MainBundle\Entity\HasCenterInterface::class);
|
||||||
$entity->getCenter()->willReturn($centerA);
|
$entity->getCenter()->willReturn($centerA);
|
||||||
|
|
||||||
@ -519,7 +500,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement(HasCenterInterface::class);
|
$entity->willImplement(HasCenterInterface::class);
|
||||||
$entity->willImplement(HasScopeInterface::class);
|
$entity->willImplement(HasScopeInterface::class);
|
||||||
$entity->getCenter()->willReturn($center);
|
$entity->getCenter()->willReturn($center);
|
||||||
@ -543,7 +524,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement(HasCentersInterface::class);
|
$entity->willImplement(HasCentersInterface::class);
|
||||||
$entity->willImplement(HasScopesInterface::class);
|
$entity->willImplement(HasScopesInterface::class);
|
||||||
$entity->getCenters()->willReturn([$centerA, $centerB]);
|
$entity->getCenters()->willReturn([$centerA, $centerB]);
|
||||||
@ -566,7 +547,7 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$helper = $this->getAuthorizationHelper();
|
$helper = $this->getAuthorizationHelper();
|
||||||
$entity = $this->getProphet()->prophesize();
|
$entity = $this->prophesize();
|
||||||
$entity->willImplement(HasCentersInterface::class);
|
$entity->willImplement(HasCentersInterface::class);
|
||||||
$entity->getCenters()->willReturn([$centerB, $centerC]);
|
$entity->getCenters()->willReturn([$centerB, $centerC]);
|
||||||
|
|
||||||
@ -579,6 +560,6 @@ final class AuthorizationHelperTest extends KernelTestCase
|
|||||||
private function getAuthorizationHelper()
|
private function getAuthorizationHelper()
|
||||||
{
|
{
|
||||||
return self::$container
|
return self::$container
|
||||||
->get('chill.main.security.authorization.helper');
|
->get(AuthorizationHelper::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user