Skip to content

Commit 04de564

Browse files
committed
Add tests
1 parent aa767d2 commit 04de564

File tree

3 files changed

+114
-17
lines changed

3 files changed

+114
-17
lines changed

tests/Unit/FileMessageTest.php

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Message-ID: <[email protected]>
2020
MIME-Version: 1.0
2121
Content-Type: text/plain; charset="UTF-8"
22-
22+
2323
Hello World
2424
EOT;
2525

@@ -47,15 +47,15 @@
4747
MIME-Version: 1.0
4848
Content-Type: multipart/alternative;
4949
boundary="----BOUNDARY-ID----"
50-
50+
5151
------BOUNDARY-ID----
5252
Content-Type: text/plain; charset="UTF-8"
53-
53+
5454
Hello Plain
55-
55+
5656
------BOUNDARY-ID----
5757
Content-Type: text/html; charset="UTF-8"
58-
58+
5959
<html><body><p>Hello <strong>HTML</strong></p></body></html>
6060
------BOUNDARY-ID------
6161
EOT;
@@ -77,17 +77,17 @@
7777
MIME-Version: 1.0
7878
Content-Type: multipart/mixed;
7979
boundary="----BOUNDARY-ID----"
80-
80+
8181
------BOUNDARY-ID----
8282
Content-Type: text/plain; charset="UTF-8"
83-
83+
8484
Hello with Attachment
85-
85+
8686
------BOUNDARY-ID----
8787
Content-Type: application/pdf; name="file.pdf"
8888
Content-Disposition: attachment; filename="file.pdf"
8989
Content-Transfer-Encoding: base64
90-
90+
9191
JVBERi0xLjUKJeLjz9MKMyAwIG9iago8PC9MZW5ndGggNCAgIC9GaWx0ZXIvQXNjaWlIYXgg
9292
ICAgPj5zdHJlYW0Kc3R1ZmYKZW5kc3RyZWFtCmVuZG9iajAK
9393
------BOUNDARY-ID------
@@ -114,7 +114,7 @@
114114
Subject: No Attachments
115115
Date: Wed, 19 Feb 2025 12:34:56 -0500
116116
Content-Type: text/plain; charset="UTF-8"
117-
117+
118118
Just a plain text email without attachments.
119119
EOT;
120120

@@ -132,7 +132,7 @@
132132
Subject: In-Reply-To Check
133133
Date: Wed, 19 Feb 2025 12:34:56 -0500
134134
Content-Type: text/plain; charset="UTF-8"
135-
135+
136136
Check the in-reply-to header
137137
EOT;
138138

@@ -149,7 +149,7 @@
149149
Subject: Stringable Test
150150
Date: Wed, 19 Feb 2025 12:34:56 -0500
151151
Content-Type: text/plain; charset="UTF-8"
152-
152+
153153
Testing __toString
154154
EOT;
155155

@@ -165,26 +165,26 @@
165165
Subject: Test Email With Inline Image
166166
MIME-Version: 1.0
167167
Content-Type: multipart/related; boundary="BOUNDARY_STRING"
168-
168+
169169
--BOUNDARY_STRING
170170
Content-Type: text/html; charset=UTF-8
171-
171+
172172
<html>
173173
<body>
174174
<p>This is a test email with an inline image:</p>
175175
<img src="cid:inline-image-id" alt="Inline Image" />
176176
</body>
177177
</html>
178-
178+
179179
--BOUNDARY_STRING
180180
Content-Type: image/png; name="inline_image.png"
181181
Content-Transfer-Encoding: base64
182182
Content-ID: <inline-image-id>
183183
Content-Disposition: inline; filename="inline_image.png"
184-
184+
185185
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8
186186
z8BQDwABAgEA0xzY2QAAAABJRU5ErkJggg==
187-
187+
188188
--BOUNDARY_STRING--
189189
EOT;
190190

