diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-09-26 18:07:47 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-09-27 11:02:10 +0300 |
commit | b5ddae4e1534bb45c5f81a9743d7c943d04712a5 (patch) | |
tree | 610d983e9801641047f394aa75d1b0027dbd1e35 /tests | |
parent | 30b1f1e4259c99985855e4ac8a101bb2acbf4f19 (diff) |
Refactor \OCA\Mail\Mailbox::getMessage
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Controller/AccountsControllerTest.php | 8 | ||||
-rw-r--r-- | tests/Controller/MessagesControllerTest.php | 14 | ||||
-rw-r--r-- | tests/Integration/Service/MailTransmissionIntegrationTest.php | 2 | ||||
-rw-r--r-- | tests/Listener/FlagRepliedMessageListenerTest.php | 4 | ||||
-rw-r--r-- | tests/Model/IMAPMessageTest.php | 4 | ||||
-rw-r--r-- | tests/Model/MessageTest.php | 6 | ||||
-rw-r--r-- | tests/Model/RepliedMessageTest.php | 4 | ||||
-rw-r--r-- | tests/Model/ReplyMessageTest.php | 132 | ||||
-rw-r--r-- | tests/Service/MailTransmissionTest.php | 32 |
9 files changed, 34 insertions, 172 deletions
diff --git a/tests/Controller/AccountsControllerTest.php b/tests/Controller/AccountsControllerTest.php index 9cb2f4909..5afb4ffbc 100644 --- a/tests/Controller/AccountsControllerTest.php +++ b/tests/Controller/AccountsControllerTest.php @@ -88,7 +88,7 @@ class AccountsControllerTest extends TestCase { /** @var IMailTransmission|PHPUnit_Framework_MockObject_MockObject */ private $transmission; - + /** @var SetupService|PHPUnit_Framework_MockObject_MockObject */ private $setupService; @@ -355,7 +355,7 @@ class AccountsControllerTest extends TestCase { $this->assertEquals($expectedResponse, $response); } - + public function testUpdateManualFailure() { $autoDetect = false; $id = 135; @@ -416,7 +416,7 @@ class AccountsControllerTest extends TestCase { public function testSendReply() { $account = $this->createMock(Account::class); - $folderId = base64_encode('INBOX'); + $folderId = 'INBOX'; $messageId = 1234; $this->accountService->expects($this->once()) ->method('find') @@ -428,7 +428,7 @@ class AccountsControllerTest extends TestCase { ->with($this->userId, $messageData, $replyData, null, null); $expected = new JSONResponse(); - $resp = $this->controller->send(13, 'sub', 'bod', 'to@d.com', '', '', null, $folderId, $messageId, [], null); + $resp = $this->controller->send(13, 'sub', 'bod', 'to@d.com', '', '', null, base64_encode($folderId), $messageId, [], null); $this->assertEquals($expected, $resp); } diff --git a/tests/Controller/MessagesControllerTest.php b/tests/Controller/MessagesControllerTest.php index b65b20bc5..623f3b5e4 100644 --- a/tests/Controller/MessagesControllerTest.php +++ b/tests/Controller/MessagesControllerTest.php @@ -110,22 +110,16 @@ class MessagesControllerTest extends TestCase { $accountId = 17; $folderId = 'testfolder'; $messageId = 4321; + $message = $this->createMock(IMAPMessage::class); $this->accountService->expects($this->once()) ->method('find') ->with($this->equalTo($this->userId), $this->equalTo($accountId)) ->will($this->returnValue($this->account)); - $this->account->expects($this->once()) - ->method('getMailbox') - ->with($this->equalTo($folderId)) - ->will($this->returnValue($this->mailbox)); - $this->mailbox->expects($this->once()) + $this->mailManager->expects($this->once()) ->method('getMessage') - ->with($this->equalTo($messageId)) - ->will($this->returnValue($this->message)); - $this->message->expects($this->once()) - ->method('getHtmlBody') - ->willReturn(''); + ->with($this->account, $folderId, $messageId, true) + ->willReturn($message); $this->timeFactory->method('getTime')->willReturn(1000); $expectedResponse = new HtmlResponse(''); diff --git a/tests/Integration/Service/MailTransmissionIntegrationTest.php b/tests/Integration/Service/MailTransmissionIntegrationTest.php index 5d6be8a3c..8197366f7 100644 --- a/tests/Integration/Service/MailTransmissionIntegrationTest.php +++ b/tests/Integration/Service/MailTransmissionIntegrationTest.php @@ -170,7 +170,7 @@ class MailTransmissionIntegrationTest extends TestCase { ->finish(); $originalUID = $this->saveMessage('inbox', $originalMessage); - $message = NewMessageData::fromRequest($this->account, 'recipient@domain.com', null, null, null, 'hello there', []); + $message = NewMessageData::fromRequest($this->account, 'recipient@domain.com', null, null, '', 'hello there', []); $reply = new RepliedMessageData($this->account, $inbox, $originalUID); $uid = $this->transmission->sendMessage('ferdinand', $message, $reply); diff --git a/tests/Listener/FlagRepliedMessageListenerTest.php b/tests/Listener/FlagRepliedMessageListenerTest.php index 73f3ca4eb..45bd38278 100644 --- a/tests/Listener/FlagRepliedMessageListenerTest.php +++ b/tests/Listener/FlagRepliedMessageListenerTest.php @@ -134,7 +134,7 @@ class FlagRepliedMessageListenerTest extends TestCase { ->willReturn(true); $repliedMessageData->expects($this->once()) ->method('getFolderId') - ->willReturn(base64_encode('INBOX')); + ->willReturn('INBOX'); $this->mailboxMapper->expects($this->once()) ->method('find') ->with($account, 'INBOX') @@ -171,7 +171,7 @@ class FlagRepliedMessageListenerTest extends TestCase { ->willReturn(true); $repliedMessageData->expects($this->once()) ->method('getFolderId') - ->willReturn(base64_encode('INBOX')); + ->willReturn('INBOX'); $repliedMessageData->expects($this->once()) ->method('getId') ->willReturn(321); diff --git a/tests/Model/IMAPMessageTest.php b/tests/Model/IMAPMessageTest.php index 9f1693090..2eca99d08 100644 --- a/tests/Model/IMAPMessageTest.php +++ b/tests/Model/IMAPMessageTest.php @@ -86,12 +86,12 @@ class IMAPMessageTest extends TestCase { public function testSerialize() { $data = new Horde_Imap_Client_Data_Fetch(); + $data->setUid(1234); $m = new IMAPMessage(null, 'INBOX', 123, $data); - $m->setUid('1234'); $json = $m->jsonSerialize(); - $this->assertEquals('1234', $json['id']); + $this->assertEquals(1234, $json['id']); } } diff --git a/tests/Model/MessageTest.php b/tests/Model/MessageTest.php index f0216e00e..b4e42d0ef 100644 --- a/tests/Model/MessageTest.php +++ b/tests/Model/MessageTest.php @@ -107,10 +107,10 @@ class MessageTest extends TestCase { } public function testRepliedMessage() { - $reply = new Message(); + $reply = '9609171955.AA24342@cmstex2.maths.umanitoba.ca'; - $this->message->setRepliedMessage($reply); - $actual = $this->message->getRepliedMessage(); + $this->message->setInReplyTo($reply); + $actual = $this->message->getInReplyTo(); $this->assertSame($reply, $actual); } diff --git a/tests/Model/RepliedMessageTest.php b/tests/Model/RepliedMessageTest.php index be23ac27a..b4004f07a 100644 --- a/tests/Model/RepliedMessageTest.php +++ b/tests/Model/RepliedMessageTest.php @@ -24,6 +24,7 @@ namespace OCA\Mail\Tests\Model; use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Account; use OCA\Mail\Model\RepliedMessageData; +use PHPUnit\Framework\MockObject\MockObject; class RepliedMessageTest extends TestCase { @@ -35,8 +36,9 @@ class RepliedMessageTest extends TestCase { } public function testGetFolderId() { + /** @var Account|MockObject $account */ $account = $this->createMock(Account::class); - $folderId = base64_encode('INBOX'); + $folderId = 'INBOX'; $data = new RepliedMessageData($account, $folderId, null); $this->assertEquals($folderId, $data->getFolderId()); diff --git a/tests/Model/ReplyMessageTest.php b/tests/Model/ReplyMessageTest.php deleted file mode 100644 index 0a05f4bfc..000000000 --- a/tests/Model/ReplyMessageTest.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php - -/** - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * - * Mail - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ -namespace OCA\Mail\Tests\Model; - -use OCA\Mail\Model\ReplyMessage; - -class ReplyMessageTest extends MessageTest { - - protected function setUp() { - parent::setUp(); - - $this->message = new ReplyMessage(); - } - - public function testSubject() { - $subject = 'test message'; - - $this->message->setSubject($subject); - - // "Re: " should be added - $this->assertSame("Re: $subject", $this->message->getSubject()); - } - - public function testSubjectReStacking() { - $subject = 'Re: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectReCaseStacking() { - $subject = 'RE: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectAwStacking() { - $subject = 'Aw: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectAwCaseStacking() { - $subject = 'AW: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectWgStacking() { - $subject = 'Wg: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectWgCaseStacking() { - $subject = 'WG: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectFwStacking() { - $subject = 'Fw: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectFwCaseStacking() { - $subject = 'FW: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectFwdStacking() { - $subject = 'Fwd: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - - public function testSubjectFwdCaseStacking() { - $subject = 'FWD: test message'; - - $this->message->setSubject($subject); - - // Subject shouldn't change - $this->assertSame($subject, $this->message->getSubject()); - } - -} diff --git a/tests/Service/MailTransmissionTest.php b/tests/Service/MailTransmissionTest.php index 6c520f8eb..f7fdc585e 100644 --- a/tests/Service/MailTransmissionTest.php +++ b/tests/Service/MailTransmissionTest.php @@ -22,23 +22,21 @@ namespace OCA\Mail\Tests\Service; use ChristophWurst\Nextcloud\Testing\TestCase; -use Horde_Imap_Client; +use Horde_Imap_Client_Socket; use Horde_Mail_Transport; use OC\Files\Node\File; use OCA\Mail\Account; -use OCA\Mail\Address; -use OCA\Mail\AddressList; use OCA\Mail\Contracts\IAttachmentService; use OCA\Mail\Db\Alias; use OCA\Mail\Db\MailboxMapper; use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\IMAP\MessageMapper; use OCA\Mail\Mailbox; +use OCA\Mail\Model\IMAPMessage; use OCA\Mail\Model\IMessage; use OCA\Mail\Model\Message; use OCA\Mail\Model\NewMessageData; use OCA\Mail\Model\RepliedMessageData; -use OCA\Mail\Model\ReplyMessage; use OCA\Mail\Service\MailTransmission; use OCA\Mail\SMTP\SmtpClientFactory; use OCP\EventDispatcher\IEventDispatcher; @@ -185,22 +183,22 @@ class MailTransmissionTest extends TestCase { /** @var Account|MockObject $account */ $account = $this->createMock(Account::class); $messageData = NewMessageData::fromRequest($account, 'to@d.com', '', '', 'sub', 'bod'); - $folderId = base64_encode('INBOX'); + $folderId = 'INBOX'; $repliedMessageId = 321; $replyData = new RepliedMessageData($account, $folderId, $repliedMessageId); - $message = new ReplyMessage(); + $message = new Message(); $account->expects($this->once()) - ->method('newReplyMessage') + ->method('newMessage') ->willReturn($message); - $mailbox = $this->createMock(Mailbox::class); - $account->expects($this->once()) - ->method('getMailbox') - ->with(base64_decode($folderId)) - ->willReturn($mailbox); - $repliedMessage = $this->createMock(IMessage::class); - $mailbox->expects($this->once()) - ->method('getMessage') - ->with($repliedMessageId) + $client = $this->createMock(Horde_Imap_Client_Socket::class); + $this->imapClientFactory->expects($this->once()) + ->method('getClient') + ->with($account) + ->willReturn($client); + $repliedMessage = $this->createMock(IMAPMessage::class); + $this->messageMapper->expects($this->once()) + ->method('find') + ->with($client, $folderId, $repliedMessageId) ->willReturn($repliedMessage); $transport = $this->createMock(Horde_Mail_Transport::class); $this->smtpClientFactory->expects($this->once()) @@ -219,7 +217,7 @@ class MailTransmissionTest extends TestCase { $account->expects($this->once()) ->method('newMessage') ->willReturn($message); - $client = $this->createMock(\Horde_Imap_Client_Socket::class); + $client = $this->createMock(Horde_Imap_Client_Socket::class); $this->imapClientFactory->expects($this->once()) ->method('getClient') ->with($account) |