Completed
Push — color_utility_service ( 0d095e...549c77 )
by
unknown
21:50
created

ContactControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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