1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Calendar App |
4
|
|
|
* |
5
|
|
|
* @author Georg Ehrke |
6
|
|
|
* @copyright 2016 Georg Ehrke <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 3 of the License, or any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public |
19
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
namespace OCA\Calendar\Controller; |
23
|
|
|
|
24
|
|
|
use PHPUnit\Framework\TestCase; |
25
|
|
|
|
26
|
|
|
class ContactControllerTest extends TestCase { |
27
|
|
|
|
28
|
|
|
private $appName; |
29
|
|
|
private $request; |
30
|
|
|
private $contacts; |
31
|
|
|
|
32
|
|
|
private $controller; |
33
|
|
|
|
34
|
|
|
public function setUp() { |
35
|
|
|
$this->appName = 'calendar'; |
36
|
|
|
$this->request = $this->getMockBuilder('\OCP\IRequest') |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
$this->contacts = $this->getMockBuilder('OCP\Contacts\IManager') |
40
|
|
|
->disableOriginalConstructor() |
41
|
|
|
->getMock(); |
42
|
|
|
|
43
|
|
|
$this->controller = new ContactController($this->appName, |
44
|
|
|
$this->request, $this->contacts); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testSearchLocation() { |
48
|
|
|
$expected = [ |
49
|
|
|
[ |
50
|
|
|
'label' => '33 42nd Street, Random Town, Some State, United States', |
51
|
|
|
'name' => 'Person 1', |
52
|
|
|
], |
53
|
|
|
[ |
54
|
|
|
'label' => '5 Random Ave, 12782 Some big city, Yet another state, United States', |
55
|
|
|
'name' => 'Person 1', |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
'label' => 'ABC Street 2, 01337 Village, Germany', |
59
|
|
|
'name' => '', |
60
|
|
|
], |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
$apiResponse = [ |
64
|
|
|
[ |
65
|
|
|
'FN' => 'Person 1', |
66
|
|
|
'ADR' => [ |
67
|
|
|
'33 42nd Street;Random Town;Some State;;United States', |
68
|
|
|
';;5 Random Ave;12782 Some big city;Yet another state;United States', |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
[ |
72
|
|
|
'FN' => 'Person 2', |
73
|
|
|
], |
74
|
|
|
[ |
75
|
|
|
'ADR' => [ |
76
|
|
|
'ABC Street 2;01337 Village;;Germany', |
77
|
|
|
], |
78
|
|
|
], |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
$this->contacts->expects($this->once()) |
82
|
|
|
->method('search') |
83
|
|
|
->with($this->equalTo('Person'), $this->equalTo(['FN', 'ADR'])) |
84
|
|
|
->will($this->returnValue($apiResponse)); |
85
|
|
|
|
86
|
|
|
$actual = $this->controller->searchLocation('Person'); |
87
|
|
|
|
88
|
|
|
$this->assertEquals($expected, $actual->getData()); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testSearchAttendee() { |
93
|
|
|
$expected = [ |
94
|
|
|
[ |
95
|
|
|
'name' => 'Person 1', |
96
|
|
|
'email' => ['[email protected]', '[email protected]'], |
97
|
|
|
], |
98
|
|
|
[ |
99
|
|
|
'name' => '', |
100
|
|
|
'email' => ['[email protected]'], |
101
|
|
|
], |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
$apiResponse = [ |
105
|
|
|
[ |
106
|
|
|
'FN' => 'Person 1', |
107
|
|
|
'EMAIL' => [ |
108
|
|
|
'[email protected]', |
109
|
|
|
'[email protected]', |
110
|
|
|
], |
111
|
|
|
], |
112
|
|
|
[ |
113
|
|
|
'FN' => 'Person 2', |
114
|
|
|
], |
115
|
|
|
[ |
116
|
|
|
'EMAIL' => [ |
117
|
|
|
'[email protected]', |
118
|
|
|
], |
119
|
|
|
], |
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
$this->contacts->expects($this->once()) |
123
|
|
|
->method('search') |
124
|
|
|
->with($this->equalTo('Person'), $this->equalTo(['FN', 'EMAIL'])) |
125
|
|
|
->will($this->returnValue($apiResponse)); |
126
|
|
|
|
127
|
|
|
$actual = $this->controller->searchAttendee('Person'); |
128
|
|
|
|
129
|
|
|
$this->assertEquals($expected, $actual->getData()); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|