@@ -197,3 +197,42 @@
197197
expect($attachments[0]->contentId())->toBe('inline-image-id');
198198
expect($attachments[0]->filename())->toBe('inline_image.png');
199199
});
200+
201+
test('it can determine if two messages are the same', function () {
202+
$contents1 = <<<'EOT'
203+
From: "John Doe" <[email protected]>
204+
Subject: Test Subject
205+
Date: Wed, 19 Feb 2025 12:34:56 -0500
206+
Content-Type: text/plain; charset="UTF-8"
207+
208+
Test content
209+
EOT;
210+
211+
$contents2 = <<<'EOT'
212+
From: "John Doe" <[email protected]>
213+
Subject: Test Subject
214+
Date: Wed, 19 Feb 2025 12:34:56 -0500
215+
Content-Type: text/plain; charset="UTF-8"
216+
217+
Test content
218+
EOT;
219+
220+
$contents3 = <<<'EOT'
221+
From: "John Doe" <[email protected]>
222+
Subject: Different Subject
223+
Date: Wed, 19 Feb 2025 12:34:56 -0500
224+
Content-Type: text/plain; charset="UTF-8"
225+
226+
Different content
227+
EOT;
228+
229+
$message1 = new FileMessage($contents1);
230+
$message2 = new FileMessage($contents2);
231+
$message3 = new FileMessage($contents3);
232+
233+
// Same content
234+
expect($message1->is($message2))->toBeTrue();
235+
236+
// Different content
237+
expect($message1->is($message3))->toBeFalse();
238+
});

tests/Unit/MessageTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,41 @@
107107
expect($message->flags())->not->toContain('\\Flagged');
108108
expect($message->hasFlag(ImapFlag::Flagged))->toBeFalse();
109109
});
110+
111+
test('it can determine if two messages are the same', function () {
112+
$mailbox = Mailbox::make([
113+
'username' => 'foo',
114+
'password' => 'bar',
115+
]);
116+
117+
$mailbox->connect(ImapConnection::fake([
118+
'* OK Welcome to IMAP',
119+
'TAG1 OK Logged in',
120+
]));
121+
122+
$folder1 = new Folder($mailbox, 'INBOX', [], '/');
123+
$folder2 = new Folder($mailbox, 'INBOX.Sent', [], '/');
124+
125+
// Create messages with different properties
126+
$message1 = new Message($folder1, 1, [], 'header1', 'body1');
127+
$message2 = new Message($folder1, 1, [], 'header1', 'body1'); // Same as message1
128+
$message3 = new Message($folder1, 2, [], 'header1', 'body1'); // Different UID
129+
$message4 = new Message($folder2, 1, [], 'header1', 'body1'); // Different folder
130+
$message5 = new Message($folder1, 1, [], 'header2', 'body1'); // Different header
131+
$message6 = new Message($folder1, 1, [], 'header1', 'body2'); // Different body
132+
133+
// Same message
134+
expect($message1->is($message2))->toBeTrue();
135+
136+
// Different UID
137+
expect($message1->is($message3))->toBeFalse();
138+
139+
// Different folder
140+
expect($message1->is($message4))->toBeFalse();
141+
142+
// Different header
143+
expect($message1->is($message5))->toBeFalse();
144+
145+
// Different body
146+
expect($message1->is($message6))->toBeFalse();
147+
});

tests/Unit/Testing/FakeMessageTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@
5353
expect($message->uid())->toBe(1);
5454
expect((string) $message)->toBe('');
5555
});
56+
57+
test('it can determine if two messages are the same', function () {
58+
$message1 = new FakeMessage(1, ['\\Seen'], 'Test content');
59+
$message2 = new FakeMessage(1, ['\\Seen'], 'Test content');
60+
$message3 = new FakeMessage(2, ['\\Seen'], 'Test content');
61+
$message4 = new FakeMessage(1, ['\\Draft'], 'Test content');
62+
$message5 = new FakeMessage(1, ['\\Seen'], 'Different content');
63+
64+
// Same messages
65+
expect($message1->is($message2))->toBeTrue();
66+
67+
// Different UID
68+
expect($message1->is($message3))->toBeFalse();
69+
70+
// Different flags
71+
expect($message1->is($message4))->toBeFalse();
72+
73+
// Different content
74+
expect($message1->is($message5))->toBeFalse();
75+
});

0 commit comments

Comments
 (0)