Skip to content

Commit 9115c23

Browse files
committed
Add tests
1 parent de675d9 commit 9115c23

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

tests/Unit/MailboxTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,23 @@
119119
expect($folder->path())->toBe('INBOX');
120120
expect($folder->flags())->toBe(['\\HasNoChildren']);
121121
});
122+
123+
test('capabilities', function () {
124+
$mailbox = Mailbox::make([
125+
'username' => 'foo',
126+
'password' => 'bar',
127+
]);
128+
129+
$mailbox->connect(ImapConnection::fake([
130+
'* OK Welcome to IMAP',
131+
'TAG1 OK Logged in',
132+
'* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN',
133+
'TAG2 OK CAPABILITY completed',
134+
]));
135+
136+
expect($mailbox->capabilities())->toBe([
137+
'IMAP4rev1',
138+
'STARTTLS',
139+
'AUTH=PLAIN',
140+
]);
141+
});

tests/Unit/MessageTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\ImapConnection;
4+
use DirectoryTree\ImapEngine\Enums\ImapFlag;
5+
use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException;
6+
use DirectoryTree\ImapEngine\Folder;
7+
use DirectoryTree\ImapEngine\Mailbox;
8+
use DirectoryTree\ImapEngine\Message;
9+
10+
test('it moves message using MOVE when capable', function () {
11+
$mailbox = Mailbox::make([
12+
'username' => 'foo',
13+
'password' => 'bar',
14+
]);
15+
16+
$mailbox->connect(ImapConnection::fake([
17+
'* OK Welcome to IMAP',
18+
'TAG1 OK Logged in',
19+
'* CAPABILITY IMAP4rev1 STARTTLS MOVE AUTH=PLAIN',
20+
'TAG2 OK CAPABILITY completed',
21+
'TAG3 OK MOVE completed',
22+
]));
23+
24+
$folder = new Folder($mailbox, 'INBOX', [], '/');
25+
26+
$message = new Message($folder, 1, [], 'header', 'body');
27+
28+
$message->move('INBOX.Sent');
29+
})->throwsNoExceptions();
30+
31+
test('it copies and then deletes message using UIDPLUS when incapable of MOVE', function () {
32+
$mailbox = Mailbox::make([
33+
'username' => 'foo',
34+
'password' => 'bar',
35+
]);
36+
37+
$mailbox->connect(ImapConnection::fake([
38+
'* OK Welcome to IMAP',
39+
'TAG1 OK Logged in',
40+
'* CAPABILITY IMAP4rev1 STARTTLS UIDPLUS AUTH=PLAIN',
41+
'TAG2 OK CAPABILITY completed',
42+
'TAG3 OK UID MOVE completed',
43+
'TAG4 OK COPY completed',
44+
]));
45+
46+
$folder = new Folder($mailbox, 'INBOX', [], '/');
47+
48+
$message = new Message($folder, 1, [], 'header', 'body');
49+
50+
$message->move('INBOX.Sent');
51+
})->throwsNoExceptions();
52+
53+
test('it throws exception when server does not support MOVE or UIDPLUS capabilities', function () {
54+
$mailbox = Mailbox::make([
55+
'username' => 'foo',
56+
'password' => 'bar',
57+
]);
58+
59+
$mailbox->connect(ImapConnection::fake([
60+
'* OK Welcome to IMAP',
61+
'TAG1 OK Logged in',
62+
'* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN',
63+
'TAG2 OK CAPABILITY completed',
64+
]));
65+
66+
$folder = new Folder($mailbox, 'INBOX', [], '/');
67+
68+
$message = new Message($folder, 1, [], 'header', 'body');
69+
70+
$message->move('INBOX.Sent');
71+
})->throws(ImapCapabilityException::class);
72+
73+
test('it can mark and unmark a message as flagged', function () {
74+
$mailbox = Mailbox::make([
75+
'username' => 'foo',
76+
'password' => 'bar',
77+
]);
78+
79+
$mailbox->connect(ImapConnection::fake([
80+
'* OK Welcome to IMAP',
81+
'TAG1 OK Logged in',
82+
'* CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN',
83+
'TAG2 OK CAPABILITY completed',
84+
'TAG3 OK STORE completed',
85+
]));
86+
87+
$folder = new Folder($mailbox, 'INBOX', [], '/');
88+
89+
$message = new Message($folder, 1, [], 'header', 'body');
90+
91+
expect($message->isFlagged())->toBeFalse();
92+
expect($message->flags())->not->toContain('\\Flagged');
93+
94+
$message->markFlagged();
95+
96+
expect($message->isFlagged())->toBeTrue();
97+
expect($message->flags())->toContain('\\Flagged');
98+
expect($message->hasFlag(ImapFlag::Flagged))->toBeTrue();
99+
100+
$message->unmarkFlagged();
101+
102+
expect($message->isFlagged())->toBeFalse();
103+
expect($message->flags())->not->toContain('\\Flagged');
104+
expect($message->hasFlag(ImapFlag::Flagged))->toBeFalse();
105+
});

0 commit comments

Comments
 (0)