mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
add proper fallbacks to cover tests
This commit is contained in:
parent
8c34519644
commit
0f6efea12a
@ -346,6 +346,8 @@ JS
|
||||
|
||||
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
||||
$email->setTo(explode(',', $submittedFormField->Value));
|
||||
} else {
|
||||
$email->setTo(explode(',', $recipient->EmailAddress));
|
||||
}
|
||||
} else {
|
||||
$email->setTo(explode(',', $recipient->EmailAddress));
|
||||
@ -357,6 +359,8 @@ JS
|
||||
|
||||
if ($submittedFormField && trim($submittedFormField->Value)) {
|
||||
$email->setSubject($submittedFormField->Value);
|
||||
} else {
|
||||
$email->setSubject($recipient->EmailSubject);
|
||||
}
|
||||
} else {
|
||||
$email->setSubject($recipient->EmailSubject);
|
||||
|
@ -222,7 +222,7 @@ class UserForm extends Form
|
||||
|
||||
foreach ($this->getController()->data()->EmailRecipients() as $recipient) {
|
||||
foreach ($recipientFieldsMap as $textField => $dynamicFormField) {
|
||||
if (empty($recipient->$textField) && $recipient->getComponent($dynamicFormField)) {
|
||||
if (empty($recipient->$textField) && $recipient->getComponent($dynamicFormField)->exists()) {
|
||||
$requiredFields[] = $recipient->getComponent($dynamicFormField)->Name;
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ class EmailRecipient extends DataObject
|
||||
}
|
||||
|
||||
// if there is no from address and no fallback, you'll have errors if this isn't defined
|
||||
if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin)_email'))) {
|
||||
if (!$this->EmailFrom && empty(Email::getSendAllEmailsFrom()) && empty(Email::config()->get('admin_email'))) {
|
||||
$result->addError(_t(__CLASS__.".EMAILFROMREQUIRED", '"Email From" address is required'));
|
||||
}
|
||||
return $result;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\UserForms\Tests\Model;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Email\Email;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
@ -34,6 +35,12 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
UserDefinedForm::class => [UserFormFieldEditorExtension::class],
|
||||
];
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Email::config()->update('admin_email', 'no-reply@example.com');
|
||||
}
|
||||
|
||||
public function testRollbackToVersion()
|
||||
{
|
||||
$this->markTestSkipped(
|
||||
@ -70,10 +77,10 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
|
||||
$fields = $form->getCMSFields();
|
||||
|
||||
$this->assertTrue($fields->dataFieldByName('Fields') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('EmailRecipients') != null);
|
||||
$this->assertTrue($fields->dataFieldByName('Submissions') != null);
|
||||
$this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null);
|
||||
$this->assertNotNull($fields->dataFieldByName('Fields'));
|
||||
$this->assertNotNull($fields->dataFieldByName('EmailRecipients'));
|
||||
$this->assertNotNull($fields->dataFieldByName('Submissions'));
|
||||
$this->assertNotNull($fields->dataFieldByName('OnCompleteMessage'));
|
||||
}
|
||||
|
||||
|
||||
@ -107,12 +114,12 @@ class UserDefinedFormTest extends FunctionalTest
|
||||
|
||||
$fields = $popup->getCMSFields();
|
||||
|
||||
$this->assertTrue($fields->dataFieldByName('EmailSubject') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('EmailFrom') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('EmailAddress') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('HideFormData') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('SendPlain') !== null);
|
||||
$this->assertTrue($fields->dataFieldByName('EmailBody') !== null);
|
||||
$this->assertNotNull($fields->dataFieldByName('EmailSubject'));
|
||||
$this->assertNotNull($fields->dataFieldByName('EmailFrom'));
|
||||
$this->assertNotNull($fields->dataFieldByName('EmailAddress'));
|
||||
$this->assertNotNull($fields->dataFieldByName('HideFormData'));
|
||||
$this->assertNotNull($fields->dataFieldByName('SendPlain'));
|
||||
$this->assertNotNull($fields->dataFieldByName('EmailBody'));
|
||||
|
||||
// add an email field, it should now add a or from X address picker
|
||||
$email = $this->objFromFixture(EditableEmailField::class, 'email-field');
|
||||
|
Loading…
Reference in New Issue
Block a user