This commit is contained in:
Julio Cesar Laura Avendaño
2019-06-27 11:29:48 -04:00
parent a15f6273ef
commit 4207ec18c5
2 changed files with 127 additions and 21 deletions

View File

@@ -0,0 +1,68 @@
<?php
use Faker\Factory;
use Tests\TestCase;
class SpoolRunTest extends TestCase
{
/**
* Constructor of the class.
*/
function __construct()
{
}
/**
* Check if "envelope_cc" and "envelope_bcc" was set correctly in consecutive calls
*
* @covers SpoolRun::setData()
*
* @test
*/
public function it_should_check_if_cc_and_bcc_set_correctly_in_consecutive_calls()
{
// Initializing Faker instance
$faker = Factory::create();
// Instancing SpoolRun class
$spoolRun = new SpoolRun();
// Set a first set of data
$spoolRun->setData(
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
// Build the "to", "cc" an "bcc" values
$spoolRun->runHandleEnvelopeTo();
// Set a second set of data
$spoolRun->setData(
G::generateUniqueID(),
$faker->words(3, true),
$faker->companyEmail,
$faker->freeEmail,
$faker->text(),
$faker->dateTime()->format('Y-m-d H:i:s'),
$faker->companyEmail,
$faker->freeEmail
);
// Build the "to", "cc" an "bcc" values
$spoolRun->runHandleEnvelopeTo();
// Get data to check
$fileData = $spoolRun->getFileData();
// Asserts
$this->assertCount(1, $fileData['envelope_to']);
$this->assertCount(1, $fileData['envelope_cc']);
$this->assertCount(1, $fileData['envelope_bcc']);
}
}

View File

@@ -91,6 +91,16 @@ class SpoolRun
$this->appMsgUid = $v;
}
/**
* Get the fileData property
*
* @return array
*/
public function getFileData()
{
return $this->fileData;
}
/**
* get all files into spool in a list
*
@@ -212,32 +222,52 @@ class SpoolRun
}
/**
* set email parameters
* Set email parameters
*
* @param string $sAppMsgUid , $sSubject, $sFrom, $sTo, $sBody, $sDate, $sCC, $sBCC, $sTemplate
* @return none
* @param string $appMsgUid
* @param string $subject
* @param string $from
* @param string $to
* @param string $body
* @param string $date
* @param string $cc
* @param string $bcc
* @param string $template
* @param array $attachments
* @param bool $contentTypeIsHtml
* @param string $error
*
* @see SpoolRun->create()
* @see SpoolRun->resendEmails()
*/
public function setData($sAppMsgUid, $sSubject, $sFrom, $sTo, $sBody, $sDate = "", $sCC = "", $sBCC = "", $sTemplate = "", $aAttachment = array(), $bContentTypeIsHtml = true, $sError = "")
public function setData($appMsgUid, $subject, $from, $to, $body, $date = '', $cc = '', $bcc = '', $template = '', $attachments = [],
$contentTypeIsHtml = true, $error = '')
{
$this->spoolId = $sAppMsgUid;
$this->fileData['subject'] = $sSubject;
$this->fileData['from'] = $sFrom;
$this->fileData['to'] = $sTo;
$this->fileData['body'] = $sBody;
$this->fileData['date'] = ($sDate != '' ? $sDate : date('Y-m-d H:i:s'));
$this->fileData['cc'] = $sCC;
$this->fileData['bcc'] = $sBCC;
$this->fileData['template'] = $sTemplate;
$this->fileData['attachments'] = $aAttachment;
$this->fileData['envelope_to'] = array();
$this->fileData["contentTypeIsHtml"] = $bContentTypeIsHtml;
$this->fileData["error"] = $sError;
// Fill "fileData" property
$this->spoolId = $appMsgUid;
$this->fileData['subject'] = $subject;
$this->fileData['from'] = $from;
$this->fileData['to'] = $to;
$this->fileData['body'] = $body;
$this->fileData['date'] = (!empty($date) ? $date : date('Y-m-d H:i:s'));
$this->fileData['cc'] = $cc;
$this->fileData['bcc'] = $bcc;
$this->fileData['template'] = $template;
$this->fileData['attachments'] = $attachments;
$this->fileData["contentTypeIsHtml"] = $contentTypeIsHtml;
$this->fileData["error"] = $error;
// Initialize some values used internally
$this->fileData['envelope_to'] = [];
$this->fileData['envelope_cc'] = [];
$this->fileData['envelope_bcc'] = [];
// Domain validation when the email engine is "OpenMail"
if (array_key_exists('MESS_ENGINE', $this->config)) {
if ($this->config['MESS_ENGINE'] == 'OPENMAIL') {
if ($this->config['MESS_SERVER'] != '') {
if (($sAux = @gethostbyaddr($this->config['MESS_SERVER']))) {
$this->fileData['domain'] = $sAux;
if ($this->config['MESS_ENGINE'] === 'OPENMAIL') {
if (!empty($this->config['MESS_SERVER'])) {
if (($domain = @gethostbyaddr($this->config['MESS_SERVER']))) {
$this->fileData['domain'] = $domain;
} else {
$this->fileData['domain'] = $this->config['MESS_SERVER'];
}
@@ -818,4 +848,12 @@ class SpoolRun
return $appMsgUid;
}
/**
* Run the private method "handleEnvelopeTo", this method was created in order to use in the unit tests
*/
public function runHandleEnvelopeTo()
{
$this->handleEnvelopeTo();
}
}