HTML
],
],
];
}
/**
* @dataProvider doCheckToWriteProvider
* @param string $sBody
* @param string $sHtmlTemplate
* @param string[] $aExpectedWarnings
*/
public function testDoCheckToWrite(string $sBody, ?string $sHtmlTemplate, $expectedWarnings)
{
$oActionEmail = new ActionEmail();
// Set mandatory fields
$oActionEmail->Set('name', 'test');
$oActionEmail->Set('subject', 'Ga Bu Zo Meu');
// Set the fields for testing
$oActionEmail->Set('body', $sBody);
if ($sHtmlTemplate !== null) {
$oDoc = new \ormDocument($sHtmlTemplate, 'text/html', 'template.html');
$oActionEmail->Set('html_template', $oDoc);
}
$oActionEmail->DoCheckToWrite();
$aWarnings = $this->GetNonPublicProperty($oActionEmail, 'm_aCheckWarnings');
if ($expectedWarnings === null) {
$this->assertEquals($aWarnings, $expectedWarnings);
} else {
// The warning messages are localized, but the provider functions does not
// have access to the Dict class, so let's replace the value given by the
// provider by a statically precomputed and localized message
foreach ($expectedWarnings as $index => $sMessageKey) {
$expectedWarnings[$index] = static::$aWarningMessages[$sMessageKey];
}
$this->assertEquals($aWarnings, $expectedWarnings);
}
}
public function doCheckToWriteProvider()
{
return [
'no warnings' => [
'
Some text here
',
'
$content$
',
null,
],
'$content$ missing' => [
'
Some text here
',
'
no placeholder
',
[ 'warning-missing-content' ],
],
];
}
/**
* @dataProvider asynchronousValuesContentProvider
*/
public function testAsynchronousValues($sActionAsyncValue, $sConfigAsyncValue, $sExpectedValue)
{
$oConfig = utils::GetConfig();
$sCurrentEmailAsync = $oConfig->Get('email_asynchronous');
$oConfig->Set('email_asynchronous', $sConfigAsyncValue);
$oActionEmail = MetaModel::NewObject('ActionEmail', [
'name' => 'Test action',
'status' => 'disabled',
'from' => 'unit-test@openitop.org',
'subject' => 'Test subject',
'body' => 'Test body',
'asynchronous' => $sActionAsyncValue,
]);
self::assertEquals($sExpectedValue, $oActionEmail->IsAsynchronous());
$oConfig->Set('email_asynchronous', $sCurrentEmailAsync);
}
public function asynchronousValuesContentProvider()
{
return [
'ActionEmail is asynchronous' => [
'yes',
false,
true,
],
'ActionEmail is not asynchronous' => [
'no',
true,
false,
],
'ActionEmail is asynchronous and config is asynchronous' => [
'yes',
true,
true,
],
'ActionEmail is not asynchronous and config is not asynchronous' => [
'no',
false,
false,
],
'ActionEmail follows global settings, config is not asynchronous' => [
'use_global_setting',
false,
false,
],
'ActionEmail follows global settings, config is asynchronous' => [
'use_global_setting',
true,
true,
],
];
}
}