diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-02-15 10:35:21 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-02-15 12:39:20 +0300 |
commit | d3cd693c520d3bba76ef1d41b673d19ccef4fd0a (patch) | |
tree | 8bd67bd7439e03589edbd4041adc1c7dc95212af /tests | |
parent | e1313ae65eb13012c93f43b67c05a45a217fad14 (diff) |
Remove INBOX prefix from folder's display name
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/IMAP/MailboxPrefixDetectorTest.php | 115 | ||||
-rw-r--r-- | tests/Service/FolderNameTranslatorTest.php | 58 | ||||
-rw-r--r-- | tests/Service/MailManagerTest.php | 14 |
3 files changed, 177 insertions, 10 deletions
diff --git a/tests/IMAP/MailboxPrefixDetectorTest.php b/tests/IMAP/MailboxPrefixDetectorTest.php new file mode 100644 index 000000000..a9cf154dc --- /dev/null +++ b/tests/IMAP/MailboxPrefixDetectorTest.php @@ -0,0 +1,115 @@ +<?php + +/** + * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2017 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\IMAP; + +use ChristophWurst\Nextcloud\Testing\TestCase; +use OCA\Mail\Folder; +use OCA\Mail\IMAP\MailboxPrefixDetector; +use OCA\Mail\SearchFolder; + +class MailboxPrefixDetectorTest extends TestCase { + + /** @var MailboxPrefixDetector */ + private $detector; + + protected function setUp() { + parent::setUp(); + + $this->detector = new MailboxPrefixDetector(); + } + + public function testDetectWithPrefix() { + $folder1 = $this->createMock(Folder::class); + $folder2 = $this->createMock(Folder::class); + $folder1->expects($this->once()) + ->method('getMailbox') + ->willReturn('INBOX'); + $folder1->expects($this->once()) + ->method('getDelimiter') + ->willReturn('.'); + $folder2->expects($this->once()) + ->method('getMailbox') + ->willReturn('INBOX.Sent'); + $folder2->expects($this->once()) + ->method('getDelimiter') + ->willReturn('.'); + + $havePrefix = $this->detector->havePrefix([ + $folder1, + $folder2, + ]); + + $this->assertTrue($havePrefix); + } + + public function testDetectWithoutPrefix() { + $folder1 = $this->createMock(Folder::class); + $folder2 = $this->createMock(Folder::class); + $folder1->expects($this->once()) + ->method('getMailbox') + ->willReturn('INBOX'); + $folder1->expects($this->once()) + ->method('getDelimiter') + ->willReturn('.'); + $folder2->expects($this->once()) + ->method('getMailbox') + ->willReturn('Sent'); + $folder2->expects($this->once()) + ->method('getDelimiter') + ->willReturn('.'); + + $havePrefix = $this->detector->havePrefix([ + $folder1, + $folder2, + ]); + + $this->assertFalse($havePrefix); + } + + public function testDetectWithSearchFolder() { + $folder1 = $this->createMock(Folder::class); + $folder2 = $this->createMock(SearchFolder::class); + $folder1->expects($this->any()) + ->method('getMailbox') + ->willReturn('INBOX'); + $folder1->expects($this->any()) + ->method('getDelimiter') + ->willReturn('.'); + $folder2->expects($this->any()) + ->method('getMailbox') + ->willReturn('INBOX/Flagged'); + $folder2->expects($this->any()) + ->method('getDelimiter') + ->willReturn('.'); + + $havePrefix = $this->detector->havePrefix([ + $folder1, + $folder2, + ]); + + $this->assertTrue($havePrefix); + } + +} diff --git a/tests/Service/FolderNameTranslatorTest.php b/tests/Service/FolderNameTranslatorTest.php index e905ec5e2..d992b9f16 100644 --- a/tests/Service/FolderNameTranslatorTest.php +++ b/tests/Service/FolderNameTranslatorTest.php @@ -21,9 +21,9 @@ namespace OCA\Mail\Tests\Service; +use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Mail\Folder; use OCA\Mail\Service\FolderNameTranslator; -use ChristophWurst\Nextcloud\Testing\TestCase; use OCP\IL10N; use PHPUnit_Framework_MockObject_MockObject; @@ -48,24 +48,68 @@ class FolderNameTranslatorTest extends TestCase { $this->translator = new FolderNameTranslator($this->l10n); } - public function testTranslateAll() { + public function testTranslate() { $folder = $this->createMock(Folder::class); - + $folder->expects($this->any()) + ->method('getDelimiter') + ->willReturn('.'); + $folder->expects($this->any()) + ->method('getMailbox') + ->willReturn('Archive'); $folder->expects($this->once()) ->method('getSpecialUse') ->willReturn([]); + $folder->expects($this->once()) + ->method('setDisplayName') + ->with('Archive'); - $this->translator->translateAll([$folder]); + $this->translator->translateAll([$folder], false); + } + + public function testTranslatePrefixed() { + $folder1 = $this->createMock(Folder::class); + $folder2 = $this->createMock(Folder::class); + $folder1->expects($this->any()) + ->method('getDelimiter') + ->willReturn('.'); + $folder2->expects($this->any()) + ->method('getDelimiter') + ->willReturn('.'); + $folder1->expects($this->any()) + ->method('getMailbox') + ->willReturn('INBOX'); + $folder2->expects($this->any()) + ->method('getMailbox') + ->willReturn('INBOX.Sent'); + $folder1->expects($this->once()) + ->method('getSpecialUse') + ->willReturn(['inbox']); + $folder2->expects($this->once()) + ->method('getSpecialUse') + ->willReturn([]); + $folder1->expects($this->once()) + ->method('setDisplayName') + ->with('Translated Inbox'); + $folder2->expects($this->once()) + ->method('setDisplayName') + ->with('Sent'); + + $this->translator->translateAll([$folder1, $folder2], true); } public function testTranslateSpecialUse() { $folder = $this->createMock(Folder::class); - + $folder->expects($this->any()) + ->method('getMailbox') + ->willReturn('Sent'); $folder->expects($this->once()) ->method('getSpecialUse') - ->willReturn(['flagged']); + ->willReturn(['sent']); + $folder->expects($this->once()) + ->method('setDisplayName') + ->with('Translated Sent'); - $this->translator->translate($folder); + $this->translator->translateAll([$folder], false); } } diff --git a/tests/Service/MailManagerTest.php b/tests/Service/MailManagerTest.php index 3d785b414..0ca0efde3 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\IMAP\FolderMapper; use OCA\Mail\IMAP\IMAPClientFactory; +use OCA\Mail\IMAP\MailboxPrefixDetector; use OCA\Mail\IMAP\MessageMapper; use OCA\Mail\IMAP\Sync\Request; use OCA\Mail\IMAP\Sync\Synchronizer; @@ -42,6 +43,9 @@ class MailManagerTest extends TestCase { /** @var FolderMapper|PHPUnit_Framework_MockObject_MockObject */ private $folderMapper; + /** @var MailboxPrefixDetector|PHPUnit_Framework_MockObject_MockObject */ + private $prefixDetector; + /** @var MessageMapper|PHPUnit_Framework_MockObject_MockObject */ private $messageMapper; @@ -59,18 +63,22 @@ class MailManagerTest extends TestCase { $this->imapClientFactory = $this->createMock(IMAPClientFactory::class); $this->folderMapper = $this->createMock(FolderMapper::class); + $this->prefixDetector = $this->createMock(MailboxPrefixDetector::class); $this->messageMapper = $this->createMock(MessageMapper::class); $this->translator = $this->createMock(FolderNameTranslator::class); $this->sync = $this->createMock(Synchronizer::class); $this->manager = new MailManager($this->imapClientFactory, - $this->folderMapper, $this->translator, $this->sync, $this->messageMapper); + $this->folderMapper, $this->prefixDetector, $this->translator, $this->sync, + $this->messageMapper); } public function testGetFolders() { $client = $this->createMock(Horde_Imap_Client_Socket::class); $account = $this->createMock(Account::class); - + $this->prefixDetector->expects($this->once()) + ->method('havePrefix') + ->willReturn(false); $this->imapClientFactory->expects($this->once()) ->method('getClient') ->willReturn($client); @@ -93,7 +101,7 @@ class MailManagerTest extends TestCase { ->with($this->equalTo($folders)); $this->translator->expects($this->once()) ->method('translateAll') - ->with($this->equalTo($folders)); + ->with($this->equalTo($folders), $this->equalTo(false)); $this->folderMapper->expects($this->once()) ->method('buildFolderHierarchy') ->with($this->equalTo($folders)); |