PluginShortRouteTest.php 2.1 KB

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