fix for setJsonpCallback not called when recieved JsonModel + test #2433

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+15 −9
Split
@@ -84,26 +84,20 @@ public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
- if ($model instanceof Model\JsonModel) {
- // JsonModel found
- return $this->renderer;
- }
-
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
- return;
+ return ($model instanceof Model\JsonModel) ? $this->renderer : null;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
- return;
+ return ($model instanceof Model\JsonModel) ? $this->renderer : null;
}
-
$accept = $headers->get('Accept');
if (($match = $accept->match('application/json, application/javascript')) == false) {
- return;
+ return ($model instanceof Model\JsonModel) ? $this->renderer : null;
}
if ($match->getTypeString() == 'application/json') {
@@ -63,6 +63,18 @@ public function testJavascriptAcceptHeaderSelectsJsonStrategy()
$this->assertFalse($result->hasJsonpCallback());
}
+ public function testJsonModelJavascriptAcceptHeaderSetsJsonpCallback()
+ {
+ $this->event->setModel(new JsonModel());
+ $request = new HttpRequest();
+ $request->getHeaders()->addHeaderLine('Accept', 'application/javascript');
+ $request->setQuery(new Parameters(array('callback' => 'foo')));
+ $this->event->setRequest($request);
+ $result = $this->strategy->selectRenderer($this->event);
+ $this->assertSame($this->renderer, $result);
+ $this->assertTrue($result->hasJsonpCallback());
+ }
+
public function testJavascriptAcceptHeaderSelectsJsonStrategyAndSetsJsonpCallback()
{
$request = new HttpRequest();