* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\Tests\Authorization\Voter; use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Role\Role; class ExpressionVoterTest extends TestCase { /** * @dataProvider getVoteTests */ public function testVote($roles, $attributes, $expected, $tokenExpectsGetRoles = true, $expressionLanguageExpectsEvaluate = true) { $voter = new ExpressionVoter($this->createExpressionLanguage($expressionLanguageExpectsEvaluate), $this->createTrustResolver()); $this->assertSame($expected, $voter->vote($this->getToken($roles, $tokenExpectsGetRoles), null, $attributes)); } public function getVoteTests() { return array( array(array(), array(), VoterInterface::ACCESS_ABSTAIN, false, false), array(array(), array('FOO'), VoterInterface::ACCESS_ABSTAIN, false, false), array(array(), array($this->createExpression()), VoterInterface::ACCESS_DENIED, true, false), array(array('ROLE_FOO'), array($this->createExpression(), $this->createExpression()), VoterInterface::ACCESS_GRANTED), array(array('ROLE_BAR', 'ROLE_FOO'), array($this->createExpression()), VoterInterface::ACCESS_GRANTED), ); } protected function getToken(array $roles, $tokenExpectsGetRoles = true) { foreach ($roles as $i => $role) { $roles[$i] = new Role($role); } $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); if ($tokenExpectsGetRoles) { $token->expects($this->once()) ->method('getRoles') ->will($this->returnValue($roles)); } return $token; } protected function createExpressionLanguage($expressionLanguageExpectsEvaluate = true) { $mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\ExpressionLanguage')->getMock(); if ($expressionLanguageExpectsEvaluate) { $mock->expects($this->once()) ->method('evaluate') ->will($this->returnValue(true)); } return $mock; } protected function createTrustResolver() { return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface')->getMock(); } protected function createRoleHierarchy() { return $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')->getMock(); } protected function createExpression() { return $this->getMockBuilder('Symfony\Component\ExpressionLanguage\Expression') ->disableOriginalConstructor() ->getMock(); } } __halt_compiler();----SIGNATURE:----AsGkJUYaMS0yNuMg+yjvMseEMWSlWuQZi4ZwXn0xDUrBlzyj2DJcbawOGpI4LzGia8ZIU7QfI/S1MTF1IzffSUzIfEQs+TfX3pz1Dhc+aiutaGcmLcLhDDosA6EzZD4wsUT1Fhod5P6iyXqVFg+4Ewa3PN8stkpELidbRME+Dd58jL94KBscCjk90W/u8TEgicKYYXR6yt8HbBd30I1/DlZw1H33yLBPGwGypNDolOoWtIElnkxIJDsnwgL+556gRYa9yQ9T5sxVRCQnWyy8M3DGCTKTFF8l+GPum/KpMktc9bhPFpnocie9Mznv53aQcPE1oaGZPAy7nH8NFZvW/s84Dcw8lcXkaZG3YqpdBbb0sNKOBAEzGeuCp+bDOa9EyNwJ02MuKzhsMxWLwjsTg8MDInpAYAxez0DLnYId6KVQ7O/H+5N821Sd/xz4nNGxke18p0tK+u77f7/KBr9PCIvid9Mb1rsrEoqfW3EBQczYCeOpKAy+jfkkqghTvgTorqyW6fymBFzBhUgdX/dBUDQmetqXQHCvb+qxeOnvEIqAEaThQKT02t2Jetc9WBS4VIT3VDLaLd6bwSEPKrT1HPb2ayVEzALXsUTppVj2fErmH0bFTPKYMHjWFdeGXDvNdRmkJseLXKBPCvEwZpho5Rw6VJRGYPM3+SvaYqJ3OYo=----ATTACHMENT:----MTE5MTIzMzUyOTY0NTI1NyA3NDkzMTQ0MzExMDE1MjAyIDM1MjAyNzk1MzQ5ODEwNDI=