| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Tests; |
| 14 |
|
| 15 |
use Carbon\Carbon; |
| 16 |
use PHPUnit\Framework\TestCase; |
| 17 |
use Webklex\PHPIMAP\Config; |
| 18 |
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException; |
| 19 |
use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException; |
| 20 |
use Webklex\PHPIMAP\Header; |
| 21 |
use Webklex\PHPIMAP\Part; |
| 22 |
use Webklex\PHPIMAP\Structure; |
| 23 |
use Webklex\PHPIMAP\IMAP; |
| 24 |
|
| 25 |
class PartTest extends TestCase { |
| 26 |
|
| 27 |
|
| 28 |
protected Config $config; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function setUp(): void { |
| 36 |
$this->config = Config::make(); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public function testTextPart(): void { |
| 44 |
$raw_headers = "Content-Type: text/plain;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\n"; |
| 45 |
$raw_body = "\r\nAny updates?"; |
| 46 |
|
| 47 |
$headers = new Header($raw_headers, $this->config); |
| 48 |
$part = new Part($raw_body, $this->config, $headers, 0); |
| 49 |
|
| 50 |
self::assertSame("UTF-8", $part->charset); |
| 51 |
self::assertSame("text/plain", $part->content_type); |
| 52 |
self::assertSame(12, $part->bytes); |
| 53 |
self::assertSame(0, $part->part_number); |
| 54 |
self::assertSame(false, $part->ifdisposition); |
| 55 |
self::assertSame(false, $part->isAttachment()); |
| 56 |
self::assertSame("Any updates?", $part->content); |
| 57 |
self::assertSame(IMAP::MESSAGE_TYPE_TEXT, $part->type); |
| 58 |
self::assertSame(IMAP::MESSAGE_ENC_7BIT, $part->encoding); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function testHTMLPart(): void { |
| 66 |
$raw_headers = "Content-Type: text/html;\r\n charset=UTF-8\r\nContent-Transfer-Encoding: 7bit\r\n"; |
| 67 |
$raw_body = "\r\n<p></p>\r\n<p dir=\"auto\">Any updates?</p>"; |
| 68 |
|
| 69 |
$headers = new Header($raw_headers, $this->config); |
| 70 |
$part = new Part($raw_body, $this->config, $headers, 0); |
| 71 |
|
| 72 |
self::assertSame("UTF-8", $part->charset); |
| 73 |
self::assertSame("text/html", $part->content_type); |
| 74 |
self::assertSame(39, $part->bytes); |
| 75 |
self::assertSame(0, $part->part_number); |
| 76 |
self::assertSame(false, $part->ifdisposition); |
| 77 |
self::assertSame(false, $part->isAttachment()); |
| 78 |
self::assertSame("<p></p>\r\n<p dir=\"auto\">Any updates?</p>", $part->content); |
| 79 |
self::assertSame(IMAP::MESSAGE_TYPE_TEXT, $part->type); |
| 80 |
self::assertSame(IMAP::MESSAGE_ENC_7BIT, $part->encoding); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function testBase64Part(): void { |
| 88 |
$raw_headers = "Content-Type: application/octet-stream; name=6mfFxiU5Yhv9WYJx.txt\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=6mfFxiU5Yhv9WYJx.txt\r\n"; |
| 89 |
$raw_body = "em5rNTUxTVAzVFAzV1BwOUtsMWduTEVycldFZ2tKRkF0dmFLcWtUZ3JrM2RLSThkWDM4WVQ4QmFW\r\neFJjT0VSTg=="; |
| 90 |
|
| 91 |
$headers = new Header($raw_headers, $this->config); |
| 92 |
$part = new Part($raw_body, $this->config, $headers, 0); |
| 93 |
|
| 94 |
self::assertSame("", $part->charset); |
| 95 |
self::assertSame("application/octet-stream", $part->content_type); |
| 96 |
self::assertSame(90, $part->bytes); |
| 97 |
self::assertSame(0, $part->part_number); |
| 98 |
self::assertSame("znk551MP3TP3WPp9Kl1gnLErrWEgkJFAtvaKqkTgrk3dKI8dX38YT8BaVxRcOERN", base64_decode($part->content)); |
| 99 |
self::assertSame(true, $part->ifdisposition); |
| 100 |
self::assertSame("attachment", $part->disposition); |
| 101 |
self::assertSame("6mfFxiU5Yhv9WYJx.txt", $part->name); |
| 102 |
self::assertSame("6mfFxiU5Yhv9WYJx.txt", $part->filename); |
| 103 |
self::assertSame(true, $part->isAttachment()); |
| 104 |
self::assertSame(IMAP::MESSAGE_TYPE_TEXT, $part->type); |
| 105 |
self::assertSame(IMAP::MESSAGE_ENC_BASE64, $part->encoding); |
| 106 |
} |
| 107 |
} |