@@ -734,6 +734,67 @@ public function testAddUserSuccessfulGeneratePassword(): void {
734734 ));
735735 }
736736
737+ /**
738+ * `newUser.sendEmail` has to be read as a boolean. It is stored as an untyped
739+ * 'yes'/'no' string on instances created before Nextcloud 33 and as a typed
740+ * boolean once the account settings toggle has been used, so comparing it to
741+ * the string 'yes' silently skipped the mail on upgraded instances.
742+ */
743+ #[\PHPUnit \Framework \Attributes \DataProvider('dataAddUserWelcomeMail ' )]
744+ public function testAddUserSendsWelcomeMailWhenEnabled (bool $ enabled ): void {
745+ $ this ->appConfig
746+ ->expects ($ this ->atLeastOnce ())
747+ ->method ('getValueBool ' )
748+ ->with ('core ' , 'newUser.sendEmail ' , true )
749+ ->willReturn ($ enabled );
750+
751+ $ newUser = $ this ->createMock (IUser::class);
752+ $ newUser ->expects ($ this ->once ())
753+ ->method ('setSystemEMailAddress ' )
754+ ->with ('foo@bar.com ' );
755+ $ this ->userManager
756+ ->expects ($ this ->once ())
757+ ->method ('userExists ' )
758+ ->with ('NewUser ' )
759+ ->willReturn (false );
760+ $ this ->userManager
761+ ->expects ($ this ->once ())
762+ ->method ('createUser ' )
763+ ->willReturn ($ newUser );
764+ $ loggedInUser = $ this ->createMock (IUser::class);
765+ $ loggedInUser
766+ ->method ('getUID ' )
767+ ->willReturn ('adminUser ' );
768+ $ this ->userSession
769+ ->expects ($ this ->once ())
770+ ->method ('getUser ' )
771+ ->willReturn ($ loggedInUser );
772+ $ this ->groupManager
773+ ->expects ($ this ->once ())
774+ ->method ('isAdmin ' )
775+ ->with ('adminUser ' )
776+ ->willReturn (true );
777+
778+ $ emailTemplate = $ this ->createMock (IEMailTemplate::class);
779+ $ this ->newUserMailHelper
780+ ->expects ($ enabled ? $ this ->once () : $ this ->never ())
781+ ->method ('generateTemplate ' )
782+ ->willReturn ($ emailTemplate );
783+ $ this ->newUserMailHelper
784+ ->expects ($ enabled ? $ this ->once () : $ this ->never ())
785+ ->method ('sendMail ' )
786+ ->with ($ newUser , $ emailTemplate );
787+
788+ $ this ->api ->addUser ('NewUser ' , 'PasswordOfTheNewUser ' , '' , 'foo@bar.com ' );
789+ }
790+
791+ public static function dataAddUserWelcomeMail (): array {
792+ return [
793+ 'enabled ' => [true ],
794+ 'disabled ' => [false ],
795+ ];
796+ }
797+
737798 public function testAddUserSuccessfulLowercaseEmail (): void {
738799 $ this ->userManager
739800 ->expects ($ this ->once ())
0 commit comments