@@ -54,42 +54,72 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
54
54
55
55
$ this ->assertEquals ($ expectedVote , $ voter ->vote ($ this ->token , $ object , $ attributes ), $ message );
56
56
}
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
+ }
57
78
}
58
79
59
80
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
60
95
{
61
96
protected function getSupportedClasses ()
62
97
{
63
- return array ('stdClass ' );
98
+ return array ('AbstractVoterTest_Object ' );
64
99
}
65
100
66
101
protected function getSupportedAttributes ()
67
102
{
68
103
return array ('EDIT ' , 'CREATE ' );
69
104
}
70
105
71
- protected function voteOnAttribute ($ attribute , $ object , TokenInterface $ token )
106
+ protected function isGranted ($ attribute , $ object , $ user = null )
72
107
{
73
- return $ attribute === ' foo ' ;
108
+ return ' EDIT ' === $ attribute ;
74
109
}
75
110
}
76
111
77
- class DeprecatedVoterFixture extends AbstractVoter
112
+ class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
78
113
{
79
114
protected function getSupportedClasses ()
80
115
{
81
- return array (
82
- 'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture ' ,
83
- );
116
+ return array ('AbstractVoterTest_Object ' );
84
117
}
85
118
86
119
protected function getSupportedAttributes ()
87
120
{
88
- return array ('foo ' , 'bar ' , ' baz ' );
121
+ return array ('EDIT ' , 'CREATE ' );
89
122
}
90
123
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
95
125
}
0 commit comments