|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\AppOrder; |
|
25
|
|
|
|
|
26
|
|
|
use OCA\AppOrder\Service\ConfigService; |
|
27
|
|
|
use \OCA\AppOrder\Util; |
|
28
|
|
|
|
|
29
|
|
|
class UtilTest extends \PHPUnit_Framework_TestCase { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var ConfigService |
|
33
|
|
|
*/ |
|
34
|
|
|
private $service; |
|
35
|
|
|
private $userId; |
|
36
|
|
|
private $util; |
|
37
|
|
|
private $config; |
|
38
|
|
|
public function setUp() { |
|
39
|
|
|
|
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
|
|
42
|
|
|
$this->config = $this->getMockBuilder('OCP\IConfig') |
|
43
|
|
|
->disableOriginalConstructor() |
|
44
|
|
|
->getMock(); |
|
45
|
|
|
$this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
|
|
|
|
|
46
|
|
|
->disableOriginalConstructor() |
|
47
|
|
|
->getMock(); |
|
48
|
|
|
$this->userId = 'admin'; |
|
49
|
|
|
$this->util = new Util($this->service, $this->userId); |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testMatchOrder() { |
|
54
|
|
|
$nav = [ |
|
55
|
|
|
['href' => '/app/files/', 'name' => 'Files'], |
|
56
|
|
|
['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
57
|
|
|
['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
58
|
|
|
]; |
|
59
|
|
|
$order = ['/app/calendar/', '/app/tasks/']; |
|
60
|
|
|
$result = $this->util->matchOrder($nav, $order); |
|
61
|
|
|
$expected = [ |
|
62
|
|
|
'/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
63
|
|
|
'/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
64
|
|
|
'/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
65
|
|
|
]; |
|
66
|
|
|
$this->assertEquals($expected, $result); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testGetAppOrder() { |
|
70
|
|
|
$nav_system = ['/app/calendar/', '/app/tasks/']; |
|
71
|
|
|
$nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
72
|
|
|
$this->service->expects($this->once()) |
|
|
|
|
|
|
73
|
|
|
->method('getAppValue') |
|
74
|
|
|
->with('order') |
|
75
|
|
|
->will($this->returnValue(json_encode($nav_system))); |
|
76
|
|
|
$this->service->expects($this->once()) |
|
|
|
|
|
|
77
|
|
|
->method('getUserValue') |
|
78
|
|
|
->with('order', $this->userId) |
|
79
|
|
|
->will($this->returnValue(json_encode($nav_user))); |
|
80
|
|
|
$result = $this->util->getAppOrder(); |
|
81
|
|
|
$this->assertEquals(json_encode($nav_user), $result); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testGetAppOrderNoUser() { |
|
85
|
|
|
$nav_system = ['/app/calendar/', '/app/tasks/']; |
|
86
|
|
|
$nav_user = ''; |
|
87
|
|
|
$this->service->expects($this->once()) |
|
|
|
|
|
|
88
|
|
|
->method('getAppValue') |
|
89
|
|
|
->with('order') |
|
90
|
|
|
->will($this->returnValue(json_encode($nav_system))); |
|
91
|
|
|
$this->service->expects($this->once()) |
|
|
|
|
|
|
92
|
|
|
->method('getUserValue') |
|
93
|
|
|
->with('order', $this->userId) |
|
94
|
|
|
->will($this->returnValue($nav_user)); |
|
95
|
|
|
$result = $this->util->getAppOrder(); |
|
96
|
|
|
$this->assertEquals(json_encode($nav_system), $result); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.