@@ -124,6 +124,86 @@ private function getContainerWithTokenStorage($token = null)
124
124
125
125
return $ container ;
126
126
}
127
+
128
+ public function testIsGranted ()
129
+ {
130
+ $ authorizationChecker = $ this ->getMock ('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface ' );
131
+ $ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (true );
132
+
133
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
134
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (true ));
135
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ authorizationChecker ));
136
+
137
+ $ controller = new TestController ();
138
+ $ controller ->setContainer ($ container );
139
+
140
+ $ this ->assertTrue ($ controller ->isGranted ('foo ' ));
141
+ }
142
+
143
+ /**
144
+ * @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
145
+ */
146
+ public function testdenyAccessUnlessGranted ()
147
+ {
148
+ $ authorizationChecker = $ this ->getMock ('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface ' );
149
+ $ authorizationChecker ->expects ($ this ->once ())->method ('isGranted ' )->willReturn (false );
150
+
151
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
152
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (true ));
153
+ $ container ->expects ($ this ->at (1 ))->method ('get ' )->will ($ this ->returnValue ($ authorizationChecker ));
154
+
155
+ $ controller = new TestController ();
156
+ $ controller ->setContainer ($ container );
157
+
158
+ $ controller ->denyAccessUnlessGranted ('foo ' );
159
+ }
160
+
161
+ public function testRenderViewTwig ()
162
+ {
163
+ $ twig = $ this ->getMockBuilder ('\Twig_Environment ' )->disableOriginalConstructor ()->getMock ();
164
+ $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
165
+
166
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
167
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (false ));
168
+ $ container ->expects ($ this ->at (1 ))->method ('has ' )->will ($ this ->returnValue (true ));
169
+ $ container ->expects ($ this ->at (2 ))->method ('get ' )->will ($ this ->returnValue ($ twig ));
170
+
171
+ $ controller = new TestController ();
172
+ $ controller ->setContainer ($ container );
173
+
174
+ $ this ->assertEquals ('bar ' , $ controller ->renderView ('foo ' ));
175
+ }
176
+
177
+ public function testRenderTwig ()
178
+ {
179
+ $ twig = $ this ->getMockBuilder ('\Twig_Environment ' )->disableOriginalConstructor ()->getMock ();
180
+ $ twig ->expects ($ this ->once ())->method ('render ' )->willReturn ('bar ' );
181
+
182
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
183
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (false ));
184
+ $ container ->expects ($ this ->at (1 ))->method ('has ' )->will ($ this ->returnValue (true ));
185
+ $ container ->expects ($ this ->at (2 ))->method ('get ' )->will ($ this ->returnValue ($ twig ));
186
+
187
+ $ controller = new TestController ();
188
+ $ controller ->setContainer ($ container );
189
+
190
+ $ this ->assertEquals ('bar ' , $ controller ->render ('foo ' )->getContent ());
191
+ }
192
+
193
+ public function testStreamTwig ()
194
+ {
195
+ $ twig = $ this ->getMockBuilder ('\Twig_Environment ' )->disableOriginalConstructor ()->getMock ();
196
+
197
+ $ container = $ this ->getMock ('Symfony\Component\DependencyInjection\ContainerInterface ' );
198
+ $ container ->expects ($ this ->at (0 ))->method ('has ' )->will ($ this ->returnValue (false ));
199
+ $ container ->expects ($ this ->at (1 ))->method ('has ' )->will ($ this ->returnValue (true ));
200
+ $ container ->expects ($ this ->at (2 ))->method ('get ' )->will ($ this ->returnValue ($ twig ));
201
+
202
+ $ controller = new TestController ();
203
+ $ controller ->setContainer ($ container );
204
+
205
+ $ this ->assertInstanceOf ('Symfony\Component\HttpFoundation\StreamedResponse ' , $ controller ->stream ('foo ' ));
206
+ }
127
207
}
128
208
129
209
class TestController extends Controller
@@ -137,4 +217,14 @@ public function getUser()
137
217
{
138
218
return parent ::getUser ();
139
219
}
220
+
221
+ public function isGranted ($ attributes , $ object = null )
222
+ {
223
+ return parent ::isGranted ($ attributes , $ object );
224
+ }
225
+
226
+ public function denyAccessUnlessGranted ($ attributes , $ object = null , $ message = 'Access Denied. ' )
227
+ {
228
+ parent ::denyAccessUnlessGranted ($ attributes , $ object , $ message );
229
+ }
140
230
}
0 commit comments