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