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
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2017-01-27 00:30:13 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2017-02-09 22:36:58 +0300
commit378232350fa9a87c86f2cda089599e92f43d1185 (patch)
tree7d6cb565479575d5219e81dfac93d99fc34a4272 /tests/FolderTest.php
parent1524004038ac19024d97f7519a1c685287a92aaf (diff)
increase test coverage
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests/FolderTest.php')
-rw-r--r--tests/FolderTest.php161
1 files changed, 161 insertions, 0 deletions
diff --git a/tests/FolderTest.php b/tests/FolderTest.php
new file mode 100644
index 000000000..07725c514
--- /dev/null
+++ b/tests/FolderTest.php
@@ -0,0 +1,161 @@
+<?php
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * Mail
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Mail\Tests;
+
+use Horde_Imap_Client_Mailbox;
+use OCA\Mail\Account;
+use OCA\Mail\Folder;
+use PHPUnit_Framework_MockObject_MockObject;
+use Test\TestCase;
+
+class FolderTest extends TestCase {
+
+ /** @var Account|PHPUnit_Framework_MockObject_MockObject */
+ private $account;
+
+ /** @var Horde_Imap_Client_Mailbox|PHPUnit_Framework_MockObject_MockObject */
+ private $mailbox;
+
+ /** @var Folder */
+ private $folder;
+
+ private function mockFolder(array $attributes = [], $delimiter = '.') {
+ $this->account = $this->createMock(Account::class);
+ $this->mailbox = $this->createMock(Horde_Imap_Client_Mailbox::class);
+
+ $this->folder = new Folder($this->account, $this->mailbox, $attributes, $delimiter);
+ }
+
+ public function testGetMailbox() {
+ $this->mockFolder();
+ $this->mailbox->expects($this->once())
+ ->method('__get')
+ ->with($this->equalTo('utf8'))
+ ->willReturn('Sent');
+
+ $this->assertSame('Sent', $this->folder->getMailbox());
+ }
+
+ public function testGetDelimiter() {
+ $this->mockFolder([], ',');
+
+ $this->assertSame(',', $this->folder->getDelimiter());
+ }
+
+ public function testGetAttributes() {
+ $this->mockFolder(['\noselect']);
+
+ $this->assertSame(['\noselect'], $this->folder->getAttributes());
+ }
+
+ public function testAddFolder() {
+ $this->mockFolder(['\noselect']);
+ $subFolder = $this->createMock(Folder::class);
+ $subFolder->expects($this->once())
+ ->method('getMailbox')
+ ->willReturn('INBOX/FLAGED');
+
+ $this->folder->addFolder($subFolder);
+
+ $this->assertCount(1, $this->folder->getFolders());
+ }
+
+ public function testSetStatus() {
+ $this->mockFolder();
+
+ $this->folder->setStatus([
+ 'unseen' => 4,
+ ]);
+ }
+
+ public function testSpecialUse() {
+ $this->mockFolder();
+
+ $this->folder->addSpecialUse('flagged');
+
+ $this->assertCount(1, $this->folder->getSpecialUse());
+ $this->assertSame('flagged', $this->folder->getSpecialUse()[0]);
+ }
+
+ public function testDisplayName() {
+ $this->mockFolder();
+
+ $this->folder->setDisplayName('Eingang');
+ $this->assertSame('Eingang', $this->folder->getDisplayName());
+ }
+
+ public function testIsSearchable() {
+ $this->mockFolder([]);
+
+ $this->assertTrue($this->folder->isSearchable());
+ }
+
+ public function testIsNotSearchable() {
+ $this->mockFolder(['\noselect']);
+
+ $this->assertFalse($this->folder->isSearchable());
+ }
+
+ public function testJsonSerialize() {
+ $this->mockFolder();
+ $subFolder = $this->createMock(Folder::class);
+
+ $subFolder->expects($this->exactly(2))
+ ->method('getMailbox')
+ ->willReturn('Archive');
+ $subFolder->expects($this->once())
+ ->method('jsonSerialize')
+ ->willReturn(['subdir data']);
+ $this->mailbox->expects($this->once())
+ ->method('__get')
+ ->with($this->equalTo('utf8'))
+ ->willReturn('Sent');
+ $this->account->expects($this->once())
+ ->method('getId')
+ ->willReturn(123);
+
+ $this->folder->setDisplayName('Gesendet');
+ $this->folder->addSpecialUse('sent');
+ $this->folder->setStatus([
+ 'unseen' => 13,
+ 'messages' => 333,
+ ]);
+ $this->folder->addFolder($subFolder);
+
+ $expected = [
+ 'id' => base64_encode('Sent'),
+ 'accountId' => 123,
+ 'name' => 'Gesendet',
+ 'specialRole' => null,
+ 'unseen' => 13,
+ 'total' => 333,
+ 'isEmpty' => false,
+ 'noSelect' => false,
+ 'attributes' => [],
+ 'delimiter' => '.',
+ 'folders' => [['subdir data']],
+ 'specialRole' => 'sent',
+ ];
+ $this->assertEquals($expected, $this->folder->jsonSerialize());
+ }
+
+}