| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Tests\fixtures; |
| 14 |
|
| 15 |
use Webklex\PHPIMAP\Exceptions\AuthFailedException; |
| 16 |
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException; |
| 17 |
use Webklex\PHPIMAP\Exceptions\ImapBadRequestException; |
| 18 |
use Webklex\PHPIMAP\Exceptions\ImapServerErrorException; |
| 19 |
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException; |
| 20 |
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException; |
| 21 |
use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException; |
| 22 |
use Webklex\PHPIMAP\Exceptions\ResponseException; |
| 23 |
use Webklex\PHPIMAP\Exceptions\RuntimeException; |
| 24 |
use Webklex\PHPIMAP\Message; |
| 25 |
use \ReflectionException; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class DateTemplateTest extends FixtureTestCase { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
protected array $dates = [ |
| 40 |
"Fri, 5 Apr 2019 12:10:49 +0200" => "2019-04-05 10:10:49", |
| 41 |
"04 Jan 2018 10:12:47 UT" => "2018-01-04 10:12:47", |
| 42 |
"22 Jun 18 03:56:36 PM -05:00 (GMT -05:00)" => "2018-06-22 20:56:36", |
| 43 |
"Sat, 31 Aug 2013 20:08:23 +0580" => "2013-08-31 14:38:23", |
| 44 |
"Fri, 1 Feb 2019 01:30:04 +0600 (+06)" => "2019-01-31 19:30:04", |
| 45 |
"Mon, 4 Feb 2019 04:03:49 -0300 (-03)" => "2019-02-04 07:03:49", |
| 46 |
"Sun, 6 Apr 2008 21:24:33 UT" => "2008-04-06 21:24:33", |
| 47 |
"Wed, 11 Sep 2019 15:23:06 +0600 (+06)" => "2019-09-11 09:23:06", |
| 48 |
"14 Sep 2019 00:10:08 UT +0200" => "2019-09-14 00:10:08", |
| 49 |
"Tue, 08 Nov 2022 18:47:20 +0000 14:03:33 +0000" => "2022-11-08 18:47:20", |
| 50 |
"Sat, 10, Dec 2022 09:35:19 +0100" => "2022-12-10 08:35:19", |
| 51 |
"Thur, 16 Mar 2023 15:33:07 +0400" => "2023-03-16 11:33:07", |
| 52 |
"fr., 25 nov. 2022 06:27:14 +0100/fr., 25 nov. 2022 06:27:14 +0100" => "2022-11-25 05:27:14", |
| 53 |
"Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)/Di., 15 Feb. 2022 06:52:44 +0100 (MEZ)" => "2022-02-15 05:52:44", |
| 54 |
"Mi., 23 Apr. 2025 09:48:37 +0200 (MESZ)" => "2025-04-23 07:48:37", |
| 55 |
]; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function testFixture() : void { |
| 73 |
try { |
| 74 |
$message = $this->getFixture("date-template.eml"); |
| 75 |
$this->fail("Expected InvalidMessageDateException"); |
| 76 |
} catch (InvalidMessageDateException $e) { |
| 77 |
self::assertTrue(true); |
| 78 |
} |
| 79 |
|
| 80 |
self::$manager->setConfig([ |
| 81 |
"options" => [ |
| 82 |
"fallback_date" => "2021-01-01 00:00:00", |
| 83 |
], |
| 84 |
]); |
| 85 |
$message = $this->getFixture("date-template.eml", self::$manager->getConfig()); |
| 86 |
|
| 87 |
self::assertEquals("test", $message->subject); |
| 88 |
self::assertEquals("1.0", $message->mime_version); |
| 89 |
self::assertEquals("Hi!", $message->getTextBody()); |
| 90 |
self::assertFalse($message->hasHTMLBody()); |
| 91 |
self::assertEquals("2021-01-01 00:00:00", $message->date->first()->timezone("UTC")->format("Y-m-d H:i:s")); |
| 92 |
self::assertEquals("[email protected]", (string)$message->from); |
| 93 |
self::assertEquals("[email protected]", $message->to); |
| 94 |
|
| 95 |
self::$manager->setConfig([ |
| 96 |
"options" => [ |
| 97 |
"fallback_date" => null, |
| 98 |
], |
| 99 |
]); |
| 100 |
|
| 101 |
$filename = implode(DIRECTORY_SEPARATOR, [__DIR__, "..", "messages", "date-template.eml"]); |
| 102 |
$blob = file_get_contents($filename); |
| 103 |
self::assertNotFalse($blob); |
| 104 |
|
| 105 |
foreach ($this->dates as $date => $expected) { |
| 106 |
$message = Message::fromString(str_replace("%date_raw_header%", $date, $blob)); |
| 107 |
self::assertEquals("test", $message->subject); |
| 108 |
self::assertEquals("1.0", $message->mime_version); |
| 109 |
self::assertEquals("Hi!", $message->getTextBody()); |
| 110 |
self::assertFalse($message->hasHTMLBody()); |
| 111 |
self::assertEquals($expected, $message->date->first()->timezone("UTC")->format("Y-m-d H:i:s"), "Date \"$date\" should be \"$expected\""); |
| 112 |
self::assertEquals("[email protected]", (string)$message->from); |
| 113 |
self::assertEquals("[email protected]", $message->to); |
| 114 |
} |
| 115 |
} |
| 116 |
} |