2022-02-11 13:20:58 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-06-24 11:04:29 +03:00
|
|
|
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2022-02-11 13:20:58 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Mail\Tests\Unit\Service;
|
|
|
|
|
|
|
|
use ChristophWurst\Nextcloud\Testing\TestCase;
|
|
|
|
use OC\EventDispatcher\EventDispatcher;
|
|
|
|
use OCA\Mail\Account;
|
|
|
|
use OCA\Mail\Contracts\IMailManager;
|
|
|
|
use OCA\Mail\Db\LocalAttachment;
|
|
|
|
use OCA\Mail\Db\LocalMessage;
|
|
|
|
use OCA\Mail\Db\LocalMessageMapper;
|
|
|
|
use OCA\Mail\Db\Recipient;
|
|
|
|
use OCA\Mail\Exception\ClientException;
|
|
|
|
use OCA\Mail\IMAP\IMAPClientFactory;
|
2024-02-26 13:06:54 +03:00
|
|
|
use OCA\Mail\Send\Chain;
|
2022-03-25 13:37:57 +03:00
|
|
|
use OCA\Mail\Service\AccountService;
|
2022-02-11 13:20:58 +03:00
|
|
|
use OCA\Mail\Service\Attachment\AttachmentService;
|
|
|
|
use OCA\Mail\Service\MailTransmission;
|
|
|
|
use OCA\Mail\Service\OutboxService;
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
use OCP\DB\Exception;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2022-03-25 13:37:57 +03:00
|
|
|
use Psr\Log\LoggerInterface;
|
2022-02-11 13:20:58 +03:00
|
|
|
|
|
|
|
class OutboxServiceTest extends TestCase {
|
|
|
|
/** @var MailTransmission|MockObject */
|
|
|
|
private $transmission;
|
|
|
|
|
|
|
|
/** @var LocalMessageMapper|MockObject */
|
|
|
|
private $mapper;
|
|
|
|
|
|
|
|
/** @var OutboxService */
|
|
|
|
private $outboxService;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
|
|
|
|
|
|
|
/** @var ITimeFactory|MockObject */
|
|
|
|
private $time;
|
|
|
|
|
|
|
|
/** @var AttachmentService|MockObject */
|
|
|
|
private $attachmentService;
|
|
|
|
|
|
|
|
/** @var IMAPClientFactory|MockObject */
|
|
|
|
private $clientFactory;
|
|
|
|
|
|
|
|
/** @var IMailManager|MockObject */
|
|
|
|
private $mailManager;
|
|
|
|
|
2022-03-25 13:37:57 +03:00
|
|
|
/** @var AccountService|MockObject */
|
|
|
|
private $accountService;
|
|
|
|
|
|
|
|
/** @var ITimeFactory|MockObject */
|
|
|
|
private $timeFactory;
|
|
|
|
|
|
|
|
/** @var MockObject|LoggerInterface */
|
|
|
|
private $logger;
|
2024-06-26 20:33:34 +03:00
|
|
|
private MockObject|Chain $chain;
|
2022-03-25 13:37:57 +03:00
|
|
|
|
2022-02-11 13:20:58 +03:00
|
|
|
protected function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->transmission = $this->createMock(MailTransmission::class);
|
|
|
|
$this->mapper = $this->createMock(LocalMessageMapper::class);
|
|
|
|
$this->attachmentService = $this->createMock(AttachmentService::class);
|
|
|
|
$this->clientFactory = $this->createMock(IMAPClientFactory::class);
|
|
|
|
$this->mailManager = $this->createMock(IMailManager::class);
|
2022-03-25 13:37:57 +03:00
|
|
|
$this->accountService = $this->createMock(AccountService::class);
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
$this->logger = $this->createMock(LoggerInterface::class);
|
2024-02-26 13:06:54 +03:00
|
|
|
$this->chain = $this->createMock(Chain::class);
|
2022-02-11 13:20:58 +03:00
|
|
|
$this->outboxService = new OutboxService(
|
|
|
|
$this->transmission,
|
|
|
|
$this->mapper,
|
|
|
|
$this->attachmentService,
|
|
|
|
$this->createMock(EventDispatcher::class),
|
|
|
|
$this->clientFactory,
|
2022-03-25 13:37:57 +03:00
|
|
|
$this->mailManager,
|
|
|
|
$this->accountService,
|
|
|
|
$this->timeFactory,
|
|
|
|
$this->logger,
|
2024-02-26 13:06:54 +03:00
|
|
|
$this->chain,
|
2022-02-11 13:20:58 +03:00
|
|
|
);
|
|
|
|
$this->userId = 'linus';
|
|
|
|
$this->time = $this->createMock(ITimeFactory::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMessages(): void {
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('getAllForUser')
|
|
|
|
->with($this->userId)
|
|
|
|
->willReturn([
|
|
|
|
[
|
|
|
|
'id' => 1,
|
|
|
|
'type' => 0,
|
|
|
|
'account_id' => 1,
|
|
|
|
'alias_id' => 2,
|
|
|
|
'send_at' => $this->time->getTime(),
|
|
|
|
'subject' => 'Test',
|
|
|
|
'body' => 'Test',
|
|
|
|
'html' => false,
|
|
|
|
'reply_to_id' => null,
|
2024-02-26 13:06:54 +03:00
|
|
|
'draft_id' => 99,
|
|
|
|
'status' => 0,
|
|
|
|
'raw' => 'Test',
|
2022-02-11 13:20:58 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'id' => 2,
|
|
|
|
'type' => 0,
|
|
|
|
'account_id' => 1,
|
|
|
|
'alias_id' => 2,
|
|
|
|
'send_at' => $this->time->getTime(),
|
|
|
|
'subject' => 'Second Test',
|
|
|
|
'body' => 'Second Test',
|
|
|
|
'html' => true,
|
|
|
|
'reply_to_id' => null,
|
2024-02-26 13:06:54 +03:00
|
|
|
'draft_id' => null,
|
|
|
|
'status' => 0,
|
|
|
|
'raw' => 'Second Test',
|
2022-02-11 13:20:58 +03:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->outboxService->getMessages($this->userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMessagesNoneFound(): void {
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('getAllForUser')
|
|
|
|
->with($this->userId)
|
|
|
|
->willThrowException(new Exception());
|
|
|
|
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->outboxService->getMessages($this->userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetMessage(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('findById')
|
|
|
|
->with(1, $this->userId)
|
|
|
|
->willReturn($message);
|
|
|
|
|
|
|
|
$this->outboxService->getMessage(1, $this->userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoMessage(): void {
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('findById')
|
|
|
|
->with(1, $this->userId)
|
|
|
|
->willThrowException(new DoesNotExistException('Could not fetch any messages'));
|
|
|
|
|
|
|
|
$this->expectException(DoesNotExistException::class);
|
|
|
|
$this->outboxService->getMessage(1, $this->userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteMessage(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(10);
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
|
|
|
|
$this->attachmentService->expects(self::once())
|
|
|
|
->method('deleteLocalMessageAttachments')
|
|
|
|
->with($this->userId, $message->getId());
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('deleteWithRecipients')
|
|
|
|
->with($message);
|
|
|
|
|
|
|
|
$this->outboxService->deleteMessage($this->userId, $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveMessage(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
$to = [
|
|
|
|
[
|
|
|
|
'label' => 'Lewis',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$cc = [];
|
|
|
|
$bcc = [];
|
|
|
|
$attachments = [[]];
|
|
|
|
$attachmentIds = [1];
|
|
|
|
$rTo = Recipient::fromParams([
|
|
|
|
'label' => 'Lewis',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message2 = $message;
|
|
|
|
$message2->setId(10);
|
2022-05-24 18:34:50 +03:00
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
2022-02-11 13:20:58 +03:00
|
|
|
$client = $this->createMock(\Horde_Imap_Client_Socket::class);
|
|
|
|
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('saveWithRecipients')
|
|
|
|
->with($message, [$rTo], $cc, $bcc)
|
|
|
|
->willReturn($message2);
|
|
|
|
$this->clientFactory->expects(self::once())
|
|
|
|
->method('getClient')
|
|
|
|
->with($account)
|
|
|
|
->willReturn($client);
|
|
|
|
$this->attachmentService->expects(self::once())
|
|
|
|
->method('handleAttachments')
|
|
|
|
->with($account, $attachments, $client)
|
|
|
|
->willReturn($attachmentIds);
|
|
|
|
$this->attachmentService->expects(self::once())
|
|
|
|
->method('saveLocalMessageAttachments')
|
2022-05-24 18:34:50 +03:00
|
|
|
->with($this->userId, 10, $attachmentIds);
|
2022-02-11 13:20:58 +03:00
|
|
|
|
|
|
|
$this->outboxService->saveMessage($account, $message, $to, $cc, $bcc, $attachments);
|
|
|
|
}
|
|
|
|
|
2022-09-08 00:34:36 +03:00
|
|
|
public function testSaveMessageNoAttachments(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
$to = [
|
|
|
|
[
|
|
|
|
'label' => 'Lewis',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$cc = [];
|
|
|
|
$bcc = [];
|
|
|
|
$attachments = [];
|
|
|
|
$rTo = Recipient::fromParams([
|
|
|
|
'label' => 'Lewis',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message2 = $message;
|
|
|
|
$message2->setId(10);
|
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('saveWithRecipients')
|
|
|
|
->with($message, [$rTo], $cc, $bcc)
|
|
|
|
->willReturn($message2);
|
|
|
|
$this->clientFactory->expects(self::never())
|
|
|
|
->method('getClient');
|
|
|
|
$this->attachmentService->expects(self::never())
|
|
|
|
->method('handleAttachments');
|
|
|
|
$this->attachmentService->expects(self::never())
|
|
|
|
->method('saveLocalMessageAttachments');
|
|
|
|
|
|
|
|
$result = $this->outboxService->saveMessage($account, $message, $to, $cc, $bcc, $attachments);
|
|
|
|
$this->assertEquals($message2->getId(), $result->getId());
|
|
|
|
$this->assertEmpty($result->getAttachments());
|
|
|
|
}
|
|
|
|
|
2022-02-11 13:20:58 +03:00
|
|
|
public function testUpdateMessage(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(10);
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
$old = Recipient::fromParams([
|
|
|
|
'label' => 'Pam',
|
|
|
|
'email' => 'BuyMeAnAle@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message->setRecipients([$old]);
|
|
|
|
$to = [
|
|
|
|
[
|
|
|
|
'label' => 'Linus',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$cc = [];
|
|
|
|
$bcc = [];
|
|
|
|
$attachments = [['type' => '']];
|
|
|
|
$attachmentIds = [3];
|
|
|
|
$rTo = Recipient::fromParams([
|
|
|
|
'label' => 'Linus',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message2 = $message;
|
|
|
|
$message2->setRecipients([$rTo]);
|
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
2022-05-24 18:34:50 +03:00
|
|
|
'getUserId' => $this->userId
|
2022-02-11 13:20:58 +03:00
|
|
|
]);
|
|
|
|
$client = $this->createMock(\Horde_Imap_Client_Socket::class);
|
|
|
|
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('updateWithRecipients')
|
|
|
|
->with($message, [$rTo], $cc, $bcc)
|
|
|
|
->willReturn($message2);
|
|
|
|
$this->clientFactory->expects(self::once())
|
|
|
|
->method('getClient')
|
|
|
|
->with($account)
|
|
|
|
->willReturn($client);
|
|
|
|
$this->attachmentService->expects(self::once())
|
|
|
|
->method('handleAttachments')
|
|
|
|
->with($account, $attachments, $client)
|
|
|
|
->willReturn($attachmentIds);
|
|
|
|
$this->attachmentService->expects(self::once())
|
|
|
|
->method('updateLocalMessageAttachments')
|
|
|
|
->with($this->userId, $message2, $attachmentIds);
|
|
|
|
|
|
|
|
$this->outboxService->updateMessage($account, $message, $to, $cc, $bcc, $attachments);
|
|
|
|
}
|
|
|
|
|
2022-09-08 00:34:36 +03:00
|
|
|
public function testUpdateMessageNoAttachments(): void {
|
2022-02-11 13:20:58 +03:00
|
|
|
$message = new LocalMessage();
|
2022-09-08 00:34:36 +03:00
|
|
|
$message->setId(10);
|
2022-02-11 13:20:58 +03:00
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
2022-09-08 00:34:36 +03:00
|
|
|
$old = Recipient::fromParams([
|
|
|
|
'label' => 'Pam',
|
|
|
|
'email' => 'BuyMeAnAle@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message->setRecipients([$old]);
|
2022-02-11 13:20:58 +03:00
|
|
|
$to = [
|
|
|
|
[
|
2022-09-08 00:34:36 +03:00
|
|
|
'label' => 'Linus',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
2022-02-11 13:20:58 +03:00
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$cc = [];
|
|
|
|
$bcc = [];
|
2022-09-08 00:34:36 +03:00
|
|
|
$attachments = [];
|
2022-02-11 13:20:58 +03:00
|
|
|
$rTo = Recipient::fromParams([
|
2022-09-08 00:34:36 +03:00
|
|
|
'label' => 'Linus',
|
|
|
|
'email' => 'tent-living@startdewvalley.com',
|
2022-02-11 13:20:58 +03:00
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$message2 = $message;
|
2022-09-08 00:34:36 +03:00
|
|
|
$message2->setRecipients([$rTo]);
|
2022-05-24 18:34:50 +03:00
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
2024-02-26 13:06:54 +03:00
|
|
|
|
2022-02-11 13:20:58 +03:00
|
|
|
$this->mapper->expects(self::once())
|
2022-09-08 00:34:36 +03:00
|
|
|
->method('updateWithRecipients')
|
2022-02-11 13:20:58 +03:00
|
|
|
->with($message, [$rTo], $cc, $bcc)
|
|
|
|
->willReturn($message2);
|
|
|
|
$this->attachmentService->expects(self::once())
|
2022-09-08 00:34:36 +03:00
|
|
|
->method('updateLocalMessageAttachments')
|
|
|
|
->with($this->userId, $message2, $attachments);
|
|
|
|
$this->clientFactory->expects(self::never())
|
|
|
|
->method('getClient');
|
|
|
|
$this->attachmentService->expects(self::never())
|
|
|
|
->method('handleAttachments');
|
2024-02-26 13:06:54 +03:00
|
|
|
|
2022-09-08 00:34:36 +03:00
|
|
|
$result = $this->outboxService->updateMessage($account, $message, $to, $cc, $bcc, $attachments);
|
|
|
|
$this->assertEmpty($result->getAttachments());
|
2022-02-11 13:20:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSaveMessageError(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$message->setSendAt($this->time->getTime());
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('laskdjhsakjh33233928@startdewvalley.com');
|
|
|
|
$to = [
|
|
|
|
[
|
|
|
|
'label' => 'Gunther',
|
|
|
|
'email' => 'museum@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
$rTo = Recipient::fromParams([
|
|
|
|
'label' => 'Gunther',
|
|
|
|
'email' => 'museum@startdewvalley.com',
|
|
|
|
'type' => Recipient::TYPE_TO,
|
|
|
|
]);
|
|
|
|
$account = $this->createMock(Account::class);
|
|
|
|
|
|
|
|
$this->mapper->expects(self::once())
|
|
|
|
->method('saveWithRecipients')
|
|
|
|
->with($message, [$rTo], [], [])
|
|
|
|
->willThrowException(new Exception());
|
|
|
|
$this->attachmentService->expects(self::never())
|
|
|
|
->method('saveLocalMessageAttachments');
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
|
|
|
|
$this->outboxService->saveMessage($account, $message, $to, [], []);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSendMessage(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(1);
|
2024-02-26 13:06:54 +03:00
|
|
|
$message->setStatus(LocalMessage::STATUS_RAW);
|
2022-02-11 13:20:58 +03:00
|
|
|
$recipient = new Recipient();
|
|
|
|
$recipient->setEmail('museum@startdewvalley.com');
|
|
|
|
$recipient->setLabel('Gunther');
|
|
|
|
$recipient->setType(Recipient::TYPE_TO);
|
|
|
|
$recipients = [$recipient];
|
|
|
|
$attachment = new LocalAttachment();
|
|
|
|
$attachment->setMimeType('image/png');
|
|
|
|
$attachment->setFileName('SlimesInTheMines.png');
|
|
|
|
$attachment->setCreatedAt($this->time->getTime());
|
|
|
|
$attachments = [$attachment];
|
|
|
|
$message->setRecipients($recipients);
|
|
|
|
$message->setAttachments($attachments);
|
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
|
|
|
|
2024-02-26 13:06:54 +03:00
|
|
|
$this->chain->expects(self::once())
|
|
|
|
->method('process')
|
|
|
|
->with($account, $message);
|
|
|
|
|
|
|
|
$this->outboxService->sendMessage($message, $account);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSendMessageAlreadyProcessed(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(1);
|
|
|
|
$message->setStatus(LocalMessage::STATUS_PROCESSED);
|
|
|
|
$recipient = new Recipient();
|
|
|
|
$recipient->setEmail('museum@startdewvalley.com');
|
|
|
|
$recipient->setLabel('Gunther');
|
|
|
|
$recipient->setType(Recipient::TYPE_TO);
|
|
|
|
$recipients = [$recipient];
|
|
|
|
$attachment = new LocalAttachment();
|
|
|
|
$attachment->setMimeType('image/png');
|
|
|
|
$attachment->setFileName('SlimesInTheMines.png');
|
|
|
|
$attachment->setCreatedAt($this->time->getTime());
|
|
|
|
$attachments = [$attachment];
|
|
|
|
$message->setRecipients($recipients);
|
|
|
|
$message->setAttachments($attachments);
|
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->chain->expects(self::once())
|
|
|
|
->method('process')
|
2022-02-11 13:20:58 +03:00
|
|
|
->with($account, $message);
|
|
|
|
|
|
|
|
$this->outboxService->sendMessage($message, $account);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSendMessageTransmissionError(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(1);
|
2024-02-26 13:06:54 +03:00
|
|
|
$message->setStatus(LocalMessage::STATUS_NO_SENT_MAILBOX);
|
2022-02-11 13:20:58 +03:00
|
|
|
$recipient = new Recipient();
|
|
|
|
$recipient->setEmail('museum@startdewvalley.com');
|
|
|
|
$recipient->setLabel('Gunther');
|
|
|
|
$recipient->setType(Recipient::TYPE_TO);
|
|
|
|
$recipients = [$recipient];
|
|
|
|
$attachment = new LocalAttachment();
|
|
|
|
$attachment->setMimeType('image/png');
|
|
|
|
$attachment->setFileName('SlimesInTheMines.png');
|
|
|
|
$attachment->setCreatedAt($this->time->getTime());
|
|
|
|
$attachments = [$attachment];
|
|
|
|
$message->setRecipients($recipients);
|
|
|
|
$message->setAttachments($attachments);
|
|
|
|
$account = $this->createConfiguredMock(Account::class, [
|
|
|
|
'getUserId' => $this->userId
|
|
|
|
]);
|
|
|
|
|
2024-02-26 13:06:54 +03:00
|
|
|
$this->chain->expects(self::once())
|
|
|
|
->method('process')
|
|
|
|
->with($account, $message);
|
2022-02-11 13:20:58 +03:00
|
|
|
|
|
|
|
$this->outboxService->sendMessage($message, $account);
|
2024-02-26 13:06:54 +03:00
|
|
|
$this->assertEquals(LocalMessage::STATUS_NO_SENT_MAILBOX, $message->getStatus());
|
2022-02-11 13:20:58 +03:00
|
|
|
}
|
2023-08-14 19:41:58 +03:00
|
|
|
|
|
|
|
public function testConvertToOutboxMessageNoRecipients(): void {
|
|
|
|
$message = new LocalMessage();
|
|
|
|
$message->setId(10);
|
|
|
|
$message->setAccountId(1);
|
|
|
|
$sentAt = $this->time->getTime();
|
|
|
|
$message->setSendAt($sentAt);
|
|
|
|
$message->setSubject('Test');
|
|
|
|
$message->setBody('Test Test Test');
|
|
|
|
$message->setHtml(true);
|
|
|
|
$message->setInReplyToMessageId('abcd');
|
|
|
|
$message->setType(LocalMessage::TYPE_DRAFT);
|
|
|
|
|
|
|
|
$this->expectException(ClientException::class);
|
|
|
|
$this->outboxService->convertDraft($message, $sentAt);
|
|
|
|
}
|
2022-02-11 13:20:58 +03:00
|
|
|
}
|