Fix UtilTest::testDefaultApps()

Oh wow... This definitly was no best practice... 😒

Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
pull/27733/head
Daniel Rudolf 5 years ago
parent a43de10d1e
commit e16bf707aa
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538
  1. 1
      lib/private/legacy/OC_Util.php
  2. 19
      tests/lib/UtilTest.php

@ -1089,6 +1089,7 @@ class OC_Util {
* @suppress PhanDeprecatedFunction
*/
public static function getDefaultPageUrl() {
/** @var IURLGenerator $urlGenerator */
$urlGenerator = \OC::$server->get(IURLGenerator::class);
return $urlGenerator->linkToDefaultPageUrl();
}

@ -187,15 +187,16 @@ class UtilTest extends \Test\TestCase {
->willReturnCallback(function ($appId) use ($enabledApps) {
return in_array($appId, $enabledApps);
});
Dummy_OC_Util::$appManager = $appManager;
$this->overwriteService(IAppManager::class, $appManager);
// need to set a user id to make sure enabled apps are read from cache
\OC_User::setUserId($this->getUniqueID());
\OC::$server->getConfig()->setSystemValue('defaultapp', $defaultAppConfig);
$this->assertEquals('http://localhost/' . $expectedPath, Dummy_OC_Util::getDefaultPageUrl());
$this->assertEquals('http://localhost/' . $expectedPath, OC_Util::getDefaultPageUrl());
// restore old state
\OC::$WEBROOT = $oldWebRoot;
$this->restoreService(IAppManager::class);
\OC::$server->getConfig()->setSystemValue('defaultapp', $oldDefaultApps);
\OC_User::setUserId(null);
}
@ -360,17 +361,3 @@ class UtilTest extends \Test\TestCase {
], \OC_Util::$styles);
}
}
/**
* Dummy OC Util class to make it possible to override the app manager
*/
class Dummy_OC_Util extends OC_Util {
/**
* @var \OCP\App\IAppManager
*/
public static $appManager;
protected static function getAppManager() {
return self::$appManager;
}
}

Loading…
Cancel
Save