Skip to content

Commit

Permalink
FIX Ensure HTML email preview content is parsed as HTML including sho…
Browse files Browse the repository at this point in the history
…rtcodes
  • Loading branch information
robbieaverill committed Jun 12, 2017
1 parent 802c750 commit bf20e19
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
11 changes: 7 additions & 4 deletions code/model/recipients/UserDefinedForm_EmailRecipient.php
Expand Up @@ -221,7 +221,7 @@ public function getCMSFields()
'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.
Expand Down Expand Up @@ -263,7 +263,7 @@ public function getCMSFields()
'<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
Expand All @@ -288,7 +288,7 @@ public function getCMSFields()
),
$grid
));

$fields->fieldByName('Root.CustomRules')->setTitle(_t('UserDefinedForm_EmailRecipient.CUSTOMRULESTAB', 'Custom Rules'));

$this->extend('updateCMSFields', $fields);
Expand Down Expand Up @@ -417,7 +417,10 @@ public function emailTemplateExists($template = '')
*/
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();
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/model/recipients/UserDefinedForm_EmailRecipientTest.php
@@ -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);
}
}
4 changes: 4 additions & 0 deletions tests/model/recipients/UserDefinedForm_EmailRecipientTest.yml
@@ -0,0 +1,4 @@
SiteTree:
about_us:
Title: About Us
URLSegment: about-us

0 comments on commit bf20e19

Please sign in to comment.