Permalink
Browse files

allow for inheritance of Controller::$_render property within subclasses

  • Loading branch information...
mikegreiling committed Apr 12, 2013
1 parent 87a88da commit 9f3bebec0e76e84650b7874e5283902f4de4e517
Showing with 46 additions and 0 deletions.
  1. +12 −0 action/Controller.php
  2. +12 −0 tests/cases/action/ControllerTest.php
  3. +22 −0 tests/mocks/action/MockRenderAltController.php
View
@@ -141,6 +141,18 @@ public function __construct(array $config = array()) {
*/
protected function _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->response = $this->_instance('response', $this->_config['response']);
@@ -11,6 +11,7 @@
use lithium\action\Request;
use lithium\action\Controller;
use lithium\tests\mocks\action\MockPostsController;
+use lithium\tests\mocks\action\MockRenderAltController;
use lithium\tests\mocks\action\MockControllerRequest;
class ControllerTest extends \lithium\test\Unit {
@@ -303,6 +304,17 @@ public function testManuallySettingTemplate() {
$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() {
$postController = new MockPostsController();
@@ -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.