@@ -272,8 +272,10 @@ public function testSave(): void
272272 public function testSaveAndKeep2FA (): void
273273 {
274274 $ initialConfig = [
275+ 'CharEditing ' => 'textarea ' ,
275276 '2fa ' => ['backend ' => 'application ' , 'settings ' => ['secret ' => 'thisisasecret ' ]],
276- 'theme ' => 'dark ' ,
277+ 'RowActionLinks ' => 'both ' ,
278+ 'TableNavigationLinksMode ' => 'both ' ,
277279 ];
278280 $ dummyDbi = $ this ->createDbiDummy ();
279281
@@ -371,17 +373,27 @@ public function testSaveAndKeep2FA(): void
371373 // 2FA is combined with the previous config
372374 $ dummyDbi ->addResult (
373375 <<<'SQL'
374- UPDATE `pma-db`.`pma__userconfig` SET `timevalue` = NOW(), `config_data` = '{\"2fa \":{\"backend\" :\"application \",\"settings\":{\"secret\":\"thisisasecret\"}},\"theme \":\"dark \",\"Console\\/Mode \":\"collapse\" }' WHERE `username` = 'root'
376+ UPDATE `pma-db`.`pma__userconfig` SET `timevalue` = NOW(), `config_data` = '{\"CharEditing \":\"textarea\",\"TableNavigationLinksMode\" :\"text \",\"Console\\/Mode\":\"collapse\",\"2fa\":{\"backend \":\"application \",\"settings\":{\"secret \":\"thisisasecret\"}} }' WHERE `username` = 'root'
375377 SQL,
376378 [['root ' ]],
377379 ['username ' ],
378380 );
379381
380382 // Partial save without 2fa
381- $ partialConfig = ['Console/Mode ' => 'collapse ' ];
383+ $ partialConfig = [
384+ 'CharEditing ' => 'textarea ' ,
385+ 'TableNavigationLinksMode ' => 'text ' ,
386+ 'Console/Mode ' => 'collapse ' ,
387+ ];
382388 $ userPreferences ->save ($ partialConfig );
383389
384- $ encodedConfig = json_encode ([...$ initialConfig , 'Console/Mode ' => 'collapse ' ]);
390+ $ expected = [
391+ 'CharEditing ' => 'textarea ' ,
392+ 'TableNavigationLinksMode ' => 'text ' ,
393+ 'Console/Mode ' => 'collapse ' ,
394+ '2fa ' => ['backend ' => 'application ' , 'settings ' => ['secret ' => 'thisisasecret ' ]],
395+ ];
396+ $ encodedConfig = json_encode ($ expected );
385397
386398 $ dummyDbi ->addResult (
387399 <<<'SQL'
@@ -390,13 +402,54 @@ public function testSaveAndKeep2FA(): void
390402 [[$ encodedConfig , 1767029179 ]],
391403 ['config_data ' , 'ts ' ],
392404 );
405+ // phpcs:enable Generic.Files.LineLength.TooLong
393406
394407 // Check that 2fa is still present
395408 $ resultConfig = $ userPreferences ->load ()['config_data ' ];
396- self ::assertSame (' thisisasecret ' , $ resultConfig[ ' 2fa ' ][ ' settings ' ][ ' secret ' ] );
397- self :: assertSame ( ' collapse ' , $ resultConfig [ ' Console/Mode ' ]);
409+ self ::assertSame ($ expected , $ resultConfig );
410+
398411 $ dummyDbi ->assertAllSelectsConsumed ();
399- // phpcs:enable Generic.Files.LineLength.TooLong
412+ }
413+
414+ public function testSaveAndKeep2FAWithSession (): void
415+ {
416+ $ dbi = $ this ->createDatabaseInterface ();
417+ $ config = new Config ();
418+ (new ReflectionProperty (Relation::class, 'cache ' ))->setValue (null , null );
419+ $ relation = new Relation ($ dbi , $ config );
420+ $ clock = MockClock::from ('2015-10-21T05:28:00-02:00 ' );
421+ $ userPreferences = new UserPreferences ($ dbi , $ relation , new Template ($ config ), $ config , $ clock );
422+
423+ unset($ _SESSION ['userconfig ' ]);
424+ $ initialConfig = [
425+ 'CharEditing ' => 'textarea ' ,
426+ '2fa ' => ['backend ' => 'application ' , 'settings ' => ['secret ' => 'thisisasecret ' ]],
427+ 'RowActionLinks ' => 'both ' ,
428+ 'TableNavigationLinksMode ' => 'both ' ,
429+ ];
430+ $ userPreferences ->save ($ initialConfig );
431+
432+ /** @phpstan-ignore offsetAccess.notFound */
433+ self ::assertSame (['db ' => $ initialConfig , 'ts ' => 1445412480 ], $ _SESSION ['userconfig ' ]);
434+
435+ $ partialConfig = [
436+ 'CharEditing ' => 'textarea ' ,
437+ 'TableNavigationLinksMode ' => 'text ' ,
438+ 'Console/Mode ' => 'collapse ' ,
439+ ];
440+ $ userPreferences ->save ($ partialConfig );
441+
442+ $ expected = [
443+ 'db ' => [
444+ 'CharEditing ' => 'textarea ' ,
445+ 'TableNavigationLinksMode ' => 'text ' ,
446+ 'Console/Mode ' => 'collapse ' ,
447+ '2fa ' => ['backend ' => 'application ' , 'settings ' => ['secret ' => 'thisisasecret ' ]],
448+ ],
449+ 'ts ' => 1445412480 ,
450+ ];
451+ /** @psalm-suppress DocblockTypeContradiction */
452+ self ::assertSame ($ expected , $ _SESSION ['userconfig ' ]);
400453 }
401454
402455 /**
0 commit comments