mirror of
https://github.com/salesagility/SuiteCRM.git
synced 2025-03-13 04:53:21 +00:00
fixing EmailManTest
This commit is contained in:
parent
bcb3dd8c23
commit
482eb76b9a
3 changed files with 237 additions and 23 deletions
|
@ -183,6 +183,7 @@ class UploadFile
|
|||
* @param string old_id ID of original note
|
||||
* @param string new_id ID of new (copied) note
|
||||
* @param string filename Filename of file (deprecated)
|
||||
* @return boolean TRUE = success, FALSE = failed
|
||||
*/
|
||||
public static function duplicate_file($old_id, $new_id, $file_name)
|
||||
{
|
||||
|
@ -208,9 +209,19 @@ class UploadFile
|
|||
}
|
||||
|
||||
$destination = "upload://$new_id";
|
||||
if (!copy($source, $destination)) {
|
||||
$GLOBALS['log']->error("upload_file could not copy [ {$source} ] to [ {$destination} ]");
|
||||
|
||||
if (is_dir($source)) {
|
||||
LoggerManager::getLogger()->warn('Upload File error: Argument cannot be a directory. Argument was: "' . $source . '"');
|
||||
} else {
|
||||
|
||||
if (!copy($source, $destination)) {
|
||||
$GLOBALS['log']->error("upload_file could not copy [ {$source} ] to [ {$destination} ]");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -405,7 +405,15 @@ class EmailMan extends SugarBean
|
|||
$temp_array = parent::get_list_view_array();
|
||||
|
||||
$related_type = isset($temp_array['RELATED_TYPE']) ? $temp_array['RELATED_TYPE'] : null;
|
||||
$related_id = $temp_array['RELATED_ID'];
|
||||
|
||||
if (!isset($temp_array['RELATED_ID'])) {
|
||||
LoggerManager::getLogger()->warn('EmailMan List view array has not related id for list view data');
|
||||
$tempArrayRelatedId = null;
|
||||
} else {
|
||||
$tempArrayRelatedId = $temp_array['RELATED_ID'];
|
||||
}
|
||||
|
||||
$related_id = $tempArrayRelatedId;
|
||||
$is_person = SugarModule::get($related_type)->moduleImplements('Person');
|
||||
|
||||
if ($is_person) {
|
||||
|
@ -431,7 +439,14 @@ class EmailMan extends SugarBean
|
|||
$temp_array['RECIPIENT_EMAIL'] = $row['email_address'];
|
||||
}
|
||||
|
||||
$this->email1 = $temp_array['RECIPIENT_EMAIL'];
|
||||
if (!isset($temp_array['RECIPIENT_EMAIL'])) {
|
||||
LoggerManager::getLogger()->warn('EmailMan List view array has not recipient email for list view data');
|
||||
$temArrayRecipientEmail = null;
|
||||
} else {
|
||||
$temArrayRecipientEmail = $temp_array['RECIPIENT_EMAIL'];
|
||||
}
|
||||
|
||||
$this->email1 = $temArrayRecipientEmail;
|
||||
$temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
|
||||
|
||||
return $temp_array;
|
||||
|
@ -567,32 +582,67 @@ class EmailMan extends SugarBean
|
|||
$this->ref_email->status = 'sent';
|
||||
$retId = $this->ref_email->save();
|
||||
|
||||
foreach ($notes as $note) {
|
||||
if ($note->object_name == 'Note') {
|
||||
if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
|
||||
$file_location = $note->file->temp_file_location;
|
||||
$filename = $note->file->original_file_name;
|
||||
$mime_type = $note->file->mime_type;
|
||||
} else {
|
||||
$file_location = "upload://{$note->id}";
|
||||
foreach ((array)$notes as $note) {
|
||||
|
||||
if (!is_object($note)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan create a reference email but given note is not an object. Type of note was: "' . gettype($note) . '"');
|
||||
} else {
|
||||
|
||||
if ($note->object_name == 'Note') {
|
||||
if (!empty($note->file->temp_file_location) && is_file($note->file->temp_file_location)) {
|
||||
$file_location = $note->file->temp_file_location;
|
||||
$filename = $note->file->original_file_name;
|
||||
$mime_type = $note->file->mime_type;
|
||||
} else {
|
||||
$file_location = "upload://{$note->id}";
|
||||
$filename = $note->id . $note->filename;
|
||||
$mime_type = $note->file_mime_type;
|
||||
}
|
||||
} elseif ($note->object_name == 'DocumentRevision') { // from Documents
|
||||
$filename = $note->id . $note->filename;
|
||||
$file_location = "upload://$filename";
|
||||
$mime_type = $note->file_mime_type;
|
||||
}
|
||||
} elseif ($note->object_name == 'DocumentRevision') { // from Documents
|
||||
$filename = $note->id . $note->filename;
|
||||
$file_location = "upload://$filename";
|
||||
$mime_type = $note->file_mime_type;
|
||||
|
||||
}
|
||||
|
||||
$noteAudit = new Note();
|
||||
$noteAudit->parent_id = $retId;
|
||||
$noteAudit->parent_type = $this->ref_email->module_dir;
|
||||
$noteAudit->description = "[" . $note->filename . "] " . $mod_strings['LBL_ATTACHMENT_AUDIT'];
|
||||
|
||||
if (!isset($note->filename)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan create ref email error: Note filename is undefined.');
|
||||
$noteFilename = null;
|
||||
} else {
|
||||
$noteFilename = $note->filename ;
|
||||
}
|
||||
|
||||
$noteAudit->description = "[" . $noteFilename . "] " . $mod_strings['LBL_ATTACHMENT_AUDIT'];
|
||||
|
||||
|
||||
if (!isset($filename)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan create ref email error: Filename is undefined.');
|
||||
$filename = null;
|
||||
}
|
||||
|
||||
$noteAudit->filename = $filename;
|
||||
|
||||
if (!isset($mime_type)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan create ref email error: Mime Type is undefined.');
|
||||
$mime_type = null;
|
||||
}
|
||||
|
||||
$noteAudit->file_mime_type = $mime_type;
|
||||
$noteAudit_id = $noteAudit->save();
|
||||
|
||||
UploadFile::duplicate_file($note->id, $noteAudit_id, $filename);
|
||||
if (!isset($note->id)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan create ref email but Note ID is undefined.');
|
||||
$noteId = null;
|
||||
} else {
|
||||
$noteId = $note->id;
|
||||
}
|
||||
|
||||
UploadFile::duplicate_file($noteId, $noteAudit_id, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,7 +706,21 @@ class EmailMan extends SugarBean
|
|||
$email->to_addrs_emails = $module->email1 . ';';
|
||||
$email->type = 'archived';
|
||||
$email->deleted = '0';
|
||||
$email->name = $this->current_campaign->name . ': ' . $mail->Subject;
|
||||
|
||||
if (!isset($this->current_campaign)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan has not current campaign for create individual email.');
|
||||
$currentCampaignNameMailSubject = null;
|
||||
} else {
|
||||
$currentCampaignNameMailSubject = $this->current_campaign->name . ': ' . $mail->Subject;
|
||||
}
|
||||
|
||||
$email->name = $currentCampaignNameMailSubject;
|
||||
|
||||
if (!isset($mail->ContentType)) {
|
||||
LoggerManager::getLogger()->warn('EmailMan given an mail for creating individual email but there is not content type.');
|
||||
$mail->ContentType = null;
|
||||
}
|
||||
|
||||
if ($mail->ContentType == "text/plain") {
|
||||
$email->description = $mail->Body;
|
||||
$email->description_html = null;
|
||||
|
|
|
@ -128,6 +128,7 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
{
|
||||
$state = new SuiteCRM\StateSaver();
|
||||
$state->pushErrorLevel();
|
||||
$state->pushTable('campaign_log');
|
||||
|
||||
//error_reporting(E_ERROR | E_PARSE);
|
||||
|
||||
|
@ -154,11 +155,22 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
|
||||
// clean up
|
||||
|
||||
$state->popTable('campaign_log');
|
||||
$state->popErrorLevel();
|
||||
}
|
||||
|
||||
public function testcreate_indiv_email()
|
||||
{
|
||||
// save state
|
||||
|
||||
$state = new SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
$state->pushTable('emails_text');
|
||||
|
||||
// test
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
|
||||
$result = $emailMan->create_indiv_email(new Contact(), new Email());
|
||||
|
@ -168,17 +180,53 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
|
||||
$email = new Email();
|
||||
$email->mark_deleted($result);
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_text');
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testverify_campaign()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
$result = $emailMan->verify_campaign('');
|
||||
$this->assertEquals(false, $result);
|
||||
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testsendEmail()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
|
||||
//test without setting any attributes
|
||||
|
@ -190,29 +238,80 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
$emailMan->related_id = 1;
|
||||
$result = $emailMan->sendEmail(new SugarPHPMailer(), 1, true);
|
||||
$this->assertEquals(true, $result);
|
||||
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testvalid_email_address()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
|
||||
$this->assertEquals(false, $emailMan->valid_email_address(''));
|
||||
$this->assertEquals(false, $emailMan->valid_email_address('test'));
|
||||
$this->assertEquals(true, $emailMan->valid_email_address('test@test.com'));
|
||||
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testis_primary_email_address()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
|
||||
$bean = new Contact();
|
||||
|
||||
//test without setting any email
|
||||
$this->assertEquals(false, $emailMan->is_primary_email_address($bean));
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testcreate_export_query()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
|
||||
//test with empty string params
|
||||
|
@ -224,12 +323,26 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
$expected = 'SELECT emailman.* FROM emailman where (emailman.user_id="") AND ( emailman.deleted IS NULL OR emailman.deleted=0 )';
|
||||
$actual = $emailMan->create_export_query('emailman.id', 'emailman.user_id=""');
|
||||
$this->assertSame($expected, $actual);
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testmark_deleted()
|
||||
{
|
||||
$state = new SuiteCRM\StateSaver();
|
||||
$state->pushErrorLevel();
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
|
||||
// test
|
||||
|
||||
|
||||
//error_reporting(E_ERROR | E_PARSE);
|
||||
|
||||
|
@ -243,14 +356,30 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
} catch (Exception $e) {
|
||||
$this->fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
|
||||
}
|
||||
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popErrorLevel();
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
|
||||
public function testcreate_ref_email()
|
||||
{
|
||||
|
||||
// save state
|
||||
|
||||
$state = new \SuiteCRM\StateSaver();
|
||||
$state->pushTable('campaign_log');
|
||||
$state->pushTable('emails');
|
||||
$state->pushTable('aod_indexevent');
|
||||
$state->pushTable('emails_email_addr_rel');
|
||||
$state->pushTable('emails_text');
|
||||
$state->pushTable('notes');
|
||||
$state->pushGlobals();
|
||||
|
||||
// test
|
||||
|
||||
$emailMan = new EmailMan();
|
||||
$emailMan->test = true;
|
||||
|
||||
|
@ -261,5 +390,15 @@ class EmailManTest extends SuiteCRM\StateChecker_PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(36, strlen($result));
|
||||
$email = new Email();
|
||||
$email->mark_deleted($result);
|
||||
|
||||
// clean up
|
||||
|
||||
$state->popGlobals();
|
||||
$state->popTable('notes');
|
||||
$state->popTable('emails_text');
|
||||
$state->popTable('emails_email_addr_rel');
|
||||
$state->popTable('aod_indexevent');
|
||||
$state->popTable('emails');
|
||||
$state->popTable('campaign_log');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue