PluginShortRouteTest.php 2.1 KB

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