Skip to content

Commit

Permalink
Controller: Updated the set method so that data can be overwritten wh…
Browse files Browse the repository at this point in the history
…en set again.

ControllerTest: Added tests for the set method.
  • Loading branch information
Howard3 authored and nateabele committed Jun 4, 2011
1 parent 3870c61 commit 5c4f147
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/lithium/action/Controller.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function __invoke($request, $dispatchParams, array $options = array()) {
* @return void * @return void
*/ */
public function set($data = array()) { public function set($data = array()) {
$this->_render['data'] += (array) $data; $this->_render['data'] = (array) $data + $this->_render['data'];
} }


/** /**
Expand Down
18 changes: 18 additions & 0 deletions libraries/lithium/tests/cases/action/ControllerTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ public function testManuallySettingTemplate() {
$this->assertEqual('foo', $result['template']); $this->assertEqual('foo', $result['template']);
} }


public function testSetData() {
$postController = new MockPostsController();

$setData = array('foo' => 'bar');
$postController->set($setData);
$_render = $postController->access('_render');
$data = $_render['data'];
$expected = $setData;
$this->assertEqual($expected, $data);

$setData = array('foo' => 'baz');
$postController->set($setData);
$_render = $postController->access('_render');
$data = $_render['data'];
$expected = $setData;
$this->assertEqual($expected, $data);
}

public function testResponseTypeBasedOnRequestHeaderType() { public function testResponseTypeBasedOnRequestHeaderType() {
$request = new MockControllerRequest(array( $request = new MockControllerRequest(array(
'env' => array('HTTP_ACCEPT' => 'application/json,*/*') 'env' => array('HTTP_ACCEPT' => 'application/json,*/*')
Expand Down

0 comments on commit 5c4f147

Please sign in to comment.