|
| 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 | + |
| 23 | +namespace Test\Route; |
| 24 | + |
| 25 | +use OC\Route\Router; |
| 26 | +use OCP\ILogger; |
| 27 | +use Test\TestCase; |
| 28 | + |
| 29 | +/** |
| 30 | + * Class RouterTest |
| 31 | + * |
| 32 | + * @package Test\Route |
| 33 | + */ |
| 34 | +class RouterTest extends TestCase { |
| 35 | + public function generateRouteProvider(): array { |
| 36 | + return [ |
| 37 | + ['files.view.index', '/index.php/apps/files/'], |
| 38 | + // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details |
| 39 | + ['ocs.dav.direct.getUrl', '/index.php/ocsapp/apps/dav/api/v1/direct'], |
| 40 | + // special route name - should load all apps and then find the route |
| 41 | + ['files_ajax_list', '/index.php/apps/files/ajax/list.php'], |
| 42 | + ]; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @dataProvider generateRouteProvider |
| 47 | + * @param $routeName |
| 48 | + * @param $expected |
| 49 | + */ |
| 50 | + public function testGenerate($routeName, $expected): void { |
| 51 | + /** @var ILogger $logger */ |
| 52 | + $logger = $this->createMock(ILogger::class); |
| 53 | + $router = new Router($logger); |
| 54 | + |
| 55 | + $this->assertEquals($expected, $router->generate($routeName)); |
| 56 | + } |
| 57 | + |
| 58 | + public function testGenerateTwice(): void { |
| 59 | + /** @var ILogger $logger */ |
| 60 | + $logger = $this->createMock(ILogger::class); |
| 61 | + $router = new Router($logger); |
| 62 | + |
| 63 | + $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index')); |
| 64 | + $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl')); |
| 65 | + $this->assertEquals('/index.php/apps/files/ajax/list.php', $router->generate('files_ajax_list')); |
| 66 | + $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index')); |
| 67 | + } |
| 68 | +} |
0 commit comments