Skip to content

Commit

Permalink
Don't load Helpers in dataviews when _serialize is set.
Browse files Browse the repository at this point in the history
Loading helpers when they aren't going to be used is wasteful.
  • Loading branch information
markstory committed Aug 28, 2013
1 parent b8320fd commit c03edd9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Cake/Test/Case/View/JsonViewTest.php
Expand Up @@ -53,6 +53,25 @@ public function testRenderWithoutView() {
$this->assertSame('application/json', $Response->type());
}

/**
* 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
*
Expand Down
19 changes: 19 additions & 0 deletions lib/Cake/Test/Case/View/XmlViewTest.php
Expand Up @@ -79,6 +79,25 @@ public function testRenderWithoutView() {
$this->assertSame($expected, $output);
}

/**
* 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
*
Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/View/JsonView.php
Expand Up @@ -72,6 +72,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.
*
Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/View/XmlView.php
Expand Up @@ -72,6 +72,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.
*
Expand Down

0 comments on commit c03edd9

Please sign in to comment.