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:
authorMorris Jobke <hey@morrisjobke.de>2020-08-11 23:28:29 +0300
committerMorris Jobke <hey@morrisjobke.de>2020-08-19 23:00:47 +0300
commit387cac4c5fb9c797a94b8312778cd503cc951dda (patch)
tree7c391f107f498100b2fb16d182ff069dfe44f2b8 /tests
parent053ee7b3860c352004bede82d040b4bd34ecb072 (diff)
Properly inject IRouter into URLGenerator to properly encapsulate tests
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/UrlGeneratorTest.php25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php
index 5043dfb7a52..b5db39dbf39 100644
--- a/tests/lib/UrlGeneratorTest.php
+++ b/tests/lib/UrlGeneratorTest.php
@@ -12,6 +12,7 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\Route\IRouter;
/**
* Class UrlGeneratorTest
@@ -26,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 */
@@ -36,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;
}
@@ -86,6 +91,15 @@ 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);
}
@@ -171,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);
}