RouterTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public function testGenerateConsecutively(): void {
  25. /** @var LoggerInterface $logger */
  26. $logger = $this->createMock(LoggerInterface::class);
  27. $logger->method('info')
  28. ->willReturnCallback(
  29. function (string $message, array $data) {
  30. $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
  31. }
  32. );
  33. $router = new Router(
  34. $logger,
  35. $this->createMock(IRequest::class),
  36. $this->createMock(IConfig::class),
  37. $this->createMock(IEventLogger::class),
  38. $this->createMock(ContainerInterface::class),
  39. $this->createMock(IAppManager::class),
  40. );
  41. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  42. // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
  43. $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl'));
  44. // test caching
  45. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  46. }
  47. }