StaticTest.php 3.9 KB

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