2017-04-06 21:20:47 +03:00
< ? php
/**
* @ copyright 2017 , Morris Jobke < hey @ morrisjobke . de >
*
* @ author Morris Jobke < hey @ morrisjobke . de >
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*
*/
namespace Test\Mail ;
use OC\Mail\EMailTemplate ;
2017-04-07 23:42:43 +03:00
use OCP\Defaults ;
2017-04-07 15:51:05 +03:00
use OCP\IL10N ;
use OCP\IURLGenerator ;
2017-04-06 21:20:47 +03:00
use Test\TestCase ;
class EMailTemplateTest extends TestCase {
2017-04-07 23:42:43 +03:00
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */
2017-04-06 21:20:47 +03:00
private $defaults ;
2017-04-07 15:51:05 +03:00
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator ;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n ;
/** @var EMailTemplate */
private $emailTemplate ;
2019-11-21 18:40:38 +03:00
public function setUp () : void {
2017-04-06 21:20:47 +03:00
parent :: setUp ();
2017-04-07 23:42:43 +03:00
$this -> defaults = $this -> createMock ( Defaults :: class );
2017-04-07 15:51:05 +03:00
$this -> urlGenerator = $this -> createMock ( IURLGenerator :: class );
$this -> l10n = $this -> createMock ( IL10N :: class );
2017-04-06 21:20:47 +03:00
2017-04-07 15:51:05 +03:00
$this -> emailTemplate = new EMailTemplate (
$this -> defaults ,
$this -> urlGenerator ,
2017-09-05 14:55:36 +03:00
$this -> l10n ,
'test.TestTemplate' ,
[]
2017-04-07 15:51:05 +03:00
);
}
public function testEMailTemplateCustomFooter () {
2017-04-06 21:20:47 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getColorPrimary' )
-> willReturn ( '#0082c9' );
2017-04-07 15:51:05 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getLogo' )
-> willReturn ( '/img/logo-mail-header.png' );
2017-04-12 12:52:58 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getName' )
-> willReturn ( 'TestCloud' );
2017-12-08 14:16:05 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getTextColorPrimary' )
-> willReturn ( '#ffffff' );
2017-04-07 15:51:05 +03:00
$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' );
2017-11-09 11:24:35 +03:00
$this -> emailTemplate -> addBodyText ( 'Welcome to your Nextcloud account, you can add, protect, and share your data.' );
2017-04-07 15:51:05 +03:00
$this -> emailTemplate -> addBodyText ( 'Your username is: abc' );
$this -> emailTemplate -> addBodyButtonGroup (
2017-04-06 21:20:47 +03:00
'Set your password' , 'https://example.org/resetPassword/123' ,
'Install Client' , 'https://nextcloud.com/install/#install-clients'
);
2017-04-07 15:51:05 +03:00
$this -> emailTemplate -> addFooter (
2017-04-18 10:53:02 +03:00
'TestCloud - A safe home for your data<br>This is an automatically sent email, please do not reply.'
2017-04-06 21:20:47 +03:00
);
$expectedHTML = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email.html' );
2017-04-19 01:09:25 +03:00
$this -> assertSame ( $expectedHTML , $this -> emailTemplate -> renderHtml ());
2017-04-07 15:51:05 +03:00
$expectedTXT = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email.txt' );
$this -> assertSame ( $expectedTXT , $this -> emailTemplate -> renderText ());
}
2017-04-06 21:20:47 +03:00
2017-04-07 15:51:05 +03:00
public function testEMailTemplateDefaultFooter () {
$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' );
2017-12-08 14:16:05 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getTextColorPrimary' )
-> willReturn ( '#ffffff' );
2017-04-07 15:51:05 +03:00
$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' );
2017-11-09 11:24:35 +03:00
$this -> emailTemplate -> addBodyText ( 'Welcome to your Nextcloud account, you can add, protect, and share your data.' );
2017-04-07 15:51:05 +03:00
$this -> emailTemplate -> addBodyText ( 'Your username is: abc' );
$this -> emailTemplate -> addBodyButtonGroup (
'Set your password' , 'https://example.org/resetPassword/123' ,
'Install Client' , 'https://nextcloud.com/install/#install-clients'
);
$this -> emailTemplate -> addFooter ();
2017-04-06 21:20:47 +03:00
2017-04-07 15:51:05 +03:00
$expectedHTML = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-custom.html' );
2017-04-19 01:09:25 +03:00
$this -> assertSame ( $expectedHTML , $this -> emailTemplate -> renderHtml ());
2017-04-07 15:51:05 +03:00
$expectedTXT = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-custom.txt' );
$this -> assertSame ( $expectedTXT , $this -> emailTemplate -> renderText ());
2017-04-06 21:20:47 +03:00
}
2017-04-12 00:13:34 +03:00
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' );
2017-12-08 14:16:05 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getTextColorPrimary' )
-> willReturn ( '#ffffff' );
2017-04-12 00:13:34 +03:00
$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' );
2017-11-09 11:24:35 +03:00
$this -> emailTemplate -> addBodyText ( 'Welcome to your Nextcloud account, you can add, protect, and share your data.' );
2017-04-12 00:13:34 +03:00
$this -> emailTemplate -> addBodyText ( 'Your username is: abc' );
$this -> emailTemplate -> addBodyButton (
2017-04-12 01:24:58 +03:00
'Set your password' , 'https://example.org/resetPassword/123' ,
false
2017-04-12 00:13:34 +03:00
);
$this -> emailTemplate -> addFooter ();
$expectedHTML = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-single-button.html' );
2017-04-19 01:09:25 +03:00
$this -> assertSame ( $expectedHTML , $this -> emailTemplate -> renderHtml ());
2017-04-12 00:13:34 +03:00
$expectedTXT = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-single-button.txt' );
$this -> assertSame ( $expectedTXT , $this -> emailTemplate -> renderText ());
}
2017-04-06 21:20:47 +03:00
2017-04-12 01:45:05 +03:00
public function testEMailTemplateAlternativePlainTexts () {
$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' );
2017-12-08 14:16:05 +03:00
$this -> defaults
-> expects ( $this -> any ())
-> method ( 'getTextColorPrimary' )
-> willReturn ( '#ffffff' );
2017-04-12 01:45:05 +03:00
$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' , 'Welcome aboard - text' );
2017-11-09 11:24:35 +03:00
$this -> emailTemplate -> addBodyText ( 'Welcome to your Nextcloud account, you can add, protect, and share your data.' , 'Welcome to your Nextcloud account, you can add, protect, and share your data. - text' );
2017-04-12 01:45:05 +03:00
$this -> emailTemplate -> addBodyText ( 'Your username is: abc' );
$this -> emailTemplate -> addBodyButtonGroup (
'Set your password' , 'https://example.org/resetPassword/123' ,
'Install Client' , 'https://nextcloud.com/install/#install-clients' ,
'Set your password - text' , 'Install Client - text'
);
$this -> emailTemplate -> addFooter ();
$expectedHTML = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-custom.html' );
2017-04-19 01:09:25 +03:00
$this -> assertSame ( $expectedHTML , $this -> emailTemplate -> renderHtml ());
2017-04-12 01:45:05 +03:00
$expectedTXT = file_get_contents ( \OC :: $SERVERROOT . '/tests/data/emails/new-account-email-custom-text-alternative.txt' );
$this -> assertSame ( $expectedTXT , $this -> emailTemplate -> renderText ());
}
2017-04-06 21:20:47 +03:00
}