@@ -2618,6 +2618,108 @@ public function testEditUserAdminEditChangeLanguageInvalidLanguage(): void {
26182618 $ this ->assertEquals ([], $ this ->api ->editUser ('UserToEdit ' , 'language ' , 'ru ' )->getData ());
26192619 }
26202620
2621+ /**
2622+ * Debian and Ubuntu ship the tz database's backward links in a separate
2623+ * tzdata-legacy package, so pick an alias this platform actually knows
2624+ * instead of hardcoding one.
2625+ */
2626+ private static function findBackwardCompatibleTimezone (): ?string {
2627+ $ aliases = array_diff (
2628+ \DateTimeZone::listIdentifiers (\DateTimeZone::ALL_WITH_BC ),
2629+ \DateTimeZone::listIdentifiers (),
2630+ );
2631+ return $ aliases === [] ? null : reset ($ aliases );
2632+ }
2633+
2634+ public static function dataEditUserSelfEditChangeTimezone (): array {
2635+ return [
2636+ 'primary identifier ' => ['Europe/Vienna ' ],
2637+ 'backward compatible alias ' => [self ::findBackwardCompatibleTimezone ()],
2638+ ];
2639+ }
2640+
2641+ #[\PHPUnit \Framework \Attributes \DataProvider('dataEditUserSelfEditChangeTimezone ' )]
2642+ public function testEditUserSelfEditChangeTimezone (?string $ timezone ): void {
2643+ if ($ timezone === null ) {
2644+ $ this ->markTestSkipped ('No backward compatible timezone aliases in this platform \'s tz database ' );
2645+ }
2646+
2647+ $ loggedInUser = $ this ->createMock (IUser::class);
2648+ $ loggedInUser
2649+ ->expects ($ this ->any ())
2650+ ->method ('getUID ' )
2651+ ->willReturn ('UserToEdit ' );
2652+ $ targetUser = $ this ->createMock (IUser::class);
2653+ $ this ->config ->expects ($ this ->once ())
2654+ ->method ('setUserValue ' )
2655+ ->with ('UserToEdit ' , 'core ' , 'timezone ' , $ timezone );
2656+ $ this ->userSession
2657+ ->expects ($ this ->once ())
2658+ ->method ('getUser ' )
2659+ ->willReturn ($ loggedInUser );
2660+ $ this ->userManager
2661+ ->expects ($ this ->once ())
2662+ ->method ('get ' )
2663+ ->with ('UserToEdit ' )
2664+ ->willReturn ($ targetUser );
2665+ $ this ->groupManager
2666+ ->expects ($ this ->atLeastOnce ())
2667+ ->method ('isAdmin ' )
2668+ ->with ('UserToEdit ' )
2669+ ->willReturn (false );
2670+ $ targetUser
2671+ ->expects ($ this ->any ())
2672+ ->method ('getUID ' )
2673+ ->willReturn ('UserToEdit ' );
2674+
2675+ $ backend = $ this ->createMock (UserInterface::class);
2676+ $ targetUser
2677+ ->expects ($ this ->any ())
2678+ ->method ('getBackend ' )
2679+ ->willReturn ($ backend );
2680+
2681+ $ this ->assertEquals ([], $ this ->api ->editUser ('UserToEdit ' , 'timezone ' , $ timezone )->getData ());
2682+ }
2683+
2684+ public function testEditUserSelfEditChangeTimezoneInvalid (): void {
2685+ $ this ->expectException (OCSException::class);
2686+
2687+ $ loggedInUser = $ this ->createMock (IUser::class);
2688+ $ loggedInUser
2689+ ->expects ($ this ->any ())
2690+ ->method ('getUID ' )
2691+ ->willReturn ('UserToEdit ' );
2692+ $ targetUser = $ this ->createMock (IUser::class);
2693+ $ this ->config ->expects ($ this ->never ())
2694+ ->method ('setUserValue ' );
2695+ $ this ->userSession
2696+ ->expects ($ this ->once ())
2697+ ->method ('getUser ' )
2698+ ->willReturn ($ loggedInUser );
2699+ $ this ->userManager
2700+ ->expects ($ this ->once ())
2701+ ->method ('get ' )
2702+ ->with ('UserToEdit ' )
2703+ ->willReturn ($ targetUser );
2704+ $ this ->groupManager
2705+ ->expects ($ this ->atLeastOnce ())
2706+ ->method ('isAdmin ' )
2707+ ->with ('UserToEdit ' )
2708+ ->willReturn (false );
2709+ $ targetUser
2710+ ->expects ($ this ->any ())
2711+ ->method ('getUID ' )
2712+ ->willReturn ('UserToEdit ' );
2713+
2714+ $ backend = $ this ->createMock (UserInterface::class);
2715+ $ targetUser
2716+ ->expects ($ this ->any ())
2717+ ->method ('getBackend ' )
2718+ ->willReturn ($ backend );
2719+
2720+ $ this ->api ->editUser ('UserToEdit ' , 'timezone ' , 'Mars/Olympus_Mons ' );
2721+ }
2722+
26212723 public function testEditUserSubadminUserAccessible (): void {
26222724 $ this ->config
26232725 ->expects ($ this ->once ())
0 commit comments