Merge branch '5.8' into 5

This commit is contained in:
Maxime Rainville 2021-04-14 11:30:53 +12:00
commit a917fbe2ea
5 changed files with 36 additions and 5 deletions

View File

@ -345,6 +345,8 @@ JS
// Add specific template data for the current recipient
$emailData['HideFormData'] = (bool) $recipient->HideFormData;
// Include any parsed merge field references from the CMS editor - this is already escaped
// This string substitution works for both HTML and plain text emails.
// $recipient->getEmailBodyContent() will retrieve the relevant version of the email
$emailData['Body'] = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
// Push the template data to the Email's data
@ -414,7 +416,8 @@ JS
$this->extend('updateEmail', $email, $recipient, $emailData);
if ((bool)$recipient->SendPlain) {
$body = strip_tags($recipient->getEmailBodyContent()) . "\n";
// decode previously encoded html tags because the email is being sent as text/plain
$body = html_entity_decode($emailData['Body']) . "\n";
if (isset($emailData['Fields']) && !$emailData['HideFormData']) {
foreach ($emailData['Fields'] as $field) {
if ($field instanceof SubmittedFileField) {

View File

@ -1 +1 @@
<textarea $AttributesHTML<% if $RightTitle %> aria-describedby="{$Name}_right_title"<% end_if %>>$Value</textarea>
<textarea $AttributesHTML<% if $RightTitle %> aria-describedby="{$Name}_right_title"<% end_if %>>$Value.HTMLATT</textarea>

View File

@ -68,16 +68,18 @@ class UserDefinedFormControllerTest extends FunctionalTest
// load the form
$this->get($form->URLSegment);
/** @var EditableTextField $field */
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
$data = [$field->Name => 'Basic Value <b>HTML</b>'];
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, $data);
// should have a submitted form field now
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
$this->assertListAllMatch(
[
'Name' => 'basic_text_name',
'Value' => 'Basic Value',
'Value' => 'Basic Value <b>HTML</b>',
'Title' => 'Basic Text Field'
],
$submitted
@ -93,8 +95,12 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
// submitted html tags are escaped for the html value
$value = 'class="readonly">My body html Basic Value &lt;b&gt;HTML&lt;/b&gt;</span>';
$this->assertTrue(strpos($email['Content'], $value) !== false, 'Email contains the merge field value');
$value = $parser->getBySelector('dd');
$this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
$this->assertEquals('Basic Value <b>HTML</b>', (string) $value[0], 'Email contains the value');
// no html
$this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
@ -102,6 +108,10 @@ class UserDefinedFormControllerTest extends FunctionalTest
$this->assertContains('Basic Text Field: Basic Value', $nohtml['Content'], 'Email contains no html');
// submitted html tags are not escaped because the email is being sent as text/plain
$value = 'My body text Basic Value <b>HTML</b>';
$this->assertContains($value, $nohtml['Content'], 'Email contains the merge field value');
// no data
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
$nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');

View File

@ -5,6 +5,7 @@ namespace SilverStripe\UserForms\Tests\Model\Recipient;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
use SilverStripe\UserForms\Model\UserDefinedForm;
class EmailRecipientTest extends SapphireTest
{
@ -50,4 +51,19 @@ class EmailRecipientTest extends SapphireTest
$this->assertSame('test2@example.com', $recipient->EmailFrom);
$this->assertSame('test3@example.com', $recipient->EmailReplyTo);
}
public function testGetEmailTemplateDropdownValues()
{
$form = new UserDefinedForm();
$form->write();
$recipient = new EmailRecipient();
$recipient->FormID = $form->ID;
$recipient->FormClass = UserDefinedForm::class;
$ds = DIRECTORY_SEPARATOR;
$expected = [
"email{$ds}SubmittedFormEmail" => 'SubmittedFormEmail',
"email{$ds}SubmittedFormEmailPlain" => 'SubmittedFormEmailPlain'
];
$this->assertSame($expected, $recipient->getEmailTemplateDropdownValues());
}
}

View File

@ -317,12 +317,14 @@ SilverStripe\UserForms\Model\Recipient\EmailRecipient:
EmailAddress: test@example.com
EmailSubject: Email Subject
EmailFrom: no-reply@example.com
EmailBodyHtml: '<div class="form__field-holder"><span id="Form_ItemEditForm_MergeField" class="readonly">My body html $basic_text_name</span></div>'
no-html:
EmailAddress: nohtml@example.com
EmailSubject: Email Subject
EmailFrom: no-reply@example.com
SendPlain: true
EmailBody: 'My body text $basic_text_name'
no-data:
EmailAddress: nodata@example.com