Skip to content

Commit 7aa1dd9

Browse files
committed
feat: make unit test for checking imap quotas
1 parent fd03601 commit 7aa1dd9

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

src/FolderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function select(bool $force = false): void;
5959
/**
6060
* Get the folder's quotas
6161
*
62-
* @return array{STORAGE: array{usage: int|null, limit: int|null}, MESSAGES: array{usage: int|null, limit: int|null}, usage: int|null, limit: int|null}
62+
* @return array{STORAGE: array{usage: int|null, limit: int|null}, MESSAGE: array{usage: int|null, limit: int|null}, usage: int|null, limit: int|null}
6363
*/
6464
public function quota(): array;
6565

src/Testing/FakeFolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function expunge(): array
142142
public function quota(): array
143143
{
144144
return [
145-
'MESSAGES' => [
145+
'MESSAGE' => [
146146
'usage' => 0,
147147
'limit' => 0,
148148
],

tests/Integration/FoldersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@
109109
expect($folder->quota())
110110
->toBeArray()
111111
->toHaveKeys(['STORAGE', 'MESSAGE', 'usage', 'limit']);
112-
});
112+
})
113+
->skip(true, 'Greenamil does not properly support IMAP quotas currently.');

tests/Unit/FolderTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use DirectoryTree\ImapEngine\Connection\ImapConnection;
4+
use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException;
35
use DirectoryTree\ImapEngine\Folder;
46
use DirectoryTree\ImapEngine\Mailbox;
57

@@ -50,3 +52,59 @@
5052
// The name should remain unchanged.
5153
expect($mixedFolder->name())->toBe($mixedUtf8FolderName);
5254
});
55+
56+
test('it returns quota data for the mailbox', function () {
57+
$mailbox = Mailbox::make([
58+
'username' => 'foo',
59+
'password' => 'bar',
60+
]);
61+
62+
$mailbox->connect(ImapConnection::fake([
63+
'* OK Welcome to IMAP',
64+
'TAG1 OK Logged in',
65+
'* LIST (\\HasNoChildren) "/" "INBOX"',
66+
'TAG2 OK LIST completed',
67+
'* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE QUOTA',
68+
'TAG3 OK CAPABILITY completed',
69+
'* QUOTA "INBOX" (STORAGE 54 512)',
70+
'* QUOTA "INBOX" (MESSAGE 12 1024)',
71+
'TAG4 OK GETQUOTAROOT completed',
72+
]));
73+
74+
expect($mailbox->inbox()->quota())
75+
->toBeArray()
76+
->toHaveKeys(['STORAGE', 'MESSAGE', 'usage', 'limit'])
77+
->toMatchArray([
78+
'STORAGE' => [
79+
'usage' => 54,
80+
'limit' => 512,
81+
],
82+
'MESSAGE' => [
83+
'usage' => 12,
84+
'limit' => 1024,
85+
],
86+
'usage' => 54,
87+
'limit' => 512,
88+
]);
89+
});
90+
91+
test('it throws an imap capability exception when inspecting quotas when the imap server does not support quotas', function () {
92+
$mailbox = Mailbox::make([
93+
'username' => 'foo',
94+
'password' => 'bar',
95+
]);
96+
97+
$mailbox->connect(ImapConnection::fake([
98+
'* OK Welcome to IMAP',
99+
'TAG1 OK Logged in',
100+
'* LIST (\\HasNoChildren) "/" "INBOX"',
101+
'TAG2 OK LIST completed',
102+
'* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE',
103+
'TAG3 OK CAPABILITY completed',
104+
'* QUOTA "INBOX" (STORAGE 54 512)',
105+
'* QUOTA "INBOX" (MESSAGE 12 1024)',
106+
'TAG4 OK GETQUOTAROOT completed',
107+
]));
108+
109+
$mailbox->inbox()->quota();
110+
})->throws(ImapCapabilityException::class);

0 commit comments

Comments
 (0)