Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Route/RouterTest.php52
-rw-r--r--tests/lib/UrlGeneratorTest.php29
2 files changed, 79 insertions, 2 deletions
diff --git a/tests/lib/Route/RouterTest.php b/tests/lib/Route/RouterTest.php
new file mode 100644
index 00000000000..4fcd9d65cd1
--- /dev/null
+++ b/tests/lib/Route/RouterTest.php
@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Route;
+
+use OC\Route\Router;
+use OCP\ILogger;
+use Test\TestCase;
+
+/**
+ * Class RouterTest
+ *
+ * @package Test\Route
+ */
+class RouterTest extends TestCase {
+ public function testGenerateConsecutively(): void {
+ /** @var ILogger $logger */
+ $logger = $this->createMock(ILogger::class);
+ $router = new Router($logger);
+
+ $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
+
+ // the OCS route is the prefixed one for the AppFramework - see /ocs/v1.php for routing details
+ $this->assertEquals('/index.php/ocsapp/apps/dav/api/v1/direct', $router->generate('ocs.dav.direct.getUrl'));
+
+ // special route name - should load all apps and then find the route
+ $this->assertEquals('/index.php/apps/files/ajax/list.php', $router->generate('files_ajax_list'));
+
+ // test caching
+ $this->assertEquals('/index.php/apps/files/', $router->generate('files.view.index'));
+ }
+}
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 46508a217d8..b5db39dbf39 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -12,9 +12,12 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\Route\IRouter;
/**
* Class UrlGeneratorTest
+ *
+ * @package Test
*/
class UrlGeneratorTest extends \Test\TestCase {
@@ -24,6 +27,8 @@ class UrlGeneratorTest extends \Test\TestCase {
private $cacheFactory;
/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */
private $request;
+ /** @var \PHPUnit\Framework\MockObject\MockObject|IRouter */
+ private $router;
/** @var IURLGenerator */
private $urlGenerator;
/** @var string */
@@ -34,10 +39,12 @@ class UrlGeneratorTest extends \Test\TestCase {
$this->config = $this->createMock(IConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->request = $this->createMock(IRequest::class);
+ $this->router = $this->createMock(IRouter::class);
$this->urlGenerator = new \OC\URLGenerator(
$this->config,
$this->cacheFactory,
- $this->request
+ $this->request,
+ $this->router
);
$this->originalWebRoot = \OC::$WEBROOT;
}
@@ -84,14 +91,23 @@ class UrlGeneratorTest extends \Test\TestCase {
public function testLinkToRouteAbsolute($route, $expected) {
$this->mockBaseUrl();
\OC::$WEBROOT = '/nextcloud';
+ $this->router->expects($this->once())
+ ->method('generate')
+ ->willReturnCallback(function ($routeName, $parameters) {
+ if ($routeName === 'core.Preview.getPreview') {
+ return '/index.php/core/preview.png';
+ } elseif ($routeName === 'cloud_federation_api.requesthandlercontroller.addShare') {
+ return '/index.php/ocm/shares';
+ }
+ });
$result = $this->urlGenerator->linkToRouteAbsolute($route);
$this->assertEquals($expected, $result);
}
public function provideRoutes() {
return [
- ['files_ajax_list', 'http://localhost/nextcloud/index.php/apps/files/ajax/list.php'],
['core.Preview.getPreview', 'http://localhost/nextcloud/index.php/core/preview.png'],
+ ['cloud_federation_api.requesthandlercontroller.addShare', 'http://localhost/nextcloud/index.php/ocm/shares'],
];
}
@@ -169,6 +185,15 @@ class UrlGeneratorTest extends \Test\TestCase {
public function testLinkToOCSRouteAbsolute(string $route, string $expected) {
$this->mockBaseUrl();
\OC::$WEBROOT = '/nextcloud';
+ $this->router->expects($this->once())
+ ->method('generate')
+ ->willReturnCallback(function ($routeName, $parameters) {
+ if ($routeName === 'ocs.core.OCS.getCapabilities') {
+ return '/index.php/ocsapp/cloud/capabilities';
+ } elseif ($routeName === 'ocs.core.WhatsNew.dismiss') {
+ return '/index.php/ocsapp/core/whatsnew';
+ }
+ });
$result = $this->urlGenerator->linkToOCSRouteAbsolute($route);
$this->assertEquals($expected, $result);
}