[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_app/tests/cases/plain/request/ -> lmbRoutesToUrlTest.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  lmb_require('limb/web_app/src/request/lmbRoutes.class.php');
  10  lmb_require('limb/net/src/lmbUri.class.php');
  11  
  12  class lmbRoutesToUrlTest extends UnitTestCase
  13  {
  14    function setUp()
  15    {
  16      $toolkit = lmbToolkit :: save();
  17    }
  18  
  19    function tearDown()
  20    {
  21      lmbToolkit :: restore();
  22    }
  23  
  24    function testToUrl()
  25    {
  26      $config = array('blog' => array('path' => '/blog',
  27                            'defaults' => array('controller' => 'Blog',
  28                                                'action' => 'display')),
  29                      'news' => array('path' => '/news',
  30                            'defaults' => array('controller' => 'Newsline',
  31                                                'action' => 'display')));
  32  
  33      $routes = new lmbRoutes($config);
  34      $this->assertEqual($routes->toUrl(array(), 'blog'), '/blog');
  35      $this->assertEqual($routes->toUrl(array(), 'news'), '/news');
  36    }
  37  
  38    function testToUrlUseNamedParam()
  39    {
  40      $config = array('default' => array('path' => '/:controller/display',
  41                            'defaults' => array('action' => 'display')));
  42  
  43      $routes = new lmbRoutes($config);
  44      $this->assertEqual($routes->toUrl(array('controller' => 'news'), 'default'), '/news/display');
  45    }
  46  
  47    function testToUrlApplyDefaultParamValue()
  48    {
  49      $config = array('default' => array('path' => '/:controller/:action',
  50                            'defaults' => array('action' => 'display')));
  51  
  52      $routes = new lmbRoutes($config);
  53      $this->assertEqual($routes->toUrl(array('controller' => 'news'), 'default'), '/news/display');
  54    }
  55  
  56    function testThrowExceptionIfNotEnoughParams()
  57    {
  58      $config = array('default' => array('path' => '/:controller/:action'));
  59  
  60      $routes = new lmbRoutes($config);
  61      try
  62      {
  63        $routes->toUrl(array('controller' => 'news'), 'default');
  64        $this->assertTrue(false);
  65      }
  66      catch(lmbException $e){}
  67    }
  68  
  69    function testThrowExceptionIfNotFoundAnyMatchingRoute()
  70    {
  71      $config = array('default' => array('path' => '/:controller/:action',
  72                            'defaults' => array('action' => 'display')));
  73  
  74      $routes = new lmbRoutes($config);
  75      try
  76      {
  77        $routes->toUrl(array(), 'default');
  78        $this->assertTrue(false);
  79      }
  80      catch(lmbException $e){}
  81    }
  82  
  83    function testToUrlTryToGuessRoute()
  84    {
  85      $config = array('default' => array('path' => '/:controller/display',
  86                            'defaults' => array('action' => 'display')),
  87                       'full' => array('path' => '/:controller/:action',
  88                            'defaults' => array('action' => 'display')));
  89  
  90      $routes = new lmbRoutes($config);
  91      $this->assertEqual($routes->toUrl(array('controller' => 'news',
  92                                              'action' => 'archive')), '/news/archive');
  93    }
  94  
  95    function testNoSuchRoute()
  96    {
  97      $config = array(
  98        'AdminPanel' =>
  99          array('path' => '/admin',
 100                'defaults' => array('controller' => 'AdminPanel',
 101                                    'action' => 'admin_display')),
 102  
 103        'EdPrograms' =>
 104          array('path' => '/admin/programs/:action',
 105                'defaults' => array('controller' => 'EdPrograms',
 106                                    'action' => 'admin_display')),
 107  
 108        'EdCourses' =>
 109          array('path' => '/admin/courses/:action',
 110                'defaults' => array('controller' => 'EdCourses',
 111                                    'action' => 'admin_display')),
 112  
 113      );
 114  
 115      $routes = new lmbRoutes($config);
 116      try
 117      {
 118        $routes->toUrl(array('action' => 'create'), 'Course');
 119        $this->assertTrue(false);
 120      }
 121      catch(lmbException $e){}
 122    }
 123  
 124    function testApplyUrlFilter()
 125    {
 126      $config = array('default' => array('path' => '/:controller/:action',
 127                                         'defaults' => array('action' => 'display'),
 128                                         'url_filter' => array($this, '_processUrlResult')));
 129  
 130      $routes = new lmbRoutes($config);
 131      $this->assertEqual($routes->toUrl(array('controller' => 'admin_news',
 132                                              'action' => 'archive')), '/admin/news/archive');
 133    }
 134  
 135    function _processUrlResult(&$path, $route)
 136    {
 137      $path = str_replace('/admin_', '/admin/', $path);
 138    }
 139  }
 140  ?>


Generated: Thu Aug 28 04:51:15 2008 Cross-referenced by PHPXref 0.7