diff --git a/lib/Cron/Workers/StatsNotifications/Worker.php b/lib/Cron/Workers/StatsNotifications/Worker.php index cafded0bf2..3a216dfff7 100644 --- a/lib/Cron/Workers/StatsNotifications/Worker.php +++ b/lib/Cron/Workers/StatsNotifications/Worker.php @@ -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), 'body' => [ 'html' => $this->renderer->render('emails/statsNotification.html', $context), + 'text' => $this->renderer->render('emails/statsNotification.txt', $context), ], ]; } diff --git a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php index c34e1d22c9..7adfb0f3ff 100644 --- a/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php +++ b/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php @@ -119,22 +119,24 @@ class WorkerTest extends \MailPoetTest { } function testRendersTemplate() { - $this->renderer->expects($this->once()) - ->method('render') - ->with( - $this->stringContains('statsNotification.html'), - $this->callback(function($context){ - return is_array($context); - })); + $this->renderer->expects($this->exactly(2)) + ->method('render'); + $this->renderer->expects($this->at(0)) + ->method('render') + ->with($this->equalTo('emails/statsNotification.html')); + + $this->renderer->expects($this->at(1)) + ->method('render') + ->with($this->equalTo('emails/statsNotification.txt')); $this->stats_notifications->process(); } function testAddsSubjectToContext() { - $this->renderer->expects($this->once()) + $this->renderer->expects($this->exactly(2)) // html + text template ->method('render') ->with( - $this->stringContains('statsNotification.html'), + $this->anything(), $this->callback(function($context){ return $context['subject'] === 'Email Subject1'; })); @@ -143,10 +145,10 @@ class WorkerTest extends \MailPoetTest { } function testAddsPreHeaderToContext() { - $this->renderer->expects($this->once()) + $this->renderer->expects($this->exactly(2)) // html + text template ->method('render') ->with( - $this->stringContains('statsNotification.html'), + $this->anything(), $this->callback(function($context){ 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() { - $this->renderer->expects($this->once()) + $this->renderer->expects($this->exactly(2)) // html + text template ->method('render') ->with( - $this->stringContains('statsNotification.html'), + $this->anything(), $this->callback(function($context){ return strpos($context['linkSettings'], 'mailpoet-settings') && strpos($context['linkStats'], 'mailpoet-newsletters#/stats'); @@ -168,10 +170,10 @@ class WorkerTest extends \MailPoetTest { } function testAddsLinksToContext() { - $this->renderer->expects($this->once()) + $this->renderer->expects($this->exactly(2)) // html + text template ->method('render') ->with( - $this->stringContains('statsNotification.html'), + $this->anything(), $this->callback(function($context){ return ($context['topLink'] === 'Link url2') && ($context['topLinkClicks'] === 2); diff --git a/views/emails/statsNotification.txt b/views/emails/statsNotification.txt new file mode 100644 index 0000000000..5a595a7596 --- /dev/null +++ b/views/emails/statsNotification.txt @@ -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 %>