Merge branch 'support/3.1' into support/3.2

# Conflicts:
#	sources/Core/Email/EmailLaminas.php
This commit is contained in:
Stephen Abello
2024-11-08 09:41:48 +01:00
2 changed files with 44 additions and 42 deletions

View File

@@ -45,4 +45,43 @@ class EMailTest extends ItopTestCase {
$oConfig->Set('email_transport', $sCurrentEmailTransport);
$oConfig->Set('email_asynchronous', $sCurrentEmailAsync);
}
/**
* @return void
* @throws \ConfigException
* @throws \CoreException
* @covers Email::SetBody()
* @covers Email::Send()
*/
public function testCheckPartsHeadersOnSendEmailWithAttachment(): void
{
$oConfig = utils::GetConfig();
$sCurrentEmailTransport = $oConfig->Get('email_transport');
$sCurrentEmailAsync = $oConfig->Get('email_asynchronous');
// Set our email transport to file, so we can read it after
$oConfig->Set('email_transport', 'LogFile');
$oConfig->Set('email_asynchronous', false);
$oEmail = new Email();
$oEmail->SetRecipientTO('email@email.com');
$oEmail->SetRecipientFrom('email2@email2.com');
$oEmail->SetSubject('dummy subject');
$oEmail->SetBody('dummy body', 'text/plain');
$oEmail->AddAttachment('Dummy attachment', 'attachment.txt', 'text/plain');
// Send the mail and check if there's any issue
$aIssues = [];
$oEmail->Send($aIssues);
$this->assertEmpty($aIssues);
// Check if our charset is correctly set
// We know this file may be used by other future test, but as we can't configure output filename, it is what it is
$sEmailContent = file_get_contents(APPROOT.'log/mail.log');
$this->assertStringContainsString('Content-Type: text/plain; charset=UTF-8', $sEmailContent);
// Set our previous email transport value back, so it doesn't affect other tests
$oConfig->Set('email_transport', $sCurrentEmailTransport);
$oConfig->Set('email_asynchronous', $sCurrentEmailAsync);
}
}