RouterTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\App\IAppManager;
  25. use OCP\Diagnostics\IEventLogger;
  26. use OCP\IConfig;
  27. use OCP\IRequest;
  28. use Psr\Container\ContainerInterface;
  29. use Psr\Log\LoggerInterface;
  30. use Test\TestCase;
  31. /**
  32. * Class RouterTest
  33. *
  34. * @group RoutingWeirdness
  35. *
  36. * @package Test\Route
  37. */
  38. class RouterTest extends TestCase {
  39. public function testGenerateConsecutively(): void {
  40. /** @var LoggerInterface $logger */
  41. $logger = $this->createMock(LoggerInterface::class);
  42. $logger->method('info')
  43. ->willReturnCallback(
  44. function (string $message, array $data) {
  45. $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
  46. }
  47. );
  48. $router = new Router(
  49. $logger,
  50. $this->createMock(IRequest::class),
  51. $this->createMock(IConfig::class),
  52. $this->createMock(IEventLogger::class),
  53. $this->createMock(ContainerInterface::class),
  54. $this->createMock(IAppManager::class),
  55. );
  56. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  57. // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
  58. $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl'));
  59. // test caching
  60. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  61. }
  62. }