Merge pull request #11622 from nextcloud/feature/11617

Add function to generate urls for OCS routes
This commit is contained in:
Roeland Jago Douma 2018-10-09 20:50:37 +02:00 committed by GitHub
commit a9f4817b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -91,6 +91,19 @@ class URLGenerator implements IURLGenerator {
return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
}
public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string {
$route = \OC::$server->getRouter()->generate('ocs.'.$routeName, $arguments, false);
if (strpos($route, '/index.php') === 0) {
$route = substr($route, 10);
}
$route = substr($route, 7);
$route = '/ocs/v2.php' . $route;
return $this->getAbsoluteURL($route);
}
/**
* Creates an url
* @param string $app app

View File

@ -50,6 +50,14 @@ interface IURLGenerator {
*/
public function linkToRouteAbsolute(string $routeName, array $arguments = array()): string;
/**
* @param string $routeName
* @param array $arguments
* @return string
* @since 15.0.0
*/
public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string;
/**
* Returns an URL for an image or file
* @param string $appName the name of the app

View File

@ -162,4 +162,22 @@ class UrlGeneratorTest extends \Test\TestCase {
$this->assertEquals($expected, $actual);
}
/**
* @dataProvider provideOCSRoutes
*/
public function testLinkToOCSRouteAbsolute(string $route, string $expected) {
$this->mockBaseUrl();
\OC::$WEBROOT = '/nextcloud';
$result = $this->urlGenerator->linkToOCSRouteAbsolute($route);
$this->assertEquals($expected, $result);
}
public function provideOCSRoutes() {
return [
['core.OCS.getCapabilities', 'http://localhost/nextcloud/ocs/v2.php/cloud/capabilities'],
['core.WhatsNew.dismiss', 'http://localhost/nextcloud/ocs/v2.php/core/whatsnew'],
];
}
}