[limb-svn] r7098 - in 3.x/trunk/limb/web_app: src/filter tests/cases/plain/filter tests/cases/plain/request

svn at limb-project.com svn at limb-project.com
Wed Jul 9 01:10:06 MSD 2008


Author: pachanga
Date: 2008-07-09 01:10:04 +0400 (Wed, 09 Jul 2008)
New Revision: 7098
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7098

Modified:
   3.x/trunk/limb/web_app/src/filter/lmbRequestDispatchingFilter.class.php
   3.x/trunk/limb/web_app/tests/cases/plain/filter/lmbRequestDispatchingFilterTest.class.php
   3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesDispatchTest.class.php
   3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesRequestDispatcherTest.class.php
Log:
-- fixing tests and some other minor improvements

Modified: 3.x/trunk/limb/web_app/src/filter/lmbRequestDispatchingFilter.class.php
===================================================================
--- 3.x/trunk/limb/web_app/src/filter/lmbRequestDispatchingFilter.class.php	2008-07-08 06:09:25 UTC (rev 7097)
+++ 3.x/trunk/limb/web_app/src/filter/lmbRequestDispatchingFilter.class.php	2008-07-08 21:10:04 UTC (rev 7098)
@@ -17,11 +17,13 @@
  */
 class lmbRequestDispatchingFilter implements lmbInterceptingFilter
 {
+  protected $toolkit;
   protected $dispatcher;
   protected $default_controller_name;
 
   function __construct($dispatcher, $default_controller_name = 'not_found')
   {
+    $this->toolkit = lmbToolkit :: instance();
     $this->dispatcher = $dispatcher;
     $this->setDefaultControllerName($default_controller_name);
   }
@@ -33,10 +35,8 @@
 
   function run($filter_chain)
   {
-    $toolkit = lmbToolkit :: instance();
+    $dispatched_params = $this->dispatcher->dispatch($this->toolkit->getRequest());
 
-    $dispatched_params = $this->dispatcher->dispatch($toolkit->getRequest());
-
     $this->_putOtherParamsToRequest($dispatched_params);
     
     $controller = $this->_createController($dispatched_params);
@@ -48,7 +48,7 @@
     else
       $controller = $this->_createDefaultController();
 
-    $toolkit->setDispatchedController($controller);
+    $this->toolkit->setDispatchedController($controller);
 
     $filter_chain->next();
   }
@@ -60,11 +60,11 @@
 
     try
     {
-      $controller = lmbToolkit :: instance()->createController($dispatched_params['controller']);
+      $controller = $this->toolkit->createController($dispatched_params['controller']);
     }
     catch(lmbException $e)
     {
-      $controller = lmbToolkit :: instance()->createController($this->default_controller_name);
+      $controller = $this->toolkit->createController($this->default_controller_name);
     }
 
     return $controller;
@@ -72,14 +72,14 @@
 
   protected function _createDefaultController()
   {
-    $controller = lmbToolkit :: instance()->createController($this->default_controller_name);
+    $controller = $this->toolkit->createController($this->default_controller_name);
     $controller->setCurrentAction($controller->getDefaultAction());
     return $controller;
   }
 
   protected function _putOtherParamsToRequest($dispatched_params)
   {
-    lmbToolkit :: instance()->getRequest()->merge($dispatched_params);
+    $this->toolkit->getRequest()->merge($dispatched_params);
   }
 }
 

Modified: 3.x/trunk/limb/web_app/tests/cases/plain/filter/lmbRequestDispatchingFilterTest.class.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/plain/filter/lmbRequestDispatchingFilterTest.class.php	2008-07-08 06:09:25 UTC (rev 7097)
+++ 3.x/trunk/limb/web_app/tests/cases/plain/filter/lmbRequestDispatchingFilterTest.class.php	2008-07-08 21:10:04 UTC (rev 7098)
@@ -23,15 +23,22 @@
   {
     $this->name = $name;
     parent :: __construct();
-    
-    $this->param = $this->request->get('param', null);
   }
-  
+
   function doDisplay()
   {
   }
 }
 
+class RememberRequestParamsController extends lmbController
+{
+  function __construct()
+  {
+    parent :: __construct();
+    $this->param = $this->request->get('param', null);
+  }
+}
+
 //this class used to test exceptions since SimpleTest does not support exception generation by mocks yet.
 class lmbRequestDispatchingFilterTestTools extends lmbAbstractTools
 {
@@ -85,20 +92,6 @@
     lmbToolkit :: restore();
   }
 
-  protected function _setUpMocks($dispatched_params, $controller = null, $default_controller_name = '')
-  {
-    $this->chain->expectOnce('next');
-
-    $this->dispatcher->expectOnce('dispatch', array($this->request));
-    $this->dispatcher->setReturnValue('dispatch', $dispatched_params);
-
-    if($controller)
-    {
-      $this->mock_tools->expectArgumentsAt(0, 'createController', array($controller->getName()));
-      $this->mock_tools->setReturnValueAt(0, 'createController', $controller, array($controller->getName()));
-    }
-  }
-
   function testSetDispatchedRequestInToolkit()
   {
     $controller = new lmbRequestDispatchingTestingController($controller_name = 'SomeController');
@@ -110,7 +103,7 @@
 
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($controller, 'display', __LINE__);
+    $this->_assertDispatchedOk($controller, 'display', __LINE__);
   }
 
   function testUseDefaultActionFromControllerIsActionWasNotDispatchedFromRequest()
