allow overwriting the appmanager in oc_util by subclassing

This commit is contained in:
Robin Appelman 2015-02-18 14:24:50 +01:00
parent e672f8cc8f
commit 5542fafd36
2 changed files with 32 additions and 27 deletions

View File

@ -11,6 +11,10 @@ class OC_Util {
private static $rootMounted = false;
private static $fsSetup = false;
protected static function getAppManager() {
return \OC::$server->getAppManager();
}
private static function initLocalStorageRootFS() {
// mount local file backend as root
$configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
@ -926,7 +930,7 @@ class OC_Util {
// find the first app that is enabled for the current user
foreach ($defaultApps as $defaultApp) {
$defaultApp = OC_App::cleanAppId(strip_tags($defaultApp));
if (OC_App::isEnabled($defaultApp)) {
if (static::getAppManager()->isEnabledForUser($defaultApp)) {
$appId = $defaultApp;
break;
}

View File

@ -1,11 +1,11 @@
<?php
/**
* Copyright (c) 2012 Lukas Reschke <lukas@statuscode.ch>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class Test_Util extends \Test\TestCase {
public function testGetVersion() {
$version = \OC_Util::getVersion();
@ -210,14 +210,12 @@ class Test_Util extends \Test\TestCase {
/**
* @dataProvider baseNameProvider
*/
public function testBaseName($expected, $file)
{
public function testBaseName($expected, $file) {
$base = \OC_Util::basename($file);
$this->assertEquals($expected, $base);
}
public function baseNameProvider()
{
public function baseNameProvider() {
return array(
array('public_html', '/home/user/public_html/'),
array('public_html', '/home/user/public_html'),
@ -341,15 +339,21 @@ class Test_Util extends \Test\TestCase {
$oldWebRoot = \OC::$WEBROOT;
\OC::$WEBROOT = '';
Dummy_OC_App::setEnabledApps($enabledApps);
$appManager = $this->getMock('\OCP\App\IAppManager');
$appManager->expects($this->any())
->method('isEnabledForUser')
->will($this->returnCallback(function($appId) use ($enabledApps){
return in_array($appId, $enabledApps);
}));
Dummy_OC_Util::$appManager = $appManager;
// need to set a user id to make sure enabled apps are read from cache
\OC_User::setUserId($this->getUniqueID());
\OCP\Config::setSystemValue('defaultapp', $defaultAppConfig);
$this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl());
$this->assertEquals('http://localhost/' . $expectedPath, Dummy_OC_Util::getDefaultPageUrl());
// restore old state
\OC::$WEBROOT = $oldWebRoot;
Dummy_OC_App::restore();
\OCP\Config::setSystemValue('defaultapp', $oldDefaultApps);
\OC_User::setUserId(null);
}
@ -405,18 +409,15 @@ class Test_Util extends \Test\TestCase {
}
/**
* Dummy OC Apps class to make it possible to override
* enabled apps
* Dummy OC Util class to make it possible to override the app manager
*/
class Dummy_OC_App extends OC_App {
private static $enabledAppsCacheBackup;
class Dummy_OC_Util extends OC_Util {
/**
* @var \OCP\App\IAppManager
*/
public static $appManager;
public static function setEnabledApps($enabledApps) {
self::$enabledAppsCacheBackup = self::$enabledAppsCache;
self::$enabledAppsCache = $enabledApps;
}
public static function restore() {
self::$enabledAppsCache = self::$enabledAppsCacheBackup;
protected static function getAppManager() {
return self::$appManager;
}
}