-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathDashboardServiceTest.php
More file actions
124 lines (94 loc) · 3.29 KB
/
Copy pathDashboardServiceTest.php
File metadata and controls
124 lines (94 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Dashboard\Tests;
use OC\Accounts\Account;
use OCA\Dashboard\Service\DashboardService;
use OCP\Accounts\IAccountManager;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Config\IUserConfig;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class DashboardServiceTest extends TestCase {
private IUserConfig&MockObject $userConfig;
private IAppConfig&MockObject $appConfig;
private IUserManager&MockObject $userManager;
private IAccountManager&MockObject $accountManager;
private DashboardService $service;
protected function setUp(): void {
parent::setUp();
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->accountManager = $this->createMock(IAccountManager::class);
$this->service = new DashboardService(
$this->userConfig,
$this->appConfig,
'alice',
$this->userManager,
$this->accountManager,
);
}
public function testGetLayoutRemovesEmptyAndDuplicateEntries(): void {
$this->appConfig->method('getAppValueString')
->with('layout', 'recommendations,spreed,mail,calendar')
->willReturn('recommendations,spreed,mail,calendar');
$this->userConfig->method('getValueString')
->with('alice', 'dashboard', 'layout', 'recommendations,spreed,mail,calendar')
->willReturn('spreed,,mail,mail,calendar,spreed');
$layout = $this->service->getLayout();
$this->assertSame(['spreed', 'mail', 'calendar'], $layout);
}
public function testSanitizeLayoutRemovesEmptyAndDuplicateEntries(): void {
$layout = $this->service->sanitizeLayout(['files', 'calendar', 'files', '', 'mail', 'calendar']);
$this->assertSame(['files', 'calendar', 'mail'], $layout);
}
public function testGetBirthdate(): void {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);
$account = new Account($user);
$account->setProperty(
IAccountManager::PROPERTY_BIRTHDATE,
'2024-12-10T00:00:00.000Z',
IAccountManager::SCOPE_LOCAL,
IAccountManager::VERIFIED,
);
$this->accountManager->method('getAccount')
->willReturn($account);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
}
public function testGetBirthdatePropertyDoesNotExist(): void {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);
$account = new Account($user);
$this->accountManager->method('getAccount')
->willReturn($account);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('', $birthdate);
}
public function testGetBirthdateUserNotFound(): void {
$this->userManager->method('get')
->willReturn(null);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('', $birthdate);
}
public function testGetBirthdateNoUserId(): void {
$service = new DashboardService(
$this->userConfig,
$this->appConfig,
null,
$this->userManager,
$this->accountManager,
);
$birthdate = $service->getBirthdate();
$this->assertEquals('', $birthdate);
}
}