diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-08-11 22:28:29 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-08-19 22:00:47 +0200 |
commit | 387cac4c5fb9c797a94b8312778cd503cc951dda (patch) | |
tree | 7c391f107f498100b2fb16d182ff069dfe44f2b8 /tests/lib/UrlGeneratorTest.php | |
parent | 053ee7b3860c352004bede82d040b4bd34ecb072 (diff) | |
download | nextcloud-server-387cac4c5fb9c797a94b8312778cd503cc951dda.tar.gz nextcloud-server-387cac4c5fb9c797a94b8312778cd503cc951dda.zip |
Properly inject IRouter into URLGenerator to properly encapsulate tests
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'tests/lib/UrlGeneratorTest.php')
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 25 |
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); } |