diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php index f41d49188..37da4f50b 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/EmailServerTest.php @@ -250,4 +250,101 @@ class EmailServerTest extends TestCase $this->expectException(Exception::class); $actual = $this->emailServer->getEmailServer($emailServerUid); } + + /** + * It tests the sendTestMail method with a successful result + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method() + { + // The data that will be sent to the method + $data = [ + "FROM_EMAIL" => "admin@processmaker.com", + "FROM_NAME" => "Administrator", + "MESS_ENGINE" => "MAIL", + "MESS_SERVER" => "localhost", + "MESS_PORT" => 25, + "MESS_ACCOUNT" => "admin@processmaker.com", + "MESS_PASSWORD" => "", + "TO" => "admin@processmaker.com", + "MESS_RAUTH" => true + ]; + + // Create the EmailServer object + $emailServer = new EmailServer(); + // Call the sendTestMail method + $result = $emailServer->sendTestMail($data); + + // Assert the status is true + $this->assertTrue($result['status']); + // Assert the success is true + $this->assertTrue($result['success']); + // Assert the message of the result + $this->assertEquals('**ID_MAIL_TEST_SUCCESS**', $result['msg']); + } + + /** + * It tests the sendTestMail method with a failed result + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method_failure() + { + // The data that will be sent to the method + $data = [ + "FROM_EMAIL" => "admin@processmaker.com", + "FROM_NAME" => "Administrator", + "MESS_ENGINE" => "PHPMAILER", + "MESS_SERVER" => "smtp.gmail.com", + "MESS_PORT" => 587, + "MESS_ACCOUNT" => "admin@processmaker.com", + "MESS_PASSWORD" => "", + "TO" => "admin@processmaker.com", + "MESS_RAUTH" => false, + ]; + + // Create the EmailServer object + $emailServer = new EmailServer(); + // Call the sendTestMail method + $result = $emailServer->sendTestMail($data); + + // Assert the status is false + $this->assertFalse($result['status']); + // Assert the status is false + $this->assertFalse($result['success']); + // Assert the message of the result is empty + $this->assertEmpty($result['msg']); + } + + /** + * It tests the sendTestMail method with an exception + * + * @covers \ProcessMaker\BusinessModel\EmailServer::sendTestMail() + * @test + */ + public function it_should_test_the_send_test_mail_method_exception() + { + // The data that will be sent to the method + $data = []; + + // Create the EmailServer object + $emailServer = new EmailServer(); + + // This expects an exception message + $this->expectExceptionMessage("Undefined index: MESS_ENGINE"); + + // Call the sendTestMail method + $emailServer->sendTestMail($data); + } + + /** + * Call the tearDown method + */ + public function tearDown() + { + parent::tearDown(); // TODO: Change the autogenerated stub + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php index 6af4c2957..be8a3a9f9 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/EmailServer.php @@ -195,7 +195,7 @@ class EmailServer $bodyPre = new TemplatePower(PATH_TPL . "admin" . PATH_SEP . "email.tpl"); $bodyPre->prepare(); - $bodyPre->assign("server", $_SERVER["SERVER_NAME"]); + $bodyPre->assign("server", System::getServerProtocol() . System::getServerHost()); $bodyPre->assign("date", date("H:i:s")); $bodyPre->assign("ver", System::getVersion()); $bodyPre->assign("engine", $engine); diff --git a/workflow/engine/templates/admin/email.tpl b/workflow/engine/templates/admin/email.tpl index b3cf8eb2a..914324205 100644 --- a/workflow/engine/templates/admin/email.tpl +++ b/workflow/engine/templates/admin/email.tpl @@ -2,7 +2,7 @@ - +