Skip to content

Commit

Permalink
allow for inheritance of Controller::$_render property within subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegreiling committed Apr 12, 2013
1 parent 87a88da commit 9f3bebe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions action/Controller.php
Expand Up @@ -141,6 +141,18 @@ public function __construct(array $config = array()) {
*/ */
protected function _init() { protected function _init() {
parent::_init(); parent::_init();

foreach (static::_parents() as $parent) {
$inherit = get_class_vars($parent);

if (isset($inherit['_render'])) {
$this->_render += $inherit['_render'];
}
if ($parent === __CLASS__) {
break;
}
}

$this->request = $this->request ?: $this->_config['request']; $this->request = $this->request ?: $this->_config['request'];
$this->response = $this->_instance('response', $this->_config['response']); $this->response = $this->_instance('response', $this->_config['response']);


Expand Down
12 changes: 12 additions & 0 deletions tests/cases/action/ControllerTest.php
Expand Up @@ -11,6 +11,7 @@
use lithium\action\Request; use lithium\action\Request;
use lithium\action\Controller; use lithium\action\Controller;
use lithium\tests\mocks\action\MockPostsController; use lithium\tests\mocks\action\MockPostsController;
use lithium\tests\mocks\action\MockRenderAltController;
use lithium\tests\mocks\action\MockControllerRequest; use lithium\tests\mocks\action\MockControllerRequest;


class ControllerTest extends \lithium\test\Unit { class ControllerTest extends \lithium\test\Unit {
Expand Down Expand Up @@ -303,6 +304,17 @@ public function testManuallySettingTemplate() {
$this->assertEqual('foo', $result['template']); $this->assertEqual('foo', $result['template']);
} }


public function testRenderPropertyInheritance() {
$controller = new MockRenderAltController();

$expected = array(
'data' => array('foo' => 'bar'), 'layout' => 'alternate', 'type' => null, 'auto' => true,
'template' => null, 'hasRendered' => false, 'negotiate' => false
);
$result = $controller->access('_render');
$this->assertEqual($expected, $result);
}

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


Expand Down
22 changes: 22 additions & 0 deletions tests/mocks/action/MockRenderAltController.php
@@ -0,0 +1,22 @@
<?php
/**
* Lithium: the most rad php framework
*
* @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/

namespace lithium\tests\mocks\action;

class MockRenderAltController extends \lithium\action\Controller {
protected $_render = array(
'data' => array('foo' => 'bar'),
'layout' => 'alternate'
);

public function access($var) {
return $this->{$var};
}
}

?>

0 comments on commit 9f3bebe

Please sign in to comment.