PluginShortRouteTest.php 2.2 KB

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