Skip to content

Commit b806cbb

Browse files
committed
Add tests for update notification controller for non-default updater server URL
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
1 parent 3c2dd08 commit b806cbb

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

apps/updatenotification/tests/Settings/AdminTest.php

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,176 @@ public function testGetFormWithUpdate() {
158158
$this->assertEquals($expected, $this->admin->getForm());
159159
}
160160

161+
public function testGetFormWithUpdateAndChangedUpdateServer() {
162+
$channels = [
163+
'daily',
164+
'beta',
165+
'stable',
166+
'production',
167+
];
168+
$currentChannel = Util::getChannel();
169+
if ($currentChannel === 'git') {
170+
$channels[] = 'git';
171+
}
172+
173+
$this->config
174+
->expects($this->exactly(2))
175+
->method('getAppValue')
176+
->willReturnMap([
177+
['core', 'lastupdatedat', '', '12345'],
178+
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
179+
]);
180+
$this->config
181+
->expects($this->once())
182+
->method('getSystemValue')
183+
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
184+
->willReturn('https://updates.nextcloud.com/updater_server_changed/');
185+
$this->dateTimeFormatter
186+
->expects($this->once())
187+
->method('formatDateTime')
188+
->with('12345')
189+
->willReturn('LastCheckedReturnValue');
190+
$this->updateChecker
191+
->expects($this->once())
192+
->method('getUpdateState')
193+
->willReturn([
194+
'updateAvailable' => true,
195+
'updateVersion' => '8.1.2',
196+
'updateVersionString' => 'Nextcloud 8.1.2',
197+
'downloadLink' => 'https://downloads.nextcloud.org/server',
198+
'changes' => [],
199+
'updaterEnabled' => true,
200+
'versionIsEol' => false,
201+
]);
202+
203+
$group = $this->createMock(IGroup::class);
204+
$group->expects($this->any())
205+
->method('getDisplayName')
206+
->willReturn('Administrators');
207+
$group->expects($this->any())
208+
->method('getGID')
209+
->willReturn('admin');
210+
$this->groupManager->expects($this->once())
211+
->method('get')
212+
->with('admin')
213+
->willReturn($group);
214+
215+
$this->subscriptionRegistry
216+
->expects($this->once())
217+
->method('delegateHasValidSubscription')
218+
->willReturn(true);
219+
220+
$params = [
221+
'json' => json_encode([
222+
'isNewVersionAvailable' => true,
223+
'isUpdateChecked' => true,
224+
'lastChecked' => 'LastCheckedReturnValue',
225+
'currentChannel' => Util::getChannel(),
226+
'channels' => $channels,
227+
'newVersion' => '8.1.2',
228+
'newVersionString' => 'Nextcloud 8.1.2',
229+
'downloadLink' => 'https://downloads.nextcloud.org/server',
230+
'changes' => [],
231+
'updaterEnabled' => true,
232+
'versionIsEol' => false,
233+
'isDefaultUpdateServerURL' => false,
234+
'updateServerURL' => 'https://updates.nextcloud.com/updater_server_changed/',
235+
'notifyGroups' => [
236+
['value' => 'admin', 'label' => 'Administrators'],
237+
],
238+
'hasValidSubscription' => true,
239+
]),
240+
];
241+
242+
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
243+
$this->assertEquals($expected, $this->admin->getForm());
244+
}
245+
246+
public function testGetFormWithUpdateAndCustomersUpdateServer() {
247+
$channels = [
248+
'daily',
249+
'beta',
250+
'stable',
251+
'production',
252+
];
253+
$currentChannel = Util::getChannel();
254+
if ($currentChannel === 'git') {
255+
$channels[] = 'git';
256+
}
257+
258+
$this->config
259+
->expects($this->exactly(2))
260+
->method('getAppValue')
261+
->willReturnMap([
262+
['core', 'lastupdatedat', '', '12345'],
263+
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
264+
]);
265+
$this->config
266+
->expects($this->once())
267+
->method('getSystemValue')
268+
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
269+
->willReturn('https://updates.nextcloud.com/customers/ABC-DEF/');
270+
$this->dateTimeFormatter
271+
->expects($this->once())
272+
->method('formatDateTime')
273+
->with('12345')
274+
->willReturn('LastCheckedReturnValue');
275+
$this->updateChecker
276+
->expects($this->once())
277+
->method('getUpdateState')
278+
->willReturn([
279+
'updateAvailable' => true,
280+
'updateVersion' => '8.1.2',
281+
'updateVersionString' => 'Nextcloud 8.1.2',
282+
'downloadLink' => 'https://downloads.nextcloud.org/server',
283+
'changes' => [],
284+
'updaterEnabled' => true,
285+
'versionIsEol' => false,
286+
]);
287+
288+
$group = $this->createMock(IGroup::class);
289+
$group->expects($this->any())
290+
->method('getDisplayName')
291+
->willReturn('Administrators');
292+
$group->expects($this->any())
293+
->method('getGID')
294+
->willReturn('admin');
295+
$this->groupManager->expects($this->once())
296+
->method('get')
297+
->with('admin')
298+
->willReturn($group);
299+
300+
$this->subscriptionRegistry
301+
->expects($this->once())
302+
->method('delegateHasValidSubscription')
303+
->willReturn(true);
304+
305+
$params = [
306+
'json' => json_encode([
307+
'isNewVersionAvailable' => true,
308+
'isUpdateChecked' => true,
309+
'lastChecked' => 'LastCheckedReturnValue',
310+
'currentChannel' => Util::getChannel(),
311+
'channels' => $channels,
312+
'newVersion' => '8.1.2',
313+
'newVersionString' => 'Nextcloud 8.1.2',
314+
'downloadLink' => 'https://downloads.nextcloud.org/server',
315+
'changes' => [],
316+
'updaterEnabled' => true,
317+
'versionIsEol' => false,
318+
'isDefaultUpdateServerURL' => true,
319+
'updateServerURL' => 'https://updates.nextcloud.com/customers/ABC-DEF/',
320+
'notifyGroups' => [
321+
['value' => 'admin', 'label' => 'Administrators'],
322+
],
323+
'hasValidSubscription' => true,
324+
]),
325+
];
326+
327+
$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
328+
$this->assertEquals($expected, $this->admin->getForm());
329+
}
330+
161331

162332
public function testGetSection() {
163333
$this->assertSame('overview', $this->admin->getSection());

0 commit comments

Comments
 (0)