Add text template

[MAILPOET-1571]
This commit is contained in:
Pavel Dohnal
2019-01-28 14:16:43 +01:00
parent 3eb640597b
commit d7db761f73
3 changed files with 58 additions and 15 deletions

View File

@@ -84,6 +84,7 @@ class Worker {
'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $newsletter->subject), 'subject' => sprintf(_x('Stats for email %s', 'title of an automatic email containing statistics (newsletter open rate, click rate, etc)', 'mailpoet'), $newsletter->subject),
'body' => [ 'body' => [
'html' => $this->renderer->render('emails/statsNotification.html', $context), 'html' => $this->renderer->render('emails/statsNotification.html', $context),
'text' => $this->renderer->render('emails/statsNotification.txt', $context),
], ],
]; ];
} }

View File

@@ -119,22 +119,24 @@ class WorkerTest extends \MailPoetTest {
} }
function testRendersTemplate() { function testRendersTemplate() {
$this->renderer->expects($this->once()) $this->renderer->expects($this->exactly(2))
->method('render') ->method('render');
->with( $this->renderer->expects($this->at(0))
$this->stringContains('statsNotification.html'), ->method('render')
$this->callback(function($context){ ->with($this->equalTo('emails/statsNotification.html'));
return is_array($context);
})); $this->renderer->expects($this->at(1))
->method('render')
->with($this->equalTo('emails/statsNotification.txt'));
$this->stats_notifications->process(); $this->stats_notifications->process();
} }
function testAddsSubjectToContext() { function testAddsSubjectToContext() {
$this->renderer->expects($this->once()) $this->renderer->expects($this->exactly(2)) // html + text template
->method('render') ->method('render')
->with( ->with(
$this->stringContains('statsNotification.html'), $this->anything(),
$this->callback(function($context){ $this->callback(function($context){
return $context['subject'] === 'Email Subject1'; return $context['subject'] === 'Email Subject1';
})); }));
@@ -143,10 +145,10 @@ class WorkerTest extends \MailPoetTest {
} }
function testAddsPreHeaderToContext() { function testAddsPreHeaderToContext() {
$this->renderer->expects($this->once()) $this->renderer->expects($this->exactly(2)) // html + text template
->method('render') ->method('render')
->with( ->with(
$this->stringContains('statsNotification.html'), $this->anything(),
$this->callback(function($context){ $this->callback(function($context){
return $context['preheader'] === '40.00% opens, 60.00% clicks, 20.00% unsubscribes in a nutshell.'; return $context['preheader'] === '40.00% opens, 60.00% clicks, 20.00% unsubscribes in a nutshell.';
})); }));
@@ -155,10 +157,10 @@ class WorkerTest extends \MailPoetTest {
} }
function testAddsWPUrlsToContext() { function testAddsWPUrlsToContext() {
$this->renderer->expects($this->once()) $this->renderer->expects($this->exactly(2)) // html + text template
->method('render') ->method('render')
->with( ->with(
$this->stringContains('statsNotification.html'), $this->anything(),
$this->callback(function($context){ $this->callback(function($context){
return strpos($context['linkSettings'], 'mailpoet-settings') return strpos($context['linkSettings'], 'mailpoet-settings')
&& strpos($context['linkStats'], 'mailpoet-newsletters#/stats'); && strpos($context['linkStats'], 'mailpoet-newsletters#/stats');
@@ -168,10 +170,10 @@ class WorkerTest extends \MailPoetTest {
} }
function testAddsLinksToContext() { function testAddsLinksToContext() {
$this->renderer->expects($this->once()) $this->renderer->expects($this->exactly(2)) // html + text template
->method('render') ->method('render')
->with( ->with(
$this->stringContains('statsNotification.html'), $this->anything(),
$this->callback(function($context){ $this->callback(function($context){
return ($context['topLink'] === 'Link url2') return ($context['topLink'] === 'Link url2')
&& ($context['topLinkClicks'] === 2); && ($context['topLinkClicks'] === 2);

View File

@@ -0,0 +1,40 @@
<%= __('Your stats are in!') %>
<%= subject %>
<%= __('open rate') %>: <%= number_format_i18n(opened) %>%
<% if opened > 30 %>
<%= __('EXCELLENT') %>
<% elseif opened > 10 %>
<%= __('GOOD') %>
<% else %>
<%= __('BAD') %>
<% endif %>
<%= __('click rate') %>: <%= number_format_i18n(clicked) %>%
<% if clicked > 3 %>
<%= __('EXCELLENT') %>
<% elseif clicked > 1 %>
<%= __('GOOD') %>
<% else %>
<%= __('BAD') %>
<% endif %>
<% if topLinkClicks > 0 %>
<%= __('Most clicked link') %>
<%= topLink %>
<%= __('%s unique clicks')|replace({'%s': topLinkClicks}) %>
<% endif %>
<% if premiumPluginActive %>
<%= __('View all stats') %>
<%= linkStats %>
<% else %>
<%= __('See Premium features') %>
<%= premiumPage %>
<% endif %>
<%= __('How to improve my open rate?') %> https://mailpoet.com/how-to-improve-open-rates
<%= __('And my click rate?') %> https://mailpoet.com/how-to-improve-click-rates
<%= __('Disable these emails') %> <%= linkSettings %>