1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - 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
|
|
View Code Duplication |
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
|
|
View Code Duplication |
public function testSearchAttendee() { |
|
|
|
|
91
|
|
|
$expected = [ |
92
|
|
|
[ |
93
|
|
|
'name' => 'Person 1', |
94
|
|
|
'email' => '[email protected]', |
95
|
|
|
], |
96
|
|
|
[ |
97
|
|
|
'name' => 'Person 1', |
98
|
|
|
'email' => '[email protected]', |
99
|
|
|
], |
100
|
|
|
[ |
101
|
|
|
'name' => '', |
102
|
|
|
'email' => '[email protected]', |
103
|
|
|
], |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
$apiResponse = [ |
107
|
|
|
[ |
108
|
|
|
'FN' => 'Person 1', |
109
|
|
|
'EMAIL' => [ |
110
|
|
|
'[email protected]', |
111
|
|
|
'[email protected]', |
112
|
|
|
], |
113
|
|
|
], |
114
|
|
|
[ |
115
|
|
|
'FN' => 'Person 2', |
116
|
|
|
], |
117
|
|
|
[ |
118
|
|
|
'EMAIL' => [ |
119
|
|
|
'[email protected]', |
120
|
|
|
], |
121
|
|
|
], |
122
|
|
|
]; |
123
|
|
|
|
124
|
|
|
$this->contacts->expects($this->once()) |
125
|
|
|
->method('search') |
126
|
|
|
->with($this->equalTo('Person'), $this->equalTo(['FN', 'EMAIL'])) |
127
|
|
|
->will($this->returnValue($apiResponse)); |
128
|
|
|
|
129
|
|
|
$actual = $this->controller->searchAttendee('Person'); |
130
|
|
|
|
131
|
|
|
$this->assertEquals($expected, $actual->getData()); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.