Also adds `\OCP\Mail\IMailer::createEMailTemplate` as helper so the functionality can easily be used within apps. Signed-off-by: Lukas Reschke <lukas@statuscode.ch>tags/v12.0.0beta1
@@ -211,6 +211,7 @@ return array( | |||
'OCP\\Lock\\ILockingProvider' => $baseDir . '/lib/public/Lock/ILockingProvider.php', | |||
'OCP\\Lock\\LockedException' => $baseDir . '/lib/public/Lock/LockedException.php', | |||
'OCP\\Lockdown\\ILockdownManager' => $baseDir . '/lib/public/Lockdown/ILockdownManager.php', | |||
'OCP\\Mail\\IEMailTemplate' => $baseDir . '/lib/public/Mail/IEMailTemplate.php', | |||
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php', | |||
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php', | |||
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php', | |||
@@ -638,7 +639,6 @@ return array( | |||
'OC\\Log\\Rotate' => $baseDir . '/lib/private/Log/Rotate.php', | |||
'OC\\Log\\Syslog' => $baseDir . '/lib/private/Log/Syslog.php', | |||
'OC\\Mail\\EMailTemplate' => $baseDir . '/lib/private/Mail/EMailTemplate.php', | |||
'OC\\Mail\\IEMailTemplate' => $baseDir . '/lib/private/Mail/IEMailTemplate.php', | |||
'OC\\Mail\\Mailer' => $baseDir . '/lib/private/Mail/Mailer.php', | |||
'OC\\Mail\\Message' => $baseDir . '/lib/private/Mail/Message.php', | |||
'OC\\Memcache\\APCu' => $baseDir . '/lib/private/Memcache/APCu.php', |
@@ -241,6 +241,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OCP\\Lock\\ILockingProvider' => __DIR__ . '/../../..' . '/lib/public/Lock/ILockingProvider.php', | |||
'OCP\\Lock\\LockedException' => __DIR__ . '/../../..' . '/lib/public/Lock/LockedException.php', | |||
'OCP\\Lockdown\\ILockdownManager' => __DIR__ . '/../../..' . '/lib/public/Lockdown/ILockdownManager.php', | |||
'OCP\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/public/Mail/IEMailTemplate.php', | |||
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php', | |||
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php', | |||
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php', | |||
@@ -668,7 +669,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c | |||
'OC\\Log\\Rotate' => __DIR__ . '/../../..' . '/lib/private/Log/Rotate.php', | |||
'OC\\Log\\Syslog' => __DIR__ . '/../../..' . '/lib/private/Log/Syslog.php', | |||
'OC\\Mail\\EMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/EMailTemplate.php', | |||
'OC\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/private/Mail/IEMailTemplate.php', | |||
'OC\\Mail\\Mailer' => __DIR__ . '/../../..' . '/lib/private/Mail/Mailer.php', | |||
'OC\\Mail\\Message' => __DIR__ . '/../../..' . '/lib/private/Mail/Message.php', | |||
'OC\\Memcache\\APCu' => __DIR__ . '/../../..' . '/lib/private/Memcache/APCu.php', |
@@ -28,6 +28,7 @@ namespace OC\Mail; | |||
use OCP\Defaults; | |||
use OCP\IL10N; | |||
use OCP\IURLGenerator; | |||
use OCP\Mail\IEMailTemplate; | |||
/** | |||
* Class EMailTemplate |
@@ -24,6 +24,8 @@ namespace OC\Mail; | |||
use OCP\Defaults; | |||
use OCP\IConfig; | |||
use OCP\IL10N; | |||
use OCP\IURLGenerator; | |||
use OCP\Mail\IMailer; | |||
use OCP\ILogger; | |||
@@ -54,18 +56,28 @@ class Mailer implements IMailer { | |||
private $logger; | |||
/** @var Defaults */ | |||
private $defaults; | |||
/** @var IURLGenerator */ | |||
private $urlGenerator; | |||
/** @var IL10N */ | |||
private $l10n; | |||
/** | |||
* @param IConfig $config | |||
* @param ILogger $logger | |||
* @param Defaults $defaults | |||
* @param IURLGenerator $urlGenerator | |||
* @param IL10N $l10n | |||
*/ | |||
function __construct(IConfig $config, | |||
public function __construct(IConfig $config, | |||
ILogger $logger, | |||
Defaults $defaults) { | |||
Defaults $defaults, | |||
IURLGenerator $urlGenerator, | |||
IL10N $l10n) { | |||
$this->config = $config; | |||
$this->logger = $logger; | |||
$this->defaults = $defaults; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->l10n = $l10n; | |||
} | |||
/** | |||
@@ -77,6 +89,14 @@ class Mailer implements IMailer { | |||
return new Message(new \Swift_Message()); | |||
} | |||
public function createEMailTemplate() { | |||
return new EMailTemplate( | |||
$this->defaults, | |||
$this->urlGenerator, | |||
$this->l10n | |||
); | |||
} | |||
/** | |||
* Send the specified message. Also sets the from address to the value defined in config.php | |||
* if no-one has been passed. |
@@ -727,7 +727,9 @@ class Server extends ServerContainer implements IServerContainer { | |||
return new Mailer( | |||
$c->getConfig(), | |||
$c->getLogger(), | |||
$c->query(Defaults::class) | |||
$c->query(Defaults::class), | |||
$c->getURLGenerator(), | |||
$c->getL10N('lib') | |||
); | |||
}); | |||
$this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
@@ -21,9 +21,7 @@ | |||
* | |||
*/ | |||
namespace OC\Mail; | |||
use OCP\Defaults; | |||
namespace OCP\Mail; | |||
/** | |||
* Interface IEMailTemplate | |||
@@ -49,19 +47,25 @@ use OCP\Defaults; | |||
* | |||
* $htmlContent = $emailTemplate->renderHTML(); | |||
* $plainContent = $emailTemplate->renderText(); | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
interface IEMailTemplate { | |||
/** | |||
* @param Defaults $themingDefaults | |||
* @param \OCP\Defaults $themingDefaults | |||
* @param \OCP\IURLGenerator $urlGenerator | |||
* @param \OCP\IL10N $l10n | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function __construct(Defaults $themingDefaults, | |||
public function __construct(\OCP\Defaults $themingDefaults, | |||
\OCP\IURLGenerator $urlGenerator, | |||
\OCP\IL10N $l10n); | |||
/** | |||
* Adds a header to the email | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function addHeader(); | |||
@@ -69,6 +73,8 @@ interface IEMailTemplate { | |||
* Adds a heading to the email | |||
* | |||
* @param string $title | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function addHeading($title); | |||
@@ -76,6 +82,8 @@ interface IEMailTemplate { | |||
* Adds a paragraph to the body of the email | |||
* | |||
* @param string $text | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function addBodyText($text); | |||
@@ -86,6 +94,8 @@ interface IEMailTemplate { | |||
* @param string $urlLeft URL of left button | |||
* @param string $textRight Text of right button | |||
* @param string $urlRight URL of right button | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight); | |||
@@ -93,6 +103,8 @@ interface IEMailTemplate { | |||
* Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email | |||
* | |||
* @param string $text | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function addFooter($text = ''); | |||
@@ -100,6 +112,8 @@ interface IEMailTemplate { | |||
* Returns the rendered HTML email as string | |||
* | |||
* @return string | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function renderHTML(); | |||
@@ -107,6 +121,8 @@ interface IEMailTemplate { | |||
* Returns the rendered plain text email as string | |||
* | |||
* @return string | |||
* | |||
* @since 12.0.0 | |||
*/ | |||
public function renderText(); | |||
} |
@@ -54,6 +54,14 @@ interface IMailer { | |||
*/ | |||
public function createMessage(); | |||
/** | |||
* Creates a new email template object | |||
* | |||
* @return IEMailTemplate | |||
* @since 12.0.0 | |||
*/ | |||
public function createEMailTemplate(); | |||
/** | |||
* Send the specified message. Also sets the from address to the value defined in config.php | |||
* if no-one has been passed. |
@@ -8,32 +8,44 @@ | |||
namespace Test\Mail; | |||
use OC\Mail\EMailTemplate; | |||
use OC\Mail\Mailer; | |||
use OCP\Defaults; | |||
use OCP\IConfig; | |||
use OCP\IL10N; | |||
use OCP\ILogger; | |||
use OCP\IURLGenerator; | |||
use Test\TestCase; | |||
class MailerTest extends TestCase { | |||
/** @var IConfig */ | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $config; | |||
/** @var Defaults */ | |||
/** @var Defaults|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $defaults; | |||
/** @var ILogger */ | |||
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $logger; | |||
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $urlGenerator; | |||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $l10n; | |||
/** @var Mailer */ | |||
private $mailer; | |||
function setUp() { | |||
public function setUp() { | |||
parent::setUp(); | |||
$this->config = $this->getMockBuilder('\OCP\IConfig') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->defaults = $this->getMockBuilder('\OCP\Defaults') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->logger = $this->getMockBuilder('\OCP\ILogger') | |||
->disableOriginalConstructor()->getMock(); | |||
$this->mailer = new Mailer($this->config, $this->logger, $this->defaults); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->defaults = $this->createMock(Defaults::class); | |||
$this->logger = $this->createMock(ILogger::class); | |||
$this->urlGenerator = $this->createMock(IURLGenerator::class); | |||
$this->l10n = $this->createMock(IL10N::class); | |||
$this->mailer = new Mailer( | |||
$this->config, | |||
$this->logger, | |||
$this->defaults, | |||
$this->urlGenerator, | |||
$this->l10n | |||
); | |||
} | |||
public function testGetMailInstance() { | |||
@@ -120,4 +132,7 @@ class MailerTest extends TestCase { | |||
$this->assertSame($expected, $this->mailer->validateMailAddress($email)); | |||
} | |||
public function testCreateEMailTemplate() { | |||
$this->assertSame(EMailTemplate::class, get_class($this->mailer->createEMailTemplate())); | |||
} | |||
} |