|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OCA\AppOrder\Tests\Unit\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use OCP\IRequest; |
|
6
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
7
|
|
|
use OCP\AppFramework\Http; |
|
8
|
|
|
use \OCA\AppOrder\Service; |
|
9
|
|
|
use \OCA\AppOrder\AppInfo\Application; |
|
10
|
|
|
use \OCA\AppOrder\Controller; |
|
11
|
|
|
|
|
12
|
|
|
class SettingsControllerTest extends \Test\TestCase { |
|
13
|
|
|
|
|
14
|
|
|
private $container; |
|
15
|
|
|
private $request; |
|
16
|
|
|
private $service; |
|
17
|
|
|
private $navigationManager; |
|
18
|
|
|
private $userId; |
|
19
|
|
|
private $appName; |
|
20
|
|
|
private $controller; |
|
21
|
|
|
private $config; |
|
22
|
|
|
public function setUp() { |
|
23
|
|
|
|
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$app = new Application(); |
|
27
|
|
|
$this->container = $app->getContainer(); |
|
28
|
|
|
$this->request = $this->getMockBuilder('OCP\IRequest') |
|
29
|
|
|
->disableOriginalConstructor() |
|
30
|
|
|
->getMock(); |
|
31
|
|
|
$this->config = $this->getMockBuilder('OCP\IConfig') |
|
32
|
|
|
->disableOriginalConstructor() |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
$this->service = $this->getMockBuilder('\OCA\AppOrder\Service\ConfigService') |
|
35
|
|
|
->disableOriginalConstructor() |
|
36
|
|
|
->getMock(); |
|
37
|
|
|
$this->navigationManager = $this->getMockBuilder('\OCP\INavigationManager')->setMethods(['getAll', 'add', 'setActiveEntry']) |
|
38
|
|
|
->disableOriginalConstructor() |
|
39
|
|
|
->getMock(); |
|
40
|
|
|
$this->userId = 'admin'; |
|
41
|
|
|
$this->appName = 'apporder'; |
|
42
|
|
|
$this->controller = new \OCA\AppOrder\Controller\SettingsController( |
|
43
|
|
|
$this->appName, $this->request, $this->service, $this->navigationManager, |
|
44
|
|
|
$this->userId |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testAdminIndex() { |
|
50
|
|
|
$nav_custom = ['/app/calendar/', '/app/tasks/']; |
|
51
|
|
|
$nav_oc = [ |
|
52
|
|
|
['href' => '/app/files/', 'name' => 'Files'], |
|
53
|
|
|
['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
54
|
|
|
['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
55
|
|
|
]; |
|
56
|
|
|
$nav_final = [ |
|
57
|
|
|
'/app/calendar/' => $nav_oc[1], '/app/tasks/' => $nav_oc[2], '/app/files/' => $nav_oc[0] |
|
58
|
|
|
]; |
|
59
|
|
|
$this->service->expects($this->once()) |
|
60
|
|
|
->method('getAppValue') |
|
61
|
|
|
->with('order') |
|
62
|
|
|
->will($this->returnValue(json_encode($nav_custom))); |
|
63
|
|
|
$this->navigationManager->expects($this->once()) |
|
64
|
|
|
->method('getAll') |
|
65
|
|
|
->will($this->returnValue($nav_oc)); |
|
66
|
|
|
|
|
67
|
|
|
$result = $this->controller->adminIndex(); |
|
68
|
|
|
$expected = new \OCP\AppFramework\Http\TemplateResponse( |
|
69
|
|
|
$this->appName, |
|
70
|
|
|
'admin', |
|
71
|
|
|
["nav" => $nav_final], |
|
72
|
|
|
'blank' |
|
73
|
|
|
); |
|
74
|
|
|
$this->assertEquals($expected, $result); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testMatchOrder() { |
|
78
|
|
|
$nav = [ |
|
79
|
|
|
['href' => '/app/files/', 'name' => 'Files'], |
|
80
|
|
|
['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
81
|
|
|
['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
82
|
|
|
]; |
|
83
|
|
|
$order = ['/app/calendar/', '/app/tasks/']; |
|
84
|
|
|
$result = $this->controller->matchOrder($nav, $order); |
|
85
|
|
|
$expected = [ |
|
86
|
|
|
'/app/calendar/' => ['href' => '/app/calendar/', 'name' => 'Calendar'], |
|
87
|
|
|
'/app/tasks/' => ['href' => '/app/tasks/', 'name' => 'Tasks'], |
|
88
|
|
|
'/app/files/' => ['href' => '/app/files/', 'name' => 'Files'], |
|
89
|
|
|
]; |
|
90
|
|
|
$this->assertEquals($expected, $result); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testGetAppOrder() { |
|
94
|
|
|
$nav_system = ['/app/calendar/', '/app/tasks/']; |
|
95
|
|
|
$nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
96
|
|
|
$this->service->expects($this->once()) |
|
97
|
|
|
->method('getAppValue') |
|
98
|
|
|
->with('order') |
|
99
|
|
|
->will($this->returnValue(json_encode($nav_system))); |
|
100
|
|
|
$this->service->expects($this->once()) |
|
101
|
|
|
->method('getUserValue') |
|
102
|
|
|
->with('order', $this->userId) |
|
103
|
|
|
->will($this->returnValue(json_encode($nav_user))); |
|
104
|
|
|
$result = $this->controller->getAppOrder(); |
|
105
|
|
|
$this->assertEquals(json_encode($nav_user), $result); |
|
106
|
|
|
} |
|
107
|
|
|
public function testGetAppOrderNoUser() { |
|
108
|
|
|
$nav_system = ['/app/calendar/', '/app/tasks/']; |
|
109
|
|
|
$nav_user = ''; |
|
110
|
|
|
$this->service->expects($this->once()) |
|
111
|
|
|
->method('getAppValue') |
|
112
|
|
|
->with('order') |
|
113
|
|
|
->will($this->returnValue(json_encode($nav_system))); |
|
114
|
|
|
$this->service->expects($this->once()) |
|
115
|
|
|
->method('getUserValue') |
|
116
|
|
|
->with('order', $this->userId) |
|
117
|
|
|
->will($this->returnValue($nav_user)); |
|
118
|
|
|
$result = $this->controller->getAppOrder(); |
|
119
|
|
|
$this->assertEquals(json_encode($nav_system), $result); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testGetOrder() { |
|
123
|
|
|
$nav_system = ['/app/calendar/', '/app/tasks/']; |
|
124
|
|
|
$nav_user = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
125
|
|
|
$this->service->expects($this->once()) |
|
126
|
|
|
->method('getAppValue') |
|
127
|
|
|
->with('order') |
|
128
|
|
|
->will($this->returnValue(json_encode($nav_system))); |
|
129
|
|
|
$this->service->expects($this->once()) |
|
130
|
|
|
->method('getUserValue') |
|
131
|
|
|
->with('order', $this->userId) |
|
132
|
|
|
->will($this->returnValue(json_encode($nav_user))); |
|
133
|
|
|
$order = ['/app/files/', '/app/calendar/', '/app/tasks/']; |
|
134
|
|
|
$result = $this->controller->getOrder(); |
|
135
|
|
|
$expected = array('status' => 'success', 'order' => json_encode($order)); |
|
136
|
|
|
$this->assertEquals($expected, $result); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function testSavePersonal() { |
|
140
|
|
|
$order = "RANDOMORDER"; |
|
141
|
|
|
$expected = array( |
|
142
|
|
|
'status' => 'success', |
|
143
|
|
|
'data' => array('message'=> 'User order saved successfully.'), |
|
144
|
|
|
'order' => $order |
|
145
|
|
|
); |
|
146
|
|
|
$result = $this->controller->savePersonal($order); |
|
147
|
|
|
$this->assertEquals($expected, $result); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function testSaveDefaultOrder() { |
|
151
|
|
|
$order = "RANDOMORDER"; |
|
152
|
|
|
$expected = array( |
|
153
|
|
|
'status' => 'success', |
|
154
|
|
|
'order' => $order |
|
155
|
|
|
); |
|
156
|
|
|
$result = $this->controller->saveDefaultOrder($order); |
|
157
|
|
|
$this->assertEquals($expected, $result); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|