FIX Ensure HTML email preview content is parsed as HTML including shortcodes

This commit is contained in:
Robbie Averill 2017-06-09 10:38:49 +12:00
parent 802c750a77
commit bf20e19285
3 changed files with 35 additions and 4 deletions

View File

@ -221,7 +221,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
'The email address which the recipient is able to \'reply\' to.'
))
));
$fields->fieldByName('Root.EmailDetails')->setTitle(_t('UserDefinedForm_EmailRecipient.EMAILDETAILSTAB', 'Email Details'));
// Only show the preview link if the recipient has been saved.
@ -263,7 +263,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
'<div id="EmailPreview" class="field toggle-html-only">' . $preview . '</div>'
)
));
$fields->fieldByName('Root.EmailContent')->setTitle(_t('UserDefinedForm_EmailRecipient.EMAILCONTENTTAB', 'Email Content'));
// Custom rules for sending this field
@ -288,7 +288,7 @@ class UserDefinedForm_EmailRecipient extends DataObject
),
$grid
));
$fields->fieldByName('Root.CustomRules')->setTitle(_t('UserDefinedForm_EmailRecipient.CUSTOMRULESTAB', 'Custom Rules'));
$this->extend('updateCMSFields', $fields);
@ -417,7 +417,10 @@ class UserDefinedForm_EmailRecipient extends DataObject
*/
public function getEmailBodyContent()
{
return $this->SendPlain ? $this->EmailBody : $this->EmailBodyHtml;
if ($this->SendPlain) {
return DBField::create_field('HTMLText', $this->EmailBody)->NoHTML();
}
return DBField::create_field('HTMLText', $this->EmailBodyHtml)->RAW();
}
/**

View File

@ -0,0 +1,24 @@
<?php
class UserDefinedForm_EmailRecipientTest extends SapphireTest
{
protected static $fixture_file = 'UserDefinedForm_EmailRecipientTest.yml';
public function testShortcodesAreRenderedInEmailPreviewContent()
{
$page = $this->objFromFixture('SiteTree', 'about_us');
$recipient = UserDefinedForm_EmailRecipient::create();
$recipient->SendPlain = false;
$recipient->EmailBodyHtml = '<p>Some email content. About us: [sitetree_link,id=' . $page->ID . '].</p>';
$result = $recipient->getEmailBodyContent();
$this->assertContains('/about-us/', $result);
$recipient->SendPlain = true;
$recipient->EmailBody = 'Some email content. About us: [sitetree_link,id=' . $page->ID . '].';
$result = $recipient->getEmailBodyContent();
$this->assertContains('/about-us/', $result);
}
}

View File

@ -0,0 +1,4 @@
SiteTree:
about_us:
Title: About Us
URLSegment: about-us