OSDN Git Service

- add test for Ethna_UrlHandler.
authorichii386 <ichii386@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 6 Nov 2006 13:16:38 +0000 (13:16 +0000)
committerichii386 <ichii386@2ef88817-412d-0410-a32c-8029a115e976>
Mon, 6 Nov 2006 13:16:38 +0000 (13:16 +0000)
- fix bug with dealing more than one path_ext parameters at actionToRequest.
- retab.

class/Ethna_UrlHandler.php
test/Ethna_UrlHandler_Test.php [new file with mode: 0644]

index cb4c9b7..a13b074 100644 (file)
 <?php
 /**
- *     Ethna_UrlHandler.php
+ *  Ethna_UrlHandler.php
  *
- *     @author         Masaki Fujimoto <fujimoto@php.net>
- *     @package    Ethna
- *     @version    $Id$
+ *  @author     Masaki Fujimoto <fujimoto@php.net>
+ *  @package    Ethna
+ *  @version    $Id$
  */
 
 /**
- *     ¥¢¥¯¥·¥ç¥ó¥²¡¼¥È¥¦¥§¥¤¥¯¥é¥¹
+ *  ¥¢¥¯¥·¥ç¥ó¥²¡¼¥È¥¦¥§¥¤¥¯¥é¥¹
  *
- *     @author         Masaki Fujimoto <fujimoto@php.net>
- *     @access         public
- *     @package        GREE
+ *  @author     Masaki Fujimoto <fujimoto@php.net>
+ *  @access     public
+ *  @package    Ethna
  */
 class Ethna_UrlHandler
 {
-       /**     @var    array   ¥¢¥¯¥·¥ç¥ó¥Þ¥Ã¥Ô¥ó¥° */
-       var     $action_map = array(
+    /** @var    array   ¥¢¥¯¥·¥ç¥ó¥Þ¥Ã¥Ô¥ó¥° */
+    var $action_map = array(
         /*
-                * 'user'       => array(
-                *      'user_login' => array(
-                *              'path'                  => 'login',
-                *              'path_regexp'   => false,
-                *              'path_ext'              => false,
-                *              'option'                => array(),
-                *      ),
-                * ),
+         * 'user'   => array(
+         *  'user_login' => array(
+         *      'path'          => 'login',
+         *      'path_regexp'   => false,
+         *      'path_ext'      => false,
+         *      'option'        => array(),
+         *  ),
+         * ),
          */
-       );
-
-       /**
-        *      Ethna_UrlHandler¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
-        *
-        *      @access public
-        */
-       function Ethna_UrlHandler()
-       {
-       }
-
-       /**
-        *      Ethna_UrlHandler¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò¼èÆÀ¤¹¤ë
-        *
-        *      @access public
-        */
-       function &getInstance($class_name = null)
-       {
-               static $instance = array();
+    );
+
+    /**
+     *  Ethna_UrlHandler¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
+     *
+     *  @access public
+     */
+    function Ethna_UrlHandler()
+    {
+    }
+
+    /**
+     *  Ethna_UrlHandler¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤ò¼èÆÀ¤¹¤ë
+     *
+     *  @access public
+     */
+    function &getInstance($class_name = null)
+    {
+        static $instance = array();
 
         if (is_null($class_name)) {
             $class_name = __CLASS__;
         }
 
-               if (isset($instance[$class_name]) && is_object($instance[$class_name])) {
-                       return $instance[$class_name];
-               }
-
-               $instance[$class_name] =& new $class_name();
-
-               return $instance[$class_name];
-       }
-
-       /**
-        *      ¥¢¥¯¥·¥ç¥ó¤ò¥æ¡¼¥¶¥ê¥¯¥¨¥¹¥È¤ËÊÑ´¹¤¹¤ë
-        *
-        *      @access public
-        */
-       function actionToRequest($action, $param)
-       {
-               $url_handler = null;
-               $action_value = null;
-               foreach ($this->action_map as $key => $value) {
-                       if (isset($value[$action])) {
-                               $url_handler = $key;
-                               $action_value = $value[$action];
-                               break;
-                       }
-               }
-               if (is_null($url_handler)) {
-                       return null;
-               }
-
-               // url_handler specific path
-               $method = sprintf("_getPath_%s", ucfirst($url_handler));
-               if (method_exists($this, $method)) {
-                       list($path, $path_key) = $this->$method($action, $param);
-                       if ($path == "") {
-                               return null;
-                       }
-               } else {
-                       return null;
-               }
-
-               // append action path
-               if ($action_value['path']) {
-                       $path .= "/" . $action_value['path'];
-               }
-
-               // append path_ext key
-               $path_ext_list = is_array($action_value['path_regexp']) ? $action_value['path_ext'] : array($action_value['path_ext']);
-               foreach ($path_ext_list as $index => $path_ext) {
-                       $path_ext_match = false;
-            if (is_array($path_ext) == false) {
+        if (isset($instance[$class_name]) && is_object($instance[$class_name])) {
+            return $instance[$class_name];
+        }
+
+        $instance[$class_name] =& new $class_name();
+
+        return $instance[$class_name];
+    }
+
+    /**
+     *  ¥¢¥¯¥·¥ç¥ó¤ò¥æ¡¼¥¶¥ê¥¯¥¨¥¹¥È¤ËÊÑ´¹¤¹¤ë
+     *
+     *  @access public
+     */
+    function actionToRequest($action, $param)
+    {
+        $url_handler = null;
+        $action_value = null;
+        foreach ($this->action_map as $key => $value) {
+            if (isset($value[$action])) {
+                $url_handler = $key;
+                $action_value = $value[$action];
+                break;
+            }
+        }
+        if (is_null($url_handler)) {
+            return null;
+        }
+
+        // url_handler specific path
+        $method = sprintf("_getPath_%s", ucfirst($url_handler));
+        if (method_exists($this, $method) === false) {
+            return null;
+        }
+        list($path, $path_key) = $this->$method($action, $param);
+        if ($path == "") {
+            return null;
+        }
+
+        // append action path
+        if ($action_value['path']) {
+            $path .= "/" . $action_value['path'];
+        }
+
+        // path_ext candidate list
+        if (is_array($action_value['path_regexp'])) {
+            // try most matcher
+            $tmp = array_map('count', $action_value['path_ext']);
+            arsort($tmp);
+            $path_ext_list_indices = array_keys($tmp);
+            $path_ext_list = $action_value['path_ext'];
+        } else {
+            $path_ext_list_indices = array(0);
+            $path_ext_list = array(0 => $action_value['path_ext']);
+        }
+
+        // fix path_ext to use
+        foreach ($path_ext_list_indices as $index) {
+            if (is_array($path_ext_list[$index]) === false) {
+                // no parameters needed.
+                $path_ext = $path_ext_list[$index];
+                break;
+            }
+            $path_ext_match = true;
+            foreach ($path_ext_list[$index] as $key => $value) {
+                if (isset($param[$key]) === false) {
+                    $path_ext_match = false;
+                    break;
+                }
+            }
+            if ($path_ext_match) {
+                $path_ext = $path_ext_list[$index];
+                break;
+            }
+        }
+        if (isset($path_ext) === false) {
+            return null;
+        }
+
+        // append extra parameters to path.
+        if (is_array($path_ext)) {
+            foreach ($path_ext as $key => $value) {
+                $path_key[] = $key;
+                $ext_param = $param[$key];
+
+                // output filter
+                if (isset($value['output_filter']) && $value['output_filter'] != "") {
+                    $method = $value['output_filter'];
+                    if (method_exists($this, $method)) {
+                        $ext_param = $this->$method($ext_param);
+                    }
+                }
+
+                // remove form (pre|suf)fix
+                if (isset($value['form_prefix']) && $value['form_prefix'] != "") {
+                    $s = $value['form_prefix'];
+                    if (substr($ext_param, 0, strlen($s)) == $s) {
+                        $ext_param = substr($ext_param, strlen($s));
+                    }
+                }
+                if (isset($value['form_suffix']) && $value['form_suffix'] != "") {
+                    $s = $value['form_suffix'];
+                    if (substr($ext_param, -strlen($s)) == $s) {
+                        $ext_param = substr($ext_param, 0, -strlen($s));
+                    }
+                }
+
+                // urlencode (url (pre|suf)fixes need not to be encoded.)
+                $ext_param = urlencode($ext_param);
+
+                // add url (pre|suf)fix
+                if (isset($value['url_prefix']) && $value['url_prefix'] != "") {
+                    $ext_param = $value['url_prefix'] . $ext_param;
+                }
+                if (isset($value['url_suffix']) && $value['url_suffix'] != "") {
+                    $ext_param = $ext_param . $value['url_suffix'];
+                }
+
+                $path .= '/' . $ext_param;
+            }
+        }
+
+        list($path, $is_slash) = $this->_normalizePath($path);
+        return array($path, $path_key);
+    }
+
+    /**
+     *  ¥æ¡¼¥¶¥ê¥¯¥¨¥¹¥È¤ò¥¢¥¯¥·¥ç¥ó¤ËÊÑ´¹¤¹¤ë
+     *
+     *  @access public
+     */
+    function requestToAction($http_vars)
+    {
+        if (isset($http_vars['__url_handler__']) == false
+            || isset($this->action_map[$http_vars['__url_handler__']]) == false) {
+            return array();
+        }
+
+        $url_handler = $http_vars['__url_handler__'];
+        $action_map = $this->action_map[$url_handler];
+
+        // parameter fix
+        $method = sprintf("_normalizeRequest_%s", ucfirst($url_handler));
+        if (method_exists($this, $method)) {
+            $http_vars = $this->$method($http_vars);
+        }
+
+        // normalize
+        if (isset($http_vars['__url_info__'])) {
+            $path = $http_vars['__url_info__'];
+        } else {
+            $path = "";
+        }
+        list($path, $is_slash) = $this->_normalizePath($path);
+
+        // match
+        $action = null;
+        $action_value = null;
+        $action_match = null;
+        $action_regexp_index = null;
+        foreach ($action_map as $key => $value) {
+            $match_length = strlen($value['path']);
+
+            // check necessary match
+            if (strncmp($path, $value['path'], $match_length) != 0) {
                 continue;
             }
-                       foreach ($path_ext as $ext => $ext_value) {
-                               if (isset($param[$ext]) == false) {
-                                       break;
-                               }
-
-                               $path_ext_match = true;
-                               $path_key[] = $ext;
-
-                               $ext_param = $param[$ext];
-                               if (isset($ext_value['output_filter']) && $ext_value['output_filter'] != "") {
-                                       $method = $ext_value['output_filter'];
-                                       if (method_exists($this, $method)) {
-                                               $ext_param = $this->$method($ext_param);
-                                       }
-                               }
-
-                               // remove form (pre|suf)fix, add url (pre|suf)fix
-                               if (isset($ext_value['form_prefix']) && $ext_value['form_prefix'] != "") {
-                                       $s = $ext_value['form_prefix'];
-                                       if (substr($ext_param, 0, strlen($s)) == $s) {
-                                               $ext_param = substr($ext_param, strlen($s));
-                                       }
-                               }
-                               if (isset($ext_value['form_suffix']) && $ext_value['form_suffix'] != "") {
-                                       $s = $ext_value['form_suffix'];
-                                       if (substr($ext_param, -strlen($s)) == $s) {
-                                               $ext_param = substr($ext_param, 0, -strlen($s));
-                                       }
-                               }
-
-                               $ext_param_prefix = $ext_param_suffix = "";
-                               if (isset($ext_value['url_prefix']) && $ext_value['url_prefix'] != "") {
-                                       $ext_param_prefix = $ext_value['url_prefix'];
-                               }
-                               if (isset($ext_value['url_suffix']) && $ext_value['url_suffix'] != "") {
-                                       $ext_param_suffix = $ext_value['url_suffix'];
-                               }
-
-                               $path .= "/" . $ext_param_prefix . urlencode($ext_param) . $ext_param_suffix;
-                       }
-                       if ($path_ext_match) {
-                               break;
-                       }
-               }
-
-               return array($path, $path_key);
-       }
-
-       /**
-        *      ¥æ¡¼¥¶¥ê¥¯¥¨¥¹¥È¤ò¥¢¥¯¥·¥ç¥ó¤ËÊÑ´¹¤¹¤ë
-        *
-        *      @access public
-        */
-       function requestToAction($http_vars)
-       {
-               if (isset($http_vars['__url_handler__']) == false ||
-                       isset($this->action_map[$http_vars['__url_handler__']]) == false) {
-                       return array();
-               }
-
-               $url_handler = $http_vars['__url_handler__'];
-
-               // parameter fix
-               $method = sprintf("_normalizeRequest_%s", ucfirst($url_handler));
-               if (method_exists($this, $method)) {
-                       $http_vars = $this->$method($http_vars);
-               }
-
-               $action_map = $this->action_map[$url_handler];
-
-               // normalize
-               if (isset($http_vars['__url_info__'])) {
-                       $path = $http_vars['__url_info__'];
-               } else {
-                       $path = "";
-               }
-               list($path, $is_slash) = $this->_normalizePath($path);
-
-               // match
-               $action = null;
-               $action_value = null;
-               $action_match = null;
-               $action_regexp_index = null;
-               foreach ($action_map as $key => $value) {
-                       $match_length = strlen($value['path']);
-                       if (strncmp($path, $value['path'], $match_length) != 0) {
-                               continue;
-                       }
-
-                       // try exact match
-                       if ($path == $value['path']) {
-                               $action = $key;
-                               break;
-                       }
-
-                       // continue in case w/ incomplete match
-                       if ($path != "" && $match_length > 0 && $path{$match_length} != "/") {
-                               continue;
-                       }
-                       if ($is_slash && $path{strlen($path)-1} == "/") {
-                               continue;
-                       }
-
-                       // try regexp
-                       if ($value['path_regexp']) {
-                               if (is_array($value['path_regexp'])) {
-                                       foreach ($value['path_regexp'] as $index => $regexp) {
-                                               if (preg_match($regexp, $path, $tmp)) {
-                                                       $action = $key;
-                                                       $action_match = $tmp;
-                                                       $action_regexp_index = $index;
-                                                       break;
-                                               }
-                                       }
-                               } else {
-                                       if (preg_match($value['path_regexp'], $path, $tmp)) {
-                                               $action = $key;
-                                               $action_match = $tmp;
-                                               break;
-                                       }
-                               }
-                       }
-               }
-               if (is_null($action)) {
-                       return array();
-               }
-               $action_value = $action_map[$action];
-
-               // build parameters
+
+            // try exact match
+            if ($path == $value['path']) {
+                $action = $key;
+                break;
+            }
+
+            // continue in case w/ incomplete match
+            if ($path != "" && $match_length > 0 && $path{$match_length} != "/") {
+                continue;
+            }
+            if ($is_slash && $path{strlen($path)-1} == "/") {
+                continue;
+            }
+
+            // try regexp
+            if ($value['path_regexp']) {
+                if (is_array($value['path_regexp'])) {
+                    foreach ($value['path_regexp'] as $index => $regexp) {
+                        if (preg_match($regexp, $path, $tmp)) {
+                            $action = $key;
+                            $action_match = $tmp;
+                            $action_regexp_index = $index;
+                            break;
+                        }
+                    }
+                } else {
+                    if (preg_match($value['path_regexp'], $path, $tmp)) {
+                        $action = $key;
+                        $action_match = $tmp;
+                        break;
+                    }
+                }
+            }
+        }
+        if (is_null($action)) {
+            return array();
+        }
+        $action_value = $action_map[$action];
+
+        // build parameters
         $http_vars = $this->buildActionParameter($http_vars, $action);
 
-               // extra parameters
-               $path_ext = is_null($action_regexp_index) ? $action_value['path_ext'] : $action_value['path_ext'][$action_regexp_index];
-               if (is_array($path_ext) && is_array($action_match)) {
-                       $n = 1;
-                       foreach ($path_ext as $key => $value) {
-                               if (isset($action_match[$n]) == false) {
-                                       break;
-                               }
-
-                               // remove url (pre|suf)fix, add form (pre|suf)fix
-                               if (isset($value['url_prefix']) && $value['url_prefix'] != "") {
-                                       $s = $value['url_prefix'];
-                                       if (substr($action_match[$n], 0, strlen($s)) == $s) {
-                                               $action_match[$n] = substr($action_match[$n], strlen($s));
-                                       }
-                               }
-                               if (isset($value['url_suffix']) && $value['url_suffix'] != "") {
-                                       $s = $value['url_suffix'];
-                                       if (substr($action_match[$n], -strlen($s)) == $s) {
-                                               $action_match[$n] = substr($action_match[$n], 0, -strlen($s));
-                                       }
-                               }
-
-                               if (isset($value['form_prefix']) && $value['form_prefix'] != "") {
-                                       $action_match[$n] = $value['form_prefix'] . $action_match[$n];
-                               }
-                               if (isset($value['form_suffix']) && $value['form_suffix'] != "") {
-                                       $action_match[$n] = $action_match[$n] . $value['form_suffix'];
-                               }
-
-                               if (isset($value['input_filter']) && $value['input_filter'] != "") {
-                                       $method = $value['input_filter'];
-                                       if (method_exists($this, $method)) {
-                                               $action_match[$n] = $this->$method($action_match[$n]);
-                                       }
-                               }
-
-                               $http_vars[$key] = $action_match[$n];
-                               $n++;
-                       }
-               }
-
-               return $http_vars;
-       }
-
-       /**
-        *      ¥²¡¼¥È¥¦¥§¥¤¥Ñ¥¹¤òÀµµ¬²½¤¹¤ë
-        *
-        *      @access private
-        */
-       function _normalizePath($path)
-       {
-               if ($path == "") {
-                       return array($path, false);
-               }
-
-               $is_slash = false;
-               $path = preg_replace('|/+|', '/', $path);
-
-               if ($path{0} == '/') {
-                       $path = substr($path, 1);
-               }
-               if ($path{strlen($path)-1} == '/') {
-                       $path = substr($path, 0, strlen($path)-1);
-                       $is_slash = true;
-               }
-
-               return array($path, $is_slash);
-       }
+        // extra parameters
+        $path_ext = is_null($action_regexp_index)
+                    ? $action_value['path_ext']
+                    : $action_value['path_ext'][$action_regexp_index];
+        if (is_array($path_ext) && is_array($action_match)) {
+            $n = 1;
+            foreach ($path_ext as $key => $value) {
+                if (isset($action_match[$n]) == false) {
+                    break;
+                }
+
+                // remove url (pre|suf)fix
+                if (isset($value['url_prefix']) && $value['url_prefix'] != "") {
+                    $s = $value['url_prefix'];
+                    if (substr($action_match[$n], 0, strlen($s)) == $s) {
+                        $action_match[$n] = substr($action_match[$n], strlen($s));
+                    }
+                }
+                if (isset($value['url_suffix']) && $value['url_suffix'] != "") {
+                    $s = $value['url_suffix'];
+                    if (substr($action_match[$n], -strlen($s)) == $s) {
+                        $action_match[$n] = substr($action_match[$n], 0, -strlen($s));
+                    }
+                }
+
+                // add form (pre|suf)fix
+                if (isset($value['form_prefix']) && $value['form_prefix'] != "") {
+                    $action_match[$n] = $value['form_prefix'] . $action_match[$n];
+                }
+                if (isset($value['form_suffix']) && $value['form_suffix'] != "") {
+                    $action_match[$n] = $action_match[$n] . $value['form_suffix'];
+                }
+
+                // input filter
+                if (isset($value['input_filter']) && $value['input_filter'] != "") {
+                    $method = $value['input_filter'];
+                    if (method_exists($this, $method)) {
+                        $action_match[$n] = $this->$method($action_match[$n]);
+                    }
+                }
+
+                $http_vars[$key] = $action_match[$n];
+                $n++;
+            }
+        }
+
+        return $http_vars;
+    }
+
+    /**
+     *  ¥²¡¼¥È¥¦¥§¥¤¥Ñ¥¹¤òÀµµ¬²½¤¹¤ë
+     *
+     *  @access private
+     */
+    function _normalizePath($path)
+    {
+        if ($path == "") {
+            return array($path, false);
+        }
+
+        $is_slash = false;
+        $path = preg_replace('|/+|', '/', $path);
+
+        if ($path{0} == '/') {
+            $path = substr($path, 1);
+        }
+        if ($path{strlen($path)-1} == '/') {
+            $path = substr($path, 0, strlen($path)-1);
+            $is_slash = true;
+        }
+
+        return array($path, $is_slash);
+    }
 
     /**
      *  ¥¢¥¯¥·¥ç¥ó¤ò¥ê¥¯¥¨¥¹¥È¥Ñ¥é¥á¡¼¥¿¤ËÊÑ´¹¤¹¤ë
@@ -335,7 +366,9 @@ class Ethna_UrlHandler
                     if (is_numeric($k)) {
                         $k = '';
                     }
-                    $param .= sprintf('%s=%s&', urlencode(sprintf('%s[%s]', $key, $k)), urlencode($v));
+                    $param .= sprintf('%s=%s&',
+                                      urlencode(sprintf('%s[%s]', $key, $k)),
+                                      urlencode($v));
                 }
             } else if (is_null($value) == false) {
                 $param .= sprintf('%s=%s&', urlencode($key), urlencode($value));
@@ -345,14 +378,14 @@ class Ethna_UrlHandler
         return substr($param, 0, -1);
     }
 
-       // {{{ ¥²¡¼¥È¥¦¥§¥¤¥ê¥¯¥¨¥¹¥ÈÀµµ¬²½
-       // }}}
+    // {{{ ¥²¡¼¥È¥¦¥§¥¤¥ê¥¯¥¨¥¹¥ÈÀµµ¬²½
+    // }}}
 
-       // {{{ ¥²¡¼¥È¥¦¥§¥¤¥Ñ¥¹À¸À®
-       // }}}
+    // {{{ ¥²¡¼¥È¥¦¥§¥¤¥Ñ¥¹À¸À®
+    // }}}
 
-       // {{{ ¥Õ¥£¥ë¥¿
-       // }}}
+    // {{{ ¥Õ¥£¥ë¥¿
+    // }}}
 }
 
 // vim: foldmethod=marker tabstop=4 shiftwidth=4 autoindent
diff --git a/test/Ethna_UrlHandler_Test.php b/test/Ethna_UrlHandler_Test.php
new file mode 100644 (file)
index 0000000..2bce495
--- /dev/null
@@ -0,0 +1,337 @@
+<?php
+/**
+ *  Ethna_UrlHandler_Test.php
+ */
+
+/**
+ *  Ethna_UrlHandler¥¯¥é¥¹¤Î¥Æ¥¹¥È¥±¡¼¥¹
+ *
+ *  @access public
+ */
+class Ethna_UrlHandler_Test extends UnitTestCase
+{
+    var $url_handler;
+
+    function setup()
+    {
+        $this->url_handler =& new Test_UrlHandler($this);
+    }
+
+    // {{{ $_simple_map
+    var $_simple_map = array(
+        'entrypoint' => array(
+            'test_foo_bar' => array(
+                'path'          => 'foo/bar',
+                'path_regexp'   => false,
+                'path_ext'      => false,
+            ),
+        ),
+    );
+    // }}}
+
+    // {{{ $_complex_map
+    var $_complex_map = array(
+        'entrypoint' => array(
+            'test_foo_bar' => array(
+                'path'          => 'foo/bar',
+                'path_regexp'   => array(
+                    'dummy_index1' => '|foo/bar/([^/]*)$|',
+                    'dummy_index2' => '|foo/bar/([^/]*)/([^/]*)$|',
+                ),
+                'path_ext'      => array(
+                    'dummy_index1' => array(
+                        'param1'   => array(),
+                    ),
+                    'dummy_index2' => array(
+                        'param1'   => array(),
+                        'param2'   => array(),
+                    ),
+                ),
+            ),
+        ),
+    );
+    // }}}
+
+    // {{{ $_prefix_suffix_map
+    var $_prefix_suffix_map = array(
+        'entrypoint' => array(
+            'test_foo_bar' => array(
+                'path'          => 'foo/bar',
+                'path_regexp'   => '|foo/bar/(.*)$|',
+                'path_ext'      => array(
+                    'param1' => array(
+                        'url_prefix'    => 'URL-',
+                        'url_suffix'    => '-URL',
+                        'form_prefix'   => 'FORM-',
+                        'form_suffix'   => '-FORM',
+                    ),
+                ),
+            ),
+        ),
+    );
+    // }}}
+
+    // {{{ test_requestToAction_simple
+    function test_requestToAction_simple()
+    {
+        // pathinfo ¤«¤é action ¼èÆÀ
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',      // not empty
+            '__url_info__'      => '/foo/bar',  // null or not empty
+            'param3'            => 'value3',
+        );
+
+        $this->url_handler->action_map = $this->_simple_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+
+        // action ¤ò¼õ¤±¼è¤ë
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual(count($diff), 1);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+
+        // action ¤ò¼õ¤±¼è¤ë°Ê³°¤ÎÊѲ½¤¬¤Ê¤¤¤³¤È¤ò³Îǧ
+        $diff = array_diff($http_vars, $injected);
+        $this->assertEqual(count($diff), 0);
+
+
+        // action ¤ò¼õ¤±¼è¤ë
+        $this->url_handler->action_map = $this->_complex_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual(count($diff), 1);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+
+    }
+    // }}}
+
+    // {{{ test_requestToAction_nopathinfo
+    function test_requestToAction_nopathinfo()
+    {
+        // pathinfo ¤Ê¤·
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+            '__url_info__'      => null,
+        );
+
+        $this->url_handler->action_map = $this->_complex_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+
+        // ÊѲ½¤Ê¤·
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual(count($diff), 0);
+    }
+    // }}}
+
+    // {{{ test_requestToAction_withparams1
+    function test_requestToAction_withparams1()
+    {
+        // pathinfo ¤«¤é action ¤È¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+            '__url_info__'      => '/foo/bar/aaa',
+        );
+
+        // °ìÃפ¹¤ë action_map ¤¬¤Ê¤¤: ¥¨¥é¡¼¤È¤·¤Æ array() ¤òÊÖ¤¹
+        $this->url_handler->action_map = $this->_simple_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $this->assertEqual(count($injected), 0);
+
+
+        // action ¤È¥Ñ¥é¥á¡¼¥¿ param1 ¤ò¼õ¤±¼è¤ë
+        $this->url_handler->action_map = $this->_complex_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual(count($diff), 2);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], 'aaa');
+    }
+    // }}}
+
+    // {{{ test_requestToAction_withparams2
+    function test_requestToAction_withparams2()
+    {
+        // pathinfo ¤«¤é action ¤ÈÊ£¿ô¤Î¥Ñ¥é¥á¡¼¥¿¤ò¼õ¤±¼è¤ë
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+            '__url_info__'      => '/foo/bar/aaa/bbb',
+        );
+
+        $this->url_handler->action_map = $this->_complex_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual(count($diff), 3);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], 'aaa');
+        $this->assertEqual($diff['param2'], 'bbb');
+    }
+    // }}}
+
+    // {{{ test_requestToAction_withparams3
+    function test_requestToAction_withparams3()
+    {
+        // ÄêµÁ¤µ¤ì¤¿°Ê¾å¤Î¥Ñ¥é¥á¡¼¥¿¤¬¤¢¤ë¾ì¹ç
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+            '__url_info__'      => '/foo/bar/aaa/bbb/ccc',
+        );
+
+        $this->url_handler->action_map = $this->_complex_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $this->assertEqual(count($injected), 0);
+    }
+    // }}}
+
+    // {{{ test_requestToAction_misc
+    function test_requestToAction_misc()
+    {
+        // Èù̯¤Ê pathinfo ¤Î¥Á¥§¥Ã¥¯
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+        );
+        $this->url_handler->action_map = $this->_complex_map;
+
+        // Í¾Ê¬¤Ê slash ¤¬Á°¸å¤Ë¤Ä¤¤¤Æ¤¤¤ë
+        $http_vars['__url_info__'] = '///foo///bar///value1///';
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], 'value1');
+        $this->assertFalse(isset($diff['param2']));
+
+        // path ¤¬ '/./' ¤ò´Þ¤à
+        $http_vars['__url_info__'] = '/foo/bar/./value1';
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], '.');
+        $this->assertEqual($diff['param2'], 'value1');
+
+        // path ¤¬ '/../' ¤ò´Þ¤à
+        $http_vars['__url_info__'] = '/foo/bar/../baz';
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], '..');
+        $this->assertEqual($diff['param2'], 'baz');
+
+        // Ä¹¤¤¥ê¥¯¥¨¥¹¥È
+        $http_vars['__url_info__'] = '/foo/bar/' . str_repeat('a', 10000);
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertTrue(isset($diff['param1']));
+        $this->assertFalse(isset($diff['param2']));
+    }
+    // }}}
+
+    // {{{ test_requestToAction_prefix_suffix
+    function test_requestToAction_prefix_suffix()
+    {
+        $http_vars = array(
+            '__url_handler__'   => 'entrypoint',
+            '__url_info__'      => '/foo/bar/URL-value1-URL',
+            'param3'            => 'value3',
+        );
+
+        $this->url_handler->action_map = $this->_prefix_suffix_map;
+        $injected = $this->url_handler->requestToAction($http_vars);
+        $diff = array_diff($injected, $http_vars);
+        $this->assertEqual($diff['action_test_foo_bar'], true);
+        $this->assertEqual($diff['param1'], 'FORM-value1-FORM');
+    }
+    // }}}
+
+    // {{{ test_actionToRequest_simple
+    function test_actionToRequest_simple()
+    {
+        $action = 'test_foo_bar';
+        $param = array(
+            'hoge' => 'fuga',
+        );
+
+        $this->url_handler->action_map = $this->_simple_map;
+        $ret = $this->url_handler->actionToRequest($action, $param);
+        $this->assertFalse(is_null($ret));
+        list($path, $path_key) = $ret;
+
+        // action "test_foo_bar" ¤ËÂбþ¤¹¤ë¤Î¤Ï "entrypoint" ¤Î "/foo/bar"
+        $this->assertEqual($path, 'entrypoint/foo/bar');
+        $this->assertTrue($path_key == array());
+    }
+    // }}}
+
+    // {{{ test_actionToRequest_unknownaction
+    function test_actionToRequest_unknownaction()
+    {
+        $action = 'test_unknown_action';
+        $param = array(
+            'hoge' => 'fuga',
+        );
+
+        $this->url_handler->action_map = $this->_simple_map;
+        $ret = $this->url_handler->actionToRequest($action, $param);
+        $this->assertTrue(is_null($ret));
+    }
+    // }}}
+
+    // {{{ test_actionToRequest_param1
+    function test_actionToRequest_param1()
+    {
+        $action = 'test_foo_bar';
+        $param = array(
+            'hoge' => 'fuga',
+            'param1' => 'value1',
+        );
+
+        $this->url_handler->action_map = $this->_complex_map;
+        list($path, $path_key) = $this->url_handler->actionToRequest($action, $param);
+        $this->assertEqual($path, 'entrypoint/foo/bar/value1');
+        $this->assertTrue($path_key == array('param1'));
+    }
+    // }}}
+
+    // {{{ test_actionToRequest_param2
+    function test_actionToRequest_param2()
+    {
+        $action = 'test_foo_bar';
+        $param = array(
+            'hoge' => 'fuga',
+            'param1' => 'value1',
+            'param2' => 'value2',
+        );
+
+        $this->url_handler->action_map = $this->_complex_map;
+        list($path, $path_key) = $this->url_handler->actionToRequest($action, $param);
+        $this->assertEqual($path, 'entrypoint/foo/bar/value1/value2');
+        $this->assertEqual($path_key, array('param1', 'param2'));
+    }
+    // }}}
+}
+
+class Test_UrlHandler extends Ethna_UrlHandler
+{
+    function _getPath_Entrypoint($action, $params)
+    {
+        return array('/entrypoint', array());
+    }
+
+    function _normalizerequest_Test($http_vars)
+    {
+        return $http_vars;
+    }
+
+    function _input_filter_Test($input)
+    {
+        return strtolower($input);
+    }
+
+    function _output_filter_Test($output)
+    {
+        return strtoupper($output);
+    }
+}
+
+?>