| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Tests\live; |
| 14 |
|
| 15 |
use Webklex\PHPIMAP\Client; |
| 16 |
use Webklex\PHPIMAP\Connection\Protocols\ProtocolInterface; |
| 17 |
use Webklex\PHPIMAP\EncodingAliases; |
| 18 |
use Webklex\PHPIMAP\Exceptions\AuthFailedException; |
| 19 |
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException; |
| 20 |
use Webklex\PHPIMAP\Exceptions\FolderFetchingException; |
| 21 |
use Webklex\PHPIMAP\Exceptions\ImapBadRequestException; |
| 22 |
use Webklex\PHPIMAP\Exceptions\ImapServerErrorException; |
| 23 |
use Webklex\PHPIMAP\Exceptions\MaskNotFoundException; |
| 24 |
use Webklex\PHPIMAP\Exceptions\ResponseException; |
| 25 |
use Webklex\PHPIMAP\Exceptions\RuntimeException; |
| 26 |
use Webklex\PHPIMAP\Folder; |
| 27 |
use Webklex\PHPIMAP\Support\Masks\AttachmentMask; |
| 28 |
use Webklex\PHPIMAP\Support\Masks\MessageMask; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
class ClientTest extends LiveMailboxTestCase { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function testConnect(): void { |
| 50 |
self::assertNotNull($this->getClient()->connect()); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function testIsConnected(): void { |
| 66 |
$client = $this->getClient()->connect(); |
| 67 |
|
| 68 |
self::assertTrue($client->isConnected()); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function testDisconnect(): void { |
| 84 |
$client = $this->getClient()->connect(); |
| 85 |
|
| 86 |
self::assertFalse($client->disconnect()->isConnected()); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public function testGetFolder(): void { |
| 103 |
$client = $this->getClient()->connect(); |
| 104 |
|
| 105 |
$folder = $client->getFolder('INBOX'); |
| 106 |
self::assertInstanceOf(Folder::class, $folder); |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function testGetFolderByName(): void { |
| 123 |
$client = $this->getClient()->connect(); |
| 124 |
|
| 125 |
$folder = $client->getFolderByName('INBOX'); |
| 126 |
self::assertInstanceOf(Folder::class, $folder); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function testGetFolderByPath(): void { |
| 143 |
$client = $this->getClient()->connect(); |
| 144 |
|
| 145 |
$folder = $client->getFolderByPath('INBOX'); |
| 146 |
self::assertInstanceOf(Folder::class, $folder); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
public function testGetFolders(): void { |
| 163 |
$client = $this->getClient()->connect(); |
| 164 |
|
| 165 |
$folders = $client->getFolders(false); |
| 166 |
self::assertTrue($folders->count() > 0); |
| 167 |
} |
| 168 |
|
| 169 |
public function testGetFoldersWithStatus(): void { |
| 170 |
$client = $this->getClient()->connect(); |
| 171 |
|
| 172 |
$folders = $client->getFoldersWithStatus(false); |
| 173 |
self::assertTrue($folders->count() > 0); |
| 174 |
} |
| 175 |
|
| 176 |
public function testOpenFolder(): void { |
| 177 |
$client = $this->getClient()->connect(); |
| 178 |
|
| 179 |
$status = $client->openFolder("INBOX"); |
| 180 |
self::assertTrue(isset($status["flags"]) && count($status["flags"]) > 0); |
| 181 |
self::assertTrue(($status["uidnext"] ?? 0) > 0); |
| 182 |
self::assertTrue(($status["uidvalidity"] ?? 0) > 0); |
| 183 |
self::assertTrue(($status["recent"] ?? -1) >= 0); |
| 184 |
self::assertTrue(($status["exists"] ?? -1) >= 0); |
| 185 |
} |
| 186 |
|
| 187 |
public function testCreateFolder(): void { |
| 188 |
$client = $this->getClient()->connect(); |
| 189 |
|
| 190 |
$delimiter = $this->getManager()->getConfig()->get("options.delimiter"); |
| 191 |
$folder_path = implode($delimiter, ['INBOX', $this->getSpecialChars()]); |
| 192 |
|
| 193 |
$folder = $client->getFolder($folder_path); |
| 194 |
|
| 195 |
$this->deleteFolder($folder); |
| 196 |
|
| 197 |
$folder = $client->createFolder($folder_path, false); |
| 198 |
self::assertInstanceOf(Folder::class, $folder); |
| 199 |
|
| 200 |
$folder = $this->getFolder($folder_path); |
| 201 |
self::assertInstanceOf(Folder::class, $folder); |
| 202 |
|
| 203 |
$this->assertEquals($this->getSpecialChars(), $folder->name); |
| 204 |
$this->assertEquals($folder_path, $folder->full_name); |
| 205 |
|
| 206 |
$folder_path = implode($delimiter, ['INBOX', EncodingAliases::convert($this->getSpecialChars(), "utf-8", "utf7-imap")]); |
| 207 |
$this->assertEquals($folder_path, $folder->path); |
| 208 |
|
| 209 |
|
| 210 |
if ($this->deleteFolder($folder) === false) { |
| 211 |
$this->fail("Could not delete folder: " . $folder->path); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
public function testCheckFolder(): void { |
| 216 |
$client = $this->getClient()->connect(); |
| 217 |
|
| 218 |
$status = $client->checkFolder("INBOX"); |
| 219 |
self::assertTrue(isset($status["flags"]) && count($status["flags"]) > 0); |
| 220 |
self::assertTrue(($status["uidnext"] ?? 0) > 0); |
| 221 |
self::assertTrue(($status["uidvalidity"] ?? 0) > 0); |
| 222 |
self::assertTrue(($status["recent"] ?? -1) >= 0); |
| 223 |
self::assertTrue(($status["exists"] ?? -1) >= 0); |
| 224 |
} |
| 225 |
|
| 226 |
public function testGetFolderPath(): void { |
| 227 |
$client = $this->getClient()->connect(); |
| 228 |
|
| 229 |
self::assertIsArray($client->openFolder("INBOX")); |
| 230 |
self::assertEquals("INBOX", $client->getFolderPath()); |
| 231 |
} |
| 232 |
|
| 233 |
public function testId(): void { |
| 234 |
$client = $this->getClient()->connect(); |
| 235 |
|
| 236 |
$info = $client->Id(); |
| 237 |
self::assertIsArray($info); |
| 238 |
$valid = false; |
| 239 |
foreach ($info as $value) { |
| 240 |
if (str_starts_with($value, "OK")) { |
| 241 |
$valid = true; |
| 242 |
break; |
| 243 |
} |
| 244 |
} |
| 245 |
self::assertTrue($valid); |
| 246 |
} |
| 247 |
|
| 248 |
public function testGetQuotaRoot(): void { |
| 249 |
if (!getenv("LIVE_MAILBOX_QUOTA_SUPPORT")) { |
| 250 |
$this->markTestSkipped("Quota support is not enabled"); |
| 251 |
} |
| 252 |
|
| 253 |
$client = $this->getClient()->connect(); |
| 254 |
|
| 255 |
$quota = $client->getQuotaRoot("INBOX"); |
| 256 |
self::assertIsArray($quota); |
| 257 |
self::assertTrue(count($quota) > 1); |
| 258 |
self::assertIsArray($quota[0]); |
| 259 |
self::assertEquals("INBOX", $quota[0][1]); |
| 260 |
self::assertIsArray($quota[1]); |
| 261 |
self::assertIsArray($quota[1][2]); |
| 262 |
self::assertTrue($quota[1][2][2] > 0); |
| 263 |
} |
| 264 |
|
| 265 |
public function testSetTimeout(): void { |
| 266 |
$client = $this->getClient()->connect(); |
| 267 |
|
| 268 |
self::assertInstanceOf(ProtocolInterface::class, $client->setTimeout(57)); |
| 269 |
self::assertEquals(57, $client->getTimeout()); |
| 270 |
} |
| 271 |
|
| 272 |
public function testExpunge(): void { |
| 273 |
$client = $this->getClient()->connect(); |
| 274 |
|
| 275 |
$client->openFolder("INBOX"); |
| 276 |
$status = $client->expunge(); |
| 277 |
|
| 278 |
self::assertIsArray($status); |
| 279 |
self::assertIsArray($status[0]); |
| 280 |
self::assertEquals("OK", $status[0][0]); |
| 281 |
} |
| 282 |
|
| 283 |
public function testGetDefaultMessageMask(): void { |
| 284 |
$client = $this->getClient(); |
| 285 |
|
| 286 |
self::assertEquals(MessageMask::class, $client->getDefaultMessageMask()); |
| 287 |
} |
| 288 |
|
| 289 |
public function testGetDefaultEvents(): void { |
| 290 |
$client = $this->getClient(); |
| 291 |
|
| 292 |
self::assertIsArray($client->getDefaultEvents("message")); |
| 293 |
} |
| 294 |
|
| 295 |
public function testSetDefaultMessageMask(): void { |
| 296 |
$client = $this->getClient(); |
| 297 |
|
| 298 |
self::assertInstanceOf(Client::class, $client->setDefaultMessageMask(AttachmentMask::class)); |
| 299 |
self::assertEquals(AttachmentMask::class, $client->getDefaultMessageMask()); |
| 300 |
|
| 301 |
$client->setDefaultMessageMask(MessageMask::class); |
| 302 |
} |
| 303 |
|
| 304 |
public function testGetDefaultAttachmentMask(): void { |
| 305 |
$client = $this->getClient(); |
| 306 |
|
| 307 |
self::assertEquals(AttachmentMask::class, $client->getDefaultAttachmentMask()); |
| 308 |
} |
| 309 |
|
| 310 |
public function testSetDefaultAttachmentMask(): void { |
| 311 |
$client = $this->getClient(); |
| 312 |
|
| 313 |
self::assertInstanceOf(Client::class, $client->setDefaultAttachmentMask(MessageMask::class)); |
| 314 |
self::assertEquals(MessageMask::class, $client->getDefaultAttachmentMask()); |
| 315 |
|
| 316 |
$client->setDefaultAttachmentMask(AttachmentMask::class); |
| 317 |
} |
| 318 |
} |