diff options
author | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-05 11:02:21 +0200 |
---|---|---|
committer | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-05 13:55:35 +0200 |
commit | a1d6189dfa11e006a130bdd1c35200c1ef21c501 (patch) | |
tree | 97ace89cac62d0daaef335fcc3fd3d10e6b3bd89 | |
parent | 4d7430949a5e6f6beba18a9b309dbc9d0d0a9a42 (diff) | |
download | nextcloud-server-a1d6189dfa11e006a130bdd1c35200c1ef21c501.tar.gz nextcloud-server-a1d6189dfa11e006a130bdd1c35200c1ef21c501.zip |
Fix UrlGeneratorTest
And again... :unamused:
Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
-rw-r--r-- | lib/private/URLGenerator.php | 9 | ||||
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 28 |
2 files changed, 11 insertions, 26 deletions
diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 7c97a76e257..1bb5610d95f 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -42,7 +42,6 @@ namespace OC; use OC\Route\Router; use OCA\Theming\ThemingDefaults; -use OCP\App\IAppManager; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; @@ -58,8 +57,6 @@ class URLGenerator implements IURLGenerator { private $config; /** @var IUserSession */ public $userSession; - /** @var IAppManager */ - public $appManager; /** @var ICacheFactory */ private $cacheFactory; /** @var IRequest */ @@ -71,13 +68,11 @@ class URLGenerator implements IURLGenerator { public function __construct(IConfig $config, IUserSession $userSession, - IAppManager $appManager, ICacheFactory $cacheFactory, IRequest $request, Router $router) { $this->config = $config; $this->userSession = $userSession; - $this->appManager = $appManager; $this->cacheFactory = $cacheFactory; $this->request = $request; $this->router = $router; @@ -290,7 +285,7 @@ class URLGenerator implements IURLGenerator { return $this->getAbsoluteURL(urldecode($_REQUEST['redirect_url'])); } - $defaultPage = \OC::$server->getConfig()->getAppValue('core', 'defaultpage'); + $defaultPage = $this->config->getAppValue('core', 'defaultpage'); if ($defaultPage) { return $this->getAbsoluteURL($defaultPage); } @@ -307,7 +302,7 @@ class URLGenerator implements IURLGenerator { // find the first app that is enabled for the current user foreach ($defaultApps as $defaultApp) { $defaultApp = \OC_App::cleanAppId(strip_tags($defaultApp)); - if ($this->appManager->isEnabledForUser($defaultApp)) { + if (\OC::$server->getAppManager()->isEnabledForUser($defaultApp)) { $appId = $defaultApp; break; } diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 27f08c42f36..259cf81164d 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -9,7 +9,6 @@ namespace Test; use OC\Route\Router; -use OCP\App\IAppManager; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; @@ -28,8 +27,6 @@ class UrlGeneratorTest extends \Test\TestCase { private $config; /** @var \PHPUnit\Framework\MockObject\MockObject|IUserSession */ private $userSession; - /** @var \PHPUnit\Framework\MockObject\MockObject|IAppManager */ - private $appManager; /** @var \PHPUnit\Framework\MockObject\MockObject|ICacheFactory */ private $cacheFactory; /** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */ @@ -45,14 +42,12 @@ class UrlGeneratorTest extends \Test\TestCase { parent::setUp(); $this->config = $this->createMock(IConfig::class); $this->userSession = $this->createMock(IUserSession::class); - $this->appManager = $this->createMock(IAppManager::class); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->request = $this->createMock(IRequest::class); $this->router = $this->createMock(Router::class); $this->urlGenerator = new \OC\URLGenerator( $this->config, $this->userSession, - $this->appManager, $this->cacheFactory, $this->request, $this->router @@ -227,6 +222,10 @@ class UrlGeneratorTest extends \Test\TestCase { $defaultAppConfig, $ignoreFrontControllerConfig )); + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('core', 'defaultpage') + ->willReturn(''); } public function testLinkToDefaultPageUrlWithRedirectUrlWithoutFrontController() { @@ -266,7 +265,7 @@ class UrlGeneratorTest extends \Test\TestCase { /** * @dataProvider provideDefaultApps */ - public function testLinkToDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { + public function testLinkToDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath) { $userId = $this->getUniqueID(); /** @var \PHPUnit\Framework\MockObject\MockObject|IUser $userMock */ @@ -288,11 +287,6 @@ class UrlGeneratorTest extends \Test\TestCase { $this->userSession->expects($this->once()) ->method('getUser') ->willReturn($userMock); - $this->appManager->expects($this->any()) - ->method('isEnabledForUser') - ->willReturnCallback(function ($appId) use ($enabledApps) { - return in_array($appId, $enabledApps); - }); $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl()); } @@ -303,25 +297,21 @@ class UrlGeneratorTest extends \Test\TestCase { [ '', '/index.php/apps/files/', - ['files'], ], // unexisting or inaccessible app specified, default to files [ 'unexist', '/index.php/apps/files/', - ['files'], ], // non-standard app [ - 'calendar', - '/index.php/apps/calendar/', - ['files', 'calendar'], + 'settings', + '/index.php/apps/settings/', ], // non-standard app with fallback [ - 'contacts,calendar', - '/index.php/apps/calendar/', - ['files', 'calendar'], + 'unexist,settings', + '/index.php/apps/settings/', ], ]; } |