mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Show correct fields in email preview
Co-authored-by: Michael Caruana <mikeyc7m@users.noreply.github.com>
This commit is contained in:
parent
ce2fe31bdd
commit
8801790b66
@ -53,16 +53,12 @@ class UserFormRecipientItemRequest extends GridFieldDetailForm_ItemRequest
|
||||
protected function getPreviewFieldData()
|
||||
{
|
||||
$data = ArrayList::create();
|
||||
|
||||
$fields = $this->record->Form()->Fields()->filter(
|
||||
'ClassName:not',
|
||||
[
|
||||
EditableLiteralField::class,
|
||||
EditableFormHeading::class,
|
||||
]
|
||||
);
|
||||
$fields = $this->record->Form()->Fields();
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if (!$field->showInReports()) {
|
||||
continue;
|
||||
}
|
||||
$data->push(ArrayData::create([
|
||||
'Name' => $field->dbObject('Name'),
|
||||
'Title' => $field->dbObject('Title'),
|
||||
|
47
tests/Model/Recipient/UserFormRecipientItemRequestTest.php
Normal file
47
tests/Model/Recipient/UserFormRecipientItemRequestTest.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\UserForms\Tests\Model\Recipient;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\PolymorphicHasManyList;
|
||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||
use SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest;
|
||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||
|
||||
class UserFormRecipientItemRequestTest extends SapphireTest
|
||||
{
|
||||
public function testShowInReportsAffectsPreview()
|
||||
{
|
||||
// classes where showInReports() returns false
|
||||
$namespace = 'SilverStripe\UserForms\Model\EditableFormField';
|
||||
$falseClasses = ['EditableFieldGroup', 'EditableFieldGroupEnd', 'EditableFormStep'];
|
||||
// some classes where showInReports() returns true (inherits from EditableFormField)
|
||||
$trueClasses = ['EditableTextField', 'EditableEmailField', 'EditableDateField'];
|
||||
$form = new UserDefinedForm();
|
||||
$form->write();
|
||||
/** @var PolymorphicHasManyList $fields */
|
||||
$fields = $form->Fields();
|
||||
foreach (array_merge($falseClasses, $trueClasses) as $class) {
|
||||
$fqcn = "$namespace\\$class";
|
||||
$obj = new $fqcn();
|
||||
$obj->Name = 'My' . $class;
|
||||
$obj->write();
|
||||
$fields->add($obj);
|
||||
}
|
||||
$recipient = new EmailRecipient();
|
||||
$recipient->EmailAddress = 'to@example.com';
|
||||
$recipient->EmailFrom = 'from@example.com';
|
||||
$recipient->EmailTemplate = 'email/SubmittedFormEmail';
|
||||
$recipient->Form = $form;
|
||||
$recipient->write();
|
||||
$recipient->setComponent('Form', $form);
|
||||
$request = new UserFormRecipientItemRequest(null, null, $recipient, null, '');
|
||||
$html = $request->preview()->getValue();
|
||||
foreach ($falseClasses as $class) {
|
||||
$this->assertNotContains('My' . $class, $html);
|
||||
}
|
||||
foreach ($trueClasses as $class) {
|
||||
$this->assertContains('My' . $class, $html);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user