diff options
-rw-r--r-- | config/config.sample.php | 72 | ||||
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/private/AppFramework/DependencyInjection/DIContainer.php | 19 | ||||
-rw-r--r-- | lib/private/L10N/Factory.php | 13 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/private/ServerContainer.php | 11 | ||||
-rw-r--r-- | lib/private/Template/CSSResourceLocator.php | 13 | ||||
-rw-r--r-- | lib/private/Template/JSResourceLocator.php | 8 | ||||
-rwxr-xr-x | lib/private/Template/ResourceLocator.php | 19 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 43 | ||||
-rw-r--r-- | tests/lib/L10N/FactoryTest.php | 8 | ||||
-rw-r--r-- | tests/lib/L10N/L10nTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Template/JSResourceLocatorTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Template/ResourceLocatorTest.php | 32 |
14 files changed, 130 insertions, 117 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index 80daf8909b9..a74f03b5cc7 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -140,7 +140,7 @@ $CONFIG = [ /** * Enable persistent connexions to the database. - * This setting uses the "persistent" option from doctrine dbal, wich in turns + * This setting uses the "persistent" option from doctrine dbal, which in turn * uses the PDO::ATTR_PERSISTENT option from de pdo driver. */ 'dbpersistent' => '', @@ -321,7 +321,7 @@ $CONFIG = [ 'auth.bruteforce.protection.enabled' => true, /** - * By default WebAuthn is available but it can be explicitly disabled by admins + * By default, WebAuthn is available, but it can be explicitly disabled by admins */ 'auth.webauthn.enabled' => true, @@ -336,16 +336,16 @@ $CONFIG = [ * passwords or when having a password policy enforcing long passwords (> 300 * characters). * - * By default the passwords are stored encrypted in the database. + * By default, the passwords are stored encrypted in the database. */ 'auth.storeCryptedPassword' => true, /** - * By default the login form is always available. There are cases (SSO) where an + * By default, the login form is always available. There are cases (SSO) where an * admin wants to avoid users entering their credentials to the system if the SSO * app is unavailable. * - * This will show an error. But the the direct login still works with adding ?direct=1 + * This will show an error. But the direct login still works with adding ?direct=1 */ 'hide_login_form' => false, @@ -438,7 +438,7 @@ $CONFIG = [ /** * This depends on ``mail_smtpmode``. Specify the IP address of your mail - * server host. This may contain multiple hosts separated by a semi-colon. If + * server host. This may contain multiple hosts separated by a semicolon. If * you need to specify the port number append it to the IP address separated by * a colon, like this: ``127.0.0.1:24``. * @@ -510,7 +510,7 @@ $CONFIG = [ 'mail_template_class' => '\OC\Mail\EMailTemplate', /** - * Email will be send by default with an HTML and a plain text body. This option + * Email will be sent by default with an HTML and a plain text body. This option * allows to only send plain text emails. */ 'mail_send_plaintext_only' => false, @@ -617,8 +617,8 @@ $CONFIG = [ * this parameter has to be set to true and will assume mod_rewrite. * * Please check, if `mod_rewrite` is active and functional before setting this - * parameter and you updated your .htaccess with `occ maintenance:update:htaccess`. - * Otherwise your nextcloud installation might not be reachable anymore. + * parameter, and you updated your .htaccess with `occ maintenance:update:htaccess`. + * Otherwise, your nextcloud installation might not be reachable anymore. * For example, try accessing resources by leaving out `index.php` in the URL. */ 'htaccess.IgnoreFrontController' => false, @@ -744,7 +744,7 @@ $CONFIG = [ * rules. Please refer to :doc:`../configuration_files/file_versioning` for * more information. * * ``D, auto`` - * keep versions at least for D days, apply expire rules to all versions + * keep versions at least for D days, apply expiration rules to all versions * that are older than D days * * ``auto, D`` * delete all versions that are older than D days automatically, delete @@ -853,7 +853,7 @@ $CONFIG = [ 'check_for_working_htaccess' => true, /** - * In rare setups (e.g. on Openshift or docker on windows) the permissions check + * In rare setups (e.g. on Openshift or Docker on Windows) the permissions check * might block the installation while the underlying system offers no means to * "correct" the permissions. In this case, set the value to false. * @@ -1029,7 +1029,7 @@ $CONFIG = [ /** * Alternate Code Locations * - * Some of the Nextcloud code may be stored in alternate locations. + * Some Nextcloud code may be stored in alternate locations. */ /** @@ -1064,7 +1064,7 @@ $CONFIG = [ 'appstoreenabled' => true, /** - * Enables the installation of apps from a self hosted apps store. + * Enables the installation of apps from a self-hosted apps store. * Requires that at least one of the configured apps directories is writeable. * * Defaults to ``https://apps.nextcloud.com/api/v1`` @@ -1392,9 +1392,9 @@ $CONFIG = [ 'port' => 6379, 'timeout' => 0.0, 'read_timeout' => 0.0, - 'user' => '', // Optional, if not defined no password will be used. - 'password' => '', // Optional, if not defined no password will be used. - 'dbindex' => 0, // Optional, if undefined SELECT will not run and will use Redis Server's default DB Index. + 'user' => '', // Optional: if not defined, no password will be used. + 'password' => '', // Optional: if not defined, no password will be used. + 'dbindex' => 0, // Optional: if undefined SELECT will not run and will use Redis Server's default DB Index. // If redis in-transit encryption is enabled, provide certificates // SSL context https://www.php.net/manual/en/context.ssl.php 'ssl_context' => [ @@ -1415,7 +1415,7 @@ $CONFIG = [ * - \RedisCluster::FAILOVER_ERROR - failover to slaves for read commands if master is unavailable (recommended) * - \RedisCluster::FAILOVER_DISTRIBUTE - randomly distribute read commands across master and slaves * - * WARNING: FAILOVER_DISTRIBUTE is a not recommended setting and we strongly + * WARNING: FAILOVER_DISTRIBUTE is a not recommended setting, and we strongly * suggest to not use it if you use Redis for file locking. Due to the way Redis * is synchronized it could happen, that the read for an existing lock is * scheduled to a slave that is not fully synchronized with the connected master @@ -1427,15 +1427,15 @@ $CONFIG = [ * https://github.com/phpredis/phpredis/commit/c5994f2a42b8a348af92d3acb4edff1328ad8ce1 */ 'redis.cluster' => [ - 'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required + 'seeds' => [ // provide some or all of the cluster servers to bootstrap discovery, port required 'localhost:7000', 'localhost:7001', ], 'timeout' => 0.0, 'read_timeout' => 0.0, 'failover_mode' => \RedisCluster::FAILOVER_ERROR, - 'user' => '', // Optional, if not defined no password will be used. - 'password' => '', // Optional, if not defined no password will be used. + 'user' => '', // Optional: if not defined, no password will be used. + 'password' => '', // Optional: if not defined, no password will be used. // If redis in-transit encryption is enabled, provide certificates // SSL context https://www.php.net/manual/en/context.ssl.php 'ssl_context' => [ @@ -1527,7 +1527,7 @@ $CONFIG = [ 'objectstore' => [ 'class' => 'OC\\Files\\ObjectStore\\Swift', 'arguments' => [ - // trystack will use your facebook id as the user name + // trystack will use your facebook id as the username 'username' => 'facebook100000123456789', // in the trystack dashboard go to user -> settings -> API Password to // generate a password @@ -1592,7 +1592,7 @@ $CONFIG = [ * ``-preview-NUMBER`` where NUMBER is between 0 and 255. * * Keep in mind that only previews of files are put in there that don't have - * some already. Otherwise the old bucket will be used. + * some already. Otherwise, the old bucket will be used. * * To migrate existing previews to this new multibucket distribution of previews * use the occ command ``preview:repair``. For now this will only migrate @@ -1660,12 +1660,12 @@ $CONFIG = [ 'sharing.force_share_accept' => false, /** - * Set to false to prevent users from setting a custom share_folder + * Set to ``false``, to prevent users from setting a custom share_folder */ 'sharing.allow_custom_share_folder' => true, /** - * Set to false to stop sending a mail when users receive a share + * Set to ``false``, to stop sending a mail when users receive a share */ 'sharing.enable_share_mail' => true, @@ -1687,11 +1687,11 @@ $CONFIG = [ */ /** - * Additional driver options for the database connection, eg. to enable SSL + * Additional driver options for the database connection, e.g. to enable SSL * encryption in MySQL or specify a custom wait timeout on a cheap hoster. * * When setting up TLS/SSL for encrypting the connections, you need to ensure that - * the passed keys and certificates are readable by the PHP process. In addition + * the passed keys and certificates are readable by the PHP process. In addition, * PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT might need to be set to false, if the * database servers certificates CN does not match with the hostname used to connect. * The standard behavior here is different from the MySQL/MariaDB CLI client, which @@ -1747,7 +1747,7 @@ $CONFIG = [ /** * For search queries in the database, a default collation – depending on the * character set – is chosen. In some cases a different behaviour is desired, - * for instances when a accent sensitive search is desired. + * for instances when an accent sensitive search is desired. * * MariaDB and MySQL have an overlap in available collations, but also * incompatible ones, also depending on the version of the database server. @@ -1807,8 +1807,8 @@ $CONFIG = [ */ /** - * By default Nextcloud will use the Argon2 password hashing if available. - * However if for whatever reason you want to stick with the PASSWORD_DEFAULT + * By default, Nextcloud will use the Argon2 password hashing if available. + * However, if for whatever reason you want to stick with the PASSWORD_DEFAULT * of your php version. Then set the setting to true. */ 'hashing_default_password' => false, @@ -1965,7 +1965,7 @@ $CONFIG = [ /** * Allows to create external storages of type "Local" in the web interface and APIs. * - * When disable, it is still possible to create local storages with occ using + * When disabled, it is still possible to create local storages with occ using * the following command: * * % php occ files_external:create /mountpoint local null::null -c datadir=/path/to/data @@ -1992,7 +1992,7 @@ $CONFIG = [ 'filesystem_check_changes' => 0, /** - * By default Nextcloud will store the part files created during upload in the + * By default, Nextcloud will store the part files created during upload in the * same storage as the upload target. Setting this to false will store the part * files in the root of the users folder which might be required to work with certain * external storage setups that have limited rename capabilities. @@ -2032,7 +2032,7 @@ $CONFIG = [ * - IPv6 addresses, e.g. `fd9e:21a7:a92c:2323::1` * * _(CIDR notation for IPv6 is currently work in progress and thus not - * available as of yet)_ + * available yet)_ * * When an incoming request's `REMOTE_ADDR` matches any of the IP addresses * specified here, it is assumed to be a proxy instead of a client. Thus, the @@ -2167,7 +2167,7 @@ $CONFIG = [ /** * by default federation is only used internally in a Global Scale setup - * If you want to allow federation outside of your environment set it to 'global' + * If you want to allow federation outside your environment set it to 'global' */ 'gs.federation' => 'internal', @@ -2184,7 +2184,7 @@ $CONFIG = [ ], /** - * By default there is on public pages a link shown that allows users to + * By default, there is on public pages a link shown that allows users to * learn about the "simple sign up" - see https://nextcloud.com/signup/ * * If this is set to "false" it will not show the link. @@ -2192,7 +2192,7 @@ $CONFIG = [ 'simpleSignUpLink.shown' => true, /** - * By default autocompletion is enabled for the login form on Nextcloud's login page. + * By default, autocompletion is enabled for the login form on Nextcloud's login page. * While this is enabled, browsers are allowed to "remember" login names and such. * Some companies require it to be disabled to comply with their security policy. * @@ -2275,7 +2275,7 @@ $CONFIG = [ /** * Enable file metadata collection * - * This is helpful for the mobile clients and will enable a few optimization in + * This is helpful for the mobile clients and will enable few optimizations in * the future for the preview generation. * * Note that when enabled, this data will be stored in the database and might increase diff --git a/lib/base.php b/lib/base.php index fa69a7d6076..7098fb19fdd 100644 --- a/lib/base.php +++ b/lib/base.php @@ -594,6 +594,7 @@ class OC { // Add default composer PSR-4 autoloader self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; + self::$composerAutoloader->setApcuPrefix('composer_autoload'); try { self::initPaths(); diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php index 4c413a8ae87..462f9b978fd 100644 --- a/lib/private/AppFramework/DependencyInjection/DIContainer.php +++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php @@ -79,6 +79,7 @@ use Psr\Log\LoggerInterface; * @deprecated 20.0.0 */ class DIContainer extends SimpleContainer implements IAppContainer { + private string $appName; /** * @var array @@ -94,8 +95,9 @@ class DIContainer extends SimpleContainer implements IAppContainer { * @param array $urlParams * @param ServerContainer|null $server */ - public function __construct($appName, $urlParams = [], ServerContainer $server = null) { + public function __construct(string $appName, array $urlParams = [], ServerContainer $server = null) { parent::__construct(); + $this->appName = $appName; $this['appName'] = $appName; $this['urlParams'] = $urlParams; @@ -437,6 +439,15 @@ class DIContainer extends SimpleContainer implements IAppContainer { } public function query(string $name, bool $autoload = true) { + if ($name === 'AppName' || $name === 'appName') { + return $this->appName; + } + + $isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\'); + if ($isServerClass && !$this->has($name)) { + return $this->getServer()->query($name, $autoload); + } + try { return $this->queryNoFallback($name); } catch (QueryException $firstException) { @@ -461,11 +472,11 @@ class DIContainer extends SimpleContainer implements IAppContainer { if ($this->offsetExists($name)) { return parent::query($name); - } elseif ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { + } elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) { return parent::query($name); - } elseif ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { + } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) { return parent::query($name); - } elseif (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { + } elseif (str_starts_with($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\')) { return parent::query($name); } diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 7fcfab37fa6..71910873db7 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -40,6 +40,8 @@ declare(strict_types=1); namespace OC\L10N; +use OCP\ICache; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IUser; @@ -94,7 +96,9 @@ class Factory implements IFactory { protected $request; /** @var IUserSession */ - protected $userSession; + protected IUserSession $userSession; + + private ICache $cache; /** @var string */ protected $serverRoot; @@ -109,11 +113,13 @@ class Factory implements IFactory { IConfig $config, IRequest $request, IUserSession $userSession, + ICacheFactory $cacheFactory, $serverRoot ) { $this->config = $config; $this->request = $request; $this->userSession = $userSession; + $this->cache = $cacheFactory->createLocal('L10NFactory'); $this->serverRoot = $serverRoot; } @@ -338,6 +344,10 @@ class Factory implements IFactory { $key = 'null'; } + if ($availableLanguages = $this->cache->get($key)) { + $this->availableLanguages[$key] = $availableLanguages; + } + // also works with null as key if (!empty($this->availableLanguages[$key])) { return $this->availableLanguages[$key]; @@ -374,6 +384,7 @@ class Factory implements IFactory { } $this->availableLanguages[$key] = $available; + $this->cache->set($key, $available, 60); return $available; } diff --git a/lib/private/Server.php b/lib/private/Server.php index 07e90843a98..d420b6fd11d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -688,6 +688,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(\OCP\IConfig::class), $c->getRequest(), $c->get(IUserSession::class), + $c->get(ICacheFactory::class), \OC::$SERVERROOT ); }); diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 0bc99f6c152..e53737990e8 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -139,10 +139,13 @@ class ServerContainer extends SimpleContainer { public function query(string $name, bool $autoload = true) { $name = $this->sanitizeName($name); - try { - return parent::query($name, false); - } catch (QueryException $e) { - // Continue with general autoloading then + if (str_starts_with($name, 'OCA\\')) { + // Skip server container query for app namespace classes + try { + return parent::query($name, false); + } catch (QueryException $e) { + // Continue with general autoloading then + } } // In case the service starts with OCA\ we try to find the service in diff --git a/lib/private/Template/CSSResourceLocator.php b/lib/private/Template/CSSResourceLocator.php index 2cbf12ce65d..5047b3e906f 100644 --- a/lib/private/Template/CSSResourceLocator.php +++ b/lib/private/Template/CSSResourceLocator.php @@ -34,14 +34,8 @@ namespace OC\Template; use Psr\Log\LoggerInterface; class CSSResourceLocator extends ResourceLocator { - - /** - * @param string $theme - * @param array $core_map - * @param array $party_map - */ - public function __construct(LoggerInterface $logger, $theme, $core_map, $party_map) { - parent::__construct($logger, $theme, $core_map, $party_map); + public function __construct(LoggerInterface $logger) { + parent::__construct($logger); } /** @@ -50,8 +44,7 @@ class CSSResourceLocator extends ResourceLocator { public function doFind($style) { $app = substr($style, 0, strpos($style, '/')); if (strpos($style, '3rdparty') === 0 - && $this->appendIfExist($this->thirdpartyroot, $style.'.css') - || $this->appendIfExist($this->serverroot, $style.'.css') + && $this->appendIfExist($this->serverroot, $style.'.css') || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') ) { return; diff --git a/lib/private/Template/JSResourceLocator.php b/lib/private/Template/JSResourceLocator.php index 9e76655aba2..88323af75de 100644 --- a/lib/private/Template/JSResourceLocator.php +++ b/lib/private/Template/JSResourceLocator.php @@ -34,8 +34,8 @@ class JSResourceLocator extends ResourceLocator { /** @var JSCombiner */ protected $jsCombiner; - public function __construct(LoggerInterface $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) { - parent::__construct($logger, $theme, $core_map, $party_map); + public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner) { + parent::__construct($logger); $this->jsCombiner = $JSCombiner; } @@ -45,10 +45,6 @@ class JSResourceLocator extends ResourceLocator { */ public function doFind($script) { $theme_dir = 'themes/'.$this->theme.'/'; - if (strpos($script, '3rdparty') === 0 - && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) { - return; - } // Extracting the appId and the script file name $app = substr($script, 0, strpos($script, '/')); diff --git a/lib/private/Template/ResourceLocator.php b/lib/private/Template/ResourceLocator.php index 5a50cc6fd1b..9e6e2056e6b 100755 --- a/lib/private/Template/ResourceLocator.php +++ b/lib/private/Template/ResourceLocator.php @@ -36,25 +36,20 @@ abstract class ResourceLocator { protected $mapping; protected $serverroot; - protected $thirdpartyroot; protected $webroot; protected $resources = []; protected LoggerInterface $logger; - /** - * @param string $theme - * @param array $core_map - * @param array $party_map - */ - public function __construct(LoggerInterface $logger, $theme, $core_map, $party_map) { + public function __construct(LoggerInterface $logger) { $this->logger = $logger; - $this->theme = $theme; - $this->mapping = $core_map + $party_map; - $this->serverroot = key($core_map); - $this->thirdpartyroot = key($party_map); - $this->webroot = $this->mapping[$this->serverroot]; + $this->mapping = [ + \OC::$SERVERROOT => \OC::$WEBROOT + ]; + $this->serverroot = \OC::$SERVERROOT; + $this->webroot = \OC::$WEBROOT; + $this->theme = \OC_Util::getTheme(); } /** diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 3e2e004cb97..178bec9c8dc 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -44,8 +44,9 @@ namespace OC; use bantu\IniGetWrapper\IniGetWrapper; use OC\Search\SearchQuery; -use OC\Template\JSCombiner; +use OC\Template\CSSResourceLocator; use OC\Template\JSConfigHelper; +use OC\Template\JSResourceLocator; use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\IConfig; @@ -54,11 +55,16 @@ use OCP\INavigationManager; use OCP\IUserSession; use OCP\Support\Subscription\IRegistry; use OCP\Util; -use Psr\Log\LoggerInterface; class TemplateLayout extends \OC_Template { private static $versionHash = ''; + /** @var CSSResourceLocator|null */ + public static $cssLocator = null; + + /** @var JSResourceLocator|null */ + public static $jsLocator = null; + /** @var IConfig */ private $config; @@ -333,17 +339,11 @@ class TemplateLayout extends \OC_Template { * @return array */ public static function findStylesheetFiles($styles, $compileScss = true) { - // Read the selected theme from the config file - $theme = \OC_Util::getTheme(); - - $locator = new \OC\Template\CSSResourceLocator( - \OC::$server->get(LoggerInterface::class), - $theme, - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - ); - $locator->find($styles); - return $locator->getResources(); + if (!self::$cssLocator) { + self::$cssLocator = \OCP\Server::get(CSSResourceLocator::class); + } + self::$cssLocator->find($styles); + return self::$cssLocator->getResources(); } /** @@ -367,18 +367,11 @@ class TemplateLayout extends \OC_Template { * @return array */ public static function findJavascriptFiles($scripts) { - // Read the selected theme from the config file - $theme = \OC_Util::getTheme(); - - $locator = new \OC\Template\JSResourceLocator( - \OC::$server->get(LoggerInterface::class), - $theme, - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - [ \OC::$SERVERROOT => \OC::$WEBROOT ], - \OC::$server->query(JSCombiner::class) - ); - $locator->find($scripts); - return $locator->getResources(); + if (!self::$jsLocator) { + self::$jsLocator = \OCP\Server::get(JSResourceLocator::class); + } + self::$jsLocator->find($scripts); + return self::$jsLocator->getResources(); } /** diff --git a/tests/lib/L10N/FactoryTest.php b/tests/lib/L10N/FactoryTest.php index 4e01602a4f7..7af069cbff3 100644 --- a/tests/lib/L10N/FactoryTest.php +++ b/tests/lib/L10N/FactoryTest.php @@ -13,6 +13,7 @@ namespace Test\L10N; use OC\L10N\Factory; use OC\L10N\LanguageNotFoundException; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IUser; @@ -32,6 +33,9 @@ class FactoryTest extends TestCase { /** @var IUserSession|MockObject */ protected $userSession; + /** @var ICacheFactory|MockObject */ + protected $cacheFactory; + /** @var string */ protected $serverRoot; @@ -41,6 +45,7 @@ class FactoryTest extends TestCase { $this->config = $this->createMock(IConfig::class); $this->request = $this->createMock(IRequest::class); $this->userSession = $this->createMock(IUserSession::class); + $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->serverRoot = \OC::$SERVERROOT; } @@ -64,13 +69,14 @@ class FactoryTest extends TestCase { $this->config, $this->request, $this->userSession, + $this->cacheFactory, $this->serverRoot, ]) ->setMethods($methods) ->getMock(); } - return new Factory($this->config, $this->request, $this->userSession, $this->serverRoot); + return new Factory($this->config, $this->request, $this->userSession, $this->cacheFactory, $this->serverRoot); } public function dataFindAvailableLanguages(): array { diff --git a/tests/lib/L10N/L10nTest.php b/tests/lib/L10N/L10nTest.php index f410c523c05..f224592432c 100644 --- a/tests/lib/L10N/L10nTest.php +++ b/tests/lib/L10N/L10nTest.php @@ -11,6 +11,7 @@ namespace Test\L10N; use DateTime; use OC\L10N\Factory; use OC\L10N\L10N; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IRequest; use OCP\IUserSession; @@ -32,7 +33,8 @@ class L10nTest extends TestCase { $request = $this->createMock(IRequest::class); /** @var IUserSession $userSession */ $userSession = $this->createMock(IUserSession::class); - return new Factory($config, $request, $userSession, \OC::$SERVERROOT); + $cacheFactory = $this->createMock(ICacheFactory::class); + return new Factory($config, $request, $userSession, $cacheFactory, \OC::$SERVERROOT); } public function testSimpleTranslationWithTrailingColon(): void { diff --git a/tests/lib/Template/JSResourceLocatorTest.php b/tests/lib/Template/JSResourceLocatorTest.php index 7dedd4ad3c7..20fd79a91b5 100644 --- a/tests/lib/Template/JSResourceLocatorTest.php +++ b/tests/lib/Template/JSResourceLocatorTest.php @@ -63,9 +63,6 @@ class JSResourceLocatorTest extends \Test\TestCase { ); return new JSResourceLocator( $this->logger, - 'theme', - ['core' => 'map'], - ['3rd' => 'party'], $jsCombiner ); } diff --git a/tests/lib/Template/ResourceLocatorTest.php b/tests/lib/Template/ResourceLocatorTest.php index 0cb28843a53..fa329ca6581 100644 --- a/tests/lib/Template/ResourceLocatorTest.php +++ b/tests/lib/Template/ResourceLocatorTest.php @@ -8,6 +8,7 @@ namespace Test\Template; +use OC\SystemConfig; use OC\Template\ResourceNotFoundException; use Psr\Log\LoggerInterface; @@ -22,20 +23,23 @@ class ResourceLocatorTest extends \Test\TestCase { /** * @param string $theme - * @param array $core_map - * @param array $party_map - * @param array $appsRoots * @return \PHPUnit\Framework\MockObject\MockObject */ - public function getResourceLocator($theme, $core_map, $party_map, $appsRoots) { + public function getResourceLocator($theme) { + $systemConfig = $this->createMock(SystemConfig::class); + $systemConfig + ->expects($this->any()) + ->method('getValue') + ->with('theme', '') + ->willReturn($theme); + $this->overwriteService(SystemConfig::class, $systemConfig); return $this->getMockForAbstractClass('OC\Template\ResourceLocator', - [$this->logger, $theme, $core_map, $party_map, $appsRoots ], + [$this->logger], '', true, true, true, []); } public function testFind() { - $locator = $this->getResourceLocator('theme', - ['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']); + $locator = $this->getResourceLocator('theme'); $locator->expects($this->once()) ->method('doFind') ->with('foo'); @@ -47,6 +51,11 @@ class ResourceLocatorTest extends \Test\TestCase { } public function testFindNotFound() { + $systemConfig = $this->createMock(SystemConfig::class); + $systemConfig->method('getValue') + ->with('theme', '') + ->willReturn('theme'); + $this->overwriteService(SystemConfig::class, $systemConfig); $locator = $this->getResourceLocator('theme', ['core' => 'map'], ['3rd' => 'party'], ['foo' => 'bar']); $locator->expects($this->once()) @@ -65,8 +74,7 @@ class ResourceLocatorTest extends \Test\TestCase { } public function testAppendIfExist() { - $locator = $this->getResourceLocator('theme', - [__DIR__ => 'map'], ['3rd' => 'party'], ['foo' => 'bar']); + $locator = $this->getResourceLocator('theme'); /** @var \OC\Template\ResourceLocator $locator */ $method = new \ReflectionMethod($locator, 'appendIfExist'); $method->setAccessible(true); @@ -75,11 +83,7 @@ class ResourceLocatorTest extends \Test\TestCase { $resource1 = [__DIR__, 'webroot', basename(__FILE__)]; $this->assertEquals([$resource1], $locator->getResources()); - $method->invoke($locator, __DIR__, basename(__FILE__)); - $resource2 = [__DIR__, 'map', basename(__FILE__)]; - $this->assertEquals([$resource1, $resource2], $locator->getResources()); - $method->invoke($locator, __DIR__, 'does-not-exist'); - $this->assertEquals([$resource1, $resource2], $locator->getResources()); + $this->assertEquals([$resource1], $locator->getResources()); } } |