public function testEvaluate_hasPermission_correctResult() { $object = new \stdClass(); $securityContext = \Mockery::mock()->shouldReceive('isGranted')->with('read', $object)->andReturn(true)->once()->getMock(); $language = new ExpressionLanguage(); $evaluated = $language->evaluate("hasPermission(object, 'read')", ['object' => $object, 'securityContext' => $securityContext]); $this->assertTrue($evaluated); }
/** * {@inheritdoc} */ public function vote(IIdentity $identity, array $attributes, $object) { $result = self::VOTE_ABSTAIN; $variables = null; foreach ($attributes as $attribute) { if (!$this->supportsAttribute($attribute)) { continue; } if ($variables === null) { $variables = $this->getVariables($identity, $object); } $result = self::VOTE_DENIED; if ($this->language->evaluate($attribute, $variables)) { return self::VOTE_GRANTED; } } return $result; }
public function evaluate(Expression $expression, Request $request) { return $this->language->evaluate($expression, $this->getVariables($request)); }