Fix tests in 2.8
This commit is contained in:
parent
46746f8954
commit
20c90f5891
@ -54,13 +54,48 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
|
||||
{
|
||||
$voter = new AbstractVoterTest_LegacyVoter();
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testNoOverriddenMethodsThrowsException()
|
||||
{
|
||||
$voter = new AbstractVoterTest_NothingImplementedVoter();
|
||||
$voter->vote($this->token, new \stdClass(), array('EDIT'));
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_Voter extends AbstractVoter
|
||||
{
|
||||
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
|
||||
{
|
||||
return 'EDIT' === $attribute;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $class)
|
||||
{
|
||||
return $this->isClassInstanceOf($class, 'stdClass')
|
||||
&& in_array($attribute, array('EDIT', 'CREATE'));
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_LegacyVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array('stdClass');
|
||||
return array('AbstractVoterTest_Object');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
@ -68,28 +103,23 @@ class AbstractVoterTest_Voter extends AbstractVoter
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
|
||||
{
|
||||
return $attribute === 'foo';
|
||||
}
|
||||
}
|
||||
|
||||
class DeprecatedVoterFixture extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array(
|
||||
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('foo', 'bar', 'baz');
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
return 'EDIT' === $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array('AbstractVoterTest_Object');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
|
||||
}
|
||||
|
Reference in New Issue
Block a user