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,47 +89,22 @@ 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,
'copyOtpOnDisplay' => true,
'useBasicQrcodeReader' => true,
'displayMode' => 'grid',
'showAccountsIcons' => false,
'kickUserAfter' => 5,
'activeGroup' => 1,
'rememberActiveGroup' => false,
'defaultGroup' => 1,
'defaultCaptureMode' => 'advancedForm',
'useDirectCapture' => true,
'useWebauthnOnly' => true,
'getOfficialIcons' => false,
'theme' => 'dark',
'formatPassword' => false,
'formatPasswordBy' => 1,
'lang' => 'fr',
];
$this->user['preferences->showOtpAsDot'] = $userPrefs['showOtpAsDot']; foreach (config('2fauth.preferences') as $pref => $value) {
$this->user['preferences->closeOtpOnCopy'] = $userPrefs['closeOtpOnCopy']; if (is_numeric($value)) {
$this->user['preferences->copyOtpOnDisplay'] = $userPrefs['copyOtpOnDisplay']; $userPrefs[$pref] = $value + 1;
$this->user['preferences->useBasicQrcodeReader'] = $userPrefs['useBasicQrcodeReader']; } else if (is_string($value)) {
$this->user['preferences->displayMode'] = $userPrefs['displayMode']; $userPrefs[$pref] = $value . '_';
$this->user['preferences->showAccountsIcons'] = $userPrefs['showAccountsIcons']; } else if (is_bool($value)) {
$this->user['preferences->kickUserAfter'] = $userPrefs['kickUserAfter']; $userPrefs[$pref] = ! $value;
$this->user['preferences->activeGroup'] = $userPrefs['activeGroup']; }
$this->user['preferences->rememberActiveGroup'] = $userPrefs['rememberActiveGroup'];
$this->user['preferences->defaultGroup'] = $userPrefs['defaultGroup']; $this->user['preferences->' . $pref] = $userPrefs[$pref];
$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')
->json('GET', '/api/v1/user/preferences') ->json('GET', '/api/v1/user/preferences')
->assertJsonCount(count(config('2fauth.preferences')), $key = null); ->assertJsonCount(count(config('2fauth.preferences')), $key = null);