@@ -123,7 +116,7 @@
 
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($controller, $controller->getDefaultAction(), __LINE__);
+    $this->_assertDispatchedOk($controller, $controller->getDefaultAction(), __LINE__);
   }
 
   function testUse404ControllerIfNoSuchActionInDispatchedController()
@@ -143,7 +136,7 @@
     $this->filter->setDefaultControllerName('404');
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($not_found_controller, $not_found_controller->getDefaultAction(), __LINE__);
+    $this->_assertDispatchedOk($not_found_controller, $not_found_controller->getDefaultAction(), __LINE__);
   }
 
   function testControllerParamIsEmpty()
@@ -158,7 +151,7 @@
 
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($controller, 'display', __LINE__);
+    $this->_assertDispatchedOk($controller, 'display', __LINE__);
   }
 
   function testNoSuchController()
@@ -176,7 +169,7 @@
 
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($controller, 'display', __LINE__);
+    $this->_assertDispatchedOk($controller, 'display', __LINE__);
   }
 
   function testPutOtherParamsToRequest()
@@ -190,7 +183,7 @@
 
     $this->filter->run($this->chain);
 
-    $this->assertDispatchedOk($controller, $controller->getDefaultAction(), __LINE__);
+    $this->_assertDispatchedOk($controller, $controller->getDefaultAction(), __LINE__);
 
     $this->assertEqual($this->request->get('id'), 150);
     $this->assertEqual($this->request->get('extra'), 'bla-bla');
@@ -198,23 +191,47 @@
   
   function testIsRequestAvailableInControllerConstructor() 
   {
-    $dispatched_params = array('controller' => 'SomeController',
+    //this is quite a "hacky" trick which removes the fixture toolkit, this should be refactored
+    //alas, this means the whole test suite must be reconsidered as well
+    lmbToolkit :: restore();
+    lmbToolkit :: save();
+
+    $dispatched_params = array('controller' => 'RememberRequestParams',
                                'param' => 150);
 
-    $controller = new lmbRequestDispatchingTestingController('SomeController');
-    $this->_setUpMocks($dispatched_params, $controller);
+    $this->_setUpMocks($dispatched_params);
 
     $this->filter->run($this->chain);
 
+    $controller = $this->toolkit->getDispatchedController();
     $this->assertEqual($controller->param, $dispatched_params['param']);
+
+    //trick again...
+    lmbToolkit :: restore();
+    lmbToolkit :: save();
   }
 
-  function assertDispatchedOk($controller, $action, $line)
+  protected function _assertDispatchedOk($controller, $action, $line)
   {
     $dispatched_request = $this->toolkit->getDispatchedController();
     $this->assertEqual($dispatched_request->getName(), $controller->getName(), '%s ' . $line);
     $this->assertEqual($dispatched_request->getCurrentAction(), $action, '%s ' . $line);
   }
+
+  protected function _setUpMocks($dispatched_params, $controller = null)
+  {
+    $this->chain->expectOnce('next');
+
+    $this->dispatcher->expectOnce('dispatch', array($this->request));
+    $this->dispatcher->setReturnValue('dispatch', $dispatched_params);
+
+    if($controller)
+    {
+      $this->mock_tools->expectArgumentsAt(0, 'createController', array($controller->getName()));
+      $this->mock_tools->setReturnValueAt(0, 'createController', $controller, array($controller->getName()));
+    }
+  }
+
 }
 
 

Modified: 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesDispatchTest.class.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesDispatchTest.class.php	2008-07-08 06:09:25 UTC (rev 7097)
+++ 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesDispatchTest.class.php	2008-07-08 21:10:04 UTC (rev 7098)
@@ -13,7 +13,7 @@
 {
   function setUp()
   {
-    $toolkit = lmbToolkit :: save();
+    lmbToolkit :: save();
   }
 
   function tearDown()

Modified: 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesRequestDispatcherTest.class.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesRequestDispatcherTest.class.php	2008-07-08 06:09:25 UTC (rev 7097)
+++ 3.x/trunk/limb/web_app/tests/cases/plain/request/lmbRoutesRequestDispatcherTest.class.php	2008-07-08 21:10:04 UTC (rev 7098)
@@ -57,7 +57,6 @@
     $this->assertEqual($result['action'], 'admin_display');
   }
 
-
   function testNormalizeUrl()
   {
     $config_array = array(array('path' => '/:controller/:action'));
@@ -73,7 +72,6 @@
 
     $this->request->getUri()->parse('/blog////index');
     $result = $dispatcher->dispatch($this->request);
-
     $this->assertEqual($result['controller'], 'blog');
     $this->assertEqual($result['action'], 'index');
 



More information about the limb-svn mailing list