1
0

RouterTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\Route;
  23. use OC\Route\Router;
  24. use OCP\Diagnostics\IEventLogger;
  25. use OCP\IConfig;
  26. use OCP\IRequest;
  27. use Psr\Container\ContainerInterface;
  28. use Psr\Log\LoggerInterface;
  29. use Test\TestCase;
  30. /**
  31. * Class RouterTest
  32. *
  33. * @group RoutingWeirdness
  34. *
  35. * @package Test\Route
  36. */
  37. class RouterTest extends TestCase {
  38. private Router $router;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. /** @var LoggerInterface $logger */
  42. $logger = $this->createMock(LoggerInterface::class);
  43. $logger->method('info')
  44. ->willReturnCallback(
  45. function (string $message, array $data) {
  46. $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
  47. }
  48. );
  49. $this->router = new Router(
  50. $logger,
  51. $this->createMock(IRequest::class),
  52. $this->createMock(IConfig::class),
  53. $this->createMock(IEventLogger::class),
  54. $this->createMock(ContainerInterface::class),
  55. );
  56. }
  57. /**
  58. * @runInSeparateProcess
  59. * @preserveGlobalState disabled
  60. */
  61. public function testHeartbeat(): void {
  62. $this->assertEquals('/index.php/heartbeat', $this->router->generate('heartbeat'));
  63. }
  64. /**
  65. * @runInSeparateProcess
  66. * @preserveGlobalState disabled
  67. */
  68. public function testGenerateConsecutively(): void {
  69. $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
  70. // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
  71. $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $this->router->generate('ocs.dav.direct.getUrl'));
  72. // test caching
  73. $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
  74. }
  75. }