[limb-svn] r5883 - in 3.x/trunk/limb/web_app: src/controller tests/cases/plain/controller
svn at limb-project.com
svn at limb-project.com
Mon May 14 10:52:32 MSD 2007
Author: pachanga
Date: 2007-05-14 10:52:32 +0400 (Mon, 14 May 2007)
New Revision: 5883
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5883
Modified:
3.x/trunk/limb/web_app/src/controller/lmbController.class.php
3.x/trunk/limb/web_app/tests/cases/plain/controller/lmbControllerTest.class.php
Log:
-- lmbController passes it's local attributes to view
Modified: 3.x/trunk/limb/web_app/src/controller/lmbController.class.php
===================================================================
--- 3.x/trunk/limb/web_app/src/controller/lmbController.class.php 2007-05-13 21:21:58 UTC (rev 5882)
+++ 3.x/trunk/limb/web_app/src/controller/lmbController.class.php 2007-05-14 06:52:32 UTC (rev 5883)
@@ -64,10 +64,13 @@
$method = $this->_mapCurrentActionToMethod($this->_mapCurrentActionToMethod());
$res = $this->$method();
+ $this->_passLocalAttributesToView();
+
if(is_string($res))
$this->response->write($res);
elseif($this->response->isEmpty() && !$this->view->getTemplate())
- $this->response->write('Default empty output for controller "' . get_class($this) . '" action "' . $this->current_action . '"');
+ $this->response->write('Default empty output for controller "' .
+ get_class($this) . '" action "' . $this->current_action . '"');
return;
}
@@ -93,6 +96,16 @@
$this->view->setTemplate($template_path);
}
+ protected function _passLocalAttributesToView()
+ {
+ foreach(get_object_vars($this) as $name => $value)
+ {
+ if($name{0} == '_')
+ continue;
+ $this->view->set($name, $value);
+ }
+ }
+
function passToView($var, $value)
{
$this->view->set($var, $value);
Modified: 3.x/trunk/limb/web_app/tests/cases/plain/controller/lmbControllerTest.class.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/plain/controller/lmbControllerTest.class.php 2007-05-13 21:21:58 UTC (rev 5882)
+++ 3.x/trunk/limb/web_app/tests/cases/plain/controller/lmbControllerTest.class.php 2007-05-14 06:52:32 UTC (rev 5883)
@@ -33,6 +33,11 @@
return "Hi!";
}
+ function doSetVars()
+ {
+ $this->item = 'item';
+ }
+
function addValidatorRule($r)
{
$this->validator->addRule($r);
@@ -42,6 +47,11 @@
{
return $this->error_list;
}
+
+ function set($name, $value)
+ {
+ $this->$name = $value;
+ }
}
class SecondTestingController extends lmbController {}
@@ -103,6 +113,27 @@
$this->assertTrue($this->toolkit->getView()->getTemplate(), 'testing/detail.html');
}
+ function testControllerAttributesAutomaticallyPassedToView()
+ {
+ $mock_locator = new MockWactTemplateLocator();
+ $mock_locator->expectOnce('locateSourceTemplate', array('foo/set_vars.html'));
+ $mock_locator->setReturnValue('locateSourceTemplate', true, array('foo/set_vars.html'));
+ $this->toolkit->setWactLocator($mock_locator);
+
+ $controller = new TestingController();
+ $controller->set('foo', 'FOO');
+ $controller->set('bar', 'BAR');
+ $controller->set('_nope', 'NO');
+ $controller->setCurrentAction('set_vars');
+
+ $controller->performAction();
+ $view = $this->toolkit->getView();
+ $this->assertEqual($view->get('item'), 'item');//this one is set in action
+ $this->assertEqual($view->get('foo'), 'FOO');
+ $this->assertEqual($view->get('bar'), 'BAR');
+ $this->assertNull($view->get('_nope'));//this one is ignored, since it's "protected" with _
+ }
+
function testActionExistsReturnsTrueIsTemplateFound()
{
$mock_locator = new MockWactTemplateLocator();
More information about the limb-svn
mailing list