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 <christoph@winzerhof-wurst.at>2019-10-02 12:47:00 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-01-31 18:43:51 +0300
commitc287787f8df599b567f399f6022ffc88db3a0582 (patch)
tree6d1863eff65f5c43db73c1e36df6938c505ef58e /tests
parent31f89d71f860c8c2f75234537a8d64f38da696ab (diff)
Add a cache for IMAP message in the database
Co-authored-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/Integration/Db/MailboxMapperTest.php20
-rw-r--r--tests/Integration/FolderSynchronizationTest.php80
-rw-r--r--tests/Integration/Framework/ImapTestAccount.php10
-rw-r--r--tests/Unit/Controller/FoldersControllerTest.php25
-rw-r--r--tests/Unit/Controller/MessagesControllerTest.php6
-rw-r--r--tests/Unit/IMAP/Search/SearchFilterStringParserTest.php60
-rw-r--r--tests/Unit/IMAP/Search/SearchStrategyFactoryTest.php152
-rw-r--r--tests/Unit/IMAP/Sync/ResponseTest.php4
-rw-r--r--tests/Unit/IMAP/Sync/SimpleMailboxSyncTest.php2
-rw-r--r--tests/Unit/IMAP/Sync/SynchronizerTest.php20
-rw-r--r--tests/Unit/Service/AccountServiceTest.php14
-rw-r--r--tests/Unit/Service/MailManagerTest.php23
-rw-r--r--tests/Unit/Service/MailSearchTest.php43
13 files changed, 145 insertions, 314 deletions
diff --git a/tests/Integration/Db/MailboxMapperTest.php b/tests/Integration/Db/MailboxMapperTest.php
index a1107145c..0200b0f55 100644
--- a/tests/Integration/Db/MailboxMapperTest.php
+++ b/tests/Integration/Db/MailboxMapperTest.php
@@ -28,6 +28,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Account;
use OCA\Mail\Db\MailboxMapper;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use PHPUnit\Framework\MockObject\MockObject;
@@ -42,12 +43,17 @@ class MailboxMapperTest extends TestCase {
/** @var MailboxMapper */
private $mapper;
+ /** @var ITimeFactory| MockObject */
+ private $timeFactory;
+
protected function setUp(): void {
parent::setUp();
$this->db = \OC::$server->getDatabaseConnection();
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->mapper = new MailboxMapper(
- $this->db
+ $this->db,
+ $this->timeFactory
);
$qb = $this->db->getQueryBuilder();
@@ -74,7 +80,9 @@ class MailboxMapperTest extends TestCase {
->values([
'name' => $qb->createNamedParameter("folder$i"),
'account_id' => $qb->createNamedParameter($i <= 5 ? 13 : 14, IQueryBuilder::PARAM_INT),
- 'sync_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_new_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_changed_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_vanished_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
'delimiter' => $qb->createNamedParameter('.'),
'messages' => $qb->createNamedParameter($i * 100, IQueryBuilder::PARAM_INT),
'unseen' => $qb->createNamedParameter($i, IQueryBuilder::PARAM_INT),
@@ -106,7 +114,9 @@ class MailboxMapperTest extends TestCase {
->values([
'name' => $qb->createNamedParameter('INBOX'),
'account_id' => $qb->createNamedParameter(13, IQueryBuilder::PARAM_INT),
- 'sync_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_new_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_changed_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_vanished_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
'delimiter' => $qb->createNamedParameter('.'),
'messages' => $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT),
'unseen' => $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT),
@@ -137,7 +147,9 @@ class MailboxMapperTest extends TestCase {
->values([
'name' => $qb->createNamedParameter('Trash'),
'account_id' => $qb->createNamedParameter(13, IQueryBuilder::PARAM_INT),
- 'sync_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_new_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_changed_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
+ 'sync_vanished_token' => $qb->createNamedParameter('VTEsVjE0Mjg1OTkxNDk='),
'delimiter' => $qb->createNamedParameter('.'),
'messages' => $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT),
'unseen' => $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT),
diff --git a/tests/Integration/FolderSynchronizationTest.php b/tests/Integration/FolderSynchronizationTest.php
index 841a10508..c9c28bfdc 100644
--- a/tests/Integration/FolderSynchronizationTest.php
+++ b/tests/Integration/FolderSynchronizationTest.php
@@ -22,16 +22,18 @@
namespace OCA\Mail\Tests\Integration;
use OC;
+use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\FoldersController;
use OCA\Mail\Service\AccountService;
+use OCA\Mail\Service\SyncService;
use OCA\Mail\Tests\Integration\Framework\ImapTest;
use OCA\Mail\Tests\Integration\Framework\ImapTestAccount;
class FolderSynchronizationTest extends TestCase {
use ImapTest,
- ImapTestAccount;
+ ImapTestAccount;
/** @var FoldersController */
private $foldersController;
@@ -39,31 +41,45 @@ class FolderSynchronizationTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->foldersController = new FoldersController('mail', OC::$server->getRequest(), OC::$server->query(AccountService::class), $this->getTestAccountUserId(), OC::$server->query(IMailManager::class));
+ $this->foldersController = new FoldersController(
+ 'mail',
+ OC::$server->getRequest(),
+ OC::$server->query(AccountService::class),
+ $this->getTestAccountUserId(),
+ OC::$server->query(IMailManager::class),
+ OC::$server->query(SyncService::class)
+ );
}
public function testSyncEmptyMailbox() {
$account = $this->createTestAccount();
+ /** @var SyncService $syncService */
+ $syncService = OC::$server->query(SyncService::class);
+ $syncService->syncAccount(new Account($account), true);
$mailbox = 'INBOX';
- $syncToken = $this->getMailboxSyncToken($mailbox);
-
- $jsonResponse = $this->foldersController->sync($account->getId(), base64_encode($mailbox), $syncToken);
- $syncJson = $jsonResponse->getData()->jsonSerialize();
- $this->assertArrayHasKey('newMessages', $syncJson);
- $this->assertArrayHasKey('changedMessages', $syncJson);
- $this->assertArrayHasKey('vanishedMessages', $syncJson);
- $this->assertArrayHasKey('token', $syncJson);
- $this->assertEmpty($syncJson['newMessages']);
- $this->assertEmpty($syncJson['changedMessages']);
- $this->assertEmpty($syncJson['vanishedMessages']);
+ $jsonResponse = $this->foldersController->sync(
+ $account->getId(),
+ base64_encode($mailbox),
+ []
+ );
+
+ $data = $jsonResponse->getData()->jsonSerialize();
+ $this->assertArrayHasKey('newMessages', $data);
+ $this->assertArrayHasKey('changedMessages', $data);
+ $this->assertArrayHasKey('vanishedMessages', $data);
+ $this->assertEmpty($data['newMessages']);
+ $this->assertEmpty($data['changedMessages']);
+ $this->assertEmpty($data['vanishedMessages']);
}
public function testSyncNewMessage() {
// First, set up account and retrieve sync token
$account = $this->createTestAccount();
+ /** @var SyncService $syncService */
+ $syncService = OC::$server->query(SyncService::class);
+ $syncService->syncAccount(new Account($account), true);
$mailbox = 'INBOX';
- $syncToken = $this->getMailboxSyncToken($mailbox);
// Second, put a new message into the mailbox
$message = $this->getMessageBuilder()
->from('ralph@buffington@domain.tld')
@@ -71,7 +87,11 @@ class FolderSynchronizationTest extends TestCase {
->finish();
$this->saveMessage($mailbox, $message);
- $jsonResponse = $this->foldersController->sync($account->getId(), base64_encode($mailbox), $syncToken);
+ $jsonResponse = $this->foldersController->sync(
+ $account->getId(),
+ base64_encode($mailbox),
+ []
+ );
$syncJson = $jsonResponse->getData()->jsonSerialize();
$this->assertCount(1, $syncJson['newMessages']);
@@ -82,6 +102,9 @@ class FolderSynchronizationTest extends TestCase {
public function testSyncChangedMessage() {
// First, put a message into the mailbox
$account = $this->createTestAccount();
+ /** @var SyncService $syncService */
+ $syncService = OC::$server->query(SyncService::class);
+ $syncService->syncAccount(new Account($account), true);
$mailbox = 'INBOX';
$message = $this->getMessageBuilder()
->from('ralph@buffington@domain.tld')
@@ -93,19 +116,25 @@ class FolderSynchronizationTest extends TestCase {
// Third, flag it
$this->flagMessage($mailbox, $id);
- $jsonResponse = $this->foldersController->sync($account->getId(), base64_encode($mailbox), $syncToken, [
- $id
- ]);
+ $jsonResponse = $this->foldersController->sync(
+ $account->getId(),
+ base64_encode($mailbox),
+ [
+ $id
+ ]);
$syncJson = $jsonResponse->getData()->jsonSerialize();
- $this->assertCount(0, $syncJson['newMessages']);
- $this->assertCount(1, $syncJson['changedMessages']);
+ $this->assertCount(1, $syncJson['newMessages']);
+ $this->assertCount(2, $syncJson['changedMessages']);
$this->assertCount(0, $syncJson['vanishedMessages']);
}
public function testSyncVanishedMessage() {
// First, put a message into the mailbox
$account = $this->createTestAccount();
+ /** @var SyncService $syncService */
+ $syncService = OC::$server->query(SyncService::class);
+ $syncService->syncAccount(new Account($account), true);
$mailbox = 'INBOX';
$message = $this->getMessageBuilder()
->from('ralph@buffington@domain.tld')
@@ -117,15 +146,18 @@ class FolderSynchronizationTest extends TestCase {
// Third, remove it again
$this->deleteMessage($mailbox, $id);
- $jsonResponse = $this->foldersController->sync($account->getId(), base64_encode($mailbox), $syncToken, [
- $id
- ]);
+ $jsonResponse = $this->foldersController->sync(
+ $account->getId(),
+ base64_encode($mailbox),
+ [
+ $id
+ ]);
$syncJson = $jsonResponse->getData()->jsonSerialize();
$this->assertCount(0, $syncJson['newMessages']);
// TODO: deleted messages are flagged as changed? could be a testing-only issue
// $this->assertCount(0, $syncJson['changedMessages']);
- $this->assertCount(1, $syncJson['vanishedMessages']);
+ $this->assertCount(2, $syncJson['vanishedMessages']);
}
}
diff --git a/tests/Integration/Framework/ImapTestAccount.php b/tests/Integration/Framework/ImapTestAccount.php
index d6f15da67..30271542a 100644
--- a/tests/Integration/Framework/ImapTestAccount.php
+++ b/tests/Integration/Framework/ImapTestAccount.php
@@ -22,7 +22,9 @@
namespace OCA\Mail\Tests\Integration\Framework;
use OC;
+use OCA\Mail\Account;
use OCA\Mail\Db\MailAccount;
+use OCA\Mail\IMAP\MailboxSync;
use OCA\Mail\Service\AccountService;
trait ImapTestAccount {
@@ -57,7 +59,13 @@ trait ImapTestAccount {
$mailAccount->setOutboundUser('user@domain.tld');
$mailAccount->setOutboundPassword(OC::$server->getCrypto()->encrypt('mypassword'));
$mailAccount->setOutboundSslMode('none');
- return $accountService->save($mailAccount);
+ $acc = $accountService->save($mailAccount);
+
+ /** @var MailboxSync $mbSync */
+ $mbSync = OC::$server->query(MailboxSync::class);
+ $mbSync->sync(new Account($mailAccount));
+
+ return $acc;
}
}
diff --git a/tests/Unit/Controller/FoldersControllerTest.php b/tests/Unit/Controller/FoldersControllerTest.php
index c2aaf68e7..2b338b1ba 100644
--- a/tests/Unit/Controller/FoldersControllerTest.php
+++ b/tests/Unit/Controller/FoldersControllerTest.php
@@ -21,6 +21,8 @@
namespace OCA\Mail\Tests\Unit\Controller;
+use OCA\Mail\Service\SyncService;
+use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode;
use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
@@ -32,34 +34,45 @@ use OCA\Mail\Service\AccountService;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
-use PHPUnit_Framework_MockObject_MockObject;
class FoldersControllerTest extends TestCase {
/** @var string */
private $appName = 'mail';
- /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IRequest|MockObject */
private $request;
- /** @var AccountService|PHPUnit_Framework_MockObject_MockObject */
+ /** @var AccountService|MockObject */
private $accountService;
/** @var string */
private $userId = 'john';
- /** @var IMailManager|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IMailManager|MockObject */
private $mailManager;
/** @var FoldersController */
private $controller;
+ /** @var SyncService|MockObject */
+ private $syncService;
+
public function setUp(): void {
parent::setUp();
+
$this->request = $this->createMock(IRequest::class);
$this->accountService = $this->createMock(AccountService::class);
$this->mailManager = $this->createMock(IMailManager::class);
- $this->controller = new FoldersController($this->appName, $this->request, $this->accountService, $this->userId, $this->mailManager);
+ $this->syncService = $this->createMock(SyncService::class);
+ $this->controller = new FoldersController(
+ $this->appName,
+ $this->request,
+ $this->accountService,
+ $this->userId,
+ $this->mailManager,
+ $this->syncService
+ );
}
public function testIndex() {
@@ -75,7 +88,7 @@ class FoldersControllerTest extends TestCase {
->with($this->equalTo($account))
->willReturn([
$folder
- ]);
+ ]);
$account->expects($this->once())
->method('getEmail')
->willReturn('user@example.com');
diff --git a/tests/Unit/Controller/MessagesControllerTest.php b/tests/Unit/Controller/MessagesControllerTest.php
index 1178a03c4..0b215c557 100644
--- a/tests/Unit/Controller/MessagesControllerTest.php
+++ b/tests/Unit/Controller/MessagesControllerTest.php
@@ -38,6 +38,7 @@ use OCA\Mail\Model\Message;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\ItineraryService;
use OCA\Mail\Service\MailManager;
+use OCA\Mail\Service\SyncService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
@@ -71,6 +72,9 @@ class MessagesControllerTest extends TestCase {
/** @var ItineraryService|MockObject */
private $itineraryService;
+ /** @var SyncService|MockObject */
+ private $syncService;
+
/** @var string */
private $userId;
@@ -116,6 +120,7 @@ class MessagesControllerTest extends TestCase {
$this->mailManager = $this->createMock(IMailManager::class);
$this->mailSearch = $this->createMock(IMailSearch::class);
$this->itineraryService = $this->createMock(ItineraryService::class);
+ $this->syncService = $this->createMock(SyncService::class);
$this->userId = 'john';
$this->userFolder = $this->createMock(Folder::class);
$this->request = $this->createMock(Request::class);
@@ -140,6 +145,7 @@ class MessagesControllerTest extends TestCase {
$this->mailManager,
$this->mailSearch,
$this->itineraryService,
+ $this->syncService,
$this->userId,
$this->userFolder,
$this->logger,
diff --git a/tests/Unit/IMAP/Search/SearchFilterStringParserTest.php b/tests/Unit/IMAP/Search/SearchFilterStringParserTest.php
deleted file mode 100644
index 9a1affe75..000000000
--- a/tests/Unit/IMAP/Search/SearchFilterStringParserTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php declare(strict_types=1);
-
-/**
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2019 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\IMAP\Search;
-
-use ChristophWurst\Nextcloud\Testing\TestCase;
-use OCA\Mail\IMAP\Search\SearchFilterStringParser;
-
-class SearchFilterStringParserTest extends TestCase {
-
- private function search($filter) {
- $helper = new SearchFilterStringParser();
- $query = $helper->parse($filter);
- return (string)($query->build()['query']);
- }
-
- public function testSearchEmpty() {
- $this->assertEquals('ALL', $this->search(''));
- }
-
- public function testSearchTest() {
- $this->assertEquals('TEXT "dummy text"', $this->search('dummy text'));
- }
-
- public function testSearchUnread() {
- $this->assertEquals('UNSEEN', $this->search('is:unread'));
- }
-
- public function testSearchNotAnswered() {
- $this->assertEquals('UNANSWERED', $this->search('not:answered'));
- }
-
- public function testSearchFrom() {
- $this->assertEquals('FROM somebody@example.com', $this->search('from:somebody@example.com'));
- }
-
- public function testSearchMixed() {
- $this->assertEquals('UNSEEN FROM somebody@example.com TEXT nextcloud', $this->search('from:somebody@example.com is:unread nextcloud'));
- }
-}
diff --git a/tests/Unit/IMAP/Search/SearchStrategyFactoryTest.php b/tests/Unit/IMAP/Search/SearchStrategyFactoryTest.php
deleted file mode 100644
index 5f926125b..000000000
--- a/tests/Unit/IMAP/Search/SearchStrategyFactoryTest.php
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php declare(strict_types=1);
-
-/**
- * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2019 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\IMAP\Search;
-
-use ChristophWurst\Nextcloud\Testing\TestCase;
-use Horde_Imap_Client_Data_Capability;
-use Horde_Imap_Client_Search_Query;
-use Horde_Imap_Client_Socket;
-use OCA\Mail\IMAP\Search\FullScanSearchStrategy;
-use OCA\Mail\IMAP\Search\ImapSortSearchStrategy;
-use OCA\Mail\IMAP\Search\SearchStrategyFactory;
-use PHPUnit\Framework\MockObject\MockObject;
-
-class SearchStrategyFactoryTest extends TestCase {
-
- /** @var SearchStrategyFactory */
- private $factory;
-
- protected function setUp(): void {
- parent::setUp();
-
- $this->factory = new SearchStrategyFactory();
- }
-
- public function testGetStrategyForFetchNoFilter() {
- /** @var MockObject|Horde_Imap_Client_Socket $client */
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $mailbox = 'INBOX';
- $filter = new Horde_Imap_Client_Search_Query();
- $cursor = null;
- $capability = $this->createMock(Horde_Imap_Client_Data_Capability::class);
- $client->expects($this->once())
- ->method('__get')
- ->with('capability')
- ->willReturn($capability);
- $capability->expects($this->once())
- ->method('query')
- ->with('SORT')
- ->willReturn(true);
-
- $strategy = $this->factory->getStrategy(
- $client,
- $mailbox,
- $filter,
- $cursor
- );
-
- $this->assertInstanceOf(ImapSortSearchStrategy::class, $strategy);
- }
-
- public function testGetStrategyForFetchNoSort() {
- /** @var MockObject|Horde_Imap_Client_Socket $client */
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $mailbox = 'INBOX';
- $filter = new Horde_Imap_Client_Search_Query();
- $cursor = null;
- $capability = $this->createMock(Horde_Imap_Client_Data_Capability::class);
- $client->expects($this->once())
- ->method('__get')
- ->with('capability')
- ->willReturn($capability);
- $capability->expects($this->once())
- ->method('query')
- ->with('SORT')
- ->willReturn(false);
-
- $strategy = $this->factory->getStrategy(
- $client,
- $mailbox,
- $filter,
- $cursor
- );
-
- $this->assertInstanceOf(FullScanSearchStrategy::class, $strategy);
- }
-
- public function testGetStrategyForSearchWithSort() {
- /** @var MockObject|Horde_Imap_Client_Socket $client */
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $mailbox = 'INBOX';
- $filter = new Horde_Imap_Client_Search_Query();
- $filter->text('test');
- $cursor = null;
- $capability = $this->createMock(Horde_Imap_Client_Data_Capability::class);
- $client->expects($this->once())
- ->method('__get')
- ->with('capability')
- ->willReturn($capability);
- $capability->expects($this->once())
- ->method('query')
- ->with('SORT')
- ->willReturn(true);
-
- $strategy = $this->factory->getStrategy(
- $client,
- $mailbox,
- $filter,
- $cursor
- );
-
- $this->assertInstanceOf(ImapSortSearchStrategy::class, $strategy);
- }
-
- public function testGetStrategyForSearchWithoutSort() {
- /** @var MockObject|Horde_Imap_Client_Socket $client */
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $mailbox = 'INBOX';
- $filter = new Horde_Imap_Client_Search_Query();
- $filter->text('sort');
- $cursor = null;
- $capability = $this->createMock(Horde_Imap_Client_Data_Capability::class);
- $client->expects($this->once())
- ->method('__get')
- ->with('capability')
- ->willReturn($capability);
- $capability->expects($this->once())
- ->method('query')
- ->with('SORT')
- ->willReturn(true);
-
- $strategy = $this->factory->getStrategy(
- $client,
- $mailbox,
- $filter,
- $cursor
- );
-
- $this->assertInstanceOf(ImapSortSearchStrategy::class, $strategy);
- }
-
-}
diff --git a/tests/Unit/IMAP/Sync/ResponseTest.php b/tests/Unit/IMAP/Sync/ResponseTest.php
index 6d2299aa1..892324abb 100644
--- a/tests/Unit/IMAP/Sync/ResponseTest.php
+++ b/tests/Unit/IMAP/Sync/ResponseTest.php
@@ -30,13 +30,11 @@ class ResponseTest extends TestCase {
$newMessages = [];
$changedMessages = [];
$vanishedMessages = [];
- $syncToken = 'bc4564';
- $response = new Response($syncToken, $newMessages, $changedMessages, $vanishedMessages);
+ $response = new Response($newMessages, $changedMessages, $vanishedMessages);
$expected = [
'newMessages' => [],
'changedMessages' => [],
'vanishedMessages' => [],
- 'token' => $syncToken,
];
$json = $response->jsonSerialize();
diff --git a/tests/Unit/IMAP/Sync/SimpleMailboxSyncTest.php b/tests/Unit/IMAP/Sync/SimpleMailboxSyncTest.php
index 59aa4e2ba..455e89324 100644
--- a/tests/Unit/IMAP/Sync/SimpleMailboxSyncTest.php
+++ b/tests/Unit/IMAP/Sync/SimpleMailboxSyncTest.php
@@ -101,7 +101,7 @@ class SimpleMailboxSyncTest extends TestCase {
$this->hordeSync->vanisheduids = $this->createMock(Horde_Imap_Client_Ids::class);
$this->hordeSync->vanisheduids->ids = [23, 24];
- $ids = $this->sync->getVanishedMessages($this->imapClient, $this->syncRequest, $this->hordeSync);
+ $ids = $this->sync->getVanishedMessageUids($this->imapClient, $this->syncRequest, $this->hordeSync);
$this->assertEquals([23, 24], $ids);
}
diff --git a/tests/Unit/IMAP/Sync/SynchronizerTest.php b/tests/Unit/IMAP/Sync/SynchronizerTest.php
index 9c83d654a..b754822e8 100644
--- a/tests/Unit/IMAP/Sync/SynchronizerTest.php
+++ b/tests/Unit/IMAP/Sync/SynchronizerTest.php
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
@@ -30,14 +30,14 @@ use OCA\Mail\IMAP\Sync\Request;
use OCA\Mail\IMAP\Sync\Response;
use OCA\Mail\IMAP\Sync\SimpleMailboxSync;
use OCA\Mail\IMAP\Sync\Synchronizer;
-use PHPUnit_Framework_MockObject_MockObject;
+use PHPUnit\Framework\MockObject\MockObject;
class SynchronizerTest extends TestCase {
- /** @var SimpleMailboxSync|PHPUnit_Framework_MockObject_MockObject */
+ /** @var SimpleMailboxSync|MockObject */
private $simpleSync;
- /** @var FavouritesMailboxSync|PHPUnit_Framework_MockObject_MockObject */
+ /** @var FavouritesMailboxSync|MockObject */
private $favSync;
/** @var Synchronizer */
@@ -83,7 +83,7 @@ class SynchronizerTest extends TestCase {
->willReturn($flagged);
$newMessages = [];
$changedMessages = [];
- $vanishedMessages = [4, 5];
+ $vanishedMessageUids = [4, 5];
$sync->expects($this->once())
->method('getNewMessages')
->with($imapClient, $request, $hordeSync)
@@ -93,14 +93,10 @@ class SynchronizerTest extends TestCase {
->with($imapClient, $request, $hordeSync)
->willReturn($changedMessages);
$sync->expects($this->once())
- ->method('getVanishedMessages')
+ ->method('getVanishedMessageUids')
->with($imapClient, $request, $hordeSync)
- ->willReturn($vanishedMessages);
- $imapClient->expects($this->once())
- ->method('getSyncToken')
- ->with($this->equalTo('inbox'))
- ->willReturn('54321');
- $expected = new Response('54321', $newMessages, $changedMessages, $vanishedMessages);
+ ->willReturn($vanishedMessageUids);
+ $expected = new Response($newMessages, $changedMessages, $vanishedMessageUids);
$response = $this->synchronizer->sync($imapClient, $request);
diff --git a/tests/Unit/Service/AccountServiceTest.php b/tests/Unit/Service/AccountServiceTest.php
index a07be412a..9289b70c5 100644
--- a/tests/Unit/Service/AccountServiceTest.php
+++ b/tests/Unit/Service/AccountServiceTest.php
@@ -27,6 +27,7 @@ use OCA\Mail\Db\MailAccount;
use OCA\Mail\Db\MailAccountMapper;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AliasesService;
+use OCP\BackgroundJob\IJobList;
use OCP\IL10N;
use PHPUnit\Framework\MockObject\MockObject;
@@ -53,15 +54,20 @@ class AccountServiceTest extends TestCase {
/** @var MailAccount|MockObject */
private $account2;
+ /** @var IJobList|MockObject */
+ private $jobList;
+
protected function setUp(): void {
parent::setUp();
$this->mapper = $this->createMock(MailAccountMapper::class);
$this->l10n = $this->createMock(IL10N::class);
$this->aliasesService = $this->createMock(AliasesService::class);
+ $this->jobList = $this->createMock(IJobList::class);
$this->accountService = new AccountService(
$this->mapper,
- $this->aliasesService
+ $this->aliasesService,
+ $this->jobList
);
$this->account1 = $this->createMock(MailAccount::class);
@@ -73,9 +79,9 @@ class AccountServiceTest extends TestCase {
->method('findByUserId')
->with($this->user)
->will($this->returnValue([
- $this->account1,
- $this->account2,
- ]));
+ $this->account1,
+ $this->account2,
+ ]));
$expected = [
new Account($this->account1),
diff --git a/tests/Unit/Service/MailManagerTest.php b/tests/Unit/Service/MailManagerTest.php
index f6bd644b2..11a11e698 100644
--- a/tests/Unit/Service/MailManagerTest.php
+++ b/tests/Unit/Service/MailManagerTest.php
@@ -59,9 +59,6 @@ class MailManagerTest extends TestCase {
/** @var MessageMapper|MockObject */
private $messageMapper;
- /** @var Synchronizer|MockObject */
- private $sync;
-
/** @var IEventDispatcher|MockObject */
private $eventDispatcher;
@@ -73,10 +70,9 @@ class MailManagerTest extends TestCase {
$this->imapClientFactory = $this->createMock(IMAPClientFactory::class);
$this->mailboxMapper = $this->createMock(MailboxMapper::class);
- $this->mailboxSync = $this->createMock(MailboxSync::class);
$this->folderMapper = $this->createMock(FolderMapper::class);
$this->messageMapper = $this->createMock(MessageMapper::class);
- $this->sync = $this->createMock(Synchronizer::class);
+ $this->mailboxSync = $this->createMock(MailboxSync::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->manager = new MailManager(
@@ -84,7 +80,6 @@ class MailManagerTest extends TestCase {
$this->mailboxMapper,
$this->mailboxSync,
$this->folderMapper,
- $this->sync,
$this->messageMapper,
$this->eventDispatcher
);
@@ -156,22 +151,6 @@ class MailManagerTest extends TestCase {
$this->assertEquals($stats, $actual);
}
- public function testSync() {
- $account = $this->createMock(Account::class);
- $syncRequest = $this->createMock(Request::class);
- $syncResonse = $this->createMock(Response::class);
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $this->imapClientFactory->expects($this->once())
- ->method('getClient')
- ->willReturn($client);
- $this->sync->expects($this->once())
- ->method('sync')
- ->with($client, $syncRequest)
- ->willReturn($syncResonse);
-
- $this->manager->syncMessages($account, $syncRequest);
- }
-
public function testDeleteMessageSourceFolderNotFound(): void {
/** @var Account|MockObject $account */
$account = $this->createMock(Account::class);
diff --git a/tests/Unit/Service/MailSearchTest.php b/tests/Unit/Service/MailSearchTest.php
index fc4483307..2b5006ef4 100644
--- a/tests/Unit/Service/MailSearchTest.php
+++ b/tests/Unit/Service/MailSearchTest.php
@@ -28,23 +28,18 @@ use Horde_Imap_Client_Fetch_Results;
use Horde_Imap_Client_Socket;
use OCA\Mail\Account;
use OCA\Mail\Db\MailboxMapper;
+use OCA\Mail\Db\MessageMapper;
use OCA\Mail\IMAP\IMAPClientFactory;
-use OCA\Mail\IMAP\Search\SearchFilterStringParser;
-use OCA\Mail\IMAP\Search\SearchStrategyFactory;
-use OCA\Mail\Service\MailSearch;
+use OCA\Mail\IMAP\Search\Provider;
+use OCA\Mail\Service\Search\FilterStringParser;
+use OCA\Mail\Service\Search\MailSearch;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
class MailSearchTest extends TestCase {
- /** @var MockObject|IMAPClientFactory */
- private $imapClientFactory;
-
- /** @var MockObject|SearchStrategyFactory */
- private $searchStrategyFactory;
-
- /** @var MockObject|SearchFilterStringParser */
- private $searchStringParser;
+ /** @var FilterStringParser|MockObject */
+ private $filterStringParser;
/** @var MockObject|MailboxMapper */
private $mailboxMapper;
@@ -55,34 +50,32 @@ class MailSearchTest extends TestCase {
/** @var MailSearch */
private $search;
+ /** @var Provider|MockObject */
+ private $imapSearchProvider;
+
+ /** @var MessageMapper|MockObject */
+ private $messageMapper;
+
protected function setUp(): void {
parent::setUp();
- $this->imapClientFactory = $this->createMock(IMAPClientFactory::class);
- $this->searchStrategyFactory = $this->createMock(SearchStrategyFactory::class);
- $this->searchStringParser = $this->createMock(SearchFilterStringParser::class);
+ $this->filterStringParser = $this->createMock(FilterStringParser::class);
$this->mailboxMapper = $this->createMock(MailboxMapper::class);
+ $this->imapSearchProvider = $this->createMock(Provider::class);
+ $this->messageMapper = $this->createMock(MessageMapper::class);
$this->logger = $this->createMock(ILogger::class);
$this->search = new MailSearch(
- $this->imapClientFactory,
- $this->searchStrategyFactory,
- $this->searchStringParser,
+ $this->filterStringParser,
$this->mailboxMapper,
+ $this->imapSearchProvider,
+ $this->messageMapper,
$this->logger
);
}
public function testNoFindMessages() {
$account = $this->createMock(Account::class);
- $client = $this->createMock(Horde_Imap_Client_Socket::class);
- $this->imapClientFactory->expects($this->once())
- ->method('getClient')
- ->with($account)
- ->willReturn($client);
- $client->expects($this->once())
- ->method('fetch')
- ->willReturn(new Horde_Imap_Client_Fetch_Results());
$messages = $this->search->findMessages(
$account,