StaticTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  23. /** Zend_Controller_Router_Route */
  24. require_once 'Zend/Controller/Router/Route/Static.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Controller
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Controller
  32. * @group Zend_Controller_Router
  33. */
  34. class Zend_Controller_Router_Route_StaticTest extends PHPUnit_Framework_TestCase
  35. {
  36. public function testStaticMatch()
  37. {
  38. $route = new Zend_Controller_Router_Route_Static('users/all');
  39. $values = $route->match('users/all');
  40. $this->assertType('array', $values);
  41. }
  42. public function testStaticMatchFailure()
  43. {
  44. $route = new Zend_Controller_Router_Route_Static('archive/2006');
  45. $values = $route->match('users/all');
  46. $this->assertSame(false, $values);
  47. }
  48. public function testStaticMatchWithDefaults()
  49. {
  50. $route = new Zend_Controller_Router_Route_Static('users/all',
  51. array('controller' => 'ctrl', 'action' => 'act'));
  52. $values = $route->match('users/all');
  53. $this->assertType('array', $values);
  54. $this->assertSame('ctrl', $values['controller']);
  55. $this->assertSame('act', $values['action']);
  56. }
  57. public function testStaticUTFMatch()
  58. {
  59. $route = new Zend_Controller_Router_Route_Static('żółć');
  60. $values = $route->match('żółć');
  61. $this->assertType('array', $values);
  62. }
  63. public function testRootRoute()
  64. {
  65. $route = new Zend_Controller_Router_Route_Static('/');
  66. $values = $route->match('');
  67. $this->assertSame(array(), $values);
  68. }
  69. public function testAssemble()
  70. {
  71. $route = new Zend_Controller_Router_Route_Static('/about');
  72. $url = $route->assemble();
  73. $this->assertSame('about', $url);
  74. }
  75. public function testGetDefaults()
  76. {
  77. $route = new Zend_Controller_Router_Route_Static('users/all',
  78. array('controller' => 'ctrl', 'action' => 'act'));
  79. $values = $route->getDefaults();
  80. $this->assertType('array', $values);
  81. $this->assertSame('ctrl', $values['controller']);
  82. $this->assertSame('act', $values['action']);
  83. }
  84. public function testGetDefault()
  85. {
  86. $route = new Zend_Controller_Router_Route_Static('users/all',
  87. array('controller' => 'ctrl', 'action' => 'act'));
  88. $this->assertSame('ctrl', $route->getDefault('controller'));
  89. $this->assertSame(null, $route->getDefault('bogus'));
  90. }
  91. public function testGetInstance()
  92. {
  93. require_once 'Zend/Config.php';
  94. $routeConf = array(
  95. 'route' => 'users/all',
  96. 'defaults' => array(
  97. 'controller' => 'ctrl'
  98. )
  99. );
  100. $config = new Zend_Config($routeConf);
  101. $route = Zend_Controller_Router_Route_Static::getInstance($config);
  102. $this->assertType('Zend_Controller_Router_Route_Static', $route);
  103. $values = $route->match('users/all');
  104. $this->assertSame('ctrl', $values['controller']);
  105. }
  106. }