From 630cee56f7ead232affa5cac2a07a87a54d15a7c Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Fri, 15 Oct 2021 16:01:26 -0400 Subject: [PATCH] PMCORE-952-C --- .../BusinessModel/ActionsByEmailTest.php | 54 ++++++++++++++++++- .../BusinessModel/ActionsByEmail.php | 12 ++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmailTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmailTest.php index 444ab52fb..ab20ed1ee 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmailTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmailTest.php @@ -11,6 +11,7 @@ use ProcessMaker\Model\Dynaform; use ProcessMaker\Model\EmailServerModel; use ProcessMaker\Model\Process; use ProcessMaker\Model\Task; +use ProcessMaker\Model\User; use Tests\TestCase; class ActionsByEmailTest extends TestCase @@ -254,4 +255,55 @@ class ActionsByEmailTest extends TestCase //Assert the email was sent successfully $this->assertContains('**ID_EMAIL_RESENT_TO**: ' . $abeRequest->ABE_REQ_SENT_TO, $res); } -} \ No newline at end of file + + /** + * Test the loadActionByEmail method + * + * @covers \ProcessMaker\BusinessModel\ActionsByEmail::loadActionByEmail() + * @test + */ + public function it_should_test_the_load_action_by_email_method() + { + AbeConfiguration::truncate(); + AbeRequest::truncate(); + $user = factory(User::class)->create(); + $application = factory(Application::class)->create([ + 'APP_UID' => '123456asse' + ]); + $delegation = factory(Delegation::class)->create([ + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_PREVIOUS' => 0, + 'DEL_INDEX' => 1 + ]); + $delegation2 = factory(Delegation::class)->create([ + 'USR_UID' => $user->USR_UID, + 'USR_ID' => $user->USR_ID, + 'APP_UID' => $application->APP_UID, + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_PREVIOUS' => 1, + 'DEL_INDEX' => 2 + ]); + $abeConfiguration = factory(AbeConfiguration::class)->create([ + 'PRO_UID' => $delegation->PRO_UID, + 'TAS_UID' => $delegation->TAS_UID, + 'ABE_TYPE' => 'LINK', + ]); + $abeRequest = factory(AbeRequest::class)->create([ + 'ABE_UID' => $abeConfiguration->ABE_UID, + 'APP_UID' => $delegation2->APP_UID, + 'DEL_INDEX' => $delegation2->DEL_INDEX, + ]); + $arrayData = [ + 'action' => 'forwardMail', + 'REQ_UID' => $abeRequest->ABE_REQ_UID, + 'limit' => '', + 'start' => '' + ]; + $abe = new ActionsByEmail(); + $res = $abe->loadActionByEmail($arrayData); + $this->assertEquals(1, $res["totalCount"]); + } +} diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmail.php b/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmail.php index 8f707a0fc..8162befab 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmail.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/ActionsByEmail.php @@ -354,8 +354,16 @@ class ActionsByEmail $data[$index]['USER'] = ''; if ($data[$index]['ABE_MAILSERVER_OR_MAILCURRENT'] == 1) { $emailServer = new EmailServer(); - $dataEmailServer = $emailServer->getEmailServer($data[$index]['ABE_EMAIL_SERVER_UID']); - $data[$index]['USER'] = $dataEmailServer['MESS_FROM_NAME']; + if (!empty($data[$index]['ABE_EMAIL_SERVER_UID'])) { + $dataEmailServer = $emailServer->getEmailServer($data[$index]['ABE_EMAIL_SERVER_UID']); + } else { + $emailServerModel = new EmailServerModel(); + $emailServerDefault = $emailServerModel->getEmailServerDefault(); + if (isset($emailServerDefault['MESS_UID'])) { + $dataEmailServer = $emailServer->getEmailServer($emailServerDefault['MESS_UID']); + } + } + $data[$index]['USER'] = isset($dataEmailServer['MESS_FROM_NAME']) ? $dataEmailServer['MESS_FROM_NAME'] : ''; } if ($data[$index]['ABE_MAILSERVER_OR_MAILCURRENT'] == 0) { $delegation = new AppDelegation();