Completed
Push — master ( 406555...3987b8 )
by Raghu
04:09
created

ViewControllerTest::testGetTimezoneWithRegion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * ownCloud - Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2014 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
function scandir($directory) {
25
	$dir = substr(__DIR__, 0, -strlen('tests/unit/controller')) . 'controller/../timezones/';
26
	return $dir === $directory ? [
27
		'..',
28
		'.',
29
		'TIMEZONE1.ics',
30
		'TIMEZONE2.ics',
31
		'REG-CIT.ics',
32
		'INFO.md',
33
	] : [];
34
}
35
36
function file_get_contents($file) {
37
	$file_parts = explode('/', $file);
38
	end($file_parts);
39
	$file = current($file_parts);
40
	switch($file) {
41
		case 'TIMEZONE1.ics':
42
			return 'TIMEZONE1-data';
43
44
		case 'TIMEZONE2.ics':
45
			return 'ANOTHER TIMEZONE DATA';
46
47
		case 'REG-CIT.ics':
48
			return 'TIMEZONE DATA WITH REGION AND CITY';
49
50
		default:
51
			return null;
52
	}
53
}
54
55
class ViewControllerTest extends \PHPUnit_Framework_TestCase {
56
57
	private $appName;
58
	private $request;
59
60
	private $controller;
61
62
	public function setUp() {
63
		$this->appName = 'calendar';
64
		$this->request = $this->getMockBuilder('\OCP\IRequest')
65
			->disableOriginalConstructor()
66
			->getMock();
67
68
		$this->controller = new ViewController($this->appName, $this->request);
69
	}
70
71
	public function testIndex() {
72
		$actual = $this->controller->index();
73
74
		$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $actual);
75
		$this->assertEquals('main', $actual->getTemplateName());
76
	}
77
78
	public function testTimezoneList() {
79
		$actual = $this->controller->timezoneList();
80
		$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual);
81
		$this->assertEquals([
82
			'TIMEZONE1.ics',
83
			'TIMEZONE2.ics',
84
			'REG-CIT.ics',
85
		], $actual->getData());
86
	}
87
88
	public function testGetTimezone() {
89
		$actual = $this->controller->getTimezone('TIMEZONE1.ics');
90
91
		$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual);
92
		$this->assertEquals('TIMEZONE1-data', $actual->getData());
93
	}
94
95
	public function testGetTimezoneWithFakeTz() {
96
		$actual = $this->controller->getTimezone('TIMEZONE42.ics');
97
98
		$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual);
99
	}
100
101
	public function testGetTimezoneWithRegion() {
102
		$actual = $this->controller->getTimezoneWithRegion('REG', 'CIT.ics');
103
104
		$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual);
105
		$this->assertEquals('TIMEZONE DATA WITH REGION AND CITY', $actual->getData());
106
	}
107
108
	public function testGetTimezoneWithRegionWithFakeTz() {
109
		$actual = $this->controller->getTimezoneWithRegion('EUROPE', 'BERLIN.ics');
110
111
		$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual);
112
	}
113
}
114