ChainTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Controller_Router_Route_ChainTest::main');
  24. }
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. /** Zend_Config */
  27. require_once 'Zend/Config.php';
  28. /** Zend_Controller_Router_Rewrite */
  29. require_once 'Zend/Controller/Router/Rewrite.php';
  30. /** Zend_Controller_Router_Route_Chain */
  31. require_once 'Zend/Controller/Router/Route/Chain.php';
  32. /** Zend_Controller_Router_Route */
  33. require_once 'Zend/Controller/Router/Route.php';
  34. /** Zend_Controller_Router_Route_Module */
  35. require_once 'Zend/Controller/Router/Route/Module.php';
  36. /** Zend_Controller_Router_Route_Static */
  37. require_once 'Zend/Controller/Router/Route/Static.php';
  38. /** Zend_Controller_Router_Route_Regex */
  39. require_once 'Zend/Controller/Router/Route/Regex.php';
  40. /** Zend_Controller_Router_Route_Hostname */
  41. require_once 'Zend/Controller/Router/Route/Hostname.php';
  42. /** Zend_Controller_Request_Http */
  43. require_once 'Zend/Controller/Request/Http.php';
  44. /** Zend_Uri_Http */
  45. require_once 'Zend/Uri/Http.php';
  46. /** Zend_Config */
  47. require_once 'Zend/Config.php';
  48. /**
  49. * @category Zend
  50. * @package Zend_Controller
  51. * @subpackage UnitTests
  52. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  53. * @license http://framework.zend.com/license/new-bsd New BSD License
  54. * @group Zend_Controller
  55. * @group Zend_Controller_Router
  56. */
  57. class Zend_Controller_Router_Route_ChainTest extends PHPUnit_Framework_TestCase
  58. {
  59. /**
  60. * Runs the test methods of this class.
  61. *
  62. * @access public
  63. * @static
  64. */
  65. public static function main()
  66. {
  67. require_once "PHPUnit/TextUI/TestRunner.php";
  68. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Router_Route_ChainTest");
  69. $result = PHPUnit_TextUI_TestRunner::run($suite);
  70. }
  71. public function testChaining()
  72. {
  73. $request = new Zend_Controller_Router_ChainTest_Request('http://localhost/foo/bar');
  74. $foo = new Zend_Controller_Router_Route('foo');
  75. $bar = new Zend_Controller_Router_Route('bar');
  76. $chain = $foo->chain($bar);
  77. $this->assertType('Zend_Controller_Router_Route_Chain', $chain);
  78. }
  79. public function testChainingMatch()
  80. {
  81. $chain = new Zend_Controller_Router_Route_Chain();
  82. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 1));
  83. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 2));
  84. $chain->chain($foo)->chain($bar);
  85. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bla');
  86. $res = $chain->match($request);
  87. $this->assertFalse($res);
  88. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bar');
  89. $res = $chain->match($request);
  90. $this->assertEquals(1, $res['foo']);
  91. $this->assertEquals(2, $res['bar']);
  92. }
  93. public function testChainingShortcutMatch()
  94. {
  95. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 1));
  96. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 2, 'controller' => 'foo', 'action' => 'bar'));
  97. $chain = $foo->chain($bar);
  98. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bar');
  99. $res = $chain->match($request);
  100. $this->assertEquals(1, $res['foo']);
  101. $this->assertEquals(2, $res['bar']);
  102. }
  103. public function testChainingMatchFailure()
  104. {
  105. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 1));
  106. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 2, 'controller' => 'foo', 'action' => 'bar'));
  107. $chain = $foo->chain($bar);
  108. $request = new Zend_Controller_Router_ChainTest_Request('http://nope.zend.com/bar');
  109. $res = $chain->match($request);
  110. $this->assertFalse($res);
  111. }
  112. public function testChainingVariableOverriding()
  113. {
  114. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 1, 'controller' => 'foo', 'module' => 'foo'));
  115. $bar = new Zend_Controller_Router_Route('bar', array('bar' => 2, 'controller' => 'bar', 'action' => 'bar'));
  116. $chain = $foo->chain($bar);
  117. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bar');
  118. $res = $chain->match($request);
  119. $this->assertEquals('foo', $res['module']);
  120. $this->assertEquals('bar', $res['controller']);
  121. $this->assertEquals('bar', $res['action']);
  122. }
  123. public function testChainingTooLongPath()
  124. {
  125. $foo = new Zend_Controller_Router_Route_Static('foo', array('foo' => 1));
  126. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 2));
  127. $chain = $foo->chain($bar);
  128. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo/bar/baz');
  129. $res = $chain->match($request);
  130. $this->assertFalse($res);
  131. }
  132. public function testChainingRegex()
  133. {
  134. $foo = new Zend_Controller_Router_Route_Regex('f..', array('foo' => 1));
  135. $bar = new Zend_Controller_Router_Route_Regex('b..', array('bar' => 2));
  136. $chain = $foo->chain($bar);
  137. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo/bar');
  138. $res = $chain->match($request);
  139. $this->assertEquals(1, $res['foo']);
  140. $this->assertEquals(2, $res['bar']);
  141. }
  142. public function testChainingModule()
  143. {
  144. $foo = new Zend_Controller_Router_Route_Static('foo', array('foo' => 'bar'));
  145. $bar = new Zend_Controller_Router_Route_Module();
  146. $chain = $foo->chain($bar);
  147. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo/bar/baz/var/val');
  148. $res = $chain->match($request);
  149. $this->assertEquals('bar', $res['foo']);
  150. $this->assertEquals('bar', $res['controller']);
  151. $this->assertEquals('baz', $res['action']);
  152. $this->assertEquals('val', $res['var']);
  153. }
  154. public function testVariableOmittingWhenPartial()
  155. {
  156. $foo = new Zend_Controller_Router_Route(':foo', array('foo' => 'foo'));
  157. $bar = new Zend_Controller_Router_Route(':bar', array('bar' => 'bar'));
  158. $chain = $foo->chain($bar);
  159. $path = $chain->assemble(array());
  160. $this->assertEquals('foo/', $path);
  161. }
  162. public function testVariableUnsettingRoute()
  163. {
  164. $foo = new Zend_Controller_Router_Route(':foo');
  165. $bar = new Zend_Controller_Router_Route_Module(array('controller' => 'ctrl', 'action' => 'act'));
  166. $chain = $foo->chain($bar);
  167. $path = $chain->assemble(array('foo' => 'bar', 'baz' => 'bat'));
  168. $this->assertEquals('bar/ctrl/act/baz/bat', $path);
  169. }
  170. public function testVariableUnsettingRegex()
  171. {
  172. $foo = new Zend_Controller_Router_Route_Regex('([^/]+)', array(), array(1 => 'foo'), '%s');
  173. $bar = new Zend_Controller_Router_Route_Module(array('controller' => 'ctrl', 'action' => 'act'));
  174. $chain = $foo->chain($bar);
  175. $path = $chain->assemble(array('foo' => 'bar', 'baz' => 'bat'));
  176. $this->assertEquals('bar/ctrl/act/baz/bat', $path);
  177. }
  178. public function testChainingSeparatorOverriding()
  179. {
  180. $foo = new Zend_Controller_Router_Route_Static('foo', array('foo' => 1));
  181. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 2));
  182. $baz = new Zend_Controller_Router_Route_Static('baz', array('baz' => 3));
  183. $chain = $foo->chain($bar, '.');
  184. $res = $chain->match(new Zend_Controller_Router_ChainTest_Request('http://localhost/foo.bar'));
  185. $this->assertType('array', $res);
  186. $res = $chain->match(new Zend_Controller_Router_ChainTest_Request('http://localhost/foo/bar'));
  187. $this->assertEquals(false, $res);
  188. $chain->chain($baz, ':');
  189. $res = $chain->match(new Zend_Controller_Router_ChainTest_Request('http://localhost/foo.bar:baz'));
  190. $this->assertType('array', $res);
  191. }
  192. public function testI18nChaining()
  193. {
  194. $lang = new Zend_Controller_Router_Route(':lang', array('lang' => 'en'));
  195. $profile = new Zend_Controller_Router_Route('user/:id', array('controller' => 'foo', 'action' => 'bar'));
  196. $chain = $lang->chain($profile);
  197. $res = $chain->match(new Zend_Controller_Router_ChainTest_Request('http://localhost/en/user/1'));
  198. $this->assertEquals('en', $res['lang']);
  199. $this->assertEquals('1', $res['id']);
  200. }
  201. public function testChainingAssembleWithRoutePlaceholder()
  202. {
  203. $chain = new Zend_Controller_Router_Route_Chain();
  204. $foo = new Zend_Controller_Router_Route_Hostname(':account.zend.com');
  205. $bar = new Zend_Controller_Router_Route('bar/*');
  206. $chain->chain($foo)->chain($bar);
  207. $request = new Zend_Controller_Router_ChainTest_Request('http://foobar.zend.com/bar');
  208. $res = $chain->match($request);
  209. $this->assertType('array', $res);
  210. $this->assertRegexp('#[^a-z0-9]?foobar\.zend\.com/bar/foo/bar#i', $chain->assemble(array('account' => 'foobar', 'foo' => 'bar')));
  211. }
  212. public function testChainingAssembleWithStatic()
  213. {
  214. $chain = new Zend_Controller_Router_Route_Chain();
  215. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 'foo'));
  216. $bar = new Zend_Controller_Router_Route_Static('bar', array('bar' => 'bar'));
  217. $chain->chain($foo)->chain($bar);
  218. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bar');
  219. $res = $chain->match($request);
  220. $this->assertType('array', $res);
  221. $this->assertRegexp('#[^a-z0-9]?www\.zend\.com/bar$#i', $chain->assemble());
  222. }
  223. public function testChainingAssembleWithRegex()
  224. {
  225. $chain = new Zend_Controller_Router_Route_Chain();
  226. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 'foo'));
  227. $bar = new Zend_Controller_Router_Route_Regex('bar', array('bar' => 'bar'), array(), 'bar');
  228. $chain->chain($foo)->chain($bar);
  229. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/bar');
  230. $res = $chain->match($request);
  231. $this->assertType('array', $res);
  232. $this->assertRegexp('#[^a-z0-9]?www\.zend\.com/bar$#i', $chain->assemble());
  233. }
  234. public function testChainingReuse()
  235. {
  236. $foo = new Zend_Controller_Router_Route_Hostname('www.zend.com', array('foo' => 'foo'));
  237. $profile = new Zend_Controller_Router_Route('user/:id', array('controller' => 'prof'));
  238. $article = new Zend_Controller_Router_Route('article/:id', array('controller' => 'art', 'action' => 'art'));
  239. $profileChain = $foo->chain($profile);
  240. $articleChain = $foo->chain($article);
  241. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/user/1');
  242. $res = $profileChain->match($request);
  243. $this->assertType('array', $res);
  244. $this->assertEquals('prof', $res['controller']);
  245. $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/article/1');
  246. $res = $articleChain->match($request);
  247. $this->assertType('array', $res);
  248. $this->assertEquals('art', $res['controller']);
  249. $this->assertEquals('art', $res['action']);
  250. }
  251. public function testConfigChaining()
  252. {
  253. $routes = array(
  254. /** Abstract routes */
  255. 'www' => array(
  256. 'type' => 'Zend_Controller_Router_Route_Hostname',
  257. 'route' => 'www.example.com',
  258. 'abstract' => true
  259. ),
  260. 'user' => array(
  261. 'type' => 'Zend_Controller_Router_Route_Hostname',
  262. 'route' => 'user.example.com',
  263. 'abstract' => true
  264. ),
  265. 'index' => array(
  266. 'type' => 'Zend_Controller_Router_Route_Static',
  267. 'route' => '',
  268. 'abstract' => true,
  269. 'defaults' => array(
  270. 'module' => 'default',
  271. 'controller' => 'index',
  272. 'action' => 'index'
  273. )
  274. ),
  275. 'imprint' => array(
  276. 'type' => 'Zend_Controller_Router_Route_Static',
  277. 'route' => 'imprint',
  278. 'abstract' => true,
  279. 'defaults' => array(
  280. 'module' => 'default',
  281. 'controller' => 'index',
  282. 'action' => 'imprint'
  283. )
  284. ),
  285. 'profile' => array(
  286. 'type' => 'Zend_Controller_Router_Route_Static',
  287. 'route' => 'profile',
  288. 'abstract' => true,
  289. 'defaults' => array(
  290. 'module' => 'user',
  291. 'controller' => 'profile',
  292. 'action' => 'index'
  293. )
  294. ),
  295. 'profile-edit' => array(
  296. 'type' => 'Zend_Controller_Router_Route_Static',
  297. 'route' => 'profile/edit',
  298. 'abstract' => true,
  299. 'defaults' => array(
  300. 'module' => 'user',
  301. 'controller' => 'profile',
  302. 'action' => 'edit'
  303. )
  304. ),
  305. /** Chains */
  306. 'www-index' => array(
  307. 'type' => 'Zend_Controller_Router_Route_Chain',
  308. 'chain' => 'www, index' // or array('www-subdomain', 'index'); / maybe both
  309. ),
  310. 'www-imprint' => array(
  311. 'type' => 'Zend_Controller_Router_Route_Chain',
  312. 'chain' => 'www, imprint'
  313. ),
  314. 'user-index' => array(
  315. 'type' => 'Zend_Controller_Router_Route_Chain',
  316. 'chain' => 'user, index'
  317. ),
  318. 'user-profile' => array(
  319. 'type' => 'Zend_Controller_Router_Route_Chain',
  320. 'chain' => 'user, profile'
  321. ),
  322. 'user-profile-edit' => array(
  323. 'type' => 'Zend_Controller_Router_Route_Chain',
  324. 'chain' => 'user, profile-edit'
  325. )
  326. );
  327. $router = new Zend_Controller_Router_Rewrite();
  328. $front = Zend_Controller_Front::getInstance();
  329. $front->resetInstance();
  330. $front->setDispatcher(new Zend_Controller_Router_RewriteTest_Dispatcher());
  331. $front->setRequest(new Zend_Controller_Router_RewriteTest_Request());
  332. $router->setFrontController($front);
  333. $router->addConfig(new Zend_Config($routes));
  334. $request = new Zend_Controller_Router_ChainTest_Request('http://user.example.com/profile');
  335. $token = $router->route($request);
  336. $this->assertEquals('user', $token->getModuleName());
  337. $this->assertEquals('profile', $token->getControllerName());
  338. $this->assertEquals('index', $token->getActionName());
  339. $request = new Zend_Controller_Router_ChainTest_Request('http://foo.example.com/imprint');
  340. $token = $router->route($request);
  341. $this->assertEquals('default', $token->getModuleName());
  342. $this->assertEquals('imprint', $token->getControllerName());
  343. $this->assertEquals('defact', $token->getActionName());
  344. }
  345. public function testConfigChainingAlternative()
  346. {
  347. $routes = array(
  348. 'www' => array(
  349. 'type' => 'Zend_Controller_Router_Route_Hostname',
  350. 'route' => 'www.example.com',
  351. 'chains' => array(
  352. 'index' => array(
  353. 'type' => 'Zend_Controller_Router_Route_Static',
  354. 'route' => '',
  355. 'defaults' => array(
  356. 'module' => 'default',
  357. 'controller' => 'index',
  358. 'action' => 'index'
  359. )
  360. ),
  361. 'imprint' => array(
  362. 'type' => 'Zend_Controller_Router_Route_Static',
  363. 'route' => 'imprint',
  364. 'defaults' => array(
  365. 'module' => 'default',
  366. 'controller' => 'index',
  367. 'action' => 'imprint'
  368. )
  369. ),
  370. )
  371. ),
  372. 'user' => array(
  373. 'type' => 'Zend_Controller_Router_Route_Hostname',
  374. 'route' => 'user.example.com',
  375. 'chains' => array(
  376. 'profile' => array(
  377. 'type' => 'Zend_Controller_Router_Route_Static',
  378. 'route' => 'profile',
  379. 'defaults' => array(
  380. 'module' => 'user',
  381. 'controller' => 'profile',
  382. 'action' => 'index'
  383. ),
  384. 'chains' => array(
  385. 'standard' => array(
  386. 'type' => 'Zend_Controller_Router_Route_Static',
  387. 'route' => 'standard2',
  388. 'defaults' => array(
  389. 'mode' => 'standard'
  390. )
  391. ),
  392. 'detail' => array(
  393. 'type' => 'Zend_Controller_Router_Route_Static',
  394. 'route' => 'detail',
  395. 'defaults' => array(
  396. 'mode' => 'detail'
  397. )
  398. )
  399. )
  400. ),
  401. 'profile-edit' => array(
  402. 'type' => 'Zend_Controller_Router_Route_Static',
  403. 'route' => 'profile/edit',
  404. 'defaults' => array(
  405. 'module' => 'user',
  406. 'controller' => 'profile',
  407. 'action' => 'edit'
  408. )
  409. ),
  410. )
  411. ),
  412. );
  413. $router = $this->_getRouter();
  414. $router->addConfig(new Zend_Config($routes));
  415. $request = new Zend_Controller_Router_ChainTest_Request('http://user.example.com/profile/edit');
  416. $token = $router->route($request);
  417. $this->assertEquals('user', $token->getModuleName());
  418. $this->assertEquals('profile', $token->getControllerName());
  419. $this->assertEquals('edit', $token->getActionName());
  420. $request = new Zend_Controller_Router_ChainTest_Request('http://user.example.com/profile/detail');
  421. $token = $router->route($request);
  422. $this->assertEquals('user', $token->getModuleName());
  423. $this->assertEquals('profile', $token->getControllerName());
  424. $this->assertEquals('index', $token->getActionName());
  425. $this->assertEquals('detail', $token->getParam('mode'));
  426. $request = new Zend_Controller_Router_ChainTest_Request('http://user.example.com/profile');
  427. $token = $router->route($request);
  428. }
  429. public function testConfigChainingMixed()
  430. {
  431. $routes = array(
  432. 'index' => array(
  433. 'type' => 'Zend_Controller_Router_Route_Static',
  434. 'route' => '',
  435. 'defaults' => array(
  436. 'module' => 'default',
  437. 'controller' => 'index',
  438. 'action' => 'index'
  439. )
  440. ),
  441. 'www' => array(
  442. 'type' => 'Zend_Controller_Router_Route_Hostname',
  443. 'route' => 'www.example.com',
  444. 'chains' => array(
  445. 'index',
  446. 'imprint' => array(
  447. 'type' => 'Zend_Controller_Router_Route_Static',
  448. 'route' => 'imprint',
  449. 'defaults' => array(
  450. 'module' => 'default',
  451. 'controller' => 'index',
  452. 'action' => 'imprint'
  453. )
  454. ),
  455. )
  456. ),
  457. 'user' => array(
  458. 'type' => 'Zend_Controller_Router_Route_Hostname',
  459. 'route' => 'user.example.com',
  460. 'chains' => array(
  461. 'index',
  462. 'profile' => array(
  463. 'type' => 'Zend_Controller_Router_Route_Static',
  464. 'route' => 'profile',
  465. 'defaults' => array(
  466. 'module' => 'user',
  467. 'controller' => 'profile',
  468. 'action' => 'index'
  469. )
  470. ),
  471. 'profile-edit' => array(
  472. 'type' => 'Zend_Controller_Router_Route_Static',
  473. 'route' => 'profile/edit',
  474. 'defaults' => array(
  475. 'module' => 'user',
  476. 'controller' => 'profile',
  477. 'action' => 'edit'
  478. )
  479. ),
  480. )
  481. ),
  482. );
  483. $router = $this->_getRouter();
  484. $router->addConfig(new Zend_Config($routes));
  485. $request = new Zend_Controller_Router_ChainTest_Request('http://user.example.com');
  486. $token = $router->route($request);
  487. $this->assertEquals('default', $token->getModuleName());
  488. $this->assertEquals('index', $token->getControllerName());
  489. $this->assertEquals('index', $token->getActionName());
  490. $this->assertType('Zend_Controller_Router_Route_Chain', $router->getRoute('user-profile'));
  491. $this->assertType('Zend_Controller_Router_Route_Chain', $router->getRoute('www-imprint'));
  492. $this->assertType('Zend_Controller_Router_Route_Chain', $router->getRoute('www-index'));
  493. $this->assertType('Zend_Controller_Router_Route_Chain', $router->getRoute('www-index'));
  494. }
  495. protected function _getRouter()
  496. {
  497. $router = new Zend_Controller_Router_Rewrite();
  498. $front = Zend_Controller_Front::getInstance();
  499. $front->resetInstance();
  500. $front->setRequest(new Zend_Controller_Router_ChainTest_Request());
  501. $router->setFrontController($front);
  502. return $router;
  503. }
  504. }
  505. /**
  506. * Zend_Controller_Router_ChainTest_Request - request object for router testing
  507. *
  508. * @uses Zend_Controller_Request_Interface
  509. */
  510. class Zend_Controller_Router_ChainTest_Request extends Zend_Controller_Request_Http
  511. {
  512. protected $_host;
  513. protected $_port;
  514. public function __construct($uri = null)
  515. {
  516. if (null === $uri) {
  517. $uri = 'http://localhost/foo/bar/baz/2';
  518. }
  519. $uri = Zend_Uri_Http::fromString($uri);
  520. $this->_host = $uri->getHost();
  521. $this->_port = $uri->getPort();
  522. parent::__construct($uri);
  523. }
  524. public function getHttpHost() {
  525. $return = $this->_host;
  526. if ($this->_port) $return .= ':' . $this->_port;
  527. return $return;
  528. }
  529. }
  530. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Router_Route_ChainTest::main") {
  531. Zend_Controller_Router_Route_ChainTest::main();
  532. }