TwigIntegrationTest.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace JMS\SecurityExtraBundle\Tests\Functional;
  3. use JMS\SecurityExtraBundle\Security\Authorization\Expression\Expression;
  4. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  5. use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
  6. class TwigIntegrationTest extends BaseTestCase
  7. {
  8. private $context;
  9. private $twig;
  10. /**
  11. * @runInSeparateProcess
  12. */
  13. public function testIsExprGrantedWithSufficientPermissions()
  14. {
  15. $this->context->setToken(new UsernamePasswordToken('foo', 'bar', 'baz', array('FOO')));
  16. $this->assertEquals('granted',
  17. $this->twig->render('TestBundle::is_expr_granted.html.twig'));
  18. }
  19. /**
  20. * @runInSeparateProcess
  21. */
  22. public function testIsExprGranted()
  23. {
  24. $this->context->setToken(new AnonymousToken('foo', 'bar'));
  25. $this->assertEquals('denied',
  26. $this->twig->render('TestBundle::is_expr_granted.html.twig'));
  27. }
  28. protected function setUp()
  29. {
  30. parent::setUp();
  31. $this->createClient(array('config' => 'all_voters_disabled.yml'));
  32. $this->context = self::$kernel->getContainer()->get('security.context');
  33. $this->twig = self::$kernel->getContainer()->get('twig');
  34. }
  35. }