Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for setJsonpCallback not called when recieved JsonModel + test

  • Loading branch information...
commit 0627685186fd3d65b092b49abeff40d76903e415 1 parent 7a69c34
@basz basz authored
View
11 library/Zend/View/Strategy/JsonStrategy.php
@@ -84,26 +84,23 @@ public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
- if ($model instanceof Model\JsonModel) {
- // JsonModel found
- return $this->renderer;
- }
+ $earlyReturn = $model instanceof Model\JsonModel ? $this->renderer : null;
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
- return;
+ return $earlyReturn;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
- return;
+ return $earlyReturn;
}
$accept = $headers->get('Accept');
if (($match = $accept->match('application/json, application/javascript')) == false) {
- return;
+ return $earlyReturn;
}
if ($match->getTypeString() == 'application/json') {
View
12 tests/ZendTest/View/Strategy/JsonStrategyTest.php
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.