mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
bootstrap test for isGranted
This commit is contained in:
parent
a4fbf27519
commit
bcdee0be94
@ -28,7 +28,7 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||||
@ -104,7 +104,7 @@ class ExportManager
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
EntityManagerInterface $em,
|
EntityManagerInterface $em,
|
||||||
AuthorizationChecker $authorizationChecker,
|
AuthorizationCheckerInterface $authorizationChecker,
|
||||||
AuthorizationHelper $authorizationHelper,
|
AuthorizationHelper $authorizationHelper,
|
||||||
TokenStorageInterface $tokenStorage)
|
TokenStorageInterface $tokenStorage)
|
||||||
{
|
{
|
||||||
|
@ -45,10 +45,10 @@ trait PrepareUserTrait
|
|||||||
* ```
|
* ```
|
||||||
* array(
|
* array(
|
||||||
* array( 'center' => $centerA, 'permissionsGroup' => array(
|
* array( 'center' => $centerA, 'permissionsGroup' => array(
|
||||||
* [ 'role' => 'CHILL_REPORT_SEE', 'scope' => $scopeA]
|
* 'role' => 'CHILL_REPORT_SEE', 'scope' => $scopeA
|
||||||
* ),
|
* ),
|
||||||
* array( 'center' => $centerB, 'permissionsGroup' => array(
|
* array( 'center' => $centerB, 'permissionsGroup' => array(
|
||||||
* [ 'role' => 'CHILL_ACTIVITY_UPDATE', 'scope' => $scopeB]
|
* 'role' => 'CHILL_ACTIVITY_UPDATE', 'scope' => $scopeB
|
||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
* ```
|
* ```
|
||||||
|
@ -21,6 +21,7 @@ namespace Chill\MainBundle\Tests\Export;
|
|||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
use Chill\MainBundle\Export\ExportManager;
|
use Chill\MainBundle\Export\ExportManager;
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the export manager
|
* Test the export manager
|
||||||
@ -30,6 +31,11 @@ use Chill\MainBundle\Export\ExportManager;
|
|||||||
*/
|
*/
|
||||||
class ExportManagerTest extends KernelTestCase
|
class ExportManagerTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use \Chill\MainBundle\Test\PrepareCenterTrait;
|
||||||
|
use \Chill\MainBundle\Test\PrepareUserTrait;
|
||||||
|
use \Chill\MainBundle\Test\PrepareScopeTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
@ -69,10 +75,10 @@ class ExportManagerTest extends KernelTestCase
|
|||||||
* @param \Symfony\Component\Security\Core\User\UserInterface $user
|
* @param \Symfony\Component\Security\Core\User\UserInterface $user
|
||||||
* @return ExportManager
|
* @return ExportManager
|
||||||
*/
|
*/
|
||||||
public function createExportManager(
|
protected function createExportManager(
|
||||||
\Psr\Log\LoggerInterface $logger = null,
|
\Psr\Log\LoggerInterface $logger = null,
|
||||||
\Doctrine\ORM\EntityManagerInterface $em = null,
|
\Doctrine\ORM\EntityManagerInterface $em = null,
|
||||||
\Symfony\Component\Security\Core\Authorization\AuthorizationChecker $authorizationChecker = null,
|
\Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $authorizationChecker = null,
|
||||||
\Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper = null,
|
\Chill\MainBundle\Security\Authorization\AuthorizationHelper $authorizationHelper = null,
|
||||||
\Symfony\Component\Security\Core\User\UserInterface $user = null
|
\Symfony\Component\Security\Core\User\UserInterface $user = null
|
||||||
)
|
)
|
||||||
@ -287,9 +293,53 @@ class ExportManagerTest extends KernelTestCase
|
|||||||
$this->assertNotContains($formatterBar->reveal(), $obtained);
|
$this->assertNotContains($formatterBar->reveal(), $obtained);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsGrantedForElementUserIsGranted()
|
public function testIsGrantedForElementWithExportAndUserIsGranted()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
$center = $this->prepareCenter(100, 'center A');
|
||||||
|
$user = $this->prepareUser(array());
|
||||||
|
|
||||||
|
$authorizationChecker = $this->prophet->prophesize();
|
||||||
|
$authorizationChecker->willImplement('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
|
||||||
|
$authorizationChecker->isGranted('CHILL_STAT_DUMMY', $center)
|
||||||
|
->willReturn(True);
|
||||||
|
|
||||||
|
$exportManager = $this->createExportManager(null, null,
|
||||||
|
$authorizationChecker->reveal(), null, $user);
|
||||||
|
|
||||||
|
$export = $this->prophet->prophesize();
|
||||||
|
$export->willImplement('Chill\MainBundle\Export\ExportInterface');
|
||||||
|
$export->requiredRole()->willReturn(new Role('CHILL_STAT_DUMMY'));
|
||||||
|
|
||||||
|
$result = $exportManager->isGrantedForElement($export->reveal(), null, array($center));
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsGrantedForElementWithExportAndUserIsGrantedNotForAllCenters()
|
||||||
|
{
|
||||||
|
$center = $this->prepareCenter(100, 'center A');
|
||||||
|
$centerB = $this->prepareCenter(102, 'center B');
|
||||||
|
$user = $this->prepareUser(array());
|
||||||
|
|
||||||
|
$authorizationChecker = $this->prophet->prophesize();
|
||||||
|
$authorizationChecker->willImplement('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
|
||||||
|
$authorizationChecker->isGranted('CHILL_STAT_DUMMY', $center)
|
||||||
|
->willReturn(true);
|
||||||
|
$authorizationChecker->isGranted('CHILL_STAT_DUMMY', $centerB)
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
|
$exportManager = $this->createExportManager(null, null,
|
||||||
|
$authorizationChecker->reveal(), null, $user);
|
||||||
|
|
||||||
|
$export = $this->prophet->prophesize();
|
||||||
|
$export->willImplement('Chill\MainBundle\Export\ExportInterface');
|
||||||
|
$export->requiredRole()->willReturn(new Role('CHILL_STAT_DUMMY'));
|
||||||
|
|
||||||
|
$result = $exportManager->isGrantedForElement($export->reveal(), null, array($center, $centerB));
|
||||||
|
|
||||||
|
$this->assertFalse($result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user