PluginShortRouteTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * CakeRequest Test case file.
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Routing.Route
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('PluginShortRoute', 'Routing/Route');
  20. App::uses('Router', 'Routing');
  21. /**
  22. * test case for PluginShortRoute
  23. *
  24. * @package Cake.Test.Case.Routing.Route
  25. */
  26. class PluginShortRouteTest extends CakeTestCase {
  27. /**
  28. * setUp method
  29. *
  30. * @return void
  31. */
  32. public function setUp() {
  33. parent::setUp();
  34. Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
  35. Router::reload();
  36. }
  37. /**
  38. * test the parsing of routes.
  39. *
  40. * @return void
  41. */
  42. public function testParsing() {
  43. $route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
  44. $result = $route->parse('/foo');
  45. $this->assertEquals('foo', $result['plugin']);
  46. $this->assertEquals('foo', $result['controller']);
  47. $this->assertEquals('index', $result['action']);
  48. $result = $route->parse('/wrong');
  49. $this->assertFalse($result, 'Wrong plugin name matched %s');
  50. }
  51. /**
  52. * test the reverse routing of the plugin shortcut urls.
  53. *
  54. * @return void
  55. */
  56. public function testMatch() {
  57. $route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
  58. $result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index'));
  59. $this->assertFalse($result, 'plugin controller mismatch was converted. %s');
  60. $result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index'));
  61. $this->assertEquals('/foo', $result);
  62. }
  63. }