Created email senders and integration tests for these senders
parent
2a145bfa3e
commit
54baa4d6ba
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Emails;
|
||||||
|
|
||||||
|
use BusinessLogic\IntegrationTestCaseBase;
|
||||||
|
use BusinessLogic\Tickets\Attachment;
|
||||||
|
|
||||||
|
class MailgunEmailSenderIntegrationTest extends IntegrationTestCaseBase {
|
||||||
|
/**
|
||||||
|
* @var $emailSender MailgunEmailSender;
|
||||||
|
*/
|
||||||
|
private $emailSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $heskSettings array
|
||||||
|
*/
|
||||||
|
private $heskSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $modsForHeskSettings array
|
||||||
|
*/
|
||||||
|
private $modsForHeskSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $attachmentsToPurge string[]
|
||||||
|
*/
|
||||||
|
private $attachmentsToPurge;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
global $hesk_settings, $modsForHesk_settings;
|
||||||
|
|
||||||
|
$this->skip();
|
||||||
|
|
||||||
|
if (!defined('IN_SCRIPT')) {
|
||||||
|
define('IN_SCRIPT', 1);
|
||||||
|
}
|
||||||
|
require(__DIR__ . '/../../../../hesk_settings.inc.php');
|
||||||
|
require(__DIR__ . '/../../integration_test_mfh_settings.php');
|
||||||
|
|
||||||
|
$this->emailSender = new MailgunEmailSender();
|
||||||
|
$this->heskSettings = $hesk_settings;
|
||||||
|
$this->modsForHeskSettings = $modsForHesk_settings;
|
||||||
|
$this->attachmentsToPurge = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown() {
|
||||||
|
foreach ($this->attachmentsToPurge as $file) {
|
||||||
|
unlink($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSendMail() {
|
||||||
|
//-- Arrange
|
||||||
|
$emailBuilder = new EmailBuilder();
|
||||||
|
$emailBuilder->to = array('mfh1@mailinator.com');
|
||||||
|
$emailBuilder->cc = array('mfh2@mailinator.com');
|
||||||
|
$emailBuilder->bcc = array('mfh3@mailinator.com');
|
||||||
|
$emailBuilder->message = "Test PLAIN TEXT message";
|
||||||
|
$emailBuilder->htmlMessage = "Test <b>HTML</b> <i>message</i>";
|
||||||
|
$emailBuilder->subject = "MailgunEmailSenderIntegrationTest";
|
||||||
|
|
||||||
|
// Uncomment to test attachments.
|
||||||
|
$attachment = new Attachment();
|
||||||
|
$attachment->id = 1;
|
||||||
|
$attachment->fileName = "file.txt";
|
||||||
|
$attachment->savedName = "test1.txt";
|
||||||
|
$filename1 = __DIR__ . '/../../../../' . $this->heskSettings['attach_dir'] . '/' . $attachment->savedName;
|
||||||
|
file_put_contents($filename1, 'TEST DATA');
|
||||||
|
|
||||||
|
$otherAttachment = new Attachment();
|
||||||
|
$otherAttachment->id = 2;
|
||||||
|
$otherAttachment->fileName = "file2.txt";
|
||||||
|
$otherAttachment->savedName = "test2.txt";
|
||||||
|
$filename2 = __DIR__ . '/../../../../' . $this->heskSettings['attach_dir'] . '/' . $otherAttachment->savedName;
|
||||||
|
file_put_contents($filename2, 'TEST DATA 2');
|
||||||
|
|
||||||
|
$emailBuilder->attachments = array($attachment, $otherAttachment);
|
||||||
|
$this->attachmentsToPurge = array($filename1, $filename2);
|
||||||
|
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->emailSender->sendEmail($emailBuilder, $this->heskSettings, $this->modsForHeskSettings, true);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
if ($result !== true) {
|
||||||
|
$this->fail($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSendPlaintextMail() {
|
||||||
|
//-- Arrange
|
||||||
|
//$hesk_settings['smtp'] = 0 //Uncomment this to use PHPMail
|
||||||
|
$emailBuilder = new EmailBuilder();
|
||||||
|
$emailBuilder->to = array('mfh1@mailinator.com');
|
||||||
|
$emailBuilder->cc = array('mfh2@mailinator.com');
|
||||||
|
$emailBuilder->bcc = array('mfh3@mailinator.com');
|
||||||
|
$emailBuilder->message = "Test PLAIN TEXT message";
|
||||||
|
$emailBuilder->subject = "MailgunEmailSenderIntegrationTest";
|
||||||
|
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->emailSender->sendEmail($emailBuilder, $this->heskSettings, $this->modsForHeskSettings, false);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
if ($result !== true) {
|
||||||
|
$this->fail($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace BusinessLogic;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class IntegrationTestCaseBase extends TestCase {
|
||||||
|
function skip() {
|
||||||
|
$this->markTestSkipped(sprintf("Skipping Integration Test %s", get_class($this)));
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once(__DIR__ . '/BusinessLogic/IntegrationTestCaseBase.php');
|
||||||
require_once(__DIR__ . '/../bootstrap.php');
|
require_once(__DIR__ . '/../bootstrap.php');
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue