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-16 22:33:20 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2019-04-17 14:22:49 +0300
commit46469695dffff71baa0c91989923a2be45acd669 (patch)
treed8bb19d09709114433acbb73c7689c90bc293101 /tests
parent277a331a414bdcd62026989c5a0312ae269b6032 (diff)
Make it possible to create a new folder
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Controller/FoldersControllerTest.php19
-rw-r--r--tests/IMAP/FolderMapperTest.php28
-rw-r--r--tests/Service/MailManagerTest.php35
3 files changed, 76 insertions, 6 deletions
diff --git a/tests/Controller/FoldersControllerTest.php b/tests/Controller/FoldersControllerTest.php
index 5d8236dd7..eeb74854a 100644
--- a/tests/Controller/FoldersControllerTest.php
+++ b/tests/Controller/FoldersControllerTest.php
@@ -100,6 +100,25 @@ class FoldersControllerTest extends TestCase {
$this->controller->show();
}
+ public function testCreate() {
+ $account = $this->createMock(Account::class);
+ $folder = $this->createMock(Folder::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('createFolder')
+ ->with($this->equalTo($account), $this->equalTo('new'))
+ ->willReturn($folder);
+
+ $response = $this->controller->create($accountId, 'new');
+
+ $expected = new JSONResponse($folder);
+ $this->assertEquals($expected, $response);
+ }
+
public function testUpdate() {
$this->expectException(NotImplemented::class);
diff --git a/tests/IMAP/FolderMapperTest.php b/tests/IMAP/FolderMapperTest.php
index 4c2a0dc2e..ec74fef55 100644
--- a/tests/IMAP/FolderMapperTest.php
+++ b/tests/IMAP/FolderMapperTest.php
@@ -95,6 +95,34 @@ class FolderMapperTest extends TestCase {
$this->assertEquals($expected, $folders);
}
+ public function testCreateFolder() {
+ $account = $this->createMock(Account::class);
+ $client = $this->createMock(Horde_Imap_Client_Socket::class);
+ $client->expects($this->once())
+ ->method('createMailbox')
+ ->with($this->equalTo('new'));
+ $client->expects($this->once())
+ ->method('listMailboxes')
+ ->with($this->equalTo('new'), $this->equalTo(Horde_Imap_Client::MBOX_ALL),
+ $this->equalTo([
+ 'delimiter' => true,
+ 'attributes' => true,
+ 'special_use' => true,
+ ]))
+ ->willReturn([
+ [
+ 'mailbox' => new Horde_Imap_Client_Mailbox('new'),
+ 'attributes' => [],
+ 'delimiter' => '.',
+ ],
+ ]);
+
+ $created = $this->mapper->createFolder($client, $account, 'new');
+
+ $expected = new Folder($account, new Horde_Imap_Client_Mailbox('new'), [], '.');
+ $this->assertEquals($expected, $created);
+ }
+
public function testGetFoldersStatus() {
$folders = [
$this->createMock(Folder::class),
diff --git a/tests/Service/MailManagerTest.php b/tests/Service/MailManagerTest.php
index 4baeef815..03e28c1e3 100644
--- a/tests/Service/MailManagerTest.php
+++ b/tests/Service/MailManagerTest.php
@@ -24,6 +24,7 @@ namespace OCA\Mail\Tests\Service;
use ChristophWurst\Nextcloud\Testing\TestCase;
use Horde_Imap_Client_Socket;
use OCA\Mail\Account;
+use OCA\Mail\Folder;
use OCA\Mail\IMAP\FolderMapper;
use OCA\Mail\IMAP\IMAPClientFactory;
use OCA\Mail\IMAP\MessageMapper;
@@ -31,21 +32,20 @@ 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\Files\Folder;
-use PHPUnit_Framework_MockObject_MockObject;
+use PHPUnit\Framework\MockObject\MockObject;
class MailManagerTest extends TestCase {
- /** @var IMAPClientFactory|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IMAPClientFactory|MockObject */
private $imapClientFactory;
- /** @var FolderMapper|PHPUnit_Framework_MockObject_MockObject */
+ /** @var FolderMapper|MockObject */
private $folderMapper;
- /** @var MessageMapper|PHPUnit_Framework_MockObject_MockObject */
+ /** @var MessageMapper|MockObject */
private $messageMapper;
- /** @var Synchronizer|PHPUnit_Framework_MockObject_MockObject */
+ /** @var Synchronizer|MockObject */
private $sync;
/** @varr MailManager */
@@ -91,6 +91,29 @@ class MailManagerTest extends TestCase {
$this->manager->getFolders($account);
}
+ public function testCreateFolder() {
+ $client = $this->createMock(Horde_Imap_Client_Socket::class);
+ $account = $this->createMock(Account::class);
+ $this->imapClientFactory->expects($this->once())
+ ->method('getClient')
+ ->willReturn($client);
+ $folder =$this->createMock(Folder::class);
+ $this->folderMapper->expects($this->once())
+ ->method('createFolder')
+ ->with($this->equalTo($client), $this->equalTo($account), $this->equalTo('new'))
+ ->willReturn($folder);
+ $this->folderMapper->expects($this->once())
+ ->method('getFoldersStatus')
+ ->with($this->equalTo([$folder]));
+ $this->folderMapper->expects($this->once())
+ ->method('detectFolderSpecialUse')
+ ->with($this->equalTo([$folder]));
+
+ $created = $this->manager->createFolder($account, 'new');
+
+ $this->assertEquals($folder, $created);
+ }
+
public function testSync() {
$account = $this->createMock(Account::class);
$syncRequest = $this->createMock(Request::class);