Make list of tested preferences dynamic

This commit is contained in:
Bubka 2024-04-25 16:58:55 +02:00
parent 8734e9c807
commit 7a033409a5

View File

@ -89,45 +89,20 @@ class UserControllerTest extends FeatureTestCase
*/ */
public function test_allPreferences_returns_preferences_with_user_values() public function test_allPreferences_returns_preferences_with_user_values()
{ {
$userPrefs = [ $userPrefs = [];
'showOtpAsDot' => true,
'closeOtpOnCopy' => true, foreach (config('2fauth.preferences') as $pref => $value) {
'copyOtpOnDisplay' => true, if (is_numeric($value)) {
'useBasicQrcodeReader' => true, $userPrefs[$pref] = $value + 1;
'displayMode' => 'grid', } else if (is_string($value)) {
'showAccountsIcons' => false, $userPrefs[$pref] = $value . '_';
'kickUserAfter' => 5, } else if (is_bool($value)) {
'activeGroup' => 1, $userPrefs[$pref] = ! $value;
'rememberActiveGroup' => false, }
'defaultGroup' => 1,
'defaultCaptureMode' => 'advancedForm', $this->user['preferences->' . $pref] = $userPrefs[$pref];
'useDirectCapture' => true, }
'useWebauthnOnly' => true,
'getOfficialIcons' => false,
'theme' => 'dark',
'formatPassword' => false,
'formatPasswordBy' => 1,
'lang' => 'fr',
];
$this->user['preferences->showOtpAsDot'] = $userPrefs['showOtpAsDot'];
$this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy'];
$this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay'];
$this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader'];
$this->user['preferences->displayMode'] = $userPrefs['displayMode'];
$this->user['preferences->showAccountsIcons'] = $userPrefs['showAccountsIcons'];
$this->user['preferences->kickUserAfter'] = $userPrefs['kickUserAfter'];
$this->user['preferences->activeGroup'] = $userPrefs['activeGroup'];
$this->user['preferences->rememberActiveGroup'] = $userPrefs['rememberActiveGroup'];
$this->user['preferences->defaultGroup'] = $userPrefs['defaultGroup'];
$this->user['preferences->defaultCaptureMode'] = $userPrefs['defaultCaptureMode'];
$this->user['preferences->useDirectCapture'] = $userPrefs['useDirectCapture'];
$this->user['preferences->useWebauthnOnly'] = $userPrefs['useWebauthnOnly'];
$this->user['preferences->getOfficialIcons'] = $userPrefs['getOfficialIcons'];
$this->user['preferences->theme'] = $userPrefs['theme'];
$this->user['preferences->formatPassword'] = $userPrefs['formatPassword'];
$this->user['preferences->formatPasswordBy'] = $userPrefs['formatPasswordBy'];
$this->user['preferences->lang'] = $userPrefs['lang'];
$this->user->save(); $this->user->save();
$response = $this->actingAs($this->user, 'api-guard') $response = $this->actingAs($this->user, 'api-guard')