From f93b36d4ed20134b83ab2e40afb745220dfc116b Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Fri, 11 Sep 2009 17:49:49 +0200 Subject: [PATCH] Fix the routing for the required actions. --- .../Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php | 33 +++++++---- .../test/Horde/Kolab/FreeBusy/DispatchTest.php | 68 +++++++++------------- .../Mock/Controller/FreebusyController.php | 7 ++- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/framework/Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php b/framework/Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php index d9f75a5cb..09a7f1894 100644 --- a/framework/Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php +++ b/framework/Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php @@ -229,23 +229,34 @@ class Horde_Kolab_FreeBusy } if (empty($this->_params['config']['dir']) || !file_exists($routeFile)) { - $this->_mapper->connect('*(id).:(type)', + $this->_mapper->connect(':(mail).:(type)', array('controller' => 'freebusy', 'action' => 'fetch', - 'requirements' => array('type' => '(i|x|v|p|px)fb') + 'requirements' => array('type' => '(i|x|v)fb', + 'mail' => '[^/]+'), )); - $this->_mapper->connect('trigger/:id/:folder', - array('controller' => 'freebusy', - 'action' => 'trigger')); + $this->_mapper->connect('trigger/*(folder).pfb', + array('controller' => 'freebusy', + 'action' => 'trigger' + )); - $this->_mapper->connect('delete/:id', - array('controller' => 'freebusy', - 'action' => 'delete')); + $this->_mapper->connect('*(folder).:(type)', + array('controller' => 'freebusy', + 'action' => 'trigger', + 'requirements' => array('type' => '(p|px)fb'), + )); - $this->_mapper->connect('regenerate/:id', - array('controller' => 'freebusy', - 'action' => 'delete')); + $this->_mapper->connect('delete/:(mail)', + array('controller' => 'freebusy', + 'action' => 'delete', + 'requirements' => array('mail' => '[^/]+'), + )); + + $this->_mapper->connect('regenerate', + array('controller' => 'freebusy', + 'action' => 'regenerate', + )); } else { // Load application routes. include $routeFile; diff --git a/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/DispatchTest.php b/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/DispatchTest.php index 281874851..8cbf510a5 100644 --- a/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/DispatchTest.php +++ b/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/DispatchTest.php @@ -60,20 +60,28 @@ class Horde_Kolab_FreeBusy_DispatchTest extends Horde_Kolab_Test_FreeBusy * * @return NULL */ - public function testFetch() + public function testDispatching() { $urls = array( - '/freebusy/test@example.com.ifb' => array( - 'ifb', 'test@example.com'), - '/freebusy/test@example.com.vfb' => array( - 'vfb', 'test@example.com'), - '/freebusy/test@example.com.xfb' => array( - 'xfb', 'test@example.com'), - '/freebusy/test@example.com.pfb' => array( - 'pfb', 'test@example.com'), - '/freebusy/test@example.com.pxfb' => array( - 'pxfb', 'test@example.com'), + '/freebusy/test@example.com.ifb' => 'fetched "ifb" data for user "test@example.com"', + '/freebusy/test@example.com.vfb' => 'fetched "vfb" data for user "test@example.com"', + '/freebusy/test@example.com.xfb' => 'fetched "xfb" data for user "test@example.com"', '/freebusy/test@example.com.zfb' => false, + '/freebusy/delete/test@example.com' => 'deleted data for user "test@example.com"', + '/freebusy/delete' => false, + '/freebusy/delete/' => false, + '/freebusy/delete/i' => 'deleted data for user "i"', + '/freebusy/delete/i/j' => false, + '/freebusy/regenerate' => 'regenerated', + '/freebusy/regenerate/' => 'regenerated', + '/freebusy/regenerate/j' => false, + '/freebusy/trigger/test@example.com/Kalender.pfb' => 'triggered folder "test@example.com/Kalender"', + '/freebusy/trigger/test@example.com/Kalender.xfb' => false, + '/freebusy/trigger' => false, + '/freebusy/test@example.com/Kalender.pfb' => 'triggered folder "test@example.com/Kalender" and retrieved data of type "pfb"', + '/freebusy/test@example.com/Kalender.pxfb' => 'triggered folder "test@example.com/Kalender" and retrieved data of type "pxfb"', + '/freebusy/test@example.com/Kalender.ifb' => false, + '/freebusy' => false, ); foreach ($urls as $key => $result) { @@ -91,47 +99,27 @@ class Horde_Kolab_FreeBusy_DispatchTest extends Horde_Kolab_Test_FreeBusy ) ); $application = Horde_Kolab_FreeBusy::singleton($params); + + $output = ''; + if (empty($result)) { try { + ob_start(); $application->dispatch(); + $output = ob_get_contents(); + ob_end_clean(); } catch (Horde_Controller_Exception $e) { - $this->assertEquals('No routes match the path: "' . substr($key, 1) . '"', $e->getMessage()); + $this->assertEquals('No routes match the path: "' . trim($key, '/') . '"', $e->getMessage()); } + $this->assertEquals('', $output); } else { ob_start(); $application->dispatch(); $output = ob_get_contents(); ob_end_clean(); - $this->assertEquals('fetched "' . $result[0] . '" data for user "' . $result[1] . '"', $output); + $this->assertEquals($result, $output); } Horde_Kolab_FreeBusy::destroy(); } } - - /** - * Test dispatching a "trigger" call. - * - * @return NULL - */ - public function testTrigger() - { - } - - /** - * Test dispatching a "regenerate" call. - * - * @return NULL - */ - public function testRegenerate() - { - } - - /** - * Test dispatching a "delete" call. - * - * @return NULL - */ - public function testDelete() - { - } } \ No newline at end of file diff --git a/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/Mock/Controller/FreebusyController.php b/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/Mock/Controller/FreebusyController.php index 7cb1bb626..bdd80fe97 100644 --- a/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/Mock/Controller/FreebusyController.php +++ b/framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/Mock/Controller/FreebusyController.php @@ -41,7 +41,8 @@ class FreeBusyController extends Horde_Controller_Base */ public function trigger() { - $this->renderText('triggered'); + $type = isset($this->params->type) ? ' and retrieved data of type "' . $this->params->type . '"' : ''; + $this->renderText('triggered folder "' . $this->params->folder . '"' . $type); } /** @@ -51,7 +52,7 @@ class FreeBusyController extends Horde_Controller_Base */ public function fetch() { - $this->renderText('fetched "' . $this->params->type . '" data for user "' . $this->params->id . '"'); + $this->renderText('fetched "' . $this->params->type . '" data for user "' . $this->params->mail . '"'); } /** @@ -71,6 +72,6 @@ class FreeBusyController extends Horde_Controller_Base */ public function delete() { - $this->renderText('deleted'); + $this->renderText('deleted data for user "' . $this->params->mail . '"'); } } \ No newline at end of file -- 2.11.0