|
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
|
|
|
function scandir($directory) { |
|
25
|
|
|
$dir = substr(__DIR__, 0, -strlen('tests/php/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 TimezoneControllerTest 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 TimezoneController($this->appName, $this->request); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testGetTimezone() { |
|
72
|
|
|
$actual = $this->controller->getTimezone('TIMEZONE1.ics'); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual); |
|
75
|
|
|
$this->assertEquals('TIMEZONE1-data', $actual->getData()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testGetTimezoneWithFakeTz() { |
|
79
|
|
|
$actual = $this->controller->getTimezone('TIMEZONE42.ics'); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testGetTimezoneWithRegion() { |
|
85
|
|
|
$actual = $this->controller->getTimezoneWithRegion('REG', 'CIT.ics'); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\DataDisplayResponse', $actual); |
|
88
|
|
|
$this->assertEquals('TIMEZONE DATA WITH REGION AND CITY', $actual->getData()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testGetTimezoneWithRegionWithFakeTz() { |
|
92
|
|
|
$actual = $this->controller->getTimezoneWithRegion('EUROPE', 'BERLIN.ics'); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertInstanceOf('OCP\AppFramework\Http\NotFoundResponse', $actual); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|