Ensure that unsubscribe link is always saved before sending

[MAILPOET-2245]
This commit is contained in:
Rostislav Wolny
2019-09-30 15:38:08 +02:00
committed by Jack Kitterhing
parent 028c5e6de5
commit 44c6e5db91
2 changed files with 16 additions and 0 deletions

View File

@ -23,6 +23,7 @@ class Links {
// join HTML and TEXT rendered body into a text string
$content = Helpers::joinObject($rendered_newsletter);
list($content, $links) = NewsletterLinks::process($content, $newsletter_id, $queue_id);
$links = NewsletterLinks::ensureUnsubscribeLink($links);
// split the processed body with hashed links back to HTML and TEXT
list($rendered_newsletter['html'], $rendered_newsletter['text'])
= Helpers::splitObject($content);

View File

@ -53,6 +53,21 @@ class LinksTest extends \MailPoetTest {
expect($result['html'])->contains($newsletter_link->hash);
}
function testItCanEnsureThatUnsubscribeLinkIsAlwaysPresent() {
$newsletter = Newsletter::create();
$newsletter->type = Newsletter::TYPE_STANDARD;
$newsletter->save();
$rendered_newsletter = [
'html' => '<a href="http://example.com">Example Link</a>',
'text' => '<a href="http://example.com">Example Link</a>',
];
$queue = (object)['id' => 2];
Links::process($rendered_newsletter, $newsletter, $queue);
$unsubscribe_count = NewsletterLink::where('newsletter_id', $newsletter->id)
->where('url', NewsletterLink::UNSUBSCRIBE_LINK_SHORT_CODE)->count();
expect($unsubscribe_count)->equals(1);
}
function _after() {
\ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
\ORM::raw_execute('TRUNCATE ' . NewsletterLink::$_table);