getTokenWithRoleNames example

use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

class RoleVoterTest extends TestCase
{
    /** * @dataProvider getVoteTests */
    public function testVoteUsingTokenThatReturnsRoleNames($roles$attributes$expected)
    {
        $voter = new RoleVoter();

        $this->assertSame($expected$voter->vote($this->getTokenWithRoleNames($roles), null, $attributes));
    }

    public static function getVoteTests()
    {
        return [
            [[][], VoterInterface::ACCESS_ABSTAIN],
            [[]['FOO'], VoterInterface::ACCESS_ABSTAIN],
            [[]['ROLE_FOO'], VoterInterface::ACCESS_DENIED],
            [['ROLE_FOO']['ROLE_FOO'], VoterInterface::ACCESS_GRANTED],
            [['ROLE_FOO']['FOO', 'ROLE_FOO'], VoterInterface::ACCESS_GRANTED],
            [['ROLE_BAR', 'ROLE_FOO']['ROLE_FOO'], VoterInterface::ACCESS_GRANTED],

            
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;

class ExpressionVoterTest extends TestCase
{
    /** * @dataProvider getVoteTests */
    public function testVoteWithTokenThatReturnsRoleNames($roles$attributes$expected$tokenExpectsGetRoles = true, $expressionLanguageExpectsEvaluate = true)
    {
        $voter = new ExpressionVoter($this->createExpressionLanguage($expressionLanguageExpectsEvaluate)$this->createTrustResolver()$this->createAuthorizationChecker());

        $this->assertSame($expected$voter->vote($this->getTokenWithRoleNames($roles$tokenExpectsGetRoles), null, $attributes));
    }

    public static function getVoteTests()
    {
        return [
            [[][], VoterInterface::ACCESS_ABSTAIN, false, false],
            [[]['FOO'], VoterInterface::ACCESS_ABSTAIN, false, false],

            [[][self::createExpression()], VoterInterface::ACCESS_DENIED, true, false],

            [['ROLE_FOO'][self::createExpression(), self::createExpression()], VoterInterface::ACCESS_GRANTED],
            [[
use Symfony\Component\Security\Core\Role\RoleHierarchy;

class RoleHierarchyVoterTest extends RoleVoterTest
{
    /** * @dataProvider getVoteTests */
    public function testVoteUsingTokenThatReturnsRoleNames($roles$attributes$expected)
    {
        $voter = new RoleHierarchyVoter(new RoleHierarchy(['ROLE_FOO' => ['ROLE_FOOBAR']]));

        $this->assertSame($expected$voter->vote($this->getTokenWithRoleNames($roles), null, $attributes));
    }

    public static function getVoteTests()
    {
        return array_merge(parent::getVoteTests()[
            [['ROLE_FOO']['ROLE_FOOBAR'], VoterInterface::ACCESS_GRANTED],
        ]);
    }

    /** * @dataProvider getVoteWithEmptyHierarchyTests */
Home | Imprint | This part of the site doesn't use cookies.