diff options
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 12 | ||||
-rw-r--r-- | apps/sharebymail/tests/ShareByMailProviderTest.php | 40 | ||||
-rw-r--r-- | core/Controller/LostController.php | 4 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 4 | ||||
-rw-r--r-- | settings/Controller/MailSettingsController.php | 4 | ||||
-rw-r--r-- | settings/Hooks.php | 10 | ||||
-rw-r--r-- | settings/Mailer/NewUserMailHelper.php | 4 | ||||
-rw-r--r-- | tests/Core/Controller/LostControllerTest.php | 57 | ||||
-rw-r--r-- | tests/Settings/Mailer/NewUserMailHelperTest.php | 24 |
9 files changed, 46 insertions, 113 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 6e0664a8147..f610a1a5fa9 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -427,9 +427,7 @@ class ShareByMailProvider implements IShareProvider { $emailTemplate->addFooter(); } - $message->setSubject($emailTemplate->renderSubject()); - $message->setPlainBody($emailTemplate->renderText()); - $message->setHtmlBody($emailTemplate->renderHtml()); + $message->useTemplate($emailTemplate); $this->mailer->send($message); } @@ -491,9 +489,7 @@ class ShareByMailProvider implements IShareProvider { } $message->setTo([$shareWith]); - $message->setSubject($emailTemplate->renderSubject()); - $message->setBody($emailTemplate->renderText(), 'text/plain'); - $message->setHtmlBody($emailTemplate->renderHtml()); + $message->useTemplate($emailTemplate); $this->mailer->send($message); $this->createPasswordSendActivity($share, $shareWith, false); @@ -547,9 +543,7 @@ class ShareByMailProvider implements IShareProvider { $message->setFrom([$initiatorEMailAddress => $initiatorDisplayName]); } $message->setTo([$initiatorEMailAddress => $initiatorDisplayName]); - $message->setSubject($emailTemplate->renderSubject()); - $message->setBody($emailTemplate->renderText(), 'text/plain'); - $message->setHtmlBody($emailTemplate->renderHtml()); + $message->useTemplate($emailTemplate); $this->mailer->send($message); $this->createPasswordSendActivity($share, $shareWith, true); diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 23e61ee58f1..68a645ec0e6 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -835,26 +835,14 @@ class ShareByMailProviderTest extends TestCase { ->expects($this->once()) ->method('addFooter') ->with('UnitTestCloud - Testing like 1990'); - $message - ->expects($this->once()) - ->method('setSubject') - ->willReturn('Mrs. Owner User shared »file.txt« with you'); $template ->expects($this->once()) - ->method('renderText') - ->willReturn('Text Render'); - $message - ->expects($this->once()) - ->method('setPlainBody') - ->with('Text Render'); - $template - ->expects($this->once()) - ->method('renderHtml') - ->willReturn('HTML Render'); + ->method('setSubject') + ->with('Mrs. Owner User shared »file.txt« with you'); $message ->expects($this->once()) - ->method('setHtmlBody') - ->with('HTML Render'); + ->method('useTemplate') + ->with($template); $this->mailer ->expects($this->once()) ->method('send') @@ -936,26 +924,14 @@ class ShareByMailProviderTest extends TestCase { ->expects($this->once()) ->method('addFooter') ->with(''); - $message - ->expects($this->once()) - ->method('setSubject') - ->willReturn('Mr. Initiator User shared »file.txt« with you'); $template ->expects($this->once()) - ->method('renderText') - ->willReturn('Text Render'); - $message - ->expects($this->once()) - ->method('setPlainBody') - ->with('Text Render'); - $template - ->expects($this->once()) - ->method('renderHtml') - ->willReturn('HTML Render'); + ->method('setSubject') + ->with('Mr. Initiator User shared »file.txt« with you'); $message ->expects($this->once()) - ->method('setHtmlBody') - ->with('HTML Render'); + ->method('useTemplate') + ->with($template); $this->mailer ->expects($this->once()) ->method('send') diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index f4400b0f20b..04a3a07bea2 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -328,10 +328,8 @@ class LostController extends Controller { try { $message = $this->mailer->createMessage(); $message->setTo([$email => $user->getUID()]); - $message->setSubject($emailTemplate->renderSubject()); - $message->setPlainBody($emailTemplate->renderText()); - $message->setHtmlBody($emailTemplate->renderHtml()); $message->setFrom([$this->from => $this->defaults->getName()]); + $message->useTemplate($emailTemplate); $this->mailer->send($message); } catch (\Exception $e) { throw new \Exception($this->l10n->t( diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index dd2a110daeb..42f2170122e 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -750,9 +750,7 @@ class Manager implements IManager { $emailTemplate->addFooter(); } - $message->setSubject($emailTemplate->renderSubject()); - $message->setPlainBody($emailTemplate->renderText()); - $message->setHtmlBody($emailTemplate->renderHtml()); + $message->useTemplate($emailTemplate); $this->mailer->send($message); } diff --git a/settings/Controller/MailSettingsController.php b/settings/Controller/MailSettingsController.php index cb622fa9b12..02bd51e843e 100644 --- a/settings/Controller/MailSettingsController.php +++ b/settings/Controller/MailSettingsController.php @@ -159,9 +159,7 @@ class MailSettingsController extends Controller { $message = $this->mailer->createMessage(); $message->setTo([$email => $displayName]); - $message->setSubject($template->renderSubject()); - $message->setHtmlBody($template->renderHtml()); - $message->setPlainBody($template->renderText()); + $message->useTemplate($template); $errors = $this->mailer->send($message); if (!empty($errors)) { throw new \RuntimeException($this->l10n->t('Email could not be sent. Check your mail server log')); diff --git a/settings/Hooks.php b/settings/Hooks.php index 3da85b4ae74..59bd7bb905d 100644 --- a/settings/Hooks.php +++ b/settings/Hooks.php @@ -132,10 +132,7 @@ class Hooks { $message = $this->mailer->createMessage(); $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); - $message->setSubject($template->renderSubject()); - $message->setBody($template->renderText(), 'text/plain'); - $message->setHtmlBody($template->renderHtml()); - + $message->useTemplate($template); $this->mailer->send($message); } } @@ -208,10 +205,7 @@ class Hooks { $message = $this->mailer->createMessage(); $message->setTo([$oldMailAddress => $user->getDisplayName()]); - $message->setSubject($template->renderSubject()); - $message->setBody($template->renderText(), 'text/plain'); - $message->setHtmlBody($template->renderHtml()); - + $message->useTemplate($template); $this->mailer->send($message); } } diff --git a/settings/Mailer/NewUserMailHelper.php b/settings/Mailer/NewUserMailHelper.php index af1627a08e3..935b3f0e075 100644 --- a/settings/Mailer/NewUserMailHelper.php +++ b/settings/Mailer/NewUserMailHelper.php @@ -160,10 +160,8 @@ class NewUserMailHelper { IEMailTemplate $emailTemplate) { $message = $this->mailer->createMessage(); $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); - $message->setSubject($emailTemplate->renderSubject()); - $message->setHtmlBody($emailTemplate->renderHtml()); - $message->setPlainBody($emailTemplate->renderText()); $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); + $message->useTemplate($emailTemplate); $this->mailer->send($message); } } diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php index 0bdc11f8a2f..196b1da352b 100644 --- a/tests/Core/Controller/LostControllerTest.php +++ b/tests/Core/Controller/LostControllerTest.php @@ -324,20 +324,9 @@ class LostControllerTest extends \Test\TestCase { ->with(['test@example.com' => 'ExistingUser']); $message ->expects($this->at(1)) - ->method('setSubject') - ->with(' password reset'); - $message - ->expects($this->at(2)) - ->method('setPlainBody') - ->with('text body'); - $message - ->expects($this->at(3)) - ->method('setHtmlBody') - ->with('HTML body'); - $message - ->expects($this->at(4)) ->method('setFrom') ->with(['lostpassword-noreply@localhost' => null]); + $emailTemplate = $this->createMock(IEMailTemplate::class); $emailTemplate->expects($this->any()) ->method('renderHtml') @@ -345,6 +334,12 @@ class LostControllerTest extends \Test\TestCase { $emailTemplate->expects($this->any()) ->method('renderText') ->willReturn('text body'); + + $message + ->expects($this->at(2)) + ->method('useTemplate') + ->with($emailTemplate); + $this->mailer ->expects($this->at(0)) ->method('createEMailTemplate') @@ -407,20 +402,9 @@ class LostControllerTest extends \Test\TestCase { ->with(['test@example.com' => 'ExistingUser']); $message ->expects($this->at(1)) - ->method('setSubject') - ->with(' password reset'); - $message - ->expects($this->at(2)) - ->method('setPlainBody') - ->with('text body'); - $message - ->expects($this->at(3)) - ->method('setHtmlBody') - ->with('HTML body'); - $message - ->expects($this->at(4)) ->method('setFrom') ->with(['lostpassword-noreply@localhost' => null]); + $emailTemplate = $this->createMock(IEMailTemplate::class); $emailTemplate->expects($this->any()) ->method('renderHtml') @@ -428,6 +412,12 @@ class LostControllerTest extends \Test\TestCase { $emailTemplate->expects($this->any()) ->method('renderText') ->willReturn('text body'); + + $message + ->expects($this->at(2)) + ->method('useTemplate') + ->with($emailTemplate); + $this->mailer ->expects($this->at(0)) ->method('createEMailTemplate') @@ -484,20 +474,9 @@ class LostControllerTest extends \Test\TestCase { ->with(['test@example.com' => 'ExistingUser']); $message ->expects($this->at(1)) - ->method('setSubject') - ->with(' password reset'); - $message - ->expects($this->at(2)) - ->method('setPlainBody') - ->with('text body'); - $message - ->expects($this->at(3)) - ->method('setHtmlBody') - ->with('HTML body'); - $message - ->expects($this->at(4)) ->method('setFrom') ->with(['lostpassword-noreply@localhost' => null]); + $emailTemplate = $this->createMock(IEMailTemplate::class); $emailTemplate->expects($this->any()) ->method('renderHtml') @@ -505,6 +484,12 @@ class LostControllerTest extends \Test\TestCase { $emailTemplate->expects($this->any()) ->method('renderText') ->willReturn('text body'); + + $message + ->expects($this->at(2)) + ->method('useTemplate') + ->with($emailTemplate); + $this->mailer ->expects($this->at(0)) ->method('createEMailTemplate') diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index 1af1bed808c..9fd90561127 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -620,26 +620,18 @@ EOF; ->expects($this->at(0)) ->method('setTo') ->with(['recipient@example.com' => 'John Doe']); - $this->defaults - ->expects($this->exactly(2)) - ->method('getName') - ->willReturn('TestCloud'); $message ->expects($this->at(1)) - ->method('setSubject') - ->with('Your TestCloud account was created'); - $message - ->expects($this->at(2)) - ->method('setHtmlBody') - ->with($emailTemplate->renderHtml()); - $message - ->expects($this->at(3)) - ->method('setPlainBody') - ->with($emailTemplate->renderText()); - $message - ->expects($this->at(4)) ->method('setFrom') ->with(['no-reply@nextcloud.com' => 'TestCloud']); + $message + ->expects($this->at(2)) + ->method('useTemplate') + ->with($emailTemplate); + $this->defaults + ->expects($this->exactly(1)) + ->method('getName') + ->willReturn('TestCloud'); $this->mailer ->expects($this->once()) ->method('createMessage') |