diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-10 16:03:01 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-02-10 18:23:08 +0300 |
commit | a129d48104fae9a09eec2d5a5d3725817248ca1f (patch) | |
tree | ceae73e05b1cc90449007f4fa2d324772351fbb5 /tests | |
parent | 9983469f045fdd120498acee9da73bd400227d82 (diff) |
Delete cached messages when deleting them on IMAP
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Listener/MessageDeletedCacheUpdaterListenerTest.php | 69 | ||||
-rw-r--r-- | tests/Unit/Service/MailManagerTest.php | 19 |
2 files changed, 73 insertions, 15 deletions
diff --git a/tests/Unit/Listener/MessageDeletedCacheUpdaterListenerTest.php b/tests/Unit/Listener/MessageDeletedCacheUpdaterListenerTest.php new file mode 100644 index 000000000..d9692802b --- /dev/null +++ b/tests/Unit/Listener/MessageDeletedCacheUpdaterListenerTest.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace OCA\Mail\Tests\Unit\Listener; + +use ChristophWurst\Nextcloud\Testing\ServiceMockObject; +use ChristophWurst\Nextcloud\Testing\TestCase; +use OCA\Mail\Events\MessageDeletedEvent; +use OCA\Mail\Listener\MessageDeletedCacheUpdaterListener; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class MessageDeletedCacheUpdaterListenerTest extends TestCase { + + /** @var ServiceMockObject */ + private $serviceMock; + + /** @var IEventListener */ + private $listener; + + protected function setUp(): void { + parent::setUp(); + + $this->serviceMock = $this->createServiceMock(MessageDeletedCacheUpdaterListener::class); + $this->listener = $this->serviceMock->getService(); + } + + public function testHandleUnrelated() { + $event = new Event(); + $this->serviceMock->getParameter('mapper') + ->expects($this->never()) + ->method('deleteByUid'); + + $this->listener->handle($event); + } + + public function testHandle() { + $event = $this->createMock(MessageDeletedEvent::class); + $this->serviceMock->getParameter('mapper') + ->expects($this->once()) + ->method('deleteByUid') + ->with($event->getMailbox(), $event->getMessageId()); + + $this->listener->handle($event); + } + +} diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php index 11a11e698..1a4a728ed 100644 --- a/tests/Unit/Service/MailManagerTest.php +++ b/tests/Unit/Service/MailManagerTest.php @@ -34,9 +34,6 @@ use OCA\Mail\IMAP\FolderStats; use OCA\Mail\IMAP\IMAPClientFactory; use OCA\Mail\IMAP\MailboxSync; use OCA\Mail\IMAP\MessageMapper; -use OCA\Mail\IMAP\Sync\Request; -use OCA\Mail\IMAP\Sync\Response; -use OCA\Mail\IMAP\Sync\Synchronizer; use OCA\Mail\Service\MailManager; use OCP\AppFramework\Db\DoesNotExistException; use OCP\EventDispatcher\IEventDispatcher; @@ -206,12 +203,8 @@ class MailManagerTest extends TestCase { $inbox->setName('INBOX'); $trash = new Mailbox(); $trash->setName('Trash'); - $this->eventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(BeforeMessageDeletedEvent::class), - $this->anything() - ); + $this->eventDispatcher->expects($this->exactly(2)) + ->method('dispatch'); $this->mailboxMapper->expects($this->once()) ->method('find') ->with($account, 'INBOX') @@ -247,12 +240,8 @@ class MailManagerTest extends TestCase { $source->setName('Trash'); $trash = new Mailbox(); $trash->setName('Trash'); - $this->eventDispatcher->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo(BeforeMessageDeletedEvent::class), - $this->anything() - ); + $this->eventDispatcher->expects($this->exactly(2)) + ->method('dispatch'); $this->mailboxMapper->expects($this->once()) ->method('find') ->with($account, 'Trash') |