RouterTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. public function testGenerateConsecutively(): void {
  39. /** @var LoggerInterface $logger */
  40. $logger = $this->createMock(LoggerInterface::class);
  41. $logger->method('info')
  42. ->willReturnCallback(
  43. function (string $message, array $data) {
  44. $this->fail('Unexpected info log: '.(string)($data['exception'] ?? $message));
  45. }
  46. );
  47. $router = new Router(
  48. $logger,
  49. $this->createMock(IRequest::class),
  50. $this->createMock(IConfig::class),
  51. $this->createMock(IEventLogger::class),
  52. $this->createMock(ContainerInterface::class),
  53. );
  54. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  55. // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
  56. $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl'));
  57. // test caching
  58. $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
  59. }
  60. }