1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-29 01:00:20 +02:00

fix(#5131): Accurate resource open check when using log file handle

Fixes: https://github.com/e107inc/e107/issues/5131
This commit is contained in:
Nick Liu
2023-12-03 21:20:43 -06:00
parent 1637707a03
commit 688ebdfea8
2 changed files with 54 additions and 11 deletions

View File

@@ -276,4 +276,50 @@ Admin<br />
}
/**
* @see https://github.com/e107inc/e107/issues/5131
* @throws Exception if the {@link e107Email} object cannot be created.
*/
function testLogFileHandle()
{
$logFilePath = e_ROOT . MAIL_LOG_PATH . 'mailoutlog.log';
$randomString1 = uniqid();
$randomString2 = uniqid();
$this->assertFalse($this->fileContainsString($logFilePath, $randomString1));
$this->assertFalse($this->fileContainsString($logFilePath, $randomString2));
$eml = $this->make('e107Email', ['send' => function() { return true; }]);
$eml->logEnable(2);
$eml->sendEmail(
'nobody@example.com',
"$randomString1 Example",
['body' => 'Message body'],
);
$this->assertTrue($this->fileContainsString($logFilePath, $randomString1));
$eml->sendEmail(
'nobody2@example.com',
"$randomString2 Example",
['body' => 'Message body'],
);
$this->assertTrue($this->fileContainsString($logFilePath, $randomString2));
}
/**
* @param $filePath
* @param $string
* @return bool
*/
private function fileContainsString($filePath, $string)
{
if (!file_exists($filePath)) return false;
$handle = fopen($filePath, 'r');
while (($buffer = fgets($handle)) !== false) {
if (strpos($buffer, $string) !== false) {
return true;
}
}
return false;
}
}