Skip to content
This repository
Browse code

Ensure callbacks are triggered when using Xml/Json view with view tem…

…plates.

PaginatorHelper for instance needs this to correctly set options
  • Loading branch information...
commit e7dc23b920ac1b1b4825d57538a12c395939ba20 1 parent 62dd391
ceeram authored August 22, 2012
4  lib/Cake/Test/Case/View/JsonViewTest.php
@@ -76,6 +76,7 @@ public function testRenderWithView() {
76 76
 			'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
77 77
 		));
78 78
 		$Request = new CakeRequest();
  79
+		$Request->params['named'] = array('page' => 2);
79 80
 		$Response = new CakeResponse();
80 81
 		$Controller = new Controller($Request, $Response);
81 82
 		$Controller->name = $Controller->viewPath = 'Posts';
@@ -91,9 +92,10 @@ public function testRenderWithView() {
91 92
 		);
92 93
 		$Controller->set('user', $data);
93 94
 		$View = new JsonView($Controller);
  95
+		$View->helpers = array('Paginator');
94 96
 		$output = $View->render('index');
95 97
 
96  
-		$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
  98
+		$expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2'), 'paging' => array('page' => 2)));
97 99
 		$this->assertSame($expected, $output);
98 100
 		$this->assertSame('application/json', $Response->type());
99 101
 	}
5  lib/Cake/Test/test_app/View/Posts/json/index.ctp
@@ -16,9 +16,12 @@
16 16
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
17 17
  */
18 18
 
  19
+$paging = isset($this->Paginator->options['url']) ? $this->Paginator->options['url'] : null;
  20
+
19 21
 $formatted = array(
20 22
 	'user' => $user['User']['username'],
21  
-	'list' => array()
  23
+	'list' => array(),
  24
+	'paging' => $paging,
22 25
 );
23 26
 foreach ($user['Item'] as $item) {
24 27
 	$formatted['list'][] = $item['name'];
7  lib/Cake/View/JsonView.php
@@ -85,12 +85,7 @@ public function render($view = null, $layout = null) {
85 85
 			return $this->_serialize($this->viewVars['_serialize']);
86 86
 		}
87 87
 		if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
88  
-			if (!$this->_helpersLoaded) {
89  
-				$this->loadHelpers();
90  
-			}
91  
-			$content = $this->_render($viewFileName);
92  
-			$this->Blocks->set('content', $content);
93  
-			return $content;
  88
+			return parent::render($view, false);
94 89
 		}
95 90
 	}
96 91
 
7  lib/Cake/View/XmlView.php
@@ -88,12 +88,7 @@ public function render($view = null, $layout = null) {
88 88
 			return $this->_serialize($this->viewVars['_serialize']);
89 89
 		}
90 90
 		if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
91  
-			if (!$this->_helpersLoaded) {
92  
-				$this->loadHelpers();
93  
-			}
94  
-			$content = $this->_render($viewFileName);
95  
-			$this->Blocks->set('content', (string)$content);
96  
-			return $content;
  91
+			return parent::render($view, false);
97 92
 		}
98 93
 	}
99 94
 

0 notes on commit e7dc23b

Please sign in to comment.
Something went wrong with that request. Please try again.