1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Christoph Wurst <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Mail |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
use Test\TestCase; |
22
|
|
|
use OCA\Mail\Service\ContactsIntegration; |
23
|
|
|
|
24
|
|
|
class ContactsIntegrationTest extends TestCase { |
25
|
|
|
|
26
|
|
|
private $contactsManager; |
27
|
|
|
private $contactsIntegration; |
28
|
|
|
|
29
|
|
|
protected function setUp() { |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->contactsManager = $this->getMockBuilder('OCP\Contacts\IManager') |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
$this->contactsIntegration = new ContactsIntegration($this->contactsManager); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDisabledContactsManager() { |
39
|
|
|
$this->contactsManager->expects($this->once()) |
40
|
|
|
->method('isEnabled') |
41
|
|
|
->will($this->returnValue(false)); |
42
|
|
|
$this->contactsManager->expects($this->never()) |
43
|
|
|
->method('search'); |
44
|
|
|
|
45
|
|
|
$expected = []; |
46
|
|
|
$actual = $this->contactsIntegration->getMatchingRecipient("abc"); |
47
|
|
|
|
48
|
|
|
$this->assertEquals($expected, $actual); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetMatchingRecipient() { |
52
|
|
|
$term = 'jo'; // searching for: John Doe |
53
|
|
|
$searchResult = [ |
54
|
|
|
[ |
55
|
|
|
// Simple match |
56
|
|
|
'id' => 1, |
57
|
|
|
'FN' => 'Jonathan Frakes', |
58
|
|
|
'EMAIL' => '[email protected]', |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
// Array of addresses |
62
|
|
|
'id' => 2, |
63
|
|
|
'FN' => 'John Doe', |
64
|
|
|
'EMAIL' => [ |
65
|
|
|
'[email protected]', |
66
|
|
|
'[email protected]', |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
// Johann Struass II didn't have a email address ;-) |
71
|
|
|
'id' => 3, |
72
|
|
|
'FN' => 'Johann Strauss II', |
73
|
|
|
] |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$this->contactsManager->expects($this->once()) |
77
|
|
|
->method('isEnabled') |
78
|
|
|
->will($this->returnValue(true)); |
79
|
|
|
$this->contactsManager->expects($this->once()) |
80
|
|
|
->method('search') |
81
|
|
|
->with($term, ['FN', 'EMAIL']) |
82
|
|
|
->will($this->returnValue($searchResult)); |
83
|
|
|
|
84
|
|
|
$expected = [ |
85
|
|
|
[ |
86
|
|
|
'id' => 1, |
87
|
|
|
'label' => '"Jonathan Frakes" <[email protected]>', |
88
|
|
|
'value' => '"Jonathan Frakes" <[email protected]>', |
89
|
|
|
], |
90
|
|
|
[ |
91
|
|
|
'id' => 2, |
92
|
|
|
'label' => '"John Doe" <[email protected]>', |
93
|
|
|
'value' => '"John Doe" <[email protected]>', |
94
|
|
|
], |
95
|
|
|
[ |
96
|
|
|
'id' => 2, |
97
|
|
|
'label' => '"John Doe" <[email protected]>', |
98
|
|
|
'value' => '"John Doe" <[email protected]>', |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
$actual = $this->contactsIntegration->getMatchingRecipient($term); |
102
|
|
|
|
103
|
|
|
$this->assertEquals($expected, $actual); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getPhotoDataProvider() { |
107
|
|
|
return [ |
108
|
|
|
[ |
109
|
|
|
// Match with photo |
110
|
|
|
'[email protected]', |
111
|
|
|
[ |
112
|
|
|
'id' => 2, |
113
|
|
|
'FN' => 'John Doe', |
114
|
|
|
'PHOTO' => 'abcdefg' |
115
|
|
|
], |
116
|
|
|
'abcdefg', |
117
|
|
|
], |
118
|
|
|
[ |
119
|
|
|
// Match without photo |
120
|
|
|
'[email protected]', |
121
|
|
|
[ |
122
|
|
|
'id' => 2, |
123
|
|
|
'FN' => 'John Doe', |
124
|
|
|
], |
125
|
|
|
null, |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
// No match |
129
|
|
|
'[email protected]', |
130
|
|
|
[], |
131
|
|
|
null, |
132
|
|
|
], |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @dataProvider getPhotoDataProvider |
138
|
|
|
*/ |
139
|
|
|
public function testGetPhoto($email, $searchResult, $expected) { |
140
|
|
|
$this->contactsManager->expects($this->once()) |
141
|
|
|
->method('search') |
142
|
|
|
->with($email, ['EMAIL']) |
143
|
|
|
->will($this->returnValue([$searchResult])); |
144
|
|
|
|
145
|
|
|
$actual = $this->contactsIntegration->getPhoto($email); |
146
|
|
|
|
147
|
|
|
$this->assertEquals($actual, $actual); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
} |
151
|
|
|
|