PluginShortRouteTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * setUp method
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. Configure::write('Routing', array('admin' => null, 'prefixes' => array()));
  34. Router::reload();
  35. }
  36. /**
  37. * test the parsing of routes.
  38. *
  39. * @return void
  40. */
  41. public function testParsing() {
  42. $route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
  43. $result = $route->parse('/foo');
  44. $this->assertEquals('Foo', $result['plugin']);
  45. $this->assertEquals('Foo', $result['controller']);
  46. $this->assertEquals('index', $result['action']);
  47. $result = $route->parse('/wrong');
  48. $this->assertFalse($result, 'Wrong plugin name matched %s');
  49. }
  50. /**
  51. * test the reverse routing of the plugin shortcut URLs.
  52. *
  53. * @return void
  54. */
  55. public function testMatch() {
  56. $route = new PluginShortRoute('/:plugin', array('action' => 'index'), array('plugin' => 'foo|bar'));
  57. $result = $route->match(array('plugin' => 'foo', 'controller' => 'posts', 'action' => 'index'));
  58. $this->assertFalse($result, 'plugin controller mismatch was converted. %s');
  59. $result = $route->match(array('plugin' => 'foo', 'controller' => 'foo', 'action' => 'index'));
  60. $this->assertEquals('/foo', $result);
  61. }
  62. }