PluginShortRouteTest.php 2.2 KB

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