1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
<?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\Unit\IMAP\Sync;
use ChristophWurst\Nextcloud\Testing\TestCase;
use Horde_Imap_Client_Base;
use Horde_Imap_Client_Data_Sync;
use Horde_Imap_Client_Mailbox;
use OCA\Mail\IMAP\Sync\FavouritesMailboxSync;
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;
class SynchronizerTest extends TestCase {
/** @var SimpleMailboxSync|PHPUnit_Framework_MockObject_MockObject */
private $simpleSync;
/** @var FavouritesMailboxSync|PHPUnit_Framework_MockObject_MockObject */
private $favSync;
/** @var Synchronizer */
private $synchronizer;
protected function setUp() {
parent::setUp();
$this->simpleSync = $this->createMock(SimpleMailboxSync::class);
$this->favSync = $this->createMock(FavouritesMailboxSync::class);
$this->synchronizer = new Synchronizer($this->simpleSync, $this->favSync);
}
public function syncData() {
return [
[false],
[true],
];
}
/**
* @dataProvider syncData
*/
public function testSync($flagged) {
$sync = $flagged ? $this->favSync : $this->simpleSync;
$imapClient = $this->createMock(Horde_Imap_Client_Base::class);
$request = $this->createMock(Request::class);
$request->expects($this->any())
->method('getMailbox')
->willReturn('inbox');
$request->expects($this->once())
->method('getToken')
->willReturn('123456');
$hordeSync = $this->createMock(Horde_Imap_Client_Data_Sync::class);
$imapClient->expects($this->once())
->method('sync')
->with($this->equalTo(new Horde_Imap_Client_Mailbox('inbox')), $this->equalTo('123456'))
->willReturn($hordeSync);
$request->expects($this->once())
->method('isFlaggedMailbox')
->willReturn($flagged);
$newMessages = [];
$changedMessages = [];
$vanishedMessages = [4, 5];
$sync->expects($this->once())
->method('getNewMessages')
->with($imapClient, $request, $hordeSync)
->willReturn($newMessages);
$sync->expects($this->once())
->method('getChangedMessages')
->with($imapClient, $request, $hordeSync)
->willReturn($changedMessages);
$sync->expects($this->once())
->method('getVanishedMessages')
->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);
$response = $this->synchronizer->sync($imapClient, $request);
$this->assertEquals($expected, $response);
}
}
|