Skip to content

Commit a295092

Browse files
committed
fixup! fixup! Add function to generate urls for OCS routes
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 756c220 commit a295092

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/private/URLGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public function linkToRouteAbsolute(string $routeName, array $arguments = array(
9292
}
9393

9494
public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string {
95-
$route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments);
95+
$route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false);
96+
97+
if (strpos($route, '/index.php') === 0) {
98+
$route = substr($route, 10);
99+
}
100+
96101
$route = substr($route, 7);
97102
$route = '/ocs/v2.php' . $route;
98103

tests/lib/UrlGeneratorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,22 @@ public function testGetBaseUrl() {
162162
$this->assertEquals($expected, $actual);
163163
}
164164

165+
/**
166+
* @dataProvider provideOCSRoutes
167+
*/
168+
public function testLinkToOCSRouteAbsolute(string $route, string $expected) {
169+
$this->mockBaseUrl();
170+
\OC::$WEBROOT = '/owncloud';
171+
$result = $this->urlGenerator->linkToOCSRouteAbsolute($route);
172+
$this->assertEquals($expected, $result);
173+
}
174+
175+
public function provideOCSRoutes() {
176+
return [
177+
['core.OCS.getCapabilities', 'http://localhost/owncloud/ocs/v2.php/cloud/capabilities'],
178+
['core.WhatsNew.dismiss', 'http://localhost/owncloud/ocs/v2.php/core/whatsnew'],
179+
];
180+
}
181+
182+
165183
}

0 commit comments

Comments
 (0)