FIX Cast template values as array, include list in CMS fields for recipients

This commit is contained in:
Robbie Averill 2017-12-04 23:42:58 +13:00
parent e82dc5f121
commit 262510a450
2 changed files with 13 additions and 7 deletions

View File

@ -369,7 +369,8 @@ class EmailRecipient extends DataObject
$fields->insertBefore(
DropdownField::create(
'EmailTemplate',
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILTEMPLATE', 'Email template')
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.EMAILTEMPLATE', 'Email template'),
$templates
)->addExtraClass('toggle-html-only'),
'EmailBodyHtml'
);
@ -527,7 +528,7 @@ class EmailRecipient extends DataObject
{
$t = ($template ? $template : $this->EmailTemplate);
return array_key_exists($t, $this->getEmailTemplateDropdownValues());
return array_key_exists($t, (array) $this->getEmailTemplateDropdownValues());
}
/**

View File

@ -158,16 +158,22 @@ class UserDefinedFormTest extends FunctionalTest
public function testGetEmailTemplateDropdownValues()
{
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$recipient = new EmailRecipient();
$recipient->FormID = $page->ID;
$defaultValues = ['email/SubmittedFormEmail' => 'SubmittedFormEmail'];
$result = $recipient->getEmailTemplateDropdownValues();
$this->assertEquals($recipient->getEmailTemplateDropdownValues(), $defaultValues);
// Installation path can be as a project when testing in Travis, so check partial match
$this->assertContains('templates/email/SubmittedFormEmail', key($result));
$this->assertSame('SubmittedFormEmail', current($result));
}
public function testEmailTemplateExists()
{
$page = $this->objFromFixture(UserDefinedForm::class, 'basic-form-page');
$recipient = new EmailRecipient();
$recipient->FormID = $page->ID;
// Set the default template
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues()));
@ -192,10 +198,9 @@ class UserDefinedFormTest extends FunctionalTest
$this->assertTrue($recipient->canDelete());
}
$member = Member::currentUser();
$member->logOut();
$this->logOut();
$this->logInWithPermission('SITETREE_VIEW_ALL');
foreach ($form->EmailRecipients() as $recipient) {
$this->assertFalse($recipient->canEdit());
$this->assertFalse($recipient->canDelete());