Completed
Pull Request — master (#1623)
by
unknown
05:57
created

AliasesControllerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 17
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
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 OC\AppFramework\Http;
22
use OCP\AppFramework\Db\DoesNotExistException;
23
use OCP\AppFramework\Http\JSONResponse;
24
use OCA\Mail\Controller\AliasesController;
25
use OCP\IUserSession;
26
use Test\TestCase;
27
28
class AliasesControllerTest extends TestCase {
29
30
	private $controller;
31
	private $appName = 'mail';
32
	private $request;
33
	private $aliasService;
34
	private $userId = 'john';
35
	private $userSession;
36
	private $user;
37
38
	public function setUp() {
39
		$this->request = $this->getMockBuilder('OCP\IRequest')
40
			->getMock();
41
		$this->aliasService = $this->getMockBuilder('OCA\Mail\Service\AliasesService')
42
			->disableOriginalConstructor()
43
			->getMock();
44
		$this->userSession = $this->getMockBuilder('OCP\IUserSession')
45
			->getMock();
46
		$this->user = $this->getMockBuilder('OCP\IUser')
47
			->getMock();
48
49
		$this->userSession->expects($this->once())
50
			->method('getUser')
51
			->will($this->returnValue($this->user));
52
53
		$this->controller = new AliasesController($this->appName, $this->request, $this->aliasService, $this->userSession);
54
	}
55
56
	public function testIndex() {
57
		$aliases = [];
58
		$accountId = 123;
59
60
		$this->user->expects($this->once())
61
			->method('getUID')
62
			->will($this->returnValue($this->userId));
63
64
		$this->aliasService->expects($this->once())
65
			->method('findAll')
66
			->with($accountId, $this->userId)
67
			->will($this->returnValue($aliases));
68
69
		$response = $this->controller->index($accountId);
70
71
		$expectedResponse = new JSONResponse([
72
			[
73
				// complete this
74
			]
75
		]);
76
77
		$this->assertEquals($expectedResponse, $response);
78
	}
79
80
	public function testDestroy() {
81
		$aliasId = 10;
82
83
		$this->user->expects($this->once())
84
			->method('getUID')
85
			->will($this->returnValue($this->userId));
86
87
		$this->aliasService->expects($this->once())
88
			->method('delete')
89
			->with($this->equalTo($aliasId), $this->equalTo($this->userId));
90
91
		$response = $this->controller->destroy($aliasId);
92
93
		$expectedResponse = new JSONResponse();
94
		$this->assertEquals($expectedResponse, $response);
95
	}
96
97
	public function testCreate() {
98
		$accountId = 28;
99
		$alias = "[email protected]";
100
		$aliasName = "Peter Parker";
101
102
		$this->user->expects($this->once())
103
			->method('getUID')
104
			->will($this->returnValue($this->userId));
105
106
		$this->aliasService->expects($this->once())
107
			->method('create')
108
			->with($this->equalTo($accountId), $this->equalTo($alias), $this->equalTo($aliasName));
109
110
		$response = $this->controller->create($accountId, $alias, $aliasName);
111
112
		$expected = new JSONResponse([
113
			'alias' => $alias,
114
			'name' => $aliasName
115
		]);
116
117
		$this->assertEquals($expected, $response);
118
	}
119
120
121
}
122