Browse Source

When uses filter \yii\filters\PageCache, then yii\web\JsonResponseFor… (#17044)

* When uses filter \yii\filters\PageCache, then yii\web\JsonResponseFormatter sets Response::$content as null, howerer \yii\filter\PageCache has been restore content
tags/2.0.16
Vladimir Votinov 6 years ago committed by Alexander Makarov
parent
commit
3c091b802a
  1. 2
      framework/web/JsonResponseFormatter.php
  2. 13
      tests/framework/web/JsonResponseFormatterTest.php

2
framework/web/JsonResponseFormatter.php

@ -117,7 +117,7 @@ class JsonResponseFormatter extends Component implements ResponseFormatterInterf
$options |= JSON_PRETTY_PRINT;
}
$response->content = Json::encode($response->data, $options);
} else {
} elseif ($response->content === null) {
$response->content = 'null';
}
}

13
tests/framework/web/JsonResponseFormatterTest.php

@ -194,4 +194,17 @@ class JsonResponseFormatterTest extends FormatterTest
$this->formatter->format($this->response);
$this->assertEquals('null', $this->response->content);
}
/**
* Formatter must return early sets content,
* e.g. content may be sets by PageCache filter
*/
public function testFormatFilledContent()
{
$content = '{"text": "early seted content"}';
$this->response->data = null;
$this->response->content = $content;
$this->formatter->format($this->response);
$this->assertEquals($content, $this->response->content);
}
}

Loading…
Cancel
Save