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-04-19 11:13:35 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-04-19 11:13:35 +0300
commit79198f8375f26425b2b9395a7014c3ffc6881583 (patch)
tree899699ba6b6a2473405ec665c267c0ed26ddc8c1 /tests
parent36ed424ed6aae5d67829aacc04edf48d54e0d501 (diff)
Make it possible to create subfolders and show folder stats
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Controller/FoldersControllerTest.php21
-rw-r--r--tests/IMAP/FolderMapperTest.php17
-rw-r--r--tests/Service/MailManagerTest.php20
3 files changed, 57 insertions, 1 deletions
diff --git a/tests/Controller/FoldersControllerTest.php b/tests/Controller/FoldersControllerTest.php
index eeb74854a..46d56e6b5 100644
--- a/tests/Controller/FoldersControllerTest.php
+++ b/tests/Controller/FoldersControllerTest.php
@@ -21,12 +21,14 @@
namespace OCA\Mail\Tests\Controller;
+use function base64_encode;
use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\FoldersController;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Folder;
use OCA\Mail\Http\JSONResponse;
+use OCA\Mail\IMAP\FolderStats;
use OCA\Mail\Service\AccountService;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCP\IRequest;
@@ -119,6 +121,25 @@ class FoldersControllerTest extends TestCase {
$this->assertEquals($expected, $response);
}
+ public function testStats() {
+ $account = $this->createMock(Account::class);
+ $stats = $this->createMock(FolderStats::class);
+ $accountId = 28;
+ $this->accountService->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($this->userId), $this->equalTo($accountId))
+ ->willReturn($account);
+ $this->mailManager->expects($this->once())
+ ->method('getFolderStats')
+ ->with($this->equalTo($account), $this->equalTo('INBOX'))
+ ->willReturn($stats);
+
+ $response = $this->controller->stats($accountId, base64_encode('INBOX'));
+
+ $expected = new JSONResponse($stats);
+ $this->assertEquals($expected, $response);
+ }
+
public function testUpdate() {
$this->expectException(NotImplemented::class);
diff --git a/tests/IMAP/FolderMapperTest.php b/tests/IMAP/FolderMapperTest.php
index ec74fef55..44d4c432b 100644
--- a/tests/IMAP/FolderMapperTest.php
+++ b/tests/IMAP/FolderMapperTest.php
@@ -27,6 +27,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\SearchFolder;
use ChristophWurst\Nextcloud\Testing\TestCase;
@@ -192,6 +193,22 @@ class FolderMapperTest extends TestCase {
$this->mapper->getFoldersStatus($folders, $client);
}
+ public function testGetFoldersStatusAsObject() {
+ $client = $this->createMock(Horde_Imap_Client_Socket::class);
+ $client->expects($this->once())
+ ->method('status')
+ ->with('INBOX')
+ ->willReturn([
+ 'messages' => 123,
+ 'unseen' => 2,
+ ]);
+
+ $stats = $this->mapper->getFoldersStatusAsObject($client, 'INBOX');
+
+ $expected = new FolderStats(123, 2);
+ $this->assertEquals($expected, $stats);
+ }
+
public function testDetectSpecialUseFromAttributes() {
$folders = [
$this->createMock(Folder::class),
diff --git a/tests/Service/MailManagerTest.php b/tests/Service/MailManagerTest.php
index 03e28c1e3..9d144a340 100644
--- a/tests/Service/MailManagerTest.php
+++ b/tests/Service/MailManagerTest.php
@@ -26,6 +26,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\IMAPClientFactory;
use OCA\Mail\IMAP\MessageMapper;
use OCA\Mail\IMAP\Sync\Request;
@@ -48,7 +49,7 @@ class MailManagerTest extends TestCase {
/** @var Synchronizer|MockObject */
private $sync;
- /** @varr MailManager */
+ /** @var MailManager */
private $manager;
protected function setUp() {
@@ -114,6 +115,23 @@ class MailManagerTest extends TestCase {
$this->assertEquals($folder, $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);
+
+ $actual = $this->manager->getFolderStats($account, 'INBOX');
+
+ $this->assertEquals($stats, $actual);
+ }
+
public function testSync() {
$account = $this->createMock(Account::class);
$syncRequest = $this->createMock(Request::class);