Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc937f8

Browse files
committed
minor #15961 [Security] Fix tests in 2.8 (WouterJ)
This PR was merged into the 2.8 branch. Discussion ---------- [Security] Fix tests in 2.8 ping @fabpot Commits ------- 20c90f5 Fix tests in 2.8
2 parents 46746f8 + 20c90f5 commit dc937f8

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/Symfony/Component/Security/Core/Tests/Authorization/Voter/AbstractVoterTest.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,42 +54,72 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
5454

5555
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
5656
}
57+
58+
/**
59+
* @dataProvider getTests
60+
* @group legacy
61+
*/
62+
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
63+
{
64+
$voter = new AbstractVoterTest_LegacyVoter();
65+
66+
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
67+
}
68+
69+
/**
70+
* @group legacy
71+
* @expectedException \BadMethodCallException
72+
*/
73+
public function testNoOverriddenMethodsThrowsException()
74+
{
75+
$voter = new AbstractVoterTest_NothingImplementedVoter();
76+
$voter->vote($this->token, new \stdClass(), array('EDIT'));
77+
}
5778
}
5879

5980
class AbstractVoterTest_Voter extends AbstractVoter
81+
{
82+
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
83+
{
84+
return 'EDIT' === $attribute;
85+
}
86+
87+
protected function supports($attribute, $class)
88+
{
89+
return $this->isClassInstanceOf($class, 'stdClass')
90+
&& in_array($attribute, array('EDIT', 'CREATE'));
91+
}
92+
}
93+
94+
class AbstractVoterTest_LegacyVoter extends AbstractVoter
6095
{
6196
protected function getSupportedClasses()
6297
{
63-
return array('stdClass');
98+
return array('AbstractVoterTest_Object');
6499
}
65100

66101
protected function getSupportedAttributes()
67102
{
68103
return array('EDIT', 'CREATE');
69104
}
70105

71-
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
106+
protected function isGranted($attribute, $object, $user = null)
72107
{
73-
return $attribute === 'foo';
108+
return 'EDIT' === $attribute;
74109
}
75110
}
76111

77-
class DeprecatedVoterFixture extends AbstractVoter
112+
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
78113
{
79114
protected function getSupportedClasses()
80115
{
81-
return array(
82-
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
83-
);
116+
return array('AbstractVoterTest_Object');
84117
}
85118

86119
protected function getSupportedAttributes()
87120
{
88-
return array('foo', 'bar', 'baz');
121+
return array('EDIT', 'CREATE');
89122
}
90123

91-
protected function isGranted($attribute, $object, $user = null)
92-
{
93-
return 'EDIT' === $attribute;
94-
}
124+
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
95125
}

0 commit comments

Comments
 (0)