Fix the routing for the required actions.
authorGunnar Wrobel <p@rdus.de>
Fri, 11 Sep 2009 15:49:49 +0000 (17:49 +0200)
committerGunnar Wrobel <p@rdus.de>
Fri, 11 Sep 2009 15:49:49 +0000 (17:49 +0200)
framework/Kolab_FreeBusy/lib/Horde/Kolab/FreeBusy.php
framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/DispatchTest.php
framework/Kolab_FreeBusy/test/Horde/Kolab/FreeBusy/Mock/Controller/FreebusyController.php

index d9f75a5..09a7f18 100644 (file)
@@ -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;
index 2818748..8cbf510 100644 (file)
@@ -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
index 7cb1bb6..bdd80fe 100644 (file)
@@ -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