Commit 3db57c91 authored by webchick's avatar webchick

Issue #1978422 by dawehner, linclark, klausi: Fixed REST export views preview...

Issue #1978422 by dawehner, linclark, klausi: Fixed REST export views preview needs to escape the JSON output.
parent f4605338
......@@ -216,6 +216,7 @@ public function render() {
// Wrap the output in a pre tag if this is for a live preview.
if (!empty($this->view->live_preview)) {
$build['#prefix'] = '<pre>';
$build['#markup'] = check_plain($build['#markup']);
$build['#suffix'] = '</pre>';
}
......
......@@ -221,4 +221,30 @@ public function testFieldRawOutput() {
}
}
/**
* Tests the preview output for json output.
*/
public function testPreview() {
$view = views_get_view('test_serializer_display_entity');
$view->setDisplay('rest_export_1');
$this->executeView($view);
// Get the serializer service.
$serializer = $this->container->get('serializer');
$entities = array();
foreach ($view->result as $row) {
$entities[] = $row->_entity;
}
$expected = check_plain($serializer->serialize($entities, 'hal_json'));
$view->display_handler->setContentType('hal_json');
$view->live_preview = TRUE;
$build = $view->preview();
$rendered_json = $build['#markup'];
$this->assertEqual($rendered_json, $expected, 'Ensure the previewed json is escaped.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment