Ensure callbacks are triggered when using Xml/Json view with view templates.

PaginatorHelper for instance needs this to correctly set options
This commit is contained in:
Ceeram 2012-08-22 13:13:49 +02:00
parent 62dd39133b
commit e7dc23b920
4 changed files with 9 additions and 14 deletions

View file

@ -76,6 +76,7 @@ class JsonViewTest extends CakeTestCase {
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
$Request = new CakeRequest();
$Request->params['named'] = array('page' => 2);
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$Controller->name = $Controller->viewPath = 'Posts';
@ -91,9 +92,10 @@ class JsonViewTest extends CakeTestCase {
);
$Controller->set('user', $data);
$View = new JsonView($Controller);
$View->helpers = array('Paginator');
$output = $View->render('index');
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2)));
$this->assertSame($expected, $output);
$this->assertSame('application/json', $Response->type());
}

View file

@ -16,9 +16,12 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
$paging = isset($this->Paginator->options['url']) ? $this->Paginator->options['url'] : null;
$formatted = array(
'user' => $user['User']['username'],
'list' => array()
'list' => array(),
'paging' => $paging,
);
foreach ($user['Item'] as $item) {
$formatted['list'][] = $item['name'];

View file

@ -85,12 +85,7 @@ class JsonView extends View {
return $this->_serialize($this->viewVars['_serialize']);
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
$content = $this->_render($viewFileName);
$this->Blocks->set('content', $content);
return $content;
return parent::render($view, false);
}
}

View file

@ -88,12 +88,7 @@ class XmlView extends View {
return $this->_serialize($this->viewVars['_serialize']);
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
$content = $this->_render($viewFileName);
$this->Blocks->set('content', (string)$content);
return $content;
return parent::render($view, false);
}
}