RouterTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Route;
  8. use OC\Route\Router;
  9. use OCP\App\IAppManager;
  10. use OCP\Diagnostics\IEventLogger;
  11. use OCP\IConfig;
  12. use OCP\IRequest;
  13. use Psr\Container\ContainerInterface;
  14. use Psr\Log\LoggerInterface;
  15. use Test\TestCase;
  16. /**
  17. * Class RouterTest
  18. *
  19. * @group RoutingWeirdness
  20. *
  21. * @package Test\Route
  22. */
  23. class RouterTest extends TestCase {
  24. private Router $router;
  25. protected function setUp(): void {
  26. parent::setUp();
  27. /** @var LoggerInterface $logger */
  28. $logger = $this->createMock(LoggerInterface::class);
  29. $logger->method('info')
  30. ->willReturnCallback(
  31. function (string $message, array $data) {
  32. $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
  33. }
  34. );
  35. $this->router = new Router(
  36. $logger,
  37. $this->createMock(IRequest::class),
  38. $this->createMock(IConfig::class),
  39. $this->createMock(IEventLogger::class),
  40. $this->createMock(ContainerInterface::class),
  41. $this->createMock(IAppManager::class),
  42. );
  43. }
  44. public function testHeartbeat(): void {
  45. $this->assertEquals('/index.php/heartbeat', $this->router->generate('heartbeat'));
  46. }
  47. public function testGenerateConsecutively(): void {
  48. $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
  49. // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
  50. $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $this->router->generate('ocs.dav.direct.getUrl'));
  51. // test caching
  52. $this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));
  53. }
  54. }