@@ -2591,6 +2591,108 @@ public function testEditUserAdminEditChangeLanguageInvalidLanguage(): void {
25912591 $ this ->assertEquals ([], $ this ->api ->editUser ('UserToEdit ' , 'language ' , 'ru ' )->getData ());
25922592 }
25932593
2594+ /**
2595+ * Debian and Ubuntu ship the tz database's backward links in a separate
2596+ * tzdata-legacy package, so pick an alias this platform actually knows
2597+ * instead of hardcoding one.
2598+ */
2599+ private static function findBackwardCompatibleTimezone (): ?string {
2600+ $ aliases = array_diff (
2601+ \DateTimeZone::listIdentifiers (\DateTimeZone::ALL_WITH_BC ),
2602+ \DateTimeZone::listIdentifiers (),
2603+ );
2604+ return $ aliases === [] ? null : reset ($ aliases );
2605+ }
2606+
2607+ public static function dataEditUserSelfEditChangeTimezone (): array {
2608+ return [
2609+ 'primary identifier ' => ['Europe/Vienna ' ],
2610+ 'backward compatible alias ' => [self ::findBackwardCompatibleTimezone ()],
2611+ ];
2612+ }
2613+
2614+ #[\PHPUnit \Framework \Attributes \DataProvider('dataEditUserSelfEditChangeTimezone ' )]
2615+ public function testEditUserSelfEditChangeTimezone (?string $ timezone ): void {
2616+ if ($ timezone === null ) {
2617+ $ this ->markTestSkipped ('No backward compatible timezone aliases in this platform \'s tz database ' );
2618+ }
2619+
2620+ $ loggedInUser = $ this ->createMock (IUser::class);
2621+ $ loggedInUser
2622+ ->expects ($ this ->any ())
2623+ ->method ('getUID ' )
2624+ ->willReturn ('UserToEdit ' );
2625+ $ targetUser = $ this ->createMock (IUser::class);
2626+ $ this ->config ->expects ($ this ->once ())
2627+ ->method ('setUserValue ' )
2628+ ->with ('UserToEdit ' , 'core ' , 'timezone ' , $ timezone );
2629+ $ this ->userSession
2630+ ->expects ($ this ->once ())
2631+ ->method ('getUser ' )
2632+ ->willReturn ($ loggedInUser );
2633+ $ this ->userManager
2634+ ->expects ($ this ->once ())
2635+ ->method ('get ' )
2636+ ->with ('UserToEdit ' )
2637+ ->willReturn ($ targetUser );
2638+ $ this ->groupManager
2639+ ->expects ($ this ->atLeastOnce ())
2640+ ->method ('isAdmin ' )
2641+ ->with ('UserToEdit ' )
2642+ ->willReturn (false );
2643+ $ targetUser
2644+ ->expects ($ this ->any ())
2645+ ->method ('getUID ' )
2646+ ->willReturn ('UserToEdit ' );
2647+
2648+ $ backend = $ this ->createMock (UserInterface::class);
2649+ $ targetUser
2650+ ->expects ($ this ->any ())
2651+ ->method ('getBackend ' )
2652+ ->willReturn ($ backend );
2653+
2654+ $ this ->assertEquals ([], $ this ->api ->editUser ('UserToEdit ' , 'timezone ' , $ timezone )->getData ());
2655+ }
2656+
2657+ public function testEditUserSelfEditChangeTimezoneInvalid (): void {
2658+ $ this ->expectException (OCSException::class);
2659+
2660+ $ loggedInUser = $ this ->createMock (IUser::class);
2661+ $ loggedInUser
2662+ ->expects ($ this ->any ())
2663+ ->method ('getUID ' )
2664+ ->willReturn ('UserToEdit ' );
2665+ $ targetUser = $ this ->createMock (IUser::class);
2666+ $ this ->config ->expects ($ this ->never ())
2667+ ->method ('setUserValue ' );
2668+ $ this ->userSession
2669+ ->expects ($ this ->once ())
2670+ ->method ('getUser ' )
2671+ ->willReturn ($ loggedInUser );
2672+ $ this ->userManager
2673+ ->expects ($ this ->once ())
2674+ ->method ('get ' )
2675+ ->with ('UserToEdit ' )
2676+ ->willReturn ($ targetUser );
2677+ $ this ->groupManager
2678+ ->expects ($ this ->atLeastOnce ())
2679+ ->method ('isAdmin ' )
2680+ ->with ('UserToEdit ' )
2681+ ->willReturn (false );
2682+ $ targetUser
2683+ ->expects ($ this ->any ())
2684+ ->method ('getUID ' )
2685+ ->willReturn ('UserToEdit ' );
2686+
2687+ $ backend = $ this ->createMock (UserInterface::class);
2688+ $ targetUser
2689+ ->expects ($ this ->any ())
2690+ ->method ('getBackend ' )
2691+ ->willReturn ($ backend );
2692+
2693+ $ this ->api ->editUser ('UserToEdit ' , 'timezone ' , 'Mars/Olympus_Mons ' );
2694+ }
2695+
25942696 public function testEditUserSubadminUserAccessible (): void {
25952697 $ this ->appConfig
25962698 ->expects ($ this ->once ())
0 commit comments