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