| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
namespace Tests; |
| 14 |
|
| 15 |
use PHPUnit\Framework\TestCase; |
| 16 |
use Webklex\PHPIMAP\Config; |
| 17 |
use Webklex\PHPIMAP\Exceptions\InvalidMessageDateException; |
| 18 |
use Webklex\PHPIMAP\Exceptions\MessageContentFetchingException; |
| 19 |
use Webklex\PHPIMAP\Header; |
| 20 |
use Webklex\PHPIMAP\Structure; |
| 21 |
|
| 22 |
class StructureTest extends TestCase { |
| 23 |
|
| 24 |
|
| 25 |
protected Config $config; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function setUp(): void { |
| 33 |
$this->config = Config::make(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function testStructureParsing(): void { |
| 43 |
$email = file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, "messages", "[email protected]"])); |
| 44 |
if(!str_contains($email, "\r\n")){ |
| 45 |
$email = str_replace("\n", "\r\n", $email); |
| 46 |
} |
| 47 |
|
| 48 |
$raw_header = substr($email, 0, strpos($email, "\r\n\r\n")); |
| 49 |
$raw_body = substr($email, strlen($raw_header)+8); |
| 50 |
|
| 51 |
$header = new Header($raw_header, $this->config); |
| 52 |
$structure = new Structure($raw_body, $header); |
| 53 |
|
| 54 |
self::assertSame(2, count($structure->parts)); |
| 55 |
|
| 56 |
$textPart = $structure->parts[0]; |
| 57 |
|
| 58 |
self::assertSame("UTF-8", $textPart->charset); |
| 59 |
self::assertSame("text/plain", $textPart->content_type); |
| 60 |
self::assertSame(278, $textPart->bytes); |
| 61 |
|
| 62 |
$htmlPart = $structure->parts[1]; |
| 63 |
|
| 64 |
self::assertSame("UTF-8", $htmlPart->charset); |
| 65 |
self::assertSame("text/html", $htmlPart->content_type); |
| 66 |
self::assertSame(1478, $htmlPart->bytes); |
| 67 |
} |
| 68 |
} |