From 050ce1d40bf344510338a401ce6b68f76ed3f5e5 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 11 Apr 2017 16:13:34 -0500 Subject: [PATCH] Add addBodyButton to add a single button to email templates Signed-off-by: Morris Jobke --- lib/private/Mail/EMailTemplate.php | 64 +++++++ lib/public/Mail/IEMailTemplate.php | 10 + .../new-account-email-single-button.html | 174 ++++++++++++++++++ .../new-account-email-single-button.txt | 9 + tests/lib/Mail/EMailTemplateTest.php | 38 ++++ 5 files changed, 295 insertions(+) create mode 100644 tests/data/emails/new-account-email-single-button.html create mode 100644 tests/data/emails/new-account-email-single-button.txt diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 338f6594f5..b47dcf09bf 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -225,6 +225,46 @@ EOF; +EOF; + + protected $button = << + + +   + + + + + + + + + +
+ + + + + +
+
+ + + + +
+ + + + +
+ %s +
+
+
+
+
EOF; protected $bodyEnd = <<footerAdded) { + return; + } + + if (!$this->bodyOpened) { + $this->htmlBody .= $this->bodyBegin; + $this->bodyOpened = true; + } + + $color = $this->themingDefaults->getColorPrimary(); + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); + $this->plainBody .= $text . ': ' . $url . PHP_EOL; + + } + /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index a1922e8615..7b85c154c3 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -92,6 +92,16 @@ interface IEMailTemplate { */ public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); + /** + * Adds a button to the body of the email + * + * @param string $text Text of button + * @param string $url URL of button + * + * @since 12.0.0 + */ + public function addBodyButton($text, $url); + /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * diff --git a/tests/data/emails/new-account-email-single-button.html b/tests/data/emails/new-account-email-single-button.html new file mode 100644 index 0000000000..c204bedb23 --- /dev/null +++ b/tests/data/emails/new-account-email-single-button.html @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + +
+
+ + + +
+ + + + + + +
+ + + +
+ +
+ + +
+
+
+ + + + + + +
 
+ + + + + +
+

Welcome aboard

+
+ + + + + + +
 
+ + + +
+ + + + + + +
+ + + + + + +
 
+ + + + + +
+ + + + + +
+

You have now an Nextcloud account, you can add, protect, and share your data.

+
+
+ + + + + +
+ + + + + +
+

Your username is: abc

+
+
+ + + + + +
 
+ + + + + + +
+ + + + + +
+
+ + + + +
+ + + + +
+ Set your password +
+
+
+
+
+
+
+ + + + + +
 
+ + + + +
+
+ +
                                                           
+ + \ No newline at end of file diff --git a/tests/data/emails/new-account-email-single-button.txt b/tests/data/emails/new-account-email-single-button.txt new file mode 100644 index 0000000000..b93321f8c9 --- /dev/null +++ b/tests/data/emails/new-account-email-single-button.txt @@ -0,0 +1,9 @@ +Welcome aboard + +You have now an Nextcloud account, you can add, protect, and share your data. + +Your username is: abc + +Set your password: https://example.org/resetPassword/123 +-- +TestCloud - A safe home for your data diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index 9f80dad642..664da6c17e 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -125,6 +125,44 @@ class EMailTemplateTest extends TestCase { $this->assertSame($expectedTXT, $this->emailTemplate->renderText()); } + public function testEMailTemplateSingleButton() { + $this->defaults + ->expects($this->any()) + ->method('getColorPrimary') + ->willReturn('#0082c9'); + $this->defaults + ->expects($this->any()) + ->method('getName') + ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getSlogan') + ->willReturn('A safe home for your data'); + $this->defaults + ->expects($this->any()) + ->method('getLogo') + ->willReturn('/img/logo-mail-header.png'); + $this->urlGenerator + ->expects($this->once()) + ->method('getAbsoluteURL') + ->with('/img/logo-mail-header.png') + ->willReturn('https://example.org/img/logo-mail-header.png'); + + $this->emailTemplate->addHeader(); + $this->emailTemplate->addHeading('Welcome aboard'); + $this->emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.'); + $this->emailTemplate->addBodyText('Your username is: abc'); + $this->emailTemplate->addBodyButton( + 'Set your password', 'https://example.org/resetPassword/123' + ); + $this->emailTemplate->addFooter(); + + $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.html'); + $this->assertSame($expectedHTML, $this->emailTemplate->renderHTML()); + $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.txt'); + $this->assertSame($expectedTXT, $this->emailTemplate->renderText()); + } + public function testEMailTemplateAlternativePlainTexts() {