generated from Nodarx/template
feat: serve message fetches from the cache
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KTXT\ProviderImap\Tests\Unit;
|
||||
|
||||
use Generator;
|
||||
use KTXM\ProviderImap\Client\Protocol\Command\Argument\FetchOptions;
|
||||
use KTXM\ProviderImap\Client\Protocol\Parser\FetchMessageParser;
|
||||
use KTXM\ProviderImap\Providers\LiveService;
|
||||
use KTXM\ProviderImap\Providers\MessageProperties;
|
||||
use KTXM\ProviderImap\Service\Live\LiveMailService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MessageSectionsTest extends TestCase
|
||||
{
|
||||
public function testSectionsAreFetchedWithStructureAndDecoded(): void
|
||||
{
|
||||
$live = new class(new LiveService()) extends LiveMailService {
|
||||
public ?string $command = null;
|
||||
|
||||
public function messageFetch(string $collection, ?FetchOptions $options = null, int ...$uids): Generator
|
||||
{
|
||||
$this->command = $options?->toCommand();
|
||||
$structure = '(("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "BASE64" 16 1)'
|
||||
. '("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "7BIT" 12 1) "ALTERNATIVE" ("BOUNDARY" "b") NIL NIL)';
|
||||
yield 7 => FetchMessageParser::parse(
|
||||
"* 1 FETCH (UID 7 BODYSTRUCTURE {$structure} BODY[1] {16}\r\nSGVsbG8gd29ybGQ= BODY[2] {12}\r\n<p>Hello</p>)"
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
$sections = $live->messageSections('INBOX', 7, '1', '2');
|
||||
|
||||
$this->assertStringContainsString('BODYSTRUCTURE', (string) $live->command);
|
||||
$this->assertStringContainsString('BODY.PEEK[1]', (string) $live->command);
|
||||
$this->assertStringContainsString('BODY.PEEK[2]', (string) $live->command);
|
||||
$this->assertSame(['1' => 'Hello world', '2' => '<p>Hello</p>'], $sections);
|
||||
}
|
||||
|
||||
public function testCompleteSectionReplacesNestedContentAndClearsTheMark(): void
|
||||
{
|
||||
$properties = new MessageProperties([]);
|
||||
$properties->jsonDeserialize(['body' => [
|
||||
'partId' => '1', 'type' => 'multipart/alternative', 'subParts' => [
|
||||
['partId' => '1.1', 'type' => 'text/plain', 'content' => 'Hi'],
|
||||
['partId' => '1.2', 'type' => 'text/html', 'content' => '<p>Hello wor'],
|
||||
],
|
||||
]]);
|
||||
$properties->setIncompleteSections('1.2');
|
||||
|
||||
$this->assertTrue($properties->completeSection('1.2', '<p>Hello world</p>'));
|
||||
$this->assertFalse($properties->completeSection('9', 'x'));
|
||||
|
||||
$this->assertSame('<p>Hello world</p>', $properties->getBodyTextHtml());
|
||||
$this->assertSame('Hi', $properties->getBodyTextPlain());
|
||||
$this->assertSame([], $properties->getIncompleteSections());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user