[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/cms/tests/cases/request/ -> lmbCmsNodeBasedRequestDispatcherTest.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/cms/src/request/lmbCmsNodeBasedRequestDispatcher.class.php');
  10  lmb_require('limb/cms/src/model/lmCmsNode.class.php');
  11  
  12  class lmbCmsNodeBasedRequestDispatcherTest extends UnitTestCase
  13  {
  14    protected $request;
  15    protected $toolkit;
  16    protected $tree;
  17  
  18    function setUp()
  19    {
  20      $this->toolkit = lmbToolkit :: save();
  21      $this->request = $this->toolkit->getRequest();
  22      $this->tree = $this->toolkit->getCmsTree();
  23    }
  24  
  25    function tearDown()
  26    {
  27      $this->tree->deleteAll();
  28      lmbToolkit :: restore();
  29    }
  30  
  31    function testDispatchWithDefaultAction()
  32    {
  33      $root = $this->_createNode('root');
  34      $child = $this->_createNode('news', $root, 'news');
  35  
  36      $this->request->getUri()->reset('/root/news');
  37  
  38      $dispatcher = new lmbCmsNodeBasedRequestDispatcher();
  39      $result = $dispatcher->dispatch($this->request);
  40  
  41      $this->assertEqual($result['controller'], 'news');
  42    }
  43  
  44    function testDispatchWithAction()
  45    {
  46      $root = $this->_createNode('root');
  47      $child = $this->_createNode('news', $root, 'news');
  48  
  49      $this->request->getUri()->reset('/root/news');
  50      $this->request->set('action', 'show');
  51  
  52      $dispatcher = new lmbCmsNodeBasedRequestDispatcher();
  53      $result = $dispatcher->dispatch($this->request);
  54  
  55      $this->assertEqual($result['controller'], 'news');
  56      $this->assertEqual($result['action'], 'show');
  57    }
  58  
  59    function testDispatchToParent()
  60    {
  61      $root = $this->_createNode('root', null, 'default');
  62      $child = $this->_createNode('news', $root, 'news');
  63  
  64      $this->request->getUri()->reset('/root');
  65  
  66      $dispatcher = new lmbCmsNodeBasedRequestDispatcher();
  67      $result = $dispatcher->dispatch($this->request);
  68  
  69      $this->assertEqual($result['controller'], 'default');
  70    }
  71  
  72    protected function _createNode($node_identifier, $parent_node = null, $controller_name = 'default')
  73    {
  74      $node = new lmbCmsNode();
  75      $node->setTitle('title_'. mt_rand(0, 10000));
  76      $node->setIdentifier($node_identifier);
  77      $node->setControllerName($controller_name);
  78      if($parent_node)
  79        $node->setParent($parent_node);
  80      $node->save();
  81      return $node;
  82    }
  83  }
  84  
  85  ?>


Generated: Fri Dec 5 04:05:07 2008 Cross-referenced by PHPXref 0.7