diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-09-17 13:05:26 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-09-17 13:05:26 +0200 |
commit | b644e8a5e7f3dfb63bbc40ebda437719aed0ba46 (patch) | |
tree | be40807fc1b7756733ee644eff9bdca73e47c9d2 | |
parent | 0d37e16499fd0bda83d4c41dfba626b3d9a489f5 (diff) | |
parent | 3ad9489634186a13f43d40998af7b5dee1ef6c44 (diff) | |
download | nextcloud-server-b644e8a5e7f3dfb63bbc40ebda437719aed0ba46.tar.gz nextcloud-server-b644e8a5e7f3dfb63bbc40ebda437719aed0ba46.zip |
Merge pull request #10932 from owncloud/issue/10926
Add a method to get the absolute url for a route
-rw-r--r-- | lib/private/urlgenerator.php | 15 | ||||
-rw-r--r-- | lib/public/iurlgenerator.php | 8 | ||||
-rw-r--r-- | tests/lib/urlgenerator.php | 19 |
3 files changed, 41 insertions, 1 deletions
diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index af5d977eeab..f5ec9803edb 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -35,7 +35,7 @@ class URLGenerator implements IURLGenerator { * @internal param array $args with param=>value, will be appended to the returned url * @return string the url * - * Returns a url to the given app and file. + * Returns a url to the given route. */ public function linkToRoute($route, $parameters = array()) { $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters); @@ -43,6 +43,19 @@ class URLGenerator implements IURLGenerator { } /** + * Creates an absolute url using a defined route + * @param string $route + * @param array $parameters + * @internal param array $args with param=>value, will be appended to the returned url + * @return string the url + * + * Returns an absolute url to the given route. + */ + public function linkToRouteAbsolute($routeName, $arguments = array()) { + return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments)); + } + + /** * Creates an url * @param string $app app * @param string $file file diff --git a/lib/public/iurlgenerator.php b/lib/public/iurlgenerator.php index afdf1b6f299..dbbd8a3bb63 100644 --- a/lib/public/iurlgenerator.php +++ b/lib/public/iurlgenerator.php @@ -43,6 +43,14 @@ interface IURLGenerator { public function linkToRoute($routeName, $arguments = array()); /** + * Returns the absolute URL for a route + * @param string $routeName the name of the route + * @param array $arguments an array with arguments which will be filled into the url + * @return string the absolute url + */ + public function linkToRouteAbsolute($routeName, $arguments = array()); + + /** * Returns an URL for an image or file * @param string $appName the name of the app * @param string $file the name of the file diff --git a/tests/lib/urlgenerator.php b/tests/lib/urlgenerator.php index 888512ee426..066272731ee 100644 --- a/tests/lib/urlgenerator.php +++ b/tests/lib/urlgenerator.php @@ -36,6 +36,25 @@ class Test_Urlgenerator extends PHPUnit_Framework_TestCase { $this->assertEquals($expectedResult, $result); } + /** + * @dataProvider provideRoutes + */ + public function testLinkToRouteAbsolute($route, $expected) { + \OC::$WEBROOT = '/owncloud'; + $config = $this->getMock('\OCP\IConfig'); + $urlGenerator = new \OC\URLGenerator($config); + $result = $urlGenerator->linkToRouteAbsolute($route); + $this->assertEquals($expected, $result); + + } + + public function provideRoutes() { + return array( + array('files_index', 'http://localhost/owncloud/index.php/apps/files/'), + array('core_ajax_preview', 'http://localhost/owncloud/index.php/core/preview.png'), + ); + } + public function provideDocRootAppUrlParts() { return array( array('files', 'index.php', array(), '/index.php/apps/files'), |