StaticTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-2009 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. /** Zend_Controller_Router_Route */
  23. require_once 'Zend/Controller/Router/Route/Static.php';
  24. /** PHPUnit test case */
  25. require_once 'PHPUnit/Framework/TestCase.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Controller
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Controller
  33. * @group Zend_Controller_Router
  34. */
  35. class Zend_Controller_Router_Route_StaticTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function testStaticMatch()
  38. {
  39. $route = new Zend_Controller_Router_Route_Static('users/all');
  40. $values = $route->match('users/all');
  41. $this->assertType('array', $values);
  42. }
  43. public function testStaticMatchFailure()
  44. {
  45. $route = new Zend_Controller_Router_Route_Static('archive/2006');
  46. $values = $route->match('users/all');
  47. $this->assertSame(false, $values);
  48. }
  49. public function testStaticMatchWithDefaults()
  50. {
  51. $route = new Zend_Controller_Router_Route_Static('users/all',
  52. array('controller' => 'ctrl', 'action' => 'act'));
  53. $values = $route->match('users/all');
  54. $this->assertType('array', $values);
  55. $this->assertSame('ctrl', $values['controller']);
  56. $this->assertSame('act', $values['action']);
  57. }
  58. public function testStaticUTFMatch()
  59. {
  60. $route = new Zend_Controller_Router_Route_Static('żółć');
  61. $values = $route->match('żółć');
  62. $this->assertType('array', $values);
  63. }
  64. public function testRootRoute()
  65. {
  66. $route = new Zend_Controller_Router_Route_Static('/');
  67. $values = $route->match('');
  68. $this->assertSame(array(), $values);
  69. }
  70. public function testAssemble()
  71. {
  72. $route = new Zend_Controller_Router_Route_Static('/about');
  73. $url = $route->assemble();
  74. $this->assertSame('about', $url);
  75. }
  76. public function testGetDefaults()
  77. {
  78. $route = new Zend_Controller_Router_Route_Static('users/all',
  79. array('controller' => 'ctrl', 'action' => 'act'));
  80. $values = $route->getDefaults();
  81. $this->assertType('array', $values);
  82. $this->assertSame('ctrl', $values['controller']);
  83. $this->assertSame('act', $values['action']);
  84. }
  85. public function testGetDefault()
  86. {
  87. $route = new Zend_Controller_Router_Route_Static('users/all',
  88. array('controller' => 'ctrl', 'action' => 'act'));
  89. $this->assertSame('ctrl', $route->getDefault('controller'));
  90. $this->assertSame(null, $route->getDefault('bogus'));
  91. }
  92. public function testGetInstance()
  93. {
  94. require_once 'Zend/Config.php';
  95. $routeConf = array(
  96. 'route' => 'users/all',
  97. 'defaults' => array(
  98. 'controller' => 'ctrl'
  99. )
  100. );
  101. $config = new Zend_Config($routeConf);
  102. $route = Zend_Controller_Router_Route_Static::getInstance($config);
  103. $this->assertType('Zend_Controller_Router_Route_Static', $route);
  104. $values = $route->match('users/all');
  105. $this->assertSame('ctrl', $values['controller']);
  106. }
  107. }