Completed
Pull Request — master (#694)
by Georg
25:17
created

ProxyControllerTest::testProxy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.4285
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 ProxyControllerTest extends \PHPUnit_Framework_TestCase {
25
26
	private $appName;
27
	private $request;
28
	private $client;
29
30
	private $newClient;
31
	private $response;
32
33
	private $controller;
34
35 View Code Duplication
	public function setUp() {
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...
36
		$this->appName = 'calendar';
37
		$this->request = $this->getMockBuilder('\OCP\IRequest')
38
			->disableOriginalConstructor()
39
			->getMock();
40
		$this->client = $this->getMockBuilder('\OCP\Http\Client\IClientService')
41
			->disableOriginalConstructor()
42
			->getMock();
43
44
		$this->newClient = $this->getMockBuilder('\OCP\Http\Client\IClient')
45
			->disableOriginalConstructor()
46
			->getMock();
47
		$this->response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
48
			->disableOriginalConstructor()
49
			->getMock();
50
51
		$this->controller = new ProxyController($this->appName,
52
			$this->request, $this->client);
53
	}
54
55
	public function testProxy() {
56
		$testUrl = 'http://abc.def/foobar?123';
57
58
		$this->client->expects($this->once())
59
			->method('newClient')
60
			->will($this->returnValue($this->newClient));
61
		$this->newClient->expects($this->once())
62
			->method('get')
63
			->with($testUrl, [
64
				'stream' => true,
65
			])
66
			->will($this->returnValue($this->response));
67
68
		$actual = $this->controller->proxy($testUrl);
69
70
		$this->assertInstanceOf('OCA\Calendar\Http\StreamResponse', $actual);
71
		$this->assertEquals('text/calendar', $actual->getHeaders()['Content-Type']);
72
	}
73
}