Permalink
Browse files

Don't load Helpers in dataviews when _serialize is set.

Loading helpers when they aren't going to be used is wasteful.
  • Loading branch information...
1 parent b8320fd commit c03edd9d1aec43b5730c952ef018d7de72ca1f3d @markstory markstory committed Aug 27, 2013
@@ -54,6 +54,25 @@ public function testRenderWithoutView() {
}
/**
+ * Test that rendering with _serialize does not load helpers
+ *
+ * @return void
+ */
+ public function testRenderSerializeNoHelpers() {
+ $Request = new CakeRequest();
+ $Response = new CakeResponse();
+ $Controller = new Controller($Request, $Response);
+ $Controller->helpers = array('Html');
+ $Controller->set(array(
+ '_serialize' => 'tags',
+ 'tags' => array('cakephp', 'framework')
+ ));
+ $View = new JsonView($Controller);
+ $View->render();
+ $this->assertFalse(isset($View->Html), 'No helper loaded.');
+ }
+
+/**
* Test render with an array in _serialize
*
* @return void
@@ -80,6 +80,25 @@ public function testRenderWithoutView() {
}
/**
+ * Test that rendering with _serialize does not load helpers
+ *
+ * @return void
+ */
+ public function testRenderSerializeNoHelpers() {
+ $Request = new CakeRequest();
+ $Response = new CakeResponse();
+ $Controller = new Controller($Request, $Response);
+ $Controller->helpers = array('Html');
+ $Controller->set(array(
+ '_serialize' => 'tags',
+ 'tags' => array('cakephp', 'framework')
+ ));
+ $View = new XmlView($Controller);
+ $View->render();
+ $this->assertFalse(isset($View->Html), 'No helper loaded.');
+ }
+
+/**
* Test render with an array in _serialize
*
* @return void
View
@@ -73,6 +73,18 @@ public function __construct(Controller $controller = null) {
}
/**
+ * Skip loading helpers if this is a _serialize based view.
+ *
+ * @return void
+ */
+ public function loadHelpers() {
+ if (isset($this->viewVars['_serialize'])) {
+ return;
+ }
+ parent::loadHelpers();
+ }
+
+/**
* Render a JSON view.
*
* ### Special parameters
View
@@ -73,6 +73,18 @@ public function __construct(Controller $controller = null) {
}
/**
+ * Skip loading helpers if this is a _serialize based view.
+ *
+ * @return void
+ */
+ public function loadHelpers() {
+ if (isset($this->viewVars['_serialize'])) {
+ return;
+ }
+ parent::loadHelpers();
+ }
+
+/**
* Render a XML view.
*
* Uses the special '_serialize' parameter to convert a set of

0 comments on commit c03edd9

Please sign in to comment.