Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2021-04-27 21:31:52 +0300
committerGitHub <noreply@github.com>2021-04-27 21:31:52 +0300
commit1a42826dc5779fcb7c8f6521b4b139e6fca0be3c (patch)
tree6fd53d4d4c2ef8b6258cf5c6e00d5785fb60d744 /tests
parent84f3739580ae5319cd0270492c9e509f50363216 (diff)
parentdaf3cb9d5a18d5ef67f0f7b58c536f84d2138dda (diff)
Merge pull request #4969 from nextcloud/enhancement/1400/unread-counter
Reintroduce unread counter in app navigation
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/MailboxesControllerTest.php17
-rw-r--r--tests/Unit/IMAP/FolderMapperTest.php4
-rw-r--r--tests/Unit/IMAP/MailboxSyncTest.php32
-rw-r--r--tests/Unit/IMAP/Sync/ResponseTest.php1
-rw-r--r--tests/Unit/Service/MailManagerTest.php23
-rw-r--r--tests/Unit/Service/Sync/SyncServiceTest.php147
6 files changed, 186 insertions, 38 deletions
diff --git a/tests/Unit/Controller/MailboxesControllerTest.php b/tests/Unit/Controller/MailboxesControllerTest.php
index 30499a6fd..b7911aacc 100644
--- a/tests/Unit/Controller/MailboxesControllerTest.php
+++ b/tests/Unit/Controller/MailboxesControllerTest.php
@@ -31,7 +31,7 @@ use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\MailboxesController;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Folder;
-use OCA\Mail\IMAP\FolderStats;
+use OCA\Mail\IMAP\MailboxStats;
use OCA\Mail\Service\AccountService;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCP\AppFramework\Http\JSONResponse;
@@ -137,26 +137,17 @@ class MailboxesControllerTest extends TestCase {
}
public function testStats() {
- $account = $this->createMock(Account::class);
- $stats = $this->createMock(FolderStats::class);
- $accountId = 28;
$mailbox = new Mailbox();
- $mailbox->setAccountId($accountId);
+ $mailbox->setUnseen(10);
+ $mailbox->setMessages(42);
$this->mailManager->expects($this->once())
->method('getMailbox')
->with('john', 13)
->willReturn($mailbox);
- $this->accountService->expects($this->once())
- ->method('find')
- ->with($this->equalTo($this->userId), $this->equalTo($accountId))
- ->willReturn($account);
- $this->mailManager->expects($this->once())
- ->method('getMailboxStats')
- ->with($this->equalTo($account), $mailbox)
- ->willReturn($stats);
$response = $this->controller->stats(13);
+ $stats = new MailboxStats(42, 10);
$expected = new JSONResponse($stats);
$this->assertEquals($expected, $response);
}
diff --git a/tests/Unit/IMAP/FolderMapperTest.php b/tests/Unit/IMAP/FolderMapperTest.php
index e94f2eee1..4a5447ea3 100644
--- a/tests/Unit/IMAP/FolderMapperTest.php
+++ b/tests/Unit/IMAP/FolderMapperTest.php
@@ -29,7 +29,7 @@ use Horde_Imap_Client_Socket;
use OCA\Mail\Account;
use OCA\Mail\Folder;
use OCA\Mail\IMAP\FolderMapper;
-use OCA\Mail\IMAP\FolderStats;
+use OCA\Mail\IMAP\MailboxStats;
use ChristophWurst\Nextcloud\Testing\TestCase;
class FolderMapperTest extends TestCase {
@@ -207,7 +207,7 @@ class FolderMapperTest extends TestCase {
$stats = $this->mapper->getFoldersStatusAsObject($client, 'INBOX');
- $expected = new FolderStats(123, 2);
+ $expected = new MailboxStats(123, 2);
$this->assertEquals($expected, $stats);
}
diff --git a/tests/Unit/IMAP/MailboxSyncTest.php b/tests/Unit/IMAP/MailboxSyncTest.php
index 159edcee1..e1b9aca65 100644
--- a/tests/Unit/IMAP/MailboxSyncTest.php
+++ b/tests/Unit/IMAP/MailboxSyncTest.php
@@ -32,10 +32,12 @@ use OC\AppFramework\Utility\TimeFactory;
use OCA\Mail\Account;
use OCA\Mail\Db\MailAccount;
use OCA\Mail\Db\MailAccountMapper;
+use OCA\Mail\Db\Mailbox;
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Events\MailboxesSynchronizedEvent;
use OCA\Mail\Folder;
use OCA\Mail\IMAP\FolderMapper;
+use OCA\Mail\IMAP\MailboxStats;
use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\IMAP\MailboxSync;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -117,6 +119,12 @@ class MailboxSyncTest extends TestCase {
$this->createMock(Folder::class),
$this->createMock(Folder::class),
];
+ $status = [
+ 'unseen' => 10,
+ 'messages' => 42,
+ ];
+ $folders[0]->method('getStatus')->willReturn($status);
+ $folders[1]->method('getStatus')->willReturn($status);
$this->folderMapper->expects($this->once())
->method('getFolders')
->with($account, $client)
@@ -131,4 +139,28 @@ class MailboxSyncTest extends TestCase {
$this->sync->sync($account, new NullLogger());
}
+
+ public function testSyncStats() {
+ $account = $this->createMock(Account::class);
+ $client = $this->createMock(Horde_Imap_Client_Socket::class);
+ $this->imapClientFactory->expects($this->once())
+ ->method('getClient')
+ ->with($account)
+ ->willReturn($client);
+ $stats = new MailboxStats(42, 10);
+ $mailbox = new Mailbox();
+ $mailbox->setName('mailbox');
+ $this->folderMapper->expects($this->once())
+ ->method('getFoldersStatusAsObject')
+ ->with($client, $mailbox->getName())
+ ->willReturn($stats);
+ $this->mailboxMapper->expects($this->once())
+ ->method('update')
+ ->with($mailbox);
+
+ $this->sync->syncStats($account, $mailbox);
+
+ $this->assertEquals(42, $mailbox->getMessages());
+ $this->assertEquals(10, $mailbox->getUnseen());
+ }
}
diff --git a/tests/Unit/IMAP/Sync/ResponseTest.php b/tests/Unit/IMAP/Sync/ResponseTest.php
index 27fb3c6b5..ec2dfa2cf 100644
--- a/tests/Unit/IMAP/Sync/ResponseTest.php
+++ b/tests/Unit/IMAP/Sync/ResponseTest.php
@@ -34,6 +34,7 @@ class ResponseTest extends TestCase {
'newMessages' => [],
'changedMessages' => [],
'vanishedMessages' => [],
+ 'stats' => null,
];
$json = $response->jsonSerialize();
diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php
index 8406205dc..f42b586d7 100644
--- a/tests/Unit/Service/MailManagerTest.php
+++ b/tests/Unit/Service/MailManagerTest.php
@@ -37,7 +37,6 @@ use OCA\Mail\Events\BeforeMessageDeletedEvent;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Folder;
use OCA\Mail\IMAP\FolderMapper;
-use OCA\Mail\IMAP\FolderStats;
use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\IMAP\MailboxSync;
use OCA\Mail\IMAP\MessageMapper as ImapMessageMapper;
@@ -153,28 +152,6 @@ class MailManagerTest extends TestCase {
$this->assertEquals($mailbox, $created);
}
- public function testGetFolderStats() {
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $account = $this->createMock(Account::class);
- $this->imapClientFactory->expects($this->once())
- ->method('getClient')
- ->willReturn($client);
- $stats = $this->createMock(FolderStats::class);
- $this->folderMapper->expects($this->once())
- ->method('getFoldersStatusAsObject')
- ->with($this->equalTo($client), $this->equalTo('INBOX'))
- ->willReturn($stats);
- $mailbox = new Mailbox();
- $mailbox->setName('INBOX');
-
- $actual = $this->manager->getMailboxStats(
- $account,
- $mailbox
- );
-
- $this->assertEquals($stats, $actual);
- }
-
public function testDeleteMessageSourceFolderNotFound(): void {
/** @var Account|MockObject $account */
$account = $this->createMock(Account::class);
diff --git a/tests/Unit/Service/Sync/SyncServiceTest.php b/tests/Unit/Service/Sync/SyncServiceTest.php
new file mode 100644
index 000000000..1df91bc46
--- /dev/null
+++ b/tests/Unit/Service/Sync/SyncServiceTest.php
@@ -0,0 +1,147 @@
+<?php
+
+/**
+ * @copyright 2021 Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @author 2021 Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @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\Service\Sync;
+
+use OCA\Mail\Account;
+use OCA\Mail\Db\Mailbox;
+use OCA\Mail\Db\MailboxMapper;
+use OCA\Mail\Db\MessageMapper;
+use OCA\Mail\Exception\MailboxNotCachedException;
+use OCA\Mail\IMAP\MailboxStats;
+use OCA\Mail\IMAP\MailboxSync;
+use OCA\Mail\IMAP\PreviewEnhancer;
+use OCA\Mail\IMAP\Sync\Response;
+use OCA\Mail\Service\Search\FilterStringParser;
+use OCA\Mail\Service\Sync\ImapToDbSynchronizer;
+use OCA\Mail\Service\Sync\SyncService;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
+
+class SyncServiceTest extends TestCase {
+
+ /** @var ImapToDbSynchronizer */
+ private $synchronizer;
+
+ /** @var FilterStringParser */
+ private $filterStringParser;
+
+ /** @var MailboxMapper */
+ private $mailboxMapper;
+
+ /** @var MessageMapper */
+ private $messageMapper;
+
+ /** @var PreviewEnhancer */
+ private $previewEnhancer;
+
+ /** @var LoggerInterface */
+ private $loggerInterface;
+
+ /** @var MailboxSync */
+ private $mailboxSync;
+
+ /** @var SyncService */
+ private $syncService;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->synchronizer = $this->createMock(ImapToDbSynchronizer::class);
+ $this->filterStringParser = $this->createMock(FilterStringParser::class);
+ $this->mailboxMapper = $this->createMock(MailboxMapper::class);
+ $this->messageMapper = $this->createMock(MessageMapper::class);
+ $this->previewEnhancer = $this->createMock(PreviewEnhancer::class);
+ $this->loggerInterface = $this->createMock(LoggerInterface::class);
+ $this->mailboxSync = $this->createMock(MailboxSync::class);
+
+ $this->syncService = new SyncService(
+ $this->synchronizer,
+ $this->filterStringParser,
+ $this->mailboxMapper,
+ $this->messageMapper,
+ $this->previewEnhancer,
+ $this->loggerInterface,
+ $this->mailboxSync
+ );
+ }
+
+ public function testPartialSyncOnUncachedMailbox() {
+ $account = $this->createMock(Account::class);
+ $mailbox = $this->createMock(Mailbox::class);
+ $mailbox->expects($this->once())
+ ->method('isCached')
+ ->willReturn(false);
+
+ $this->expectException(MailboxNotCachedException::class);
+ $this->syncService->syncMailbox(
+ $account,
+ $mailbox,
+ 42,
+ [],
+ true
+ );
+ }
+
+ public function testSyncMailboxReturnsFolderStats() {
+ $account = $this->createMock(Account::class);
+ $account->method('getUserId')->willReturn('user');
+ $mailbox = new Mailbox();
+ $mailbox->setMessages(42);
+ $mailbox->setUnseen(10);
+ $expectedResponse = new Response(
+ [],
+ [],
+ [],
+ new MailboxStats(42, 10)
+ );
+
+ $this->messageMapper
+ ->method('findUidsForIds')
+ ->with($mailbox, [])
+ ->willReturn([]);
+ $this->synchronizer->expects($this->once())
+ ->method('sync')
+ ->with(
+ $account,
+ $mailbox,
+ $this->loggerInterface,
+ 0,
+ [],
+ true
+ );
+ $this->mailboxSync->expects($this->once())
+ ->method('syncStats')
+ ->with($account, $mailbox);
+
+ $response = $this->syncService->syncMailbox(
+ $account,
+ $mailbox,
+ 0,
+ [],
+ false
+ );
+
+ $this->assertEquals($expectedResponse, $response);
+ }
+}