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
|
|
|
class ContactControllerTest extends \PHPUnit_Framework_TestCase { |
25
|
|
|
|
26
|
|
|
private $appName; |
27
|
|
|
private $request; |
28
|
|
|
private $contacts; |
29
|
|
|
|
30
|
|
|
private $controller; |
31
|
|
|
|
32
|
|
|
public function setUp() { |
33
|
|
|
$this->appName = 'calendar'; |
34
|
|
|
$this->request = $this->getMockBuilder('\OCP\IRequest') |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMock(); |
37
|
|
|
$this->contacts = $this->getMockBuilder('OCP\Contacts\IManager') |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$this->controller = new ContactController($this->appName, |
42
|
|
|
$this->request, $this->contacts); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testSearchLocation() { |
46
|
|
|
$expected = [ |
47
|
|
|
[ |
48
|
|
|
'label' => "33 42nd Street\nRandom Town\nSome State\nUnited States", |
49
|
|
|
'name' => 'Person 1', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'label' => "5 Random Ave\n12782 Some big city\nYet another state\nUnited States", |
53
|
|
|
'name' => 'Person 1', |
54
|
|
|
], |
55
|
|
|
[ |
56
|
|
|
'label' => "ABC Street 2\n01337 Village\nGermany", |
57
|
|
|
'name' => '', |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
$apiResponse = [ |
62
|
|
|
[ |
63
|
|
|
'FN' => 'Person 1', |
64
|
|
|
'ADR' => [ |
65
|
|
|
'33 42nd Street;Random Town;Some State;;United States', |
66
|
|
|
';;5 Random Ave;12782 Some big city;Yet another state;United States', |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
[ |
70
|
|
|
'FN' => 'Person 2', |
71
|
|
|
], |
72
|
|
|
[ |
73
|
|
|
'ADR' => [ |
74
|
|
|
'ABC Street 2;01337 Village;;Germany', |
75
|
|
|
], |
76
|
|
|
], |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
$this->contacts->expects($this->once()) |
80
|
|
|
->method('search') |
81
|
|
|
->with($this->equalTo('Person'), $this->equalTo(['FN', 'ADR'])) |
82
|
|
|
->will($this->returnValue($apiResponse)); |
83
|
|
|
|
84
|
|
|
$actual = $this->controller->searchLocation('Person'); |
85
|
|
|
|
86
|
|
|
$this->assertEquals($expected, $actual->getData()); |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testSearchAttendee() { |
91
|
|
|
$expected = [ |
92
|
|
|
[ |
93
|
|
|
'name' => 'Person 1', |
94
|
|
|
'email' => ['[email protected]', '[email protected]'], |
95
|
|
|
], |
96
|
|
|
[ |
97
|
|
|
'name' => '', |
98
|
|
|
'email' => ['[email protected]'], |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
$apiResponse = [ |
103
|
|
|
[ |
104
|
|
|
'FN' => 'Person 1', |
105
|
|
|
'EMAIL' => [ |
106
|
|
|
'[email protected]', |
107
|
|
|
'[email protected]', |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
[ |
111
|
|
|
'FN' => 'Person 2', |
112
|
|
|
], |
113
|
|
|
[ |
114
|
|
|
'EMAIL' => [ |
115
|
|
|
'[email protected]', |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
$this->contacts->expects($this->once()) |
121
|
|
|
->method('search') |
122
|
|
|
->with($this->equalTo('Person'), $this->equalTo(['FN', 'EMAIL'])) |
123
|
|
|
->will($this->returnValue($apiResponse)); |
124
|
|
|
|
125
|
|
|
$actual = $this->controller->searchAttendee('Person'); |
126
|
|
|
|
127
|
|
|
$this->assertEquals($expected, $actual->getData()); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|