-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5134 from Deltik/fix/5131
Fixes: #5131 Accurate resource open check when using log file handle
- Loading branch information
Showing
2 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,4 +276,50 @@ function testSentMimeMessage() | |
|
||
} | ||
|
||
/** | ||
* @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( | ||
'[email protected]', | ||
"$randomString1 Example", | ||
['body' => 'Message body'], | ||
); | ||
$this->assertTrue($this->fileContainsString($logFilePath, $randomString1)); | ||
$eml->sendEmail( | ||
'[email protected]', | ||
"$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; | ||
} | ||
} |