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;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2017-06-09 00:38:49 +02:00
|
|
|
}
|