Skip to content

Commit a22065e

Browse files
committed
fix(config): fix tests+psalm
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 5ab47ee commit a22065e

10 files changed

Lines changed: 46 additions & 27 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@
12181218
'OC\\Comments\\ManagerFactory' => $baseDir . '/lib/private/Comments/ManagerFactory.php',
12191219
'OC\\Config' => $baseDir . '/lib/private/Config.php',
12201220
'OC\\Config\\ConfigManager' => $baseDir . '/lib/private/Config/ConfigManager.php',
1221+
'OC\\Config\\PresetManager' => $baseDir . '/lib/private/Config/PresetManager.php',
12211222
'OC\\Config\\UserConfig' => $baseDir . '/lib/private/Config/UserConfig.php',
12221223
'OC\\Console\\Application' => $baseDir . '/lib/private/Console/Application.php',
12231224
'OC\\Console\\TimestampFormatter' => $baseDir . '/lib/private/Console/TimestampFormatter.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
12591259
'OC\\Comments\\ManagerFactory' => __DIR__ . '/../../..' . '/lib/private/Comments/ManagerFactory.php',
12601260
'OC\\Config' => __DIR__ . '/../../..' . '/lib/private/Config.php',
12611261
'OC\\Config\\ConfigManager' => __DIR__ . '/../../..' . '/lib/private/Config/ConfigManager.php',
1262+
'OC\\Config\\PresetManager' => __DIR__ . '/../../..' . '/lib/private/Config/PresetManager.php',
12621263
'OC\\Config\\UserConfig' => __DIR__ . '/../../..' . '/lib/private/Config/UserConfig.php',
12631264
'OC\\Console\\Application' => __DIR__ . '/../../..' . '/lib/private/Console/Application.php',
12641265
'OC\\Console\\TimestampFormatter' => __DIR__ . '/../../..' . '/lib/private/Console/TimestampFormatter.php',

lib/private/AppConfig.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use OC\Config\PresetManager;
1717
use OCP\Config\Lexicon\Entry;
1818
use OCP\Config\Lexicon\ILexicon;
19-
use OCP\Config\Lexicon\Preset;
2019
use OCP\Config\Lexicon\Strictness;
2120
use OCP\Config\ValueType;
2221
use OCP\DB\Exception as DBException;
@@ -28,7 +27,6 @@
2827
use OCP\IConfig;
2928
use OCP\IDBConnection;
3029
use OCP\Security\ICrypto;
31-
use OCP\Server;
3230
use Psr\Log\LoggerInterface;
3331

3432
/**
@@ -1136,7 +1134,7 @@ public function getKeyDetails(string $app, string $key): array {
11361134
]);
11371135
}
11381136

1139-
return array_filter($details, static fn($v): bool => ($v !== null));
1137+
return array_filter($details, static fn ($v): bool => ($v !== null));
11401138
}
11411139

11421140
/**

lib/private/Config/ConfigManager.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
use OCP\Config\Exceptions\TypeConflictException;
1515
use OCP\Config\IUserConfig;
1616
use OCP\Config\Lexicon\Entry;
17-
use OCP\Config\Lexicon\Preset;
1817
use OCP\Config\ValueType;
1918
use OCP\IAppConfig;
20-
use OCP\IConfig;
2119
use OCP\Server;
2220
use Psr\Log\LoggerInterface;
2321

lib/private/Config/PresetManager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function setLexiconPreset(Preset $preset): void {
3737
$this->configManager->clearConfigCaches();
3838
}
3939

40+
/**
41+
* returns currently selected Preset
42+
*/
4043
public function getLexiconPreset(): Preset {
4144
if ($this->configLexiconPreset === null) {
4245
$this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(self::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;

lib/private/Config/UserConfig.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OCP\Config\IUserConfig;
1919
use OCP\Config\Lexicon\Entry;
2020
use OCP\Config\Lexicon\ILexicon;
21-
use OCP\Config\Lexicon\Preset;
2221
use OCP\Config\Lexicon\Strictness;
2322
use OCP\Config\ValueType;
2423
use OCP\DB\Exception as DBException;
@@ -27,7 +26,6 @@
2726
use OCP\IConfig;
2827
use OCP\IDBConnection;
2928
use OCP\Security\ICrypto;
30-
use OCP\Server;
3129
use Psr\Log\LoggerInterface;
3230

3331
/**

lib/private/Profile/ProfileManager.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,23 @@ private function getDefaultProfileConfig(IUser $targetUser, ?IUser $visitingUser
325325

326326
/**
327327
* modify property visibility, based on current Preset
328+
*
329+
* @psalm-suppress UnhandledMatchCondition if conditions are not met, we do not change $visibility
328330
*/
329331
private function applyDefaultProfilePreset(string $property, string &$visibility): void {
330-
$overwrite = match($this->presetManager->getLexiconPreset()) {
331-
Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match($property) {
332-
IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
333-
},
334-
Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match($property) {
335-
IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
336-
},
337-
Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match($property) {
338-
IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
339-
},
340-
default => null,
341-
};
342-
343-
if ($overwrite === null) {
332+
try {
333+
$overwrite = match ($this->presetManager->getLexiconPreset()) {
334+
Preset::SHARED, Preset::SCHOOL, Preset::UNIVERSITY => match ($property) {
335+
IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_HIDE,
336+
},
337+
Preset::PRIVATE, Preset::FAMILY, Preset::CLUB => match ($property) {
338+
IAccountManager::PROPERTY_EMAIL => self::VISIBILITY_SHOW,
339+
},
340+
Preset::SMALL, Preset::MEDIUM, Preset::LARGE => match ($property) {
341+
IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE => self::VISIBILITY_SHOW,
342+
},
343+
};
344+
} catch (\UnhandledMatchError) {
344345
return;
345346
}
346347

tests/lib/AppConfigTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use InvalidArgumentException;
1111
use OC\AppConfig;
12+
use OC\Config\ConfigManager;
13+
use OC\Config\PresetManager;
1214
use OCP\Exceptions\AppConfigTypeConflictException;
1315
use OCP\Exceptions\AppConfigUnknownKeyException;
1416
use OCP\IAppConfig;
@@ -29,6 +31,8 @@ class AppConfigTest extends TestCase {
2931
protected IAppConfig $appConfig;
3032
protected IDBConnection $connection;
3133
private IConfig $config;
34+
private ConfigManager $configManager;
35+
private PresetManager $presetManager;
3236
private LoggerInterface $logger;
3337
private ICrypto $crypto;
3438

@@ -99,6 +103,8 @@ protected function setUp(): void {
99103

100104
$this->connection = Server::get(IDBConnection::class);
101105
$this->config = Server::get(IConfig::class);
106+
$this->configManager = Server::get(ConfigManager::class);
107+
$this->presetManager = Server::get(PresetManager::class);
102108
$this->logger = Server::get(LoggerInterface::class);
103109
$this->crypto = Server::get(ICrypto::class);
104110

@@ -190,6 +196,8 @@ private function generateAppConfig(bool $preLoading = true): IAppConfig {
190196
$config = new AppConfig(
191197
$this->connection,
192198
$this->config,
199+
$this->configManager,
200+
$this->presetManager,
193201
$this->logger,
194202
$this->crypto,
195203
);

tests/lib/Config/LexiconTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\AppConfig;
1111
use OC\AppFramework\Bootstrap\Coordinator;
1212
use OC\Config\ConfigManager;
13+
use OC\Config\PresetManager;
1314
use OCP\Config\Exceptions\TypeConflictException;
1415
use OCP\Config\Exceptions\UnknownKeyException;
1516
use OCP\Config\IUserConfig;
@@ -32,6 +33,7 @@ class LexiconTest extends TestCase {
3233
private IAppConfig $appConfig;
3334
private IUserConfig $userConfig;
3435
private ConfigManager $configManager;
36+
private PresetManager $presetManager;
3537

3638
protected function setUp(): void {
3739
parent::setUp();
@@ -45,6 +47,7 @@ protected function setUp(): void {
4547
$this->appConfig = Server::get(IAppConfig::class);
4648
$this->userConfig = Server::get(IUserConfig::class);
4749
$this->configManager = Server::get(ConfigManager::class);
50+
$this->presetManager = Server::get(PresetManager::class);
4851
}
4952

5053
protected function tearDown(): void {
@@ -206,26 +209,26 @@ public function testAppConfigLexiconRenameInvertBoolean() {
206209
}
207210

208211
public function testAppConfigLexiconPreset() {
209-
$this->configManager->setLexiconPreset(Preset::FAMILY);
212+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
210213
$this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
211214
}
212215

213216
public function testAppConfigLexiconPresets() {
214-
$this->configManager->setLexiconPreset(Preset::MEDIUM);
217+
$this->presetManager->setLexiconPreset(Preset::MEDIUM);
215218
$this->assertSame('club+medium', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
216-
$this->configManager->setLexiconPreset(Preset::FAMILY);
219+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
217220
$this->assertSame('family', $this->appConfig->getValueString(TestLexicon_E::APPID, 'key3'));
218221
}
219222

220223
public function testUserConfigLexiconPreset() {
221-
$this->configManager->setLexiconPreset(Preset::FAMILY);
224+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
222225
$this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
223226
}
224227

225228
public function testUserConfigLexiconPresets() {
226-
$this->configManager->setLexiconPreset(Preset::MEDIUM);
229+
$this->presetManager->setLexiconPreset(Preset::MEDIUM);
227230
$this->assertSame('club+medium', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
228-
$this->configManager->setLexiconPreset(Preset::FAMILY);
231+
$this->presetManager->setLexiconPreset(Preset::FAMILY);
229232
$this->assertSame('family', $this->userConfig->getValueString('user1', TestLexicon_E::APPID, 'key3'));
230233
}
231234
}

tests/lib/Config/UserConfigTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
namespace Test\lib\Config;
99

10+
use OC\Config\ConfigManager;
11+
use OC\Config\PresetManager;
1012
use OC\Config\UserConfig;
1113
use OCP\Config\Exceptions\TypeConflictException;
1214
use OCP\Config\Exceptions\UnknownKeyException;
@@ -29,6 +31,8 @@
2931
class UserConfigTest extends TestCase {
3032
protected IDBConnection $connection;
3133
private IConfig $config;
34+
private ConfigManager $configManager;
35+
private PresetManager $presetManager;
3236
private LoggerInterface $logger;
3337
private ICrypto $crypto;
3438
private array $originalPreferences;
@@ -173,6 +177,8 @@ protected function setUp(): void {
173177

174178
$this->connection = Server::get(IDBConnection::class);
175179
$this->config = Server::get(IConfig::class);
180+
$this->configManager = Server::get(ConfigManager::class);
181+
$this->presetManager = Server::get(PresetManager::class);
176182
$this->logger = Server::get(LoggerInterface::class);
177183
$this->crypto = Server::get(ICrypto::class);
178184

@@ -282,6 +288,8 @@ private function generateUserConfig(array $preLoading = []): IUserConfig {
282288
$userConfig = new UserConfig(
283289
$this->connection,
284290
$this->config,
291+
$this->configManager,
292+
$this->presetManager,
285293
$this->logger,
286294
$this->crypto,
287295
);

0 commit comments

Comments
 (0)