|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use DirectoryTree\ImapEngine\Connection\ImapConnection; |
| 4 | +use DirectoryTree\ImapEngine\Exceptions\ImapCapabilityException; |
3 | 5 | use DirectoryTree\ImapEngine\Folder; |
4 | 6 | use DirectoryTree\ImapEngine\Mailbox; |
5 | 7 |
|
|
50 | 52 | // The name should remain unchanged. |
51 | 53 | expect($mixedFolder->name())->toBe($mixedUtf8FolderName); |
52 | 54 | }); |
| 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 | + ->toMatchArray([ |
| 77 | + 'INBOX' => [ |
| 78 | + 'STORAGE' => [ |
| 79 | + 'usage' => 54, |
| 80 | + 'limit' => 512, |
| 81 | + ], |
| 82 | + 'MESSAGE' => [ |
| 83 | + 'usage' => 12, |
| 84 | + 'limit' => 1024, |
| 85 | + ], |
| 86 | + ], |
| 87 | + ]); |
| 88 | +}); |
| 89 | + |
| 90 | +test('it returns quota data for the mailbox when there are no quotas', function () { |
| 91 | + $mailbox = Mailbox::make([ |
| 92 | + 'username' => 'foo', |
| 93 | + 'password' => 'bar', |
| 94 | + ]); |
| 95 | + |
| 96 | + $mailbox->connect(ImapConnection::fake([ |
| 97 | + '* OK Welcome to IMAP', |
| 98 | + 'TAG1 OK Logged in', |
| 99 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 100 | + 'TAG2 OK LIST completed', |
| 101 | + '* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE QUOTA', |
| 102 | + 'TAG3 OK CAPABILITY completed', |
| 103 | + 'TAG4 OK GETQUOTAROOT completed', |
| 104 | + ])); |
| 105 | + |
| 106 | + expect($mailbox->inbox()->quota())->toBe([]); |
| 107 | +}); |
| 108 | + |
| 109 | +test('it returns quota data for the mailbox when there are multiple resources', function () { |
| 110 | + $mailbox = Mailbox::make([ |
| 111 | + 'username' => 'foo', |
| 112 | + 'password' => 'bar', |
| 113 | + ]); |
| 114 | + |
| 115 | + $mailbox->connect(ImapConnection::fake([ |
| 116 | + '* OK Welcome to IMAP', |
| 117 | + 'TAG1 OK Logged in', |
| 118 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 119 | + 'TAG2 OK LIST completed', |
| 120 | + '* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE QUOTA', |
| 121 | + 'TAG3 OK CAPABILITY completed', |
| 122 | + '* QUOTA "FOO" (STORAGE 54 512)', |
| 123 | + '* QUOTA "FOO" (MESSAGE 12 1024)', |
| 124 | + '* QUOTA "BAR" (STORAGE 10 1024)', |
| 125 | + '* QUOTA "BAR" (MESSAGE 5 1024)', |
| 126 | + 'TAG4 OK GETQUOTAROOT completed', |
| 127 | + ])); |
| 128 | + |
| 129 | + expect($mailbox->inbox()->quota()) |
| 130 | + ->toBeArray() |
| 131 | + ->toMatchArray([ |
| 132 | + 'FOO' => [ |
| 133 | + 'STORAGE' => [ |
| 134 | + 'usage' => 54, |
| 135 | + 'limit' => 512, |
| 136 | + ], |
| 137 | + 'MESSAGE' => [ |
| 138 | + 'usage' => 12, |
| 139 | + 'limit' => 1024, |
| 140 | + ], |
| 141 | + ], |
| 142 | + 'BAR' => [ |
| 143 | + 'STORAGE' => [ |
| 144 | + 'usage' => 10, |
| 145 | + 'limit' => 1024, |
| 146 | + ], |
| 147 | + 'MESSAGE' => [ |
| 148 | + 'usage' => 5, |
| 149 | + 'limit' => 1024, |
| 150 | + ], |
| 151 | + ], |
| 152 | + ]); |
| 153 | +}); |
| 154 | + |
| 155 | +test('it returns quota data for the mailbox when there are multiple resources in the same list data', function () { |
| 156 | + $mailbox = Mailbox::make([ |
| 157 | + 'username' => 'foo', |
| 158 | + 'password' => 'bar', |
| 159 | + ]); |
| 160 | + |
| 161 | + $mailbox->connect(ImapConnection::fake([ |
| 162 | + '* OK Welcome to IMAP', |
| 163 | + 'TAG1 OK Logged in', |
| 164 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 165 | + 'TAG2 OK LIST completed', |
| 166 | + '* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE QUOTA', |
| 167 | + 'TAG3 OK CAPABILITY completed', |
| 168 | + '* QUOTA "FOO" (STORAGE 54 512 MESSAGE 12 1024)', |
| 169 | + '* QUOTA "BAR" (STORAGE 10 1024 MESSAGE 5 1024)', |
| 170 | + 'TAG4 OK GETQUOTAROOT completed', |
| 171 | + ])); |
| 172 | + |
| 173 | + expect($mailbox->inbox()->quota()) |
| 174 | + ->toBeArray() |
| 175 | + ->toMatchArray([ |
| 176 | + 'FOO' => [ |
| 177 | + 'STORAGE' => [ |
| 178 | + 'usage' => 54, |
| 179 | + 'limit' => 512, |
| 180 | + ], |
| 181 | + 'MESSAGE' => [ |
| 182 | + 'usage' => 12, |
| 183 | + 'limit' => 1024, |
| 184 | + ], |
| 185 | + ], |
| 186 | + 'BAR' => [ |
| 187 | + 'STORAGE' => [ |
| 188 | + 'usage' => 10, |
| 189 | + 'limit' => 1024, |
| 190 | + ], |
| 191 | + 'MESSAGE' => [ |
| 192 | + 'usage' => 5, |
| 193 | + 'limit' => 1024, |
| 194 | + ], |
| 195 | + ], |
| 196 | + ]); |
| 197 | +}); |
| 198 | + |
| 199 | +test('it throws an imap capability exception when inspecting quotas when the imap server does not support quotas', function () { |
| 200 | + $mailbox = Mailbox::make([ |
| 201 | + 'username' => 'foo', |
| 202 | + 'password' => 'bar', |
| 203 | + ]); |
| 204 | + |
| 205 | + $mailbox->connect(ImapConnection::fake([ |
| 206 | + '* OK Welcome to IMAP', |
| 207 | + 'TAG1 OK Logged in', |
| 208 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 209 | + 'TAG2 OK LIST completed', |
| 210 | + '* CAPABILITY IMAP4rev1 LITERAL+ UIDPLUS SORT IDLE MOVE', |
| 211 | + 'TAG3 OK CAPABILITY completed', |
| 212 | + ])); |
| 213 | + |
| 214 | + $mailbox->inbox()->quota(); |
| 215 | +})->throws(ImapCapabilityException::class); |
0 commit comments