|
3 | 3 | use DirectoryTree\ImapEngine\Connection\ImapConnection; |
4 | 4 | use DirectoryTree\ImapEngine\Connection\Streams\FakeStream; |
5 | 5 | use DirectoryTree\ImapEngine\Exceptions\ImapCommandException; |
| 6 | +use DirectoryTree\ImapEngine\Folder; |
6 | 7 | use DirectoryTree\ImapEngine\Mailbox; |
7 | 8 |
|
8 | 9 | test('config defaults', function () { |
|
94 | 95 |
|
95 | 96 | $mailbox->connect(new ImapConnection($stream)); |
96 | 97 | })->throws(ImapCommandException::class, 'IMAP command "TAG1 LOGIN [redacted] [redacted]" failed. Response: "TAG1 BAD Authentication failed"'); |
| 98 | + |
| 99 | +test('folders', function () { |
| 100 | + $stream = new FakeStream; |
| 101 | + $stream->open(); |
| 102 | + |
| 103 | + $stream->feed([ |
| 104 | + '* OK Welcome to IMAP', |
| 105 | + 'TAG1 OK Logged in', |
| 106 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 107 | + 'TAG2 OK LIST completed', |
| 108 | + ]); |
| 109 | + |
| 110 | + $mailbox = Mailbox::make(); |
| 111 | + |
| 112 | + $mailbox->connect(new ImapConnection($stream)); |
| 113 | + |
| 114 | + $folders = $mailbox->folders()->get(); |
| 115 | + |
| 116 | + $stream->assertWritten('TAG1 LOGIN "" ""'); |
| 117 | + $stream->assertWritten('TAG2 LIST "" "*"'); |
| 118 | + |
| 119 | + expect($folders)->toHaveCount(1); |
| 120 | + expect($folders[0]->path())->toBe('INBOX'); |
| 121 | + expect($folders[0]->flags())->toBe(['\\HasNoChildren']); |
| 122 | +}); |
| 123 | + |
| 124 | +test('inbox', function () { |
| 125 | + $stream = new FakeStream; |
| 126 | + $stream->open(); |
| 127 | + |
| 128 | + $stream->feed([ |
| 129 | + '* OK Welcome to IMAP', |
| 130 | + 'TAG1 OK Logged in', |
| 131 | + '* LIST (\\HasNoChildren) "/" "INBOX"', |
| 132 | + 'TAG2 OK LIST completed', |
| 133 | + ]); |
| 134 | + |
| 135 | + $mailbox = Mailbox::make(); |
| 136 | + |
| 137 | + $mailbox->connect(new ImapConnection($stream)); |
| 138 | + |
| 139 | + $folder = $mailbox->inbox(); |
| 140 | + |
| 141 | + $stream->assertWritten('TAG1 LOGIN "" ""'); |
| 142 | + $stream->assertWritten('TAG2 LIST "" "INBOX"'); |
| 143 | + |
| 144 | + expect($folder)->toBeInstanceOf(Folder::class); |
| 145 | + |
| 146 | + expect($folder->path())->toBe('INBOX'); |
| 147 | + expect($folder->flags())->toBe(['\\HasNoChildren']); |
| 148 | +}); |
0 commit comments