2017-06-09 00:38:49 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-22 02:15:22 +02:00
|
|
|
namespace SilverStripe\UserForms\Tests\Model\Recipient;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
2021-02-21 09:53:36 +01:00
|
|
|
use SilverStripe\UserForms\Model\UserDefinedForm;
|
2017-08-22 02:15:22 +02:00
|
|
|
|
|
|
|
class EmailRecipientTest extends SapphireTest
|
2017-06-09 00:38:49 +02:00
|
|
|
{
|
2017-08-22 02:15:22 +02:00
|
|
|
protected static $fixture_file = 'EmailRecipientTest.yml';
|
2017-06-09 00:38:49 +02:00
|
|
|
|
|
|
|
public function testShortcodesAreRenderedInEmailPreviewContent()
|
|
|
|
{
|
2017-08-22 02:15:22 +02:00
|
|
|
$page = $this->objFromFixture(SiteTree::class, 'about_us');
|
2017-06-09 00:38:49 +02:00
|
|
|
|
2017-08-22 02:15:22 +02:00
|
|
|
$recipient = EmailRecipient::create();
|
2017-06-09 00:38:49 +02:00
|
|
|
$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);
|
|
|
|
}
|
2019-05-03 05:55:59 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-17 05:51:11 +02:00
|
|
|
* @expectedException \SilverStripe\ORM\ValidationException
|
2019-05-03 05:55:59 +02:00
|
|
|
* @expectedExceptionMessage "Send email to" address or field is required
|
|
|
|
*/
|
|
|
|
public function testEmptyRecipientFailsValidation()
|
|
|
|
{
|
|
|
|
$recipient = new EmailRecipient();
|
|
|
|
$recipient->EmailFrom = 'test@example.com';
|
|
|
|
$recipient->write();
|
|
|
|
}
|
2020-07-14 06:41:36 +02:00
|
|
|
|
|
|
|
public function testEmailAddressesTrimmed()
|
|
|
|
{
|
|
|
|
$recipient = new EmailRecipient();
|
|
|
|
$recipient->EmailAddress = 'test1@example.com ';
|
|
|
|
$recipient->EmailFrom = 'test2@example.com ';
|
|
|
|
$recipient->EmailReplyTo = 'test3@example.com ';
|
|
|
|
$recipient->write();
|
|
|
|
$this->assertSame('test1@example.com', $recipient->EmailAddress);
|
|
|
|
$this->assertSame('test2@example.com', $recipient->EmailFrom);
|
|
|
|
$this->assertSame('test3@example.com', $recipient->EmailReplyTo);
|
|
|
|
}
|
2021-02-21 09:53:36 +01:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2017-06-09 00:38:49 +02:00
|
|
|
}
|