Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/2643' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Strategy/JsonStrategy.php
Expand Up @@ -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') {
Expand Down
12 changes: 12 additions & 0 deletions test/Strategy/JsonStrategyTest.php
Expand Up @@ -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();
Expand Down

0 comments on commit 0feacff

Please sign in to comment.