@@ -143,4 +143,41 @@ public function useSpecifiedFormatDataProvider()
143143 array ('json ' , 'json ' ),
144144 );
145145 }
146+
147+ /**
148+ * Generates a request like a symfony fragment listener does.
149+ * Set request type to master
150+ */
151+ public function testSfFragmentFormat ()
152+ {
153+ $ event = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\Event\GetResponseEvent ' )
154+ ->disableOriginalConstructor ()
155+ ->getMock ();
156+
157+ $ request = new Request ();
158+ $ attributes = array ( '_locale ' => 'en ' , '_format ' => 'json ' , '_controller ' => 'FooBundle:Index:featured ' , );
159+ $ request ->attributes ->add ($ attributes );
160+ $ request ->attributes ->set ('_route_params ' , array_replace ($ request ->attributes ->get ('_route_params ' , array ()), $ attributes ));
161+
162+ $ event ->expects ($ this ->once ())
163+ ->method ('getRequest ' )
164+ ->will ($ this ->returnValue ($ request ));
165+
166+ $ event ->expects ($ this ->any ())
167+ ->method ('getRequestType ' )
168+ ->will ($ this ->returnValue (HttpKernelInterface::MASTER_REQUEST ));
169+
170+ $ formatNegotiator = $ this ->getMockBuilder ('FOS\RestBundle\Util\FormatNegotiator ' )
171+ ->disableOriginalConstructor ()
172+ ->getMock ();
173+ $ formatNegotiator ->expects ($ this ->any ())
174+ ->method ('getBestMediaType ' )
175+ ->will ($ this ->returnValue ('application/json ' ));
176+
177+ $ listener = new FormatListener ($ formatNegotiator );
178+
179+ $ listener ->onKernelRequest ($ event );
180+
181+ $ this ->assertEquals ($ request ->getRequestFormat (), 'json ' );
182+ }
146183}
0 commit comments