@@ -24,144 +24,144 @@ |
||
24 | 24 | * @package Tests\Settings\Controller |
25 | 25 | */ |
26 | 26 | class MailSettingsControllerTest extends \Test\TestCase { |
27 | - private IConfig&MockObject $config; |
|
28 | - private IUserSession&MockObject $userSession; |
|
29 | - private IMailer&MockObject $mailer; |
|
30 | - private IL10N&MockObject $l; |
|
31 | - private IURLGenerator&MockObject $urlGenerator; |
|
32 | - private MailSettingsController $mailController; |
|
27 | + private IConfig&MockObject $config; |
|
28 | + private IUserSession&MockObject $userSession; |
|
29 | + private IMailer&MockObject $mailer; |
|
30 | + private IL10N&MockObject $l; |
|
31 | + private IURLGenerator&MockObject $urlGenerator; |
|
32 | + private MailSettingsController $mailController; |
|
33 | 33 | |
34 | - protected function setUp(): void { |
|
35 | - parent::setUp(); |
|
34 | + protected function setUp(): void { |
|
35 | + parent::setUp(); |
|
36 | 36 | |
37 | - $this->l = $this->createMock(IL10N::class); |
|
38 | - $this->config = $this->createMock(IConfig::class); |
|
39 | - $this->userSession = $this->createMock(IUserSession::class); |
|
40 | - $this->mailer = $this->createMock(IMailer::class); |
|
41 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
42 | - /** @var IRequest&MockObject $request */ |
|
43 | - $request = $this->createMock(IRequest::class); |
|
44 | - $this->mailController = new MailSettingsController( |
|
45 | - 'settings', |
|
46 | - $request, |
|
47 | - $this->l, |
|
48 | - $this->config, |
|
49 | - $this->userSession, |
|
50 | - $this->urlGenerator, |
|
51 | - $this->mailer, |
|
52 | - ); |
|
53 | - } |
|
37 | + $this->l = $this->createMock(IL10N::class); |
|
38 | + $this->config = $this->createMock(IConfig::class); |
|
39 | + $this->userSession = $this->createMock(IUserSession::class); |
|
40 | + $this->mailer = $this->createMock(IMailer::class); |
|
41 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
42 | + /** @var IRequest&MockObject $request */ |
|
43 | + $request = $this->createMock(IRequest::class); |
|
44 | + $this->mailController = new MailSettingsController( |
|
45 | + 'settings', |
|
46 | + $request, |
|
47 | + $this->l, |
|
48 | + $this->config, |
|
49 | + $this->userSession, |
|
50 | + $this->urlGenerator, |
|
51 | + $this->mailer, |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - public function testSetMailSettings(): void { |
|
56 | - $calls = [ |
|
57 | - [[ |
|
58 | - 'mail_domain' => 'nextcloud.com', |
|
59 | - 'mail_from_address' => '[email protected]', |
|
60 | - 'mail_smtpmode' => 'smtp', |
|
61 | - 'mail_smtpsecure' => 'ssl', |
|
62 | - 'mail_smtphost' => 'mx.nextcloud.org', |
|
63 | - 'mail_smtpauth' => 1, |
|
64 | - 'mail_smtpport' => '25', |
|
65 | - 'mail_sendmailmode' => 'smtp', |
|
66 | - ]], |
|
67 | - [[ |
|
68 | - 'mail_domain' => 'nextcloud.com', |
|
69 | - 'mail_from_address' => '[email protected]', |
|
70 | - 'mail_smtpmode' => 'smtp', |
|
71 | - 'mail_smtpsecure' => 'ssl', |
|
72 | - 'mail_smtphost' => 'mx.nextcloud.org', |
|
73 | - 'mail_smtpauth' => null, |
|
74 | - 'mail_smtpport' => '25', |
|
75 | - 'mail_smtpname' => null, |
|
76 | - 'mail_smtppassword' => null, |
|
77 | - 'mail_sendmailmode' => 'smtp', |
|
78 | - ]], |
|
79 | - ]; |
|
80 | - $this->config->expects($this->exactly(2)) |
|
81 | - ->method('setSystemValues') |
|
82 | - ->willReturnCallback(function () use (&$calls): void { |
|
83 | - $expected = array_shift($calls); |
|
84 | - $this->assertEquals($expected, func_get_args()); |
|
85 | - }); |
|
55 | + public function testSetMailSettings(): void { |
|
56 | + $calls = [ |
|
57 | + [[ |
|
58 | + 'mail_domain' => 'nextcloud.com', |
|
59 | + 'mail_from_address' => '[email protected]', |
|
60 | + 'mail_smtpmode' => 'smtp', |
|
61 | + 'mail_smtpsecure' => 'ssl', |
|
62 | + 'mail_smtphost' => 'mx.nextcloud.org', |
|
63 | + 'mail_smtpauth' => 1, |
|
64 | + 'mail_smtpport' => '25', |
|
65 | + 'mail_sendmailmode' => 'smtp', |
|
66 | + ]], |
|
67 | + [[ |
|
68 | + 'mail_domain' => 'nextcloud.com', |
|
69 | + 'mail_from_address' => '[email protected]', |
|
70 | + 'mail_smtpmode' => 'smtp', |
|
71 | + 'mail_smtpsecure' => 'ssl', |
|
72 | + 'mail_smtphost' => 'mx.nextcloud.org', |
|
73 | + 'mail_smtpauth' => null, |
|
74 | + 'mail_smtpport' => '25', |
|
75 | + 'mail_smtpname' => null, |
|
76 | + 'mail_smtppassword' => null, |
|
77 | + 'mail_sendmailmode' => 'smtp', |
|
78 | + ]], |
|
79 | + ]; |
|
80 | + $this->config->expects($this->exactly(2)) |
|
81 | + ->method('setSystemValues') |
|
82 | + ->willReturnCallback(function () use (&$calls): void { |
|
83 | + $expected = array_shift($calls); |
|
84 | + $this->assertEquals($expected, func_get_args()); |
|
85 | + }); |
|
86 | 86 | |
87 | - // With authentication |
|
88 | - $response = $this->mailController->setMailSettings( |
|
89 | - 'nextcloud.com', |
|
90 | - '[email protected]', |
|
91 | - 'smtp', |
|
92 | - 'ssl', |
|
93 | - 'mx.nextcloud.org', |
|
94 | - '1', |
|
95 | - '25', |
|
96 | - 'smtp' |
|
97 | - ); |
|
98 | - $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
87 | + // With authentication |
|
88 | + $response = $this->mailController->setMailSettings( |
|
89 | + 'nextcloud.com', |
|
90 | + '[email protected]', |
|
91 | + 'smtp', |
|
92 | + 'ssl', |
|
93 | + 'mx.nextcloud.org', |
|
94 | + '1', |
|
95 | + '25', |
|
96 | + 'smtp' |
|
97 | + ); |
|
98 | + $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
99 | 99 | |
100 | - // Without authentication (testing the deletion of the stored password) |
|
101 | - $response = $this->mailController->setMailSettings( |
|
102 | - 'nextcloud.com', |
|
103 | - '[email protected]', |
|
104 | - 'smtp', |
|
105 | - 'ssl', |
|
106 | - 'mx.nextcloud.org', |
|
107 | - '0', |
|
108 | - '25', |
|
109 | - 'smtp' |
|
110 | - ); |
|
111 | - $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
112 | - } |
|
100 | + // Without authentication (testing the deletion of the stored password) |
|
101 | + $response = $this->mailController->setMailSettings( |
|
102 | + 'nextcloud.com', |
|
103 | + '[email protected]', |
|
104 | + 'smtp', |
|
105 | + 'ssl', |
|
106 | + 'mx.nextcloud.org', |
|
107 | + '0', |
|
108 | + '25', |
|
109 | + 'smtp' |
|
110 | + ); |
|
111 | + $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
112 | + } |
|
113 | 113 | |
114 | - public function testStoreCredentials(): void { |
|
115 | - $this->config |
|
116 | - ->expects($this->once()) |
|
117 | - ->method('setSystemValues') |
|
118 | - ->with([ |
|
119 | - 'mail_smtpname' => 'UsernameToStore', |
|
120 | - 'mail_smtppassword' => 'PasswordToStore', |
|
121 | - ]); |
|
114 | + public function testStoreCredentials(): void { |
|
115 | + $this->config |
|
116 | + ->expects($this->once()) |
|
117 | + ->method('setSystemValues') |
|
118 | + ->with([ |
|
119 | + 'mail_smtpname' => 'UsernameToStore', |
|
120 | + 'mail_smtppassword' => 'PasswordToStore', |
|
121 | + ]); |
|
122 | 122 | |
123 | - $response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore'); |
|
124 | - $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
125 | - } |
|
123 | + $response = $this->mailController->storeCredentials('UsernameToStore', 'PasswordToStore'); |
|
124 | + $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
125 | + } |
|
126 | 126 | |
127 | - public function testSendTestMail(): void { |
|
128 | - $user = $this->createMock(User::class); |
|
129 | - $user->expects($this->any()) |
|
130 | - ->method('getUID') |
|
131 | - ->willReturn('Werner'); |
|
132 | - $user->expects($this->any()) |
|
133 | - ->method('getDisplayName') |
|
134 | - ->willReturn('Werner Brösel'); |
|
127 | + public function testSendTestMail(): void { |
|
128 | + $user = $this->createMock(User::class); |
|
129 | + $user->expects($this->any()) |
|
130 | + ->method('getUID') |
|
131 | + ->willReturn('Werner'); |
|
132 | + $user->expects($this->any()) |
|
133 | + ->method('getDisplayName') |
|
134 | + ->willReturn('Werner Brösel'); |
|
135 | 135 | |
136 | - $this->l->expects($this->any()) |
|
137 | - ->method('t') |
|
138 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
139 | - return vsprintf($text, $parameters); |
|
140 | - }); |
|
141 | - $this->userSession |
|
142 | - ->expects($this->any()) |
|
143 | - ->method('getUser') |
|
144 | - ->willReturn($user); |
|
136 | + $this->l->expects($this->any()) |
|
137 | + ->method('t') |
|
138 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
139 | + return vsprintf($text, $parameters); |
|
140 | + }); |
|
141 | + $this->userSession |
|
142 | + ->expects($this->any()) |
|
143 | + ->method('getUser') |
|
144 | + ->willReturn($user); |
|
145 | 145 | |
146 | - // Ensure that it fails when no mail address has been specified |
|
147 | - $response = $this->mailController->sendTestMail(); |
|
148 | - $this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus()); |
|
149 | - $this->assertSame('You need to set your account email before being able to send test emails. Go to for that.', $response->getData()); |
|
146 | + // Ensure that it fails when no mail address has been specified |
|
147 | + $response = $this->mailController->sendTestMail(); |
|
148 | + $this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus()); |
|
149 | + $this->assertSame('You need to set your account email before being able to send test emails. Go to for that.', $response->getData()); |
|
150 | 150 | |
151 | - // If no exception is thrown it should work |
|
152 | - $this->config |
|
153 | - ->expects($this->any()) |
|
154 | - ->method('getUserValue') |
|
155 | - ->willReturn('[email protected]'); |
|
156 | - $this->mailer->expects($this->once()) |
|
157 | - ->method('createMessage') |
|
158 | - ->willReturn($this->createMock(Message::class)); |
|
159 | - $emailTemplate = $this->createMock(IEMailTemplate::class); |
|
160 | - $this->mailer |
|
161 | - ->expects($this->once()) |
|
162 | - ->method('createEMailTemplate') |
|
163 | - ->willReturn($emailTemplate); |
|
164 | - $response = $this->mailController->sendTestMail(); |
|
165 | - $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
166 | - } |
|
151 | + // If no exception is thrown it should work |
|
152 | + $this->config |
|
153 | + ->expects($this->any()) |
|
154 | + ->method('getUserValue') |
|
155 | + ->willReturn('[email protected]'); |
|
156 | + $this->mailer->expects($this->once()) |
|
157 | + ->method('createMessage') |
|
158 | + ->willReturn($this->createMock(Message::class)); |
|
159 | + $emailTemplate = $this->createMock(IEMailTemplate::class); |
|
160 | + $this->mailer |
|
161 | + ->expects($this->once()) |
|
162 | + ->method('createEMailTemplate') |
|
163 | + ->willReturn($emailTemplate); |
|
164 | + $response = $this->mailController->sendTestMail(); |
|
165 | + $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
166 | + } |
|
167 | 167 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ]; |
80 | 80 | $this->config->expects($this->exactly(2)) |
81 | 81 | ->method('setSystemValues') |
82 | - ->willReturnCallback(function () use (&$calls): void { |
|
82 | + ->willReturnCallback(function() use (&$calls): void { |
|
83 | 83 | $expected = array_shift($calls); |
84 | 84 | $this->assertEquals($expected, func_get_args()); |
85 | 85 | }); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | $this->l->expects($this->any()) |
137 | 137 | ->method('t') |
138 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
138 | + ->willReturnCallback(function($text, $parameters = []) { |
|
139 | 139 | return vsprintf($text, $parameters); |
140 | 140 | }); |
141 | 141 | $this->userSession |
@@ -42,934 +42,934 @@ |
||
42 | 42 | * @package Tests\Settings\Controller |
43 | 43 | */ |
44 | 44 | class UsersControllerTest extends \Test\TestCase { |
45 | - private IGroupManager&MockObject $groupManager; |
|
46 | - private UserManager&MockObject $userManager; |
|
47 | - private IUserSession&MockObject $userSession; |
|
48 | - private IConfig&MockObject $config; |
|
49 | - private IMailer&MockObject $mailer; |
|
50 | - private IFactory&MockObject $l10nFactory; |
|
51 | - private IAppManager&MockObject $appManager; |
|
52 | - private IL10N&MockObject $l; |
|
53 | - private AccountManager&MockObject $accountManager; |
|
54 | - private IJobList&MockObject $jobList; |
|
55 | - private \OC\Security\IdentityProof\Manager&MockObject $securityManager; |
|
56 | - private IManager&MockObject $encryptionManager; |
|
57 | - private KnownUserService&MockObject $knownUserService; |
|
58 | - private IEncryptionModule&MockObject $encryptionModule; |
|
59 | - private IEventDispatcher&MockObject $dispatcher; |
|
60 | - private IInitialState&MockObject $initialState; |
|
61 | - |
|
62 | - protected function setUp(): void { |
|
63 | - parent::setUp(); |
|
64 | - |
|
65 | - $this->userManager = $this->createMock(UserManager::class); |
|
66 | - $this->groupManager = $this->createMock(Manager::class); |
|
67 | - $this->userSession = $this->createMock(IUserSession::class); |
|
68 | - $this->config = $this->createMock(IConfig::class); |
|
69 | - $this->l = $this->createMock(IL10N::class); |
|
70 | - $this->mailer = $this->createMock(IMailer::class); |
|
71 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
72 | - $this->appManager = $this->createMock(IAppManager::class); |
|
73 | - $this->accountManager = $this->createMock(AccountManager::class); |
|
74 | - $this->securityManager = $this->createMock(\OC\Security\IdentityProof\Manager::class); |
|
75 | - $this->jobList = $this->createMock(IJobList::class); |
|
76 | - $this->encryptionManager = $this->createMock(IManager::class); |
|
77 | - $this->knownUserService = $this->createMock(KnownUserService::class); |
|
78 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
79 | - $this->initialState = $this->createMock(IInitialState::class); |
|
80 | - |
|
81 | - $this->l->method('t') |
|
82 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
83 | - return vsprintf($text, $parameters); |
|
84 | - }); |
|
85 | - |
|
86 | - $this->encryptionModule = $this->createMock(IEncryptionModule::class); |
|
87 | - $this->encryptionManager->expects($this->any())->method('getEncryptionModules') |
|
88 | - ->willReturn(['encryptionModule' => ['callback' => function () { |
|
89 | - return $this->encryptionModule; |
|
90 | - }]]); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param bool $isAdmin |
|
95 | - * @return UsersController|MockObject |
|
96 | - */ |
|
97 | - protected function getController(bool $isAdmin = false, array $mockedMethods = []) { |
|
98 | - $this->groupManager->expects($this->any()) |
|
99 | - ->method('isAdmin') |
|
100 | - ->willReturn($isAdmin); |
|
101 | - |
|
102 | - if (empty($mockedMethods)) { |
|
103 | - return new UsersController( |
|
104 | - 'settings', |
|
105 | - $this->createMock(IRequest::class), |
|
106 | - $this->userManager, |
|
107 | - $this->groupManager, |
|
108 | - $this->userSession, |
|
109 | - $this->config, |
|
110 | - $this->l, |
|
111 | - $this->mailer, |
|
112 | - $this->l10nFactory, |
|
113 | - $this->appManager, |
|
114 | - $this->accountManager, |
|
115 | - $this->securityManager, |
|
116 | - $this->jobList, |
|
117 | - $this->encryptionManager, |
|
118 | - $this->knownUserService, |
|
119 | - $this->dispatcher, |
|
120 | - $this->initialState, |
|
121 | - ); |
|
122 | - } else { |
|
123 | - return $this->getMockBuilder(UsersController::class) |
|
124 | - ->setConstructorArgs( |
|
125 | - [ |
|
126 | - 'settings', |
|
127 | - $this->createMock(IRequest::class), |
|
128 | - $this->userManager, |
|
129 | - $this->groupManager, |
|
130 | - $this->userSession, |
|
131 | - $this->config, |
|
132 | - $this->l, |
|
133 | - $this->mailer, |
|
134 | - $this->l10nFactory, |
|
135 | - $this->appManager, |
|
136 | - $this->accountManager, |
|
137 | - $this->securityManager, |
|
138 | - $this->jobList, |
|
139 | - $this->encryptionManager, |
|
140 | - $this->knownUserService, |
|
141 | - $this->dispatcher, |
|
142 | - $this->initialState, |
|
143 | - ] |
|
144 | - ) |
|
145 | - ->onlyMethods($mockedMethods) |
|
146 | - ->getMock(); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - protected function buildPropertyMock(string $name, string $value, string $scope, string $verified = IAccountManager::VERIFIED): MockObject { |
|
151 | - $property = $this->createMock(IAccountProperty::class); |
|
152 | - $property->expects($this->any()) |
|
153 | - ->method('getName') |
|
154 | - ->willReturn($name); |
|
155 | - $property->expects($this->any()) |
|
156 | - ->method('getValue') |
|
157 | - ->willReturn($value); |
|
158 | - $property->expects($this->any()) |
|
159 | - ->method('getScope') |
|
160 | - ->willReturn($scope); |
|
161 | - $property->expects($this->any()) |
|
162 | - ->method('getVerified') |
|
163 | - ->willReturn($verified); |
|
164 | - |
|
165 | - return $property; |
|
166 | - } |
|
167 | - |
|
168 | - protected function getDefaultAccountMock(): MockObject { |
|
169 | - $propertyMocks = [ |
|
170 | - IAccountManager::PROPERTY_DISPLAYNAME => $this->buildPropertyMock( |
|
171 | - IAccountManager::PROPERTY_DISPLAYNAME, |
|
172 | - 'Default display name', |
|
173 | - IAccountManager::SCOPE_FEDERATED, |
|
174 | - ), |
|
175 | - IAccountManager::PROPERTY_ADDRESS => $this->buildPropertyMock( |
|
176 | - IAccountManager::PROPERTY_ADDRESS, |
|
177 | - 'Default address', |
|
178 | - IAccountManager::SCOPE_LOCAL, |
|
179 | - ), |
|
180 | - IAccountManager::PROPERTY_WEBSITE => $this->buildPropertyMock( |
|
181 | - IAccountManager::PROPERTY_WEBSITE, |
|
182 | - 'Default website', |
|
183 | - IAccountManager::SCOPE_LOCAL, |
|
184 | - ), |
|
185 | - IAccountManager::PROPERTY_EMAIL => $this->buildPropertyMock( |
|
186 | - IAccountManager::PROPERTY_EMAIL, |
|
187 | - 'Default email', |
|
188 | - IAccountManager::SCOPE_FEDERATED, |
|
189 | - ), |
|
190 | - IAccountManager::PROPERTY_AVATAR => $this->buildPropertyMock( |
|
191 | - IAccountManager::PROPERTY_AVATAR, |
|
192 | - '', |
|
193 | - IAccountManager::SCOPE_FEDERATED, |
|
194 | - ), |
|
195 | - IAccountManager::PROPERTY_PHONE => $this->buildPropertyMock( |
|
196 | - IAccountManager::PROPERTY_PHONE, |
|
197 | - 'Default phone', |
|
198 | - IAccountManager::SCOPE_LOCAL, |
|
199 | - ), |
|
200 | - IAccountManager::PROPERTY_TWITTER => $this->buildPropertyMock( |
|
201 | - IAccountManager::PROPERTY_TWITTER, |
|
202 | - 'Default twitter', |
|
203 | - IAccountManager::SCOPE_LOCAL, |
|
204 | - ), |
|
205 | - IAccountManager::PROPERTY_FEDIVERSE => $this->buildPropertyMock( |
|
206 | - IAccountManager::PROPERTY_FEDIVERSE, |
|
207 | - 'Default fediverse', |
|
208 | - IAccountManager::SCOPE_LOCAL, |
|
209 | - ), |
|
210 | - IAccountManager::PROPERTY_BIRTHDATE => $this->buildPropertyMock( |
|
211 | - IAccountManager::PROPERTY_BIRTHDATE, |
|
212 | - 'Default birthdate', |
|
213 | - IAccountManager::SCOPE_LOCAL, |
|
214 | - ), |
|
215 | - IAccountManager::PROPERTY_PRONOUNS => $this->buildPropertyMock( |
|
216 | - IAccountManager::PROPERTY_PRONOUNS, |
|
217 | - 'Default pronouns', |
|
218 | - IAccountManager::SCOPE_LOCAL, |
|
219 | - ), |
|
220 | - ]; |
|
221 | - |
|
222 | - $account = $this->createMock(IAccount::class); |
|
223 | - $account->expects($this->any()) |
|
224 | - ->method('getProperty') |
|
225 | - ->willReturnCallback(function (string $propertyName) use ($propertyMocks) { |
|
226 | - if (isset($propertyMocks[$propertyName])) { |
|
227 | - return $propertyMocks[$propertyName]; |
|
228 | - } |
|
229 | - throw new PropertyDoesNotExistException($propertyName); |
|
230 | - }); |
|
231 | - $account->expects($this->any()) |
|
232 | - ->method('getProperties') |
|
233 | - ->willReturn($propertyMocks); |
|
234 | - |
|
235 | - return $account; |
|
236 | - } |
|
237 | - |
|
238 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettings')] |
|
239 | - public function testSetUserSettings(string $email, bool $validEmail, int $expectedStatus): void { |
|
240 | - $controller = $this->getController(false, ['saveUserSettings']); |
|
241 | - $user = $this->createMock(IUser::class); |
|
242 | - $user->method('getUID')->willReturn('johndoe'); |
|
243 | - |
|
244 | - $this->userSession->method('getUser')->willReturn($user); |
|
245 | - |
|
246 | - if (!empty($email) && $validEmail) { |
|
247 | - $this->mailer->expects($this->once())->method('validateMailAddress') |
|
248 | - ->willReturn($validEmail); |
|
249 | - } |
|
250 | - |
|
251 | - $saveData = (!empty($email) && $validEmail) || empty($email); |
|
252 | - |
|
253 | - if ($saveData) { |
|
254 | - $this->accountManager->expects($this->once()) |
|
255 | - ->method('getAccount') |
|
256 | - ->with($user) |
|
257 | - ->willReturn($this->getDefaultAccountMock()); |
|
258 | - |
|
259 | - $controller->expects($this->once()) |
|
260 | - ->method('saveUserSettings'); |
|
261 | - } else { |
|
262 | - $controller->expects($this->never())->method('saveUserSettings'); |
|
263 | - } |
|
264 | - |
|
265 | - $result = $controller->setUserSettings( |
|
266 | - AccountManager::SCOPE_FEDERATED, |
|
267 | - 'displayName', |
|
268 | - AccountManager::SCOPE_FEDERATED, |
|
269 | - '47658468', |
|
270 | - AccountManager::SCOPE_FEDERATED, |
|
271 | - $email, |
|
272 | - AccountManager::SCOPE_FEDERATED, |
|
273 | - 'nextcloud.com', |
|
274 | - AccountManager::SCOPE_FEDERATED, |
|
275 | - 'street and city', |
|
276 | - AccountManager::SCOPE_FEDERATED, |
|
277 | - '@nextclouders', |
|
278 | - AccountManager::SCOPE_FEDERATED, |
|
279 | - '@nextclouders', |
|
280 | - AccountManager::SCOPE_FEDERATED, |
|
281 | - '2020-01-01', |
|
282 | - AccountManager::SCOPE_FEDERATED, |
|
283 | - 'they/them', |
|
284 | - AccountManager::SCOPE_FEDERATED, |
|
285 | - ); |
|
286 | - |
|
287 | - $this->assertSame($expectedStatus, $result->getStatus()); |
|
288 | - } |
|
289 | - |
|
290 | - public static function dataTestSetUserSettings(): array { |
|
291 | - return [ |
|
292 | - ['', true, Http::STATUS_OK], |
|
293 | - ['', false, Http::STATUS_OK], |
|
294 | - ['example.com', false, Http::STATUS_UNPROCESSABLE_ENTITY], |
|
295 | - ['[email protected]', true, Http::STATUS_OK], |
|
296 | - ]; |
|
297 | - } |
|
298 | - |
|
299 | - public function testSetUserSettingsWhenUserDisplayNameChangeNotAllowed(): void { |
|
300 | - $controller = $this->getController(false, ['saveUserSettings']); |
|
301 | - |
|
302 | - $avatarScope = IAccountManager::SCOPE_PUBLISHED; |
|
303 | - $displayName = 'Display name'; |
|
304 | - $displayNameScope = IAccountManager::SCOPE_PUBLISHED; |
|
305 | - $phone = '47658468'; |
|
306 | - $phoneScope = IAccountManager::SCOPE_PUBLISHED; |
|
307 | - $email = '[email protected]'; |
|
308 | - $emailScope = IAccountManager::SCOPE_PUBLISHED; |
|
309 | - $website = 'nextcloud.com'; |
|
310 | - $websiteScope = IAccountManager::SCOPE_PUBLISHED; |
|
311 | - $address = 'street and city'; |
|
312 | - $addressScope = IAccountManager::SCOPE_PUBLISHED; |
|
313 | - $twitter = '@nextclouders'; |
|
314 | - $twitterScope = IAccountManager::SCOPE_PUBLISHED; |
|
315 | - $fediverse = '@[email protected]'; |
|
316 | - $fediverseScope = IAccountManager::SCOPE_PUBLISHED; |
|
317 | - $birtdate = '2020-01-01'; |
|
318 | - $birthdateScope = IAccountManager::SCOPE_PUBLISHED; |
|
319 | - $pronouns = 'she/her'; |
|
320 | - $pronounsScope = IAccountManager::SCOPE_PUBLISHED; |
|
321 | - |
|
322 | - $user = $this->createMock(IUser::class); |
|
323 | - $user->method('getUID')->willReturn('johndoe'); |
|
324 | - |
|
325 | - $this->userSession->method('getUser')->willReturn($user); |
|
326 | - |
|
327 | - /** @var MockObject|IAccount $userAccount */ |
|
328 | - $userAccount = $this->getDefaultAccountMock(); |
|
329 | - $this->accountManager->expects($this->once()) |
|
330 | - ->method('getAccount') |
|
331 | - ->with($user) |
|
332 | - ->willReturn($userAccount); |
|
333 | - |
|
334 | - /** @var MockObject|IAccountProperty $avatarProperty */ |
|
335 | - $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR); |
|
336 | - $avatarProperty->expects($this->atLeastOnce()) |
|
337 | - ->method('setScope') |
|
338 | - ->with($avatarScope) |
|
339 | - ->willReturnSelf(); |
|
340 | - |
|
341 | - /** @var MockObject|IAccountProperty $avatarProperty */ |
|
342 | - $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_ADDRESS); |
|
343 | - $avatarProperty->expects($this->atLeastOnce()) |
|
344 | - ->method('setScope') |
|
345 | - ->with($addressScope) |
|
346 | - ->willReturnSelf(); |
|
347 | - $avatarProperty->expects($this->atLeastOnce()) |
|
348 | - ->method('setValue') |
|
349 | - ->with($address) |
|
350 | - ->willReturnSelf(); |
|
351 | - |
|
352 | - /** @var MockObject|IAccountProperty $emailProperty */ |
|
353 | - $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL); |
|
354 | - $emailProperty->expects($this->never()) |
|
355 | - ->method('setValue'); |
|
356 | - $emailProperty->expects($this->never()) |
|
357 | - ->method('setScope'); |
|
358 | - |
|
359 | - /** @var MockObject|IAccountProperty $emailProperty */ |
|
360 | - $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME); |
|
361 | - $emailProperty->expects($this->never()) |
|
362 | - ->method('setValue'); |
|
363 | - $emailProperty->expects($this->never()) |
|
364 | - ->method('setScope'); |
|
365 | - |
|
366 | - $this->config->expects($this->once()) |
|
367 | - ->method('getSystemValueBool') |
|
368 | - ->with('allow_user_to_change_display_name') |
|
369 | - ->willReturn(false); |
|
370 | - |
|
371 | - $this->appManager->expects($this->any()) |
|
372 | - ->method('isEnabledForUser') |
|
373 | - ->with('federatedfilesharing') |
|
374 | - ->willReturn(true); |
|
375 | - |
|
376 | - $this->mailer->expects($this->once())->method('validateMailAddress') |
|
377 | - ->willReturn(true); |
|
378 | - |
|
379 | - $controller->expects($this->once()) |
|
380 | - ->method('saveUserSettings'); |
|
381 | - |
|
382 | - $controller->setUserSettings( |
|
383 | - $avatarScope, |
|
384 | - $displayName, |
|
385 | - $displayNameScope, |
|
386 | - $phone, |
|
387 | - $phoneScope, |
|
388 | - $email, |
|
389 | - $emailScope, |
|
390 | - $website, |
|
391 | - $websiteScope, |
|
392 | - $address, |
|
393 | - $addressScope, |
|
394 | - $twitter, |
|
395 | - $twitterScope, |
|
396 | - $fediverse, |
|
397 | - $fediverseScope, |
|
398 | - $birtdate, |
|
399 | - $birthdateScope, |
|
400 | - $pronouns, |
|
401 | - $pronounsScope, |
|
402 | - ); |
|
403 | - } |
|
404 | - |
|
405 | - public function testSetUserSettingsWhenFederatedFilesharingNotEnabled(): void { |
|
406 | - $controller = $this->getController(false, ['saveUserSettings']); |
|
407 | - $user = $this->createMock(IUser::class); |
|
408 | - $user->method('getUID')->willReturn('johndoe'); |
|
409 | - |
|
410 | - $this->userSession->method('getUser')->willReturn($user); |
|
411 | - |
|
412 | - $defaultProperties = []; //$this->getDefaultAccountMock(); |
|
413 | - |
|
414 | - $userAccount = $this->getDefaultAccountMock(); |
|
415 | - $this->accountManager->expects($this->once()) |
|
416 | - ->method('getAccount') |
|
417 | - ->with($user) |
|
418 | - ->willReturn($userAccount); |
|
419 | - |
|
420 | - $this->appManager->expects($this->any()) |
|
421 | - ->method('isEnabledForUser') |
|
422 | - ->with('federatedfilesharing') |
|
423 | - ->willReturn(false); |
|
424 | - |
|
425 | - $avatarScope = IAccountManager::SCOPE_PUBLISHED; |
|
426 | - $displayName = 'Display name'; |
|
427 | - $displayNameScope = IAccountManager::SCOPE_PUBLISHED; |
|
428 | - $phone = '47658468'; |
|
429 | - $phoneScope = IAccountManager::SCOPE_PUBLISHED; |
|
430 | - $email = '[email protected]'; |
|
431 | - $emailScope = IAccountManager::SCOPE_PUBLISHED; |
|
432 | - $website = 'nextcloud.com'; |
|
433 | - $websiteScope = IAccountManager::SCOPE_PUBLISHED; |
|
434 | - $address = 'street and city'; |
|
435 | - $addressScope = IAccountManager::SCOPE_PUBLISHED; |
|
436 | - $twitter = '@nextclouders'; |
|
437 | - $twitterScope = IAccountManager::SCOPE_PUBLISHED; |
|
438 | - $fediverse = '@[email protected]'; |
|
439 | - $fediverseScope = IAccountManager::SCOPE_PUBLISHED; |
|
440 | - $birthdate = '2020-01-01'; |
|
441 | - $birthdateScope = IAccountManager::SCOPE_PUBLISHED; |
|
442 | - $pronouns = 'she/her'; |
|
443 | - $pronounsScope = IAccountManager::SCOPE_PUBLISHED; |
|
444 | - |
|
445 | - // All settings are changed (in the past phone, website, address and |
|
446 | - // twitter were not changed). |
|
447 | - $expectedProperties = $defaultProperties; |
|
448 | - $expectedProperties[IAccountManager::PROPERTY_AVATAR]['scope'] = $avatarScope; |
|
449 | - $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
450 | - $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['scope'] = $displayNameScope; |
|
451 | - $expectedProperties[IAccountManager::PROPERTY_EMAIL]['value'] = $email; |
|
452 | - $expectedProperties[IAccountManager::PROPERTY_EMAIL]['scope'] = $emailScope; |
|
453 | - $expectedProperties[IAccountManager::PROPERTY_PHONE]['value'] = $phone; |
|
454 | - $expectedProperties[IAccountManager::PROPERTY_PHONE]['scope'] = $phoneScope; |
|
455 | - $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['value'] = $website; |
|
456 | - $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['scope'] = $websiteScope; |
|
457 | - $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['value'] = $address; |
|
458 | - $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['scope'] = $addressScope; |
|
459 | - $expectedProperties[IAccountManager::PROPERTY_TWITTER]['value'] = $twitter; |
|
460 | - $expectedProperties[IAccountManager::PROPERTY_TWITTER]['scope'] = $twitterScope; |
|
461 | - $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['value'] = $fediverse; |
|
462 | - $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['scope'] = $fediverseScope; |
|
463 | - $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['value'] = $birthdate; |
|
464 | - $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['scope'] = $birthdateScope; |
|
465 | - $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['value'] = $pronouns; |
|
466 | - $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['scope'] = $pronounsScope; |
|
467 | - |
|
468 | - $this->mailer->expects($this->once())->method('validateMailAddress') |
|
469 | - ->willReturn(true); |
|
470 | - |
|
471 | - $controller->expects($this->once()) |
|
472 | - ->method('saveUserSettings') |
|
473 | - ->with($userAccount); |
|
474 | - |
|
475 | - $controller->setUserSettings( |
|
476 | - $avatarScope, |
|
477 | - $displayName, |
|
478 | - $displayNameScope, |
|
479 | - $phone, |
|
480 | - $phoneScope, |
|
481 | - $email, |
|
482 | - $emailScope, |
|
483 | - $website, |
|
484 | - $websiteScope, |
|
485 | - $address, |
|
486 | - $addressScope, |
|
487 | - $twitter, |
|
488 | - $twitterScope, |
|
489 | - $fediverse, |
|
490 | - $fediverseScope, |
|
491 | - $birthdate, |
|
492 | - $birthdateScope, |
|
493 | - $pronouns, |
|
494 | - $pronounsScope, |
|
495 | - ); |
|
496 | - } |
|
497 | - |
|
498 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettingsSubset')] |
|
499 | - public function testSetUserSettingsSubset(string $property, string $propertyValue): void { |
|
500 | - $controller = $this->getController(false, ['saveUserSettings']); |
|
501 | - $user = $this->createMock(IUser::class); |
|
502 | - $user->method('getUID')->willReturn('johndoe'); |
|
503 | - |
|
504 | - $this->userSession->method('getUser')->willReturn($user); |
|
505 | - |
|
506 | - /** @var IAccount&MockObject $userAccount */ |
|
507 | - $userAccount = $this->getDefaultAccountMock(); |
|
508 | - |
|
509 | - $this->accountManager->expects($this->once()) |
|
510 | - ->method('getAccount') |
|
511 | - ->with($user) |
|
512 | - ->willReturn($userAccount); |
|
513 | - |
|
514 | - $avatarScope = ($property === 'avatarScope') ? $propertyValue : null; |
|
515 | - $displayName = ($property === 'displayName') ? $propertyValue : null; |
|
516 | - $displayNameScope = ($property === 'displayNameScope') ? $propertyValue : null; |
|
517 | - $phone = ($property === 'phone') ? $propertyValue : null; |
|
518 | - $phoneScope = ($property === 'phoneScope') ? $propertyValue : null; |
|
519 | - $email = ($property === 'email') ? $propertyValue : null; |
|
520 | - $emailScope = ($property === 'emailScope') ? $propertyValue : null; |
|
521 | - $website = ($property === 'website') ? $propertyValue : null; |
|
522 | - $websiteScope = ($property === 'websiteScope') ? $propertyValue : null; |
|
523 | - $address = ($property === 'address') ? $propertyValue : null; |
|
524 | - $addressScope = ($property === 'addressScope') ? $propertyValue : null; |
|
525 | - $twitter = ($property === 'twitter') ? $propertyValue : null; |
|
526 | - $twitterScope = ($property === 'twitterScope') ? $propertyValue : null; |
|
527 | - $fediverse = ($property === 'fediverse') ? $propertyValue : null; |
|
528 | - $fediverseScope = ($property === 'fediverseScope') ? $propertyValue : null; |
|
529 | - $birthdate = ($property === 'birthdate') ? $propertyValue : null; |
|
530 | - $birthdateScope = ($property === 'birthdateScope') ? $propertyValue : null; |
|
531 | - $pronouns = ($property === 'pronouns') ? $propertyValue : null; |
|
532 | - $pronounsScope = ($property === 'pronounsScope') ? $propertyValue : null; |
|
533 | - |
|
534 | - /** @var IAccountProperty[]&MockObject[] $expectedProperties */ |
|
535 | - $expectedProperties = $userAccount->getProperties(); |
|
536 | - $isScope = strrpos($property, 'Scope') === strlen($property) - strlen('5'); |
|
537 | - switch ($property) { |
|
538 | - case 'avatarScope': |
|
539 | - $propertyId = IAccountManager::PROPERTY_AVATAR; |
|
540 | - break; |
|
541 | - case 'displayName': |
|
542 | - case 'displayNameScope': |
|
543 | - $propertyId = IAccountManager::PROPERTY_DISPLAYNAME; |
|
544 | - break; |
|
545 | - case 'phone': |
|
546 | - case 'phoneScope': |
|
547 | - $propertyId = IAccountManager::PROPERTY_PHONE; |
|
548 | - break; |
|
549 | - case 'email': |
|
550 | - case 'emailScope': |
|
551 | - $propertyId = IAccountManager::PROPERTY_EMAIL; |
|
552 | - break; |
|
553 | - case 'website': |
|
554 | - case 'websiteScope': |
|
555 | - $propertyId = IAccountManager::PROPERTY_WEBSITE; |
|
556 | - break; |
|
557 | - case 'address': |
|
558 | - case 'addressScope': |
|
559 | - $propertyId = IAccountManager::PROPERTY_ADDRESS; |
|
560 | - break; |
|
561 | - case 'twitter': |
|
562 | - case 'twitterScope': |
|
563 | - $propertyId = IAccountManager::PROPERTY_TWITTER; |
|
564 | - break; |
|
565 | - case 'fediverse': |
|
566 | - case 'fediverseScope': |
|
567 | - $propertyId = IAccountManager::PROPERTY_FEDIVERSE; |
|
568 | - break; |
|
569 | - case 'birthdate': |
|
570 | - case 'birthdateScope': |
|
571 | - $propertyId = IAccountManager::PROPERTY_BIRTHDATE; |
|
572 | - break; |
|
573 | - case 'pronouns': |
|
574 | - case 'pronounsScope': |
|
575 | - $propertyId = IAccountManager::PROPERTY_PRONOUNS; |
|
576 | - break; |
|
577 | - default: |
|
578 | - $propertyId = '404'; |
|
579 | - } |
|
580 | - $expectedProperties[$propertyId]->expects($this->any()) |
|
581 | - ->method($isScope ? 'getScope' : 'getValue') |
|
582 | - ->willReturn($propertyValue); |
|
583 | - |
|
584 | - if (!empty($email)) { |
|
585 | - $this->mailer->expects($this->once())->method('validateMailAddress') |
|
586 | - ->willReturn(true); |
|
587 | - } |
|
588 | - |
|
589 | - $controller->expects($this->once()) |
|
590 | - ->method('saveUserSettings') |
|
591 | - ->with($userAccount); |
|
592 | - |
|
593 | - $controller->setUserSettings( |
|
594 | - $avatarScope, |
|
595 | - $displayName, |
|
596 | - $displayNameScope, |
|
597 | - $phone, |
|
598 | - $phoneScope, |
|
599 | - $email, |
|
600 | - $emailScope, |
|
601 | - $website, |
|
602 | - $websiteScope, |
|
603 | - $address, |
|
604 | - $addressScope, |
|
605 | - $twitter, |
|
606 | - $twitterScope, |
|
607 | - $fediverse, |
|
608 | - $fediverseScope, |
|
609 | - $birthdate, |
|
610 | - $birthdateScope, |
|
611 | - $pronouns, |
|
612 | - $pronounsScope, |
|
613 | - ); |
|
614 | - } |
|
615 | - |
|
616 | - public static function dataTestSetUserSettingsSubset(): array { |
|
617 | - return [ |
|
618 | - ['avatarScope', IAccountManager::SCOPE_PUBLISHED], |
|
619 | - ['displayName', 'Display name'], |
|
620 | - ['displayNameScope', IAccountManager::SCOPE_PUBLISHED], |
|
621 | - ['phone', '47658468'], |
|
622 | - ['phoneScope', IAccountManager::SCOPE_PUBLISHED], |
|
623 | - ['email', '[email protected]'], |
|
624 | - ['emailScope', IAccountManager::SCOPE_PUBLISHED], |
|
625 | - ['website', 'nextcloud.com'], |
|
626 | - ['websiteScope', IAccountManager::SCOPE_PUBLISHED], |
|
627 | - ['address', 'street and city'], |
|
628 | - ['addressScope', IAccountManager::SCOPE_PUBLISHED], |
|
629 | - ['twitter', '@nextclouders'], |
|
630 | - ['twitterScope', IAccountManager::SCOPE_PUBLISHED], |
|
631 | - ['fediverse', '@[email protected]'], |
|
632 | - ['fediverseScope', IAccountManager::SCOPE_PUBLISHED], |
|
633 | - ['birthdate', '2020-01-01'], |
|
634 | - ['birthdateScope', IAccountManager::SCOPE_PUBLISHED], |
|
635 | - ['pronouns', 'he/him'], |
|
636 | - ['pronounsScope', IAccountManager::SCOPE_PUBLISHED], |
|
637 | - ]; |
|
638 | - } |
|
639 | - |
|
640 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettings')] |
|
641 | - public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void { |
|
642 | - $controller = $this->getController(); |
|
643 | - $user = $this->createMock(IUser::class); |
|
644 | - |
|
645 | - $user->method('getDisplayName')->willReturn($oldDisplayName); |
|
646 | - $user->method('getSystemEMailAddress')->willReturn($oldEmailAddress); |
|
647 | - $user->method('canChangeDisplayName')->willReturn(true); |
|
648 | - |
|
649 | - if (strtolower($data[IAccountManager::PROPERTY_EMAIL]['value']) === strtolower($oldEmailAddress ?? '')) { |
|
650 | - $user->expects($this->never())->method('setSystemEMailAddress'); |
|
651 | - } else { |
|
652 | - $user->expects($this->once())->method('setSystemEMailAddress') |
|
653 | - ->with($data[IAccountManager::PROPERTY_EMAIL]['value']); |
|
654 | - } |
|
655 | - |
|
656 | - if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ?? '') { |
|
657 | - $user->expects($this->never())->method('setDisplayName'); |
|
658 | - } else { |
|
659 | - $user->expects($this->once())->method('setDisplayName') |
|
660 | - ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
661 | - ->willReturn(true); |
|
662 | - } |
|
663 | - |
|
664 | - $properties = []; |
|
665 | - foreach ($data as $propertyName => $propertyData) { |
|
666 | - $properties[$propertyName] = $this->createMock(IAccountProperty::class); |
|
667 | - $properties[$propertyName]->expects($this->any()) |
|
668 | - ->method('getValue') |
|
669 | - ->willReturn($propertyData['value']); |
|
670 | - } |
|
671 | - |
|
672 | - $account = $this->createMock(IAccount::class); |
|
673 | - $account->expects($this->any()) |
|
674 | - ->method('getUser') |
|
675 | - ->willReturn($user); |
|
676 | - $account->expects($this->any()) |
|
677 | - ->method('getProperty') |
|
678 | - ->willReturnCallback(function (string $propertyName) use ($properties) { |
|
679 | - return $properties[$propertyName]; |
|
680 | - }); |
|
681 | - |
|
682 | - $this->accountManager->expects($this->any()) |
|
683 | - ->method('getAccount') |
|
684 | - ->willReturn($account); |
|
685 | - |
|
686 | - $this->accountManager->expects($this->once()) |
|
687 | - ->method('updateAccount') |
|
688 | - ->with($account); |
|
689 | - |
|
690 | - $this->invokePrivate($controller, 'saveUserSettings', [$account]); |
|
691 | - } |
|
692 | - |
|
693 | - public static function dataTestSaveUserSettings(): array { |
|
694 | - return [ |
|
695 | - [ |
|
696 | - [ |
|
697 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
698 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
699 | - ], |
|
700 | - '[email protected]', |
|
701 | - 'john doe' |
|
702 | - ], |
|
703 | - [ |
|
704 | - [ |
|
705 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
706 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
707 | - ], |
|
708 | - '[email protected]', |
|
709 | - 'john New doe' |
|
710 | - ], |
|
711 | - [ |
|
712 | - [ |
|
713 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
714 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
715 | - ], |
|
716 | - '[email protected]', |
|
717 | - 'john doe' |
|
718 | - ], |
|
719 | - [ |
|
720 | - [ |
|
721 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
722 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
723 | - ], |
|
724 | - '[email protected]', |
|
725 | - 'john New doe' |
|
726 | - ], |
|
727 | - [ |
|
728 | - [ |
|
729 | - IAccountManager::PROPERTY_EMAIL => ['value' => ''], |
|
730 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
731 | - ], |
|
732 | - null, |
|
733 | - 'john New doe' |
|
734 | - ], |
|
735 | - [ |
|
736 | - [ |
|
737 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
738 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
739 | - ], |
|
740 | - '[email protected]', |
|
741 | - null |
|
742 | - ], |
|
743 | - [ |
|
744 | - [ |
|
745 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
746 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
747 | - ], |
|
748 | - '[email protected]', |
|
749 | - null |
|
750 | - ], |
|
751 | - |
|
752 | - ]; |
|
753 | - } |
|
754 | - |
|
755 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettingsException')] |
|
756 | - public function testSaveUserSettingsException( |
|
757 | - array $data, |
|
758 | - string $oldEmailAddress, |
|
759 | - string $oldDisplayName, |
|
760 | - bool $setDisplayNameResult, |
|
761 | - bool $canChangeEmail, |
|
762 | - ): void { |
|
763 | - $this->expectException(ForbiddenException::class); |
|
764 | - |
|
765 | - $controller = $this->getController(); |
|
766 | - $user = $this->createMock(IUser::class); |
|
767 | - |
|
768 | - $user->method('getDisplayName')->willReturn($oldDisplayName); |
|
769 | - $user->method('getEMailAddress')->willReturn($oldEmailAddress); |
|
770 | - |
|
771 | - /** @var MockObject|IAccount $userAccount */ |
|
772 | - $userAccount = $this->createMock(IAccount::class); |
|
773 | - $userAccount->expects($this->any()) |
|
774 | - ->method('getUser') |
|
775 | - ->willReturn($user); |
|
776 | - $propertyMocks = []; |
|
777 | - foreach ($data as $propertyName => $propertyData) { |
|
778 | - /** @var MockObject|IAccountProperty $property */ |
|
779 | - $propertyMocks[$propertyName] = $this->buildPropertyMock($propertyName, $propertyData['value'], ''); |
|
780 | - } |
|
781 | - $userAccount->expects($this->any()) |
|
782 | - ->method('getProperty') |
|
783 | - ->willReturnCallback(function (string $propertyName) use ($propertyMocks) { |
|
784 | - return $propertyMocks[$propertyName]; |
|
785 | - }); |
|
786 | - |
|
787 | - if ($data[IAccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) { |
|
788 | - $user->method('canChangeDisplayName') |
|
789 | - ->willReturn($canChangeEmail); |
|
790 | - } |
|
791 | - |
|
792 | - if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) { |
|
793 | - $user->method('setDisplayName') |
|
794 | - ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
795 | - ->willReturn($setDisplayNameResult); |
|
796 | - } |
|
797 | - |
|
798 | - $this->invokePrivate($controller, 'saveUserSettings', [$userAccount]); |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - public static function dataTestSaveUserSettingsException(): array { |
|
803 | - return [ |
|
804 | - [ |
|
805 | - [ |
|
806 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
807 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
808 | - ], |
|
809 | - '[email protected]', |
|
810 | - 'john New doe', |
|
811 | - true, |
|
812 | - false |
|
813 | - ], |
|
814 | - [ |
|
815 | - [ |
|
816 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
817 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
818 | - ], |
|
819 | - '[email protected]', |
|
820 | - 'john New doe', |
|
821 | - false, |
|
822 | - true |
|
823 | - ], |
|
824 | - [ |
|
825 | - [ |
|
826 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
827 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
828 | - ], |
|
829 | - '[email protected]', |
|
830 | - 'john New doe', |
|
831 | - false, |
|
832 | - false |
|
833 | - ], |
|
834 | - |
|
835 | - ]; |
|
836 | - } |
|
837 | - |
|
838 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetVerificationCode')] |
|
839 | - public function testGetVerificationCode(string $account, string $type, array $dataBefore, array $expectedData, bool $onlyVerificationCode): void { |
|
840 | - $message = 'Use my Federated Cloud ID to share with me: [email protected]'; |
|
841 | - $signature = 'theSignature'; |
|
842 | - |
|
843 | - $code = $message . ' ' . $signature; |
|
844 | - if ($type === IAccountManager::PROPERTY_TWITTER || $type === IAccountManager::PROPERTY_FEDIVERSE) { |
|
845 | - $code = $message . ' ' . md5($signature); |
|
846 | - } |
|
847 | - |
|
848 | - $controller = $this->getController(false, ['signMessage', 'getCurrentTime']); |
|
849 | - |
|
850 | - $user = $this->createMock(IUser::class); |
|
851 | - |
|
852 | - $property = $this->buildPropertyMock($type, $dataBefore[$type]['value'], '', IAccountManager::NOT_VERIFIED); |
|
853 | - $property->expects($this->atLeastOnce()) |
|
854 | - ->method('setVerified') |
|
855 | - ->with(IAccountManager::VERIFICATION_IN_PROGRESS) |
|
856 | - ->willReturnSelf(); |
|
857 | - $property->expects($this->atLeastOnce()) |
|
858 | - ->method('setVerificationData') |
|
859 | - ->with($signature) |
|
860 | - ->willReturnSelf(); |
|
861 | - |
|
862 | - $userAccount = $this->createMock(IAccount::class); |
|
863 | - $userAccount->expects($this->any()) |
|
864 | - ->method('getUser') |
|
865 | - ->willReturn($user); |
|
866 | - $userAccount->expects($this->any()) |
|
867 | - ->method('getProperty') |
|
868 | - ->willReturn($property); |
|
869 | - |
|
870 | - $this->userSession->expects($this->once())->method('getUser')->willReturn($user); |
|
871 | - $this->accountManager->expects($this->once())->method('getAccount')->with($user)->willReturn($userAccount); |
|
872 | - $user->expects($this->any())->method('getCloudId')->willReturn('[email protected]'); |
|
873 | - $user->expects($this->any())->method('getUID')->willReturn('uid'); |
|
874 | - $controller->expects($this->once())->method('signMessage')->with($user, $message)->willReturn($signature); |
|
875 | - $controller->expects($this->any())->method('getCurrentTime')->willReturn(1234567); |
|
876 | - |
|
877 | - if ($onlyVerificationCode === false) { |
|
878 | - $this->accountManager->expects($this->once())->method('updateAccount')->with($userAccount)->willReturnArgument(1); |
|
879 | - $this->jobList->expects($this->once())->method('add') |
|
880 | - ->with('OCA\Settings\BackgroundJobs\VerifyUserData', |
|
881 | - [ |
|
882 | - 'verificationCode' => $code, |
|
883 | - 'data' => $dataBefore[$type]['value'], |
|
884 | - 'type' => $type, |
|
885 | - 'uid' => 'uid', |
|
886 | - 'try' => 0, |
|
887 | - 'lastRun' => 1234567 |
|
888 | - ]); |
|
889 | - } |
|
890 | - |
|
891 | - $result = $controller->getVerificationCode($account, $onlyVerificationCode); |
|
892 | - |
|
893 | - $data = $result->getData(); |
|
894 | - $this->assertSame(Http::STATUS_OK, $result->getStatus()); |
|
895 | - $this->assertSame($code, $data['code']); |
|
896 | - } |
|
897 | - |
|
898 | - public static function dataTestGetVerificationCode(): array { |
|
899 | - $accountDataBefore = [ |
|
900 | - IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED], |
|
901 | - IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'], |
|
902 | - ]; |
|
903 | - |
|
904 | - $accountDataAfterWebsite = [ |
|
905 | - IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'], |
|
906 | - IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'], |
|
907 | - ]; |
|
908 | - |
|
909 | - $accountDataAfterTwitter = [ |
|
910 | - IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED], |
|
911 | - IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'], |
|
912 | - ]; |
|
913 | - |
|
914 | - return [ |
|
915 | - ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, false], |
|
916 | - ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, false], |
|
917 | - ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, true], |
|
918 | - ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, true], |
|
919 | - ]; |
|
920 | - } |
|
921 | - |
|
922 | - /** |
|
923 | - * test get verification code in case no valid user was given |
|
924 | - */ |
|
925 | - public function testGetVerificationCodeInvalidUser(): void { |
|
926 | - $controller = $this->getController(); |
|
927 | - $this->userSession->expects($this->once())->method('getUser')->willReturn(null); |
|
928 | - $result = $controller->getVerificationCode('account', false); |
|
929 | - |
|
930 | - $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus()); |
|
931 | - } |
|
932 | - |
|
933 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCanAdminChangeUserPasswords')] |
|
934 | - public function testCanAdminChangeUserPasswords( |
|
935 | - bool $encryptionEnabled, |
|
936 | - bool $encryptionModuleLoaded, |
|
937 | - bool $masterKeyEnabled, |
|
938 | - bool $expected, |
|
939 | - ): void { |
|
940 | - $controller = $this->getController(); |
|
941 | - |
|
942 | - $this->encryptionManager->expects($this->any()) |
|
943 | - ->method('isEnabled') |
|
944 | - ->willReturn($encryptionEnabled); |
|
945 | - $this->encryptionManager->expects($this->any()) |
|
946 | - ->method('getEncryptionModule') |
|
947 | - ->willReturnCallback(function () use ($encryptionModuleLoaded) { |
|
948 | - if ($encryptionModuleLoaded) { |
|
949 | - return $this->encryptionModule; |
|
950 | - } else { |
|
951 | - throw new ModuleDoesNotExistsException(); |
|
952 | - } |
|
953 | - }); |
|
954 | - $this->encryptionModule->expects($this->any()) |
|
955 | - ->method('needDetailedAccessList') |
|
956 | - ->willReturn(!$masterKeyEnabled); |
|
957 | - |
|
958 | - $result = $this->invokePrivate($controller, 'canAdminChangeUserPasswords', []); |
|
959 | - $this->assertSame($expected, $result); |
|
960 | - } |
|
961 | - |
|
962 | - public static function dataTestCanAdminChangeUserPasswords(): array { |
|
963 | - return [ |
|
964 | - // encryptionEnabled, encryptionModuleLoaded, masterKeyEnabled, expectedResult |
|
965 | - [true, true, true, true], |
|
966 | - [false, true, true, true], |
|
967 | - [true, false, true, false], |
|
968 | - [false, false, true, true], |
|
969 | - [true, true, false, false], |
|
970 | - [false, true, false, false], |
|
971 | - [true, false, false, false], |
|
972 | - [false, false, false, true], |
|
973 | - ]; |
|
974 | - } |
|
45 | + private IGroupManager&MockObject $groupManager; |
|
46 | + private UserManager&MockObject $userManager; |
|
47 | + private IUserSession&MockObject $userSession; |
|
48 | + private IConfig&MockObject $config; |
|
49 | + private IMailer&MockObject $mailer; |
|
50 | + private IFactory&MockObject $l10nFactory; |
|
51 | + private IAppManager&MockObject $appManager; |
|
52 | + private IL10N&MockObject $l; |
|
53 | + private AccountManager&MockObject $accountManager; |
|
54 | + private IJobList&MockObject $jobList; |
|
55 | + private \OC\Security\IdentityProof\Manager&MockObject $securityManager; |
|
56 | + private IManager&MockObject $encryptionManager; |
|
57 | + private KnownUserService&MockObject $knownUserService; |
|
58 | + private IEncryptionModule&MockObject $encryptionModule; |
|
59 | + private IEventDispatcher&MockObject $dispatcher; |
|
60 | + private IInitialState&MockObject $initialState; |
|
61 | + |
|
62 | + protected function setUp(): void { |
|
63 | + parent::setUp(); |
|
64 | + |
|
65 | + $this->userManager = $this->createMock(UserManager::class); |
|
66 | + $this->groupManager = $this->createMock(Manager::class); |
|
67 | + $this->userSession = $this->createMock(IUserSession::class); |
|
68 | + $this->config = $this->createMock(IConfig::class); |
|
69 | + $this->l = $this->createMock(IL10N::class); |
|
70 | + $this->mailer = $this->createMock(IMailer::class); |
|
71 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
72 | + $this->appManager = $this->createMock(IAppManager::class); |
|
73 | + $this->accountManager = $this->createMock(AccountManager::class); |
|
74 | + $this->securityManager = $this->createMock(\OC\Security\IdentityProof\Manager::class); |
|
75 | + $this->jobList = $this->createMock(IJobList::class); |
|
76 | + $this->encryptionManager = $this->createMock(IManager::class); |
|
77 | + $this->knownUserService = $this->createMock(KnownUserService::class); |
|
78 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
79 | + $this->initialState = $this->createMock(IInitialState::class); |
|
80 | + |
|
81 | + $this->l->method('t') |
|
82 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
83 | + return vsprintf($text, $parameters); |
|
84 | + }); |
|
85 | + |
|
86 | + $this->encryptionModule = $this->createMock(IEncryptionModule::class); |
|
87 | + $this->encryptionManager->expects($this->any())->method('getEncryptionModules') |
|
88 | + ->willReturn(['encryptionModule' => ['callback' => function () { |
|
89 | + return $this->encryptionModule; |
|
90 | + }]]); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param bool $isAdmin |
|
95 | + * @return UsersController|MockObject |
|
96 | + */ |
|
97 | + protected function getController(bool $isAdmin = false, array $mockedMethods = []) { |
|
98 | + $this->groupManager->expects($this->any()) |
|
99 | + ->method('isAdmin') |
|
100 | + ->willReturn($isAdmin); |
|
101 | + |
|
102 | + if (empty($mockedMethods)) { |
|
103 | + return new UsersController( |
|
104 | + 'settings', |
|
105 | + $this->createMock(IRequest::class), |
|
106 | + $this->userManager, |
|
107 | + $this->groupManager, |
|
108 | + $this->userSession, |
|
109 | + $this->config, |
|
110 | + $this->l, |
|
111 | + $this->mailer, |
|
112 | + $this->l10nFactory, |
|
113 | + $this->appManager, |
|
114 | + $this->accountManager, |
|
115 | + $this->securityManager, |
|
116 | + $this->jobList, |
|
117 | + $this->encryptionManager, |
|
118 | + $this->knownUserService, |
|
119 | + $this->dispatcher, |
|
120 | + $this->initialState, |
|
121 | + ); |
|
122 | + } else { |
|
123 | + return $this->getMockBuilder(UsersController::class) |
|
124 | + ->setConstructorArgs( |
|
125 | + [ |
|
126 | + 'settings', |
|
127 | + $this->createMock(IRequest::class), |
|
128 | + $this->userManager, |
|
129 | + $this->groupManager, |
|
130 | + $this->userSession, |
|
131 | + $this->config, |
|
132 | + $this->l, |
|
133 | + $this->mailer, |
|
134 | + $this->l10nFactory, |
|
135 | + $this->appManager, |
|
136 | + $this->accountManager, |
|
137 | + $this->securityManager, |
|
138 | + $this->jobList, |
|
139 | + $this->encryptionManager, |
|
140 | + $this->knownUserService, |
|
141 | + $this->dispatcher, |
|
142 | + $this->initialState, |
|
143 | + ] |
|
144 | + ) |
|
145 | + ->onlyMethods($mockedMethods) |
|
146 | + ->getMock(); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + protected function buildPropertyMock(string $name, string $value, string $scope, string $verified = IAccountManager::VERIFIED): MockObject { |
|
151 | + $property = $this->createMock(IAccountProperty::class); |
|
152 | + $property->expects($this->any()) |
|
153 | + ->method('getName') |
|
154 | + ->willReturn($name); |
|
155 | + $property->expects($this->any()) |
|
156 | + ->method('getValue') |
|
157 | + ->willReturn($value); |
|
158 | + $property->expects($this->any()) |
|
159 | + ->method('getScope') |
|
160 | + ->willReturn($scope); |
|
161 | + $property->expects($this->any()) |
|
162 | + ->method('getVerified') |
|
163 | + ->willReturn($verified); |
|
164 | + |
|
165 | + return $property; |
|
166 | + } |
|
167 | + |
|
168 | + protected function getDefaultAccountMock(): MockObject { |
|
169 | + $propertyMocks = [ |
|
170 | + IAccountManager::PROPERTY_DISPLAYNAME => $this->buildPropertyMock( |
|
171 | + IAccountManager::PROPERTY_DISPLAYNAME, |
|
172 | + 'Default display name', |
|
173 | + IAccountManager::SCOPE_FEDERATED, |
|
174 | + ), |
|
175 | + IAccountManager::PROPERTY_ADDRESS => $this->buildPropertyMock( |
|
176 | + IAccountManager::PROPERTY_ADDRESS, |
|
177 | + 'Default address', |
|
178 | + IAccountManager::SCOPE_LOCAL, |
|
179 | + ), |
|
180 | + IAccountManager::PROPERTY_WEBSITE => $this->buildPropertyMock( |
|
181 | + IAccountManager::PROPERTY_WEBSITE, |
|
182 | + 'Default website', |
|
183 | + IAccountManager::SCOPE_LOCAL, |
|
184 | + ), |
|
185 | + IAccountManager::PROPERTY_EMAIL => $this->buildPropertyMock( |
|
186 | + IAccountManager::PROPERTY_EMAIL, |
|
187 | + 'Default email', |
|
188 | + IAccountManager::SCOPE_FEDERATED, |
|
189 | + ), |
|
190 | + IAccountManager::PROPERTY_AVATAR => $this->buildPropertyMock( |
|
191 | + IAccountManager::PROPERTY_AVATAR, |
|
192 | + '', |
|
193 | + IAccountManager::SCOPE_FEDERATED, |
|
194 | + ), |
|
195 | + IAccountManager::PROPERTY_PHONE => $this->buildPropertyMock( |
|
196 | + IAccountManager::PROPERTY_PHONE, |
|
197 | + 'Default phone', |
|
198 | + IAccountManager::SCOPE_LOCAL, |
|
199 | + ), |
|
200 | + IAccountManager::PROPERTY_TWITTER => $this->buildPropertyMock( |
|
201 | + IAccountManager::PROPERTY_TWITTER, |
|
202 | + 'Default twitter', |
|
203 | + IAccountManager::SCOPE_LOCAL, |
|
204 | + ), |
|
205 | + IAccountManager::PROPERTY_FEDIVERSE => $this->buildPropertyMock( |
|
206 | + IAccountManager::PROPERTY_FEDIVERSE, |
|
207 | + 'Default fediverse', |
|
208 | + IAccountManager::SCOPE_LOCAL, |
|
209 | + ), |
|
210 | + IAccountManager::PROPERTY_BIRTHDATE => $this->buildPropertyMock( |
|
211 | + IAccountManager::PROPERTY_BIRTHDATE, |
|
212 | + 'Default birthdate', |
|
213 | + IAccountManager::SCOPE_LOCAL, |
|
214 | + ), |
|
215 | + IAccountManager::PROPERTY_PRONOUNS => $this->buildPropertyMock( |
|
216 | + IAccountManager::PROPERTY_PRONOUNS, |
|
217 | + 'Default pronouns', |
|
218 | + IAccountManager::SCOPE_LOCAL, |
|
219 | + ), |
|
220 | + ]; |
|
221 | + |
|
222 | + $account = $this->createMock(IAccount::class); |
|
223 | + $account->expects($this->any()) |
|
224 | + ->method('getProperty') |
|
225 | + ->willReturnCallback(function (string $propertyName) use ($propertyMocks) { |
|
226 | + if (isset($propertyMocks[$propertyName])) { |
|
227 | + return $propertyMocks[$propertyName]; |
|
228 | + } |
|
229 | + throw new PropertyDoesNotExistException($propertyName); |
|
230 | + }); |
|
231 | + $account->expects($this->any()) |
|
232 | + ->method('getProperties') |
|
233 | + ->willReturn($propertyMocks); |
|
234 | + |
|
235 | + return $account; |
|
236 | + } |
|
237 | + |
|
238 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettings')] |
|
239 | + public function testSetUserSettings(string $email, bool $validEmail, int $expectedStatus): void { |
|
240 | + $controller = $this->getController(false, ['saveUserSettings']); |
|
241 | + $user = $this->createMock(IUser::class); |
|
242 | + $user->method('getUID')->willReturn('johndoe'); |
|
243 | + |
|
244 | + $this->userSession->method('getUser')->willReturn($user); |
|
245 | + |
|
246 | + if (!empty($email) && $validEmail) { |
|
247 | + $this->mailer->expects($this->once())->method('validateMailAddress') |
|
248 | + ->willReturn($validEmail); |
|
249 | + } |
|
250 | + |
|
251 | + $saveData = (!empty($email) && $validEmail) || empty($email); |
|
252 | + |
|
253 | + if ($saveData) { |
|
254 | + $this->accountManager->expects($this->once()) |
|
255 | + ->method('getAccount') |
|
256 | + ->with($user) |
|
257 | + ->willReturn($this->getDefaultAccountMock()); |
|
258 | + |
|
259 | + $controller->expects($this->once()) |
|
260 | + ->method('saveUserSettings'); |
|
261 | + } else { |
|
262 | + $controller->expects($this->never())->method('saveUserSettings'); |
|
263 | + } |
|
264 | + |
|
265 | + $result = $controller->setUserSettings( |
|
266 | + AccountManager::SCOPE_FEDERATED, |
|
267 | + 'displayName', |
|
268 | + AccountManager::SCOPE_FEDERATED, |
|
269 | + '47658468', |
|
270 | + AccountManager::SCOPE_FEDERATED, |
|
271 | + $email, |
|
272 | + AccountManager::SCOPE_FEDERATED, |
|
273 | + 'nextcloud.com', |
|
274 | + AccountManager::SCOPE_FEDERATED, |
|
275 | + 'street and city', |
|
276 | + AccountManager::SCOPE_FEDERATED, |
|
277 | + '@nextclouders', |
|
278 | + AccountManager::SCOPE_FEDERATED, |
|
279 | + '@nextclouders', |
|
280 | + AccountManager::SCOPE_FEDERATED, |
|
281 | + '2020-01-01', |
|
282 | + AccountManager::SCOPE_FEDERATED, |
|
283 | + 'they/them', |
|
284 | + AccountManager::SCOPE_FEDERATED, |
|
285 | + ); |
|
286 | + |
|
287 | + $this->assertSame($expectedStatus, $result->getStatus()); |
|
288 | + } |
|
289 | + |
|
290 | + public static function dataTestSetUserSettings(): array { |
|
291 | + return [ |
|
292 | + ['', true, Http::STATUS_OK], |
|
293 | + ['', false, Http::STATUS_OK], |
|
294 | + ['example.com', false, Http::STATUS_UNPROCESSABLE_ENTITY], |
|
295 | + ['[email protected]', true, Http::STATUS_OK], |
|
296 | + ]; |
|
297 | + } |
|
298 | + |
|
299 | + public function testSetUserSettingsWhenUserDisplayNameChangeNotAllowed(): void { |
|
300 | + $controller = $this->getController(false, ['saveUserSettings']); |
|
301 | + |
|
302 | + $avatarScope = IAccountManager::SCOPE_PUBLISHED; |
|
303 | + $displayName = 'Display name'; |
|
304 | + $displayNameScope = IAccountManager::SCOPE_PUBLISHED; |
|
305 | + $phone = '47658468'; |
|
306 | + $phoneScope = IAccountManager::SCOPE_PUBLISHED; |
|
307 | + $email = '[email protected]'; |
|
308 | + $emailScope = IAccountManager::SCOPE_PUBLISHED; |
|
309 | + $website = 'nextcloud.com'; |
|
310 | + $websiteScope = IAccountManager::SCOPE_PUBLISHED; |
|
311 | + $address = 'street and city'; |
|
312 | + $addressScope = IAccountManager::SCOPE_PUBLISHED; |
|
313 | + $twitter = '@nextclouders'; |
|
314 | + $twitterScope = IAccountManager::SCOPE_PUBLISHED; |
|
315 | + $fediverse = '@[email protected]'; |
|
316 | + $fediverseScope = IAccountManager::SCOPE_PUBLISHED; |
|
317 | + $birtdate = '2020-01-01'; |
|
318 | + $birthdateScope = IAccountManager::SCOPE_PUBLISHED; |
|
319 | + $pronouns = 'she/her'; |
|
320 | + $pronounsScope = IAccountManager::SCOPE_PUBLISHED; |
|
321 | + |
|
322 | + $user = $this->createMock(IUser::class); |
|
323 | + $user->method('getUID')->willReturn('johndoe'); |
|
324 | + |
|
325 | + $this->userSession->method('getUser')->willReturn($user); |
|
326 | + |
|
327 | + /** @var MockObject|IAccount $userAccount */ |
|
328 | + $userAccount = $this->getDefaultAccountMock(); |
|
329 | + $this->accountManager->expects($this->once()) |
|
330 | + ->method('getAccount') |
|
331 | + ->with($user) |
|
332 | + ->willReturn($userAccount); |
|
333 | + |
|
334 | + /** @var MockObject|IAccountProperty $avatarProperty */ |
|
335 | + $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR); |
|
336 | + $avatarProperty->expects($this->atLeastOnce()) |
|
337 | + ->method('setScope') |
|
338 | + ->with($avatarScope) |
|
339 | + ->willReturnSelf(); |
|
340 | + |
|
341 | + /** @var MockObject|IAccountProperty $avatarProperty */ |
|
342 | + $avatarProperty = $userAccount->getProperty(IAccountManager::PROPERTY_ADDRESS); |
|
343 | + $avatarProperty->expects($this->atLeastOnce()) |
|
344 | + ->method('setScope') |
|
345 | + ->with($addressScope) |
|
346 | + ->willReturnSelf(); |
|
347 | + $avatarProperty->expects($this->atLeastOnce()) |
|
348 | + ->method('setValue') |
|
349 | + ->with($address) |
|
350 | + ->willReturnSelf(); |
|
351 | + |
|
352 | + /** @var MockObject|IAccountProperty $emailProperty */ |
|
353 | + $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL); |
|
354 | + $emailProperty->expects($this->never()) |
|
355 | + ->method('setValue'); |
|
356 | + $emailProperty->expects($this->never()) |
|
357 | + ->method('setScope'); |
|
358 | + |
|
359 | + /** @var MockObject|IAccountProperty $emailProperty */ |
|
360 | + $emailProperty = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME); |
|
361 | + $emailProperty->expects($this->never()) |
|
362 | + ->method('setValue'); |
|
363 | + $emailProperty->expects($this->never()) |
|
364 | + ->method('setScope'); |
|
365 | + |
|
366 | + $this->config->expects($this->once()) |
|
367 | + ->method('getSystemValueBool') |
|
368 | + ->with('allow_user_to_change_display_name') |
|
369 | + ->willReturn(false); |
|
370 | + |
|
371 | + $this->appManager->expects($this->any()) |
|
372 | + ->method('isEnabledForUser') |
|
373 | + ->with('federatedfilesharing') |
|
374 | + ->willReturn(true); |
|
375 | + |
|
376 | + $this->mailer->expects($this->once())->method('validateMailAddress') |
|
377 | + ->willReturn(true); |
|
378 | + |
|
379 | + $controller->expects($this->once()) |
|
380 | + ->method('saveUserSettings'); |
|
381 | + |
|
382 | + $controller->setUserSettings( |
|
383 | + $avatarScope, |
|
384 | + $displayName, |
|
385 | + $displayNameScope, |
|
386 | + $phone, |
|
387 | + $phoneScope, |
|
388 | + $email, |
|
389 | + $emailScope, |
|
390 | + $website, |
|
391 | + $websiteScope, |
|
392 | + $address, |
|
393 | + $addressScope, |
|
394 | + $twitter, |
|
395 | + $twitterScope, |
|
396 | + $fediverse, |
|
397 | + $fediverseScope, |
|
398 | + $birtdate, |
|
399 | + $birthdateScope, |
|
400 | + $pronouns, |
|
401 | + $pronounsScope, |
|
402 | + ); |
|
403 | + } |
|
404 | + |
|
405 | + public function testSetUserSettingsWhenFederatedFilesharingNotEnabled(): void { |
|
406 | + $controller = $this->getController(false, ['saveUserSettings']); |
|
407 | + $user = $this->createMock(IUser::class); |
|
408 | + $user->method('getUID')->willReturn('johndoe'); |
|
409 | + |
|
410 | + $this->userSession->method('getUser')->willReturn($user); |
|
411 | + |
|
412 | + $defaultProperties = []; //$this->getDefaultAccountMock(); |
|
413 | + |
|
414 | + $userAccount = $this->getDefaultAccountMock(); |
|
415 | + $this->accountManager->expects($this->once()) |
|
416 | + ->method('getAccount') |
|
417 | + ->with($user) |
|
418 | + ->willReturn($userAccount); |
|
419 | + |
|
420 | + $this->appManager->expects($this->any()) |
|
421 | + ->method('isEnabledForUser') |
|
422 | + ->with('federatedfilesharing') |
|
423 | + ->willReturn(false); |
|
424 | + |
|
425 | + $avatarScope = IAccountManager::SCOPE_PUBLISHED; |
|
426 | + $displayName = 'Display name'; |
|
427 | + $displayNameScope = IAccountManager::SCOPE_PUBLISHED; |
|
428 | + $phone = '47658468'; |
|
429 | + $phoneScope = IAccountManager::SCOPE_PUBLISHED; |
|
430 | + $email = '[email protected]'; |
|
431 | + $emailScope = IAccountManager::SCOPE_PUBLISHED; |
|
432 | + $website = 'nextcloud.com'; |
|
433 | + $websiteScope = IAccountManager::SCOPE_PUBLISHED; |
|
434 | + $address = 'street and city'; |
|
435 | + $addressScope = IAccountManager::SCOPE_PUBLISHED; |
|
436 | + $twitter = '@nextclouders'; |
|
437 | + $twitterScope = IAccountManager::SCOPE_PUBLISHED; |
|
438 | + $fediverse = '@[email protected]'; |
|
439 | + $fediverseScope = IAccountManager::SCOPE_PUBLISHED; |
|
440 | + $birthdate = '2020-01-01'; |
|
441 | + $birthdateScope = IAccountManager::SCOPE_PUBLISHED; |
|
442 | + $pronouns = 'she/her'; |
|
443 | + $pronounsScope = IAccountManager::SCOPE_PUBLISHED; |
|
444 | + |
|
445 | + // All settings are changed (in the past phone, website, address and |
|
446 | + // twitter were not changed). |
|
447 | + $expectedProperties = $defaultProperties; |
|
448 | + $expectedProperties[IAccountManager::PROPERTY_AVATAR]['scope'] = $avatarScope; |
|
449 | + $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $displayName; |
|
450 | + $expectedProperties[IAccountManager::PROPERTY_DISPLAYNAME]['scope'] = $displayNameScope; |
|
451 | + $expectedProperties[IAccountManager::PROPERTY_EMAIL]['value'] = $email; |
|
452 | + $expectedProperties[IAccountManager::PROPERTY_EMAIL]['scope'] = $emailScope; |
|
453 | + $expectedProperties[IAccountManager::PROPERTY_PHONE]['value'] = $phone; |
|
454 | + $expectedProperties[IAccountManager::PROPERTY_PHONE]['scope'] = $phoneScope; |
|
455 | + $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['value'] = $website; |
|
456 | + $expectedProperties[IAccountManager::PROPERTY_WEBSITE]['scope'] = $websiteScope; |
|
457 | + $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['value'] = $address; |
|
458 | + $expectedProperties[IAccountManager::PROPERTY_ADDRESS]['scope'] = $addressScope; |
|
459 | + $expectedProperties[IAccountManager::PROPERTY_TWITTER]['value'] = $twitter; |
|
460 | + $expectedProperties[IAccountManager::PROPERTY_TWITTER]['scope'] = $twitterScope; |
|
461 | + $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['value'] = $fediverse; |
|
462 | + $expectedProperties[IAccountManager::PROPERTY_FEDIVERSE]['scope'] = $fediverseScope; |
|
463 | + $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['value'] = $birthdate; |
|
464 | + $expectedProperties[IAccountManager::PROPERTY_BIRTHDATE]['scope'] = $birthdateScope; |
|
465 | + $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['value'] = $pronouns; |
|
466 | + $expectedProperties[IAccountManager::PROPERTY_PRONOUNS]['scope'] = $pronounsScope; |
|
467 | + |
|
468 | + $this->mailer->expects($this->once())->method('validateMailAddress') |
|
469 | + ->willReturn(true); |
|
470 | + |
|
471 | + $controller->expects($this->once()) |
|
472 | + ->method('saveUserSettings') |
|
473 | + ->with($userAccount); |
|
474 | + |
|
475 | + $controller->setUserSettings( |
|
476 | + $avatarScope, |
|
477 | + $displayName, |
|
478 | + $displayNameScope, |
|
479 | + $phone, |
|
480 | + $phoneScope, |
|
481 | + $email, |
|
482 | + $emailScope, |
|
483 | + $website, |
|
484 | + $websiteScope, |
|
485 | + $address, |
|
486 | + $addressScope, |
|
487 | + $twitter, |
|
488 | + $twitterScope, |
|
489 | + $fediverse, |
|
490 | + $fediverseScope, |
|
491 | + $birthdate, |
|
492 | + $birthdateScope, |
|
493 | + $pronouns, |
|
494 | + $pronounsScope, |
|
495 | + ); |
|
496 | + } |
|
497 | + |
|
498 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetUserSettingsSubset')] |
|
499 | + public function testSetUserSettingsSubset(string $property, string $propertyValue): void { |
|
500 | + $controller = $this->getController(false, ['saveUserSettings']); |
|
501 | + $user = $this->createMock(IUser::class); |
|
502 | + $user->method('getUID')->willReturn('johndoe'); |
|
503 | + |
|
504 | + $this->userSession->method('getUser')->willReturn($user); |
|
505 | + |
|
506 | + /** @var IAccount&MockObject $userAccount */ |
|
507 | + $userAccount = $this->getDefaultAccountMock(); |
|
508 | + |
|
509 | + $this->accountManager->expects($this->once()) |
|
510 | + ->method('getAccount') |
|
511 | + ->with($user) |
|
512 | + ->willReturn($userAccount); |
|
513 | + |
|
514 | + $avatarScope = ($property === 'avatarScope') ? $propertyValue : null; |
|
515 | + $displayName = ($property === 'displayName') ? $propertyValue : null; |
|
516 | + $displayNameScope = ($property === 'displayNameScope') ? $propertyValue : null; |
|
517 | + $phone = ($property === 'phone') ? $propertyValue : null; |
|
518 | + $phoneScope = ($property === 'phoneScope') ? $propertyValue : null; |
|
519 | + $email = ($property === 'email') ? $propertyValue : null; |
|
520 | + $emailScope = ($property === 'emailScope') ? $propertyValue : null; |
|
521 | + $website = ($property === 'website') ? $propertyValue : null; |
|
522 | + $websiteScope = ($property === 'websiteScope') ? $propertyValue : null; |
|
523 | + $address = ($property === 'address') ? $propertyValue : null; |
|
524 | + $addressScope = ($property === 'addressScope') ? $propertyValue : null; |
|
525 | + $twitter = ($property === 'twitter') ? $propertyValue : null; |
|
526 | + $twitterScope = ($property === 'twitterScope') ? $propertyValue : null; |
|
527 | + $fediverse = ($property === 'fediverse') ? $propertyValue : null; |
|
528 | + $fediverseScope = ($property === 'fediverseScope') ? $propertyValue : null; |
|
529 | + $birthdate = ($property === 'birthdate') ? $propertyValue : null; |
|
530 | + $birthdateScope = ($property === 'birthdateScope') ? $propertyValue : null; |
|
531 | + $pronouns = ($property === 'pronouns') ? $propertyValue : null; |
|
532 | + $pronounsScope = ($property === 'pronounsScope') ? $propertyValue : null; |
|
533 | + |
|
534 | + /** @var IAccountProperty[]&MockObject[] $expectedProperties */ |
|
535 | + $expectedProperties = $userAccount->getProperties(); |
|
536 | + $isScope = strrpos($property, 'Scope') === strlen($property) - strlen('5'); |
|
537 | + switch ($property) { |
|
538 | + case 'avatarScope': |
|
539 | + $propertyId = IAccountManager::PROPERTY_AVATAR; |
|
540 | + break; |
|
541 | + case 'displayName': |
|
542 | + case 'displayNameScope': |
|
543 | + $propertyId = IAccountManager::PROPERTY_DISPLAYNAME; |
|
544 | + break; |
|
545 | + case 'phone': |
|
546 | + case 'phoneScope': |
|
547 | + $propertyId = IAccountManager::PROPERTY_PHONE; |
|
548 | + break; |
|
549 | + case 'email': |
|
550 | + case 'emailScope': |
|
551 | + $propertyId = IAccountManager::PROPERTY_EMAIL; |
|
552 | + break; |
|
553 | + case 'website': |
|
554 | + case 'websiteScope': |
|
555 | + $propertyId = IAccountManager::PROPERTY_WEBSITE; |
|
556 | + break; |
|
557 | + case 'address': |
|
558 | + case 'addressScope': |
|
559 | + $propertyId = IAccountManager::PROPERTY_ADDRESS; |
|
560 | + break; |
|
561 | + case 'twitter': |
|
562 | + case 'twitterScope': |
|
563 | + $propertyId = IAccountManager::PROPERTY_TWITTER; |
|
564 | + break; |
|
565 | + case 'fediverse': |
|
566 | + case 'fediverseScope': |
|
567 | + $propertyId = IAccountManager::PROPERTY_FEDIVERSE; |
|
568 | + break; |
|
569 | + case 'birthdate': |
|
570 | + case 'birthdateScope': |
|
571 | + $propertyId = IAccountManager::PROPERTY_BIRTHDATE; |
|
572 | + break; |
|
573 | + case 'pronouns': |
|
574 | + case 'pronounsScope': |
|
575 | + $propertyId = IAccountManager::PROPERTY_PRONOUNS; |
|
576 | + break; |
|
577 | + default: |
|
578 | + $propertyId = '404'; |
|
579 | + } |
|
580 | + $expectedProperties[$propertyId]->expects($this->any()) |
|
581 | + ->method($isScope ? 'getScope' : 'getValue') |
|
582 | + ->willReturn($propertyValue); |
|
583 | + |
|
584 | + if (!empty($email)) { |
|
585 | + $this->mailer->expects($this->once())->method('validateMailAddress') |
|
586 | + ->willReturn(true); |
|
587 | + } |
|
588 | + |
|
589 | + $controller->expects($this->once()) |
|
590 | + ->method('saveUserSettings') |
|
591 | + ->with($userAccount); |
|
592 | + |
|
593 | + $controller->setUserSettings( |
|
594 | + $avatarScope, |
|
595 | + $displayName, |
|
596 | + $displayNameScope, |
|
597 | + $phone, |
|
598 | + $phoneScope, |
|
599 | + $email, |
|
600 | + $emailScope, |
|
601 | + $website, |
|
602 | + $websiteScope, |
|
603 | + $address, |
|
604 | + $addressScope, |
|
605 | + $twitter, |
|
606 | + $twitterScope, |
|
607 | + $fediverse, |
|
608 | + $fediverseScope, |
|
609 | + $birthdate, |
|
610 | + $birthdateScope, |
|
611 | + $pronouns, |
|
612 | + $pronounsScope, |
|
613 | + ); |
|
614 | + } |
|
615 | + |
|
616 | + public static function dataTestSetUserSettingsSubset(): array { |
|
617 | + return [ |
|
618 | + ['avatarScope', IAccountManager::SCOPE_PUBLISHED], |
|
619 | + ['displayName', 'Display name'], |
|
620 | + ['displayNameScope', IAccountManager::SCOPE_PUBLISHED], |
|
621 | + ['phone', '47658468'], |
|
622 | + ['phoneScope', IAccountManager::SCOPE_PUBLISHED], |
|
623 | + ['email', '[email protected]'], |
|
624 | + ['emailScope', IAccountManager::SCOPE_PUBLISHED], |
|
625 | + ['website', 'nextcloud.com'], |
|
626 | + ['websiteScope', IAccountManager::SCOPE_PUBLISHED], |
|
627 | + ['address', 'street and city'], |
|
628 | + ['addressScope', IAccountManager::SCOPE_PUBLISHED], |
|
629 | + ['twitter', '@nextclouders'], |
|
630 | + ['twitterScope', IAccountManager::SCOPE_PUBLISHED], |
|
631 | + ['fediverse', '@[email protected]'], |
|
632 | + ['fediverseScope', IAccountManager::SCOPE_PUBLISHED], |
|
633 | + ['birthdate', '2020-01-01'], |
|
634 | + ['birthdateScope', IAccountManager::SCOPE_PUBLISHED], |
|
635 | + ['pronouns', 'he/him'], |
|
636 | + ['pronounsScope', IAccountManager::SCOPE_PUBLISHED], |
|
637 | + ]; |
|
638 | + } |
|
639 | + |
|
640 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettings')] |
|
641 | + public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void { |
|
642 | + $controller = $this->getController(); |
|
643 | + $user = $this->createMock(IUser::class); |
|
644 | + |
|
645 | + $user->method('getDisplayName')->willReturn($oldDisplayName); |
|
646 | + $user->method('getSystemEMailAddress')->willReturn($oldEmailAddress); |
|
647 | + $user->method('canChangeDisplayName')->willReturn(true); |
|
648 | + |
|
649 | + if (strtolower($data[IAccountManager::PROPERTY_EMAIL]['value']) === strtolower($oldEmailAddress ?? '')) { |
|
650 | + $user->expects($this->never())->method('setSystemEMailAddress'); |
|
651 | + } else { |
|
652 | + $user->expects($this->once())->method('setSystemEMailAddress') |
|
653 | + ->with($data[IAccountManager::PROPERTY_EMAIL]['value']); |
|
654 | + } |
|
655 | + |
|
656 | + if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ?? '') { |
|
657 | + $user->expects($this->never())->method('setDisplayName'); |
|
658 | + } else { |
|
659 | + $user->expects($this->once())->method('setDisplayName') |
|
660 | + ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
661 | + ->willReturn(true); |
|
662 | + } |
|
663 | + |
|
664 | + $properties = []; |
|
665 | + foreach ($data as $propertyName => $propertyData) { |
|
666 | + $properties[$propertyName] = $this->createMock(IAccountProperty::class); |
|
667 | + $properties[$propertyName]->expects($this->any()) |
|
668 | + ->method('getValue') |
|
669 | + ->willReturn($propertyData['value']); |
|
670 | + } |
|
671 | + |
|
672 | + $account = $this->createMock(IAccount::class); |
|
673 | + $account->expects($this->any()) |
|
674 | + ->method('getUser') |
|
675 | + ->willReturn($user); |
|
676 | + $account->expects($this->any()) |
|
677 | + ->method('getProperty') |
|
678 | + ->willReturnCallback(function (string $propertyName) use ($properties) { |
|
679 | + return $properties[$propertyName]; |
|
680 | + }); |
|
681 | + |
|
682 | + $this->accountManager->expects($this->any()) |
|
683 | + ->method('getAccount') |
|
684 | + ->willReturn($account); |
|
685 | + |
|
686 | + $this->accountManager->expects($this->once()) |
|
687 | + ->method('updateAccount') |
|
688 | + ->with($account); |
|
689 | + |
|
690 | + $this->invokePrivate($controller, 'saveUserSettings', [$account]); |
|
691 | + } |
|
692 | + |
|
693 | + public static function dataTestSaveUserSettings(): array { |
|
694 | + return [ |
|
695 | + [ |
|
696 | + [ |
|
697 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
698 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
699 | + ], |
|
700 | + '[email protected]', |
|
701 | + 'john doe' |
|
702 | + ], |
|
703 | + [ |
|
704 | + [ |
|
705 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
706 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
707 | + ], |
|
708 | + '[email protected]', |
|
709 | + 'john New doe' |
|
710 | + ], |
|
711 | + [ |
|
712 | + [ |
|
713 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
714 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
715 | + ], |
|
716 | + '[email protected]', |
|
717 | + 'john doe' |
|
718 | + ], |
|
719 | + [ |
|
720 | + [ |
|
721 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
722 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
723 | + ], |
|
724 | + '[email protected]', |
|
725 | + 'john New doe' |
|
726 | + ], |
|
727 | + [ |
|
728 | + [ |
|
729 | + IAccountManager::PROPERTY_EMAIL => ['value' => ''], |
|
730 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
731 | + ], |
|
732 | + null, |
|
733 | + 'john New doe' |
|
734 | + ], |
|
735 | + [ |
|
736 | + [ |
|
737 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
738 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
739 | + ], |
|
740 | + '[email protected]', |
|
741 | + null |
|
742 | + ], |
|
743 | + [ |
|
744 | + [ |
|
745 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
746 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
747 | + ], |
|
748 | + '[email protected]', |
|
749 | + null |
|
750 | + ], |
|
751 | + |
|
752 | + ]; |
|
753 | + } |
|
754 | + |
|
755 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSaveUserSettingsException')] |
|
756 | + public function testSaveUserSettingsException( |
|
757 | + array $data, |
|
758 | + string $oldEmailAddress, |
|
759 | + string $oldDisplayName, |
|
760 | + bool $setDisplayNameResult, |
|
761 | + bool $canChangeEmail, |
|
762 | + ): void { |
|
763 | + $this->expectException(ForbiddenException::class); |
|
764 | + |
|
765 | + $controller = $this->getController(); |
|
766 | + $user = $this->createMock(IUser::class); |
|
767 | + |
|
768 | + $user->method('getDisplayName')->willReturn($oldDisplayName); |
|
769 | + $user->method('getEMailAddress')->willReturn($oldEmailAddress); |
|
770 | + |
|
771 | + /** @var MockObject|IAccount $userAccount */ |
|
772 | + $userAccount = $this->createMock(IAccount::class); |
|
773 | + $userAccount->expects($this->any()) |
|
774 | + ->method('getUser') |
|
775 | + ->willReturn($user); |
|
776 | + $propertyMocks = []; |
|
777 | + foreach ($data as $propertyName => $propertyData) { |
|
778 | + /** @var MockObject|IAccountProperty $property */ |
|
779 | + $propertyMocks[$propertyName] = $this->buildPropertyMock($propertyName, $propertyData['value'], ''); |
|
780 | + } |
|
781 | + $userAccount->expects($this->any()) |
|
782 | + ->method('getProperty') |
|
783 | + ->willReturnCallback(function (string $propertyName) use ($propertyMocks) { |
|
784 | + return $propertyMocks[$propertyName]; |
|
785 | + }); |
|
786 | + |
|
787 | + if ($data[IAccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) { |
|
788 | + $user->method('canChangeDisplayName') |
|
789 | + ->willReturn($canChangeEmail); |
|
790 | + } |
|
791 | + |
|
792 | + if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) { |
|
793 | + $user->method('setDisplayName') |
|
794 | + ->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']) |
|
795 | + ->willReturn($setDisplayNameResult); |
|
796 | + } |
|
797 | + |
|
798 | + $this->invokePrivate($controller, 'saveUserSettings', [$userAccount]); |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + public static function dataTestSaveUserSettingsException(): array { |
|
803 | + return [ |
|
804 | + [ |
|
805 | + [ |
|
806 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
807 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
808 | + ], |
|
809 | + '[email protected]', |
|
810 | + 'john New doe', |
|
811 | + true, |
|
812 | + false |
|
813 | + ], |
|
814 | + [ |
|
815 | + [ |
|
816 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
817 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
818 | + ], |
|
819 | + '[email protected]', |
|
820 | + 'john New doe', |
|
821 | + false, |
|
822 | + true |
|
823 | + ], |
|
824 | + [ |
|
825 | + [ |
|
826 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
827 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'], |
|
828 | + ], |
|
829 | + '[email protected]', |
|
830 | + 'john New doe', |
|
831 | + false, |
|
832 | + false |
|
833 | + ], |
|
834 | + |
|
835 | + ]; |
|
836 | + } |
|
837 | + |
|
838 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetVerificationCode')] |
|
839 | + public function testGetVerificationCode(string $account, string $type, array $dataBefore, array $expectedData, bool $onlyVerificationCode): void { |
|
840 | + $message = 'Use my Federated Cloud ID to share with me: [email protected]'; |
|
841 | + $signature = 'theSignature'; |
|
842 | + |
|
843 | + $code = $message . ' ' . $signature; |
|
844 | + if ($type === IAccountManager::PROPERTY_TWITTER || $type === IAccountManager::PROPERTY_FEDIVERSE) { |
|
845 | + $code = $message . ' ' . md5($signature); |
|
846 | + } |
|
847 | + |
|
848 | + $controller = $this->getController(false, ['signMessage', 'getCurrentTime']); |
|
849 | + |
|
850 | + $user = $this->createMock(IUser::class); |
|
851 | + |
|
852 | + $property = $this->buildPropertyMock($type, $dataBefore[$type]['value'], '', IAccountManager::NOT_VERIFIED); |
|
853 | + $property->expects($this->atLeastOnce()) |
|
854 | + ->method('setVerified') |
|
855 | + ->with(IAccountManager::VERIFICATION_IN_PROGRESS) |
|
856 | + ->willReturnSelf(); |
|
857 | + $property->expects($this->atLeastOnce()) |
|
858 | + ->method('setVerificationData') |
|
859 | + ->with($signature) |
|
860 | + ->willReturnSelf(); |
|
861 | + |
|
862 | + $userAccount = $this->createMock(IAccount::class); |
|
863 | + $userAccount->expects($this->any()) |
|
864 | + ->method('getUser') |
|
865 | + ->willReturn($user); |
|
866 | + $userAccount->expects($this->any()) |
|
867 | + ->method('getProperty') |
|
868 | + ->willReturn($property); |
|
869 | + |
|
870 | + $this->userSession->expects($this->once())->method('getUser')->willReturn($user); |
|
871 | + $this->accountManager->expects($this->once())->method('getAccount')->with($user)->willReturn($userAccount); |
|
872 | + $user->expects($this->any())->method('getCloudId')->willReturn('[email protected]'); |
|
873 | + $user->expects($this->any())->method('getUID')->willReturn('uid'); |
|
874 | + $controller->expects($this->once())->method('signMessage')->with($user, $message)->willReturn($signature); |
|
875 | + $controller->expects($this->any())->method('getCurrentTime')->willReturn(1234567); |
|
876 | + |
|
877 | + if ($onlyVerificationCode === false) { |
|
878 | + $this->accountManager->expects($this->once())->method('updateAccount')->with($userAccount)->willReturnArgument(1); |
|
879 | + $this->jobList->expects($this->once())->method('add') |
|
880 | + ->with('OCA\Settings\BackgroundJobs\VerifyUserData', |
|
881 | + [ |
|
882 | + 'verificationCode' => $code, |
|
883 | + 'data' => $dataBefore[$type]['value'], |
|
884 | + 'type' => $type, |
|
885 | + 'uid' => 'uid', |
|
886 | + 'try' => 0, |
|
887 | + 'lastRun' => 1234567 |
|
888 | + ]); |
|
889 | + } |
|
890 | + |
|
891 | + $result = $controller->getVerificationCode($account, $onlyVerificationCode); |
|
892 | + |
|
893 | + $data = $result->getData(); |
|
894 | + $this->assertSame(Http::STATUS_OK, $result->getStatus()); |
|
895 | + $this->assertSame($code, $data['code']); |
|
896 | + } |
|
897 | + |
|
898 | + public static function dataTestGetVerificationCode(): array { |
|
899 | + $accountDataBefore = [ |
|
900 | + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED], |
|
901 | + IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'], |
|
902 | + ]; |
|
903 | + |
|
904 | + $accountDataAfterWebsite = [ |
|
905 | + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'], |
|
906 | + IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::NOT_VERIFIED, 'signature' => 'theSignature'], |
|
907 | + ]; |
|
908 | + |
|
909 | + $accountDataAfterTwitter = [ |
|
910 | + IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => IAccountManager::NOT_VERIFIED], |
|
911 | + IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => IAccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'], |
|
912 | + ]; |
|
913 | + |
|
914 | + return [ |
|
915 | + ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, false], |
|
916 | + ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, false], |
|
917 | + ['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, true], |
|
918 | + ['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, true], |
|
919 | + ]; |
|
920 | + } |
|
921 | + |
|
922 | + /** |
|
923 | + * test get verification code in case no valid user was given |
|
924 | + */ |
|
925 | + public function testGetVerificationCodeInvalidUser(): void { |
|
926 | + $controller = $this->getController(); |
|
927 | + $this->userSession->expects($this->once())->method('getUser')->willReturn(null); |
|
928 | + $result = $controller->getVerificationCode('account', false); |
|
929 | + |
|
930 | + $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus()); |
|
931 | + } |
|
932 | + |
|
933 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCanAdminChangeUserPasswords')] |
|
934 | + public function testCanAdminChangeUserPasswords( |
|
935 | + bool $encryptionEnabled, |
|
936 | + bool $encryptionModuleLoaded, |
|
937 | + bool $masterKeyEnabled, |
|
938 | + bool $expected, |
|
939 | + ): void { |
|
940 | + $controller = $this->getController(); |
|
941 | + |
|
942 | + $this->encryptionManager->expects($this->any()) |
|
943 | + ->method('isEnabled') |
|
944 | + ->willReturn($encryptionEnabled); |
|
945 | + $this->encryptionManager->expects($this->any()) |
|
946 | + ->method('getEncryptionModule') |
|
947 | + ->willReturnCallback(function () use ($encryptionModuleLoaded) { |
|
948 | + if ($encryptionModuleLoaded) { |
|
949 | + return $this->encryptionModule; |
|
950 | + } else { |
|
951 | + throw new ModuleDoesNotExistsException(); |
|
952 | + } |
|
953 | + }); |
|
954 | + $this->encryptionModule->expects($this->any()) |
|
955 | + ->method('needDetailedAccessList') |
|
956 | + ->willReturn(!$masterKeyEnabled); |
|
957 | + |
|
958 | + $result = $this->invokePrivate($controller, 'canAdminChangeUserPasswords', []); |
|
959 | + $this->assertSame($expected, $result); |
|
960 | + } |
|
961 | + |
|
962 | + public static function dataTestCanAdminChangeUserPasswords(): array { |
|
963 | + return [ |
|
964 | + // encryptionEnabled, encryptionModuleLoaded, masterKeyEnabled, expectedResult |
|
965 | + [true, true, true, true], |
|
966 | + [false, true, true, true], |
|
967 | + [true, false, true, false], |
|
968 | + [false, false, true, true], |
|
969 | + [true, true, false, false], |
|
970 | + [false, true, false, false], |
|
971 | + [true, false, false, false], |
|
972 | + [false, false, false, true], |
|
973 | + ]; |
|
974 | + } |
|
975 | 975 | } |
@@ -20,91 +20,91 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class AuthtokensTest extends TestCase { |
23 | - private IAuthTokenProvider&MockObject $authTokenProvider; |
|
24 | - private ISession&MockObject $session; |
|
25 | - private IUserSession&MockObject $userSession; |
|
26 | - private IInitialState&MockObject $initialState; |
|
27 | - private string $uid; |
|
28 | - private Authtokens $section; |
|
23 | + private IAuthTokenProvider&MockObject $authTokenProvider; |
|
24 | + private ISession&MockObject $session; |
|
25 | + private IUserSession&MockObject $userSession; |
|
26 | + private IInitialState&MockObject $initialState; |
|
27 | + private string $uid; |
|
28 | + private Authtokens $section; |
|
29 | 29 | |
30 | - protected function setUp(): void { |
|
31 | - parent::setUp(); |
|
30 | + protected function setUp(): void { |
|
31 | + parent::setUp(); |
|
32 | 32 | |
33 | - $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class); |
|
34 | - $this->session = $this->createMock(ISession::class); |
|
35 | - $this->userSession = $this->createMock(IUserSession::class); |
|
36 | - $this->initialState = $this->createMock(IInitialState::class); |
|
37 | - $this->uid = 'test123'; |
|
33 | + $this->authTokenProvider = $this->createMock(IAuthTokenProvider::class); |
|
34 | + $this->session = $this->createMock(ISession::class); |
|
35 | + $this->userSession = $this->createMock(IUserSession::class); |
|
36 | + $this->initialState = $this->createMock(IInitialState::class); |
|
37 | + $this->uid = 'test123'; |
|
38 | 38 | |
39 | - $this->section = new Authtokens( |
|
40 | - $this->authTokenProvider, |
|
41 | - $this->session, |
|
42 | - $this->userSession, |
|
43 | - $this->initialState, |
|
44 | - $this->uid |
|
45 | - ); |
|
46 | - } |
|
39 | + $this->section = new Authtokens( |
|
40 | + $this->authTokenProvider, |
|
41 | + $this->session, |
|
42 | + $this->userSession, |
|
43 | + $this->initialState, |
|
44 | + $this->uid |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - public function testGetForm(): void { |
|
49 | - $token1 = new PublicKeyToken(); |
|
50 | - $token1->setId(100); |
|
51 | - $token2 = new PublicKeyToken(); |
|
52 | - $token2->setId(200); |
|
53 | - $tokens = [ |
|
54 | - $token1, |
|
55 | - $token2, |
|
56 | - ]; |
|
57 | - $sessionToken = new PublicKeyToken(); |
|
58 | - $sessionToken->setId(100); |
|
48 | + public function testGetForm(): void { |
|
49 | + $token1 = new PublicKeyToken(); |
|
50 | + $token1->setId(100); |
|
51 | + $token2 = new PublicKeyToken(); |
|
52 | + $token2->setId(200); |
|
53 | + $tokens = [ |
|
54 | + $token1, |
|
55 | + $token2, |
|
56 | + ]; |
|
57 | + $sessionToken = new PublicKeyToken(); |
|
58 | + $sessionToken->setId(100); |
|
59 | 59 | |
60 | - $this->authTokenProvider->expects($this->once()) |
|
61 | - ->method('getTokenByUser') |
|
62 | - ->with($this->uid) |
|
63 | - ->willReturn($tokens); |
|
64 | - $this->session->expects($this->once()) |
|
65 | - ->method('getId') |
|
66 | - ->willReturn('session123'); |
|
67 | - $this->authTokenProvider->expects($this->once()) |
|
68 | - ->method('getToken') |
|
69 | - ->with('session123') |
|
70 | - ->willReturn($sessionToken); |
|
60 | + $this->authTokenProvider->expects($this->once()) |
|
61 | + ->method('getTokenByUser') |
|
62 | + ->with($this->uid) |
|
63 | + ->willReturn($tokens); |
|
64 | + $this->session->expects($this->once()) |
|
65 | + ->method('getId') |
|
66 | + ->willReturn('session123'); |
|
67 | + $this->authTokenProvider->expects($this->once()) |
|
68 | + ->method('getToken') |
|
69 | + ->with('session123') |
|
70 | + ->willReturn($sessionToken); |
|
71 | 71 | |
72 | - $calls = [ |
|
73 | - [ |
|
74 | - 'app_tokens', [ |
|
75 | - [ |
|
76 | - 'id' => 100, |
|
77 | - 'name' => null, |
|
78 | - 'lastActivity' => 0, |
|
79 | - 'type' => 0, |
|
80 | - 'canDelete' => false, |
|
81 | - 'current' => true, |
|
82 | - 'scope' => [IToken::SCOPE_FILESYSTEM => true], |
|
83 | - 'canRename' => false, |
|
84 | - ], |
|
85 | - [ |
|
86 | - 'id' => 200, |
|
87 | - 'name' => null, |
|
88 | - 'lastActivity' => 0, |
|
89 | - 'type' => 0, |
|
90 | - 'canDelete' => true, |
|
91 | - 'scope' => [IToken::SCOPE_FILESYSTEM => true], |
|
92 | - 'canRename' => true, |
|
93 | - ], |
|
94 | - ] |
|
95 | - ], |
|
96 | - ['can_create_app_token', true], |
|
97 | - ]; |
|
98 | - $this->initialState->expects($this->exactly(2)) |
|
99 | - ->method('provideInitialState') |
|
100 | - ->willReturnCallback(function () use (&$calls): void { |
|
101 | - $expected = array_shift($calls); |
|
102 | - $this->assertEquals($expected, func_get_args()); |
|
103 | - }); |
|
72 | + $calls = [ |
|
73 | + [ |
|
74 | + 'app_tokens', [ |
|
75 | + [ |
|
76 | + 'id' => 100, |
|
77 | + 'name' => null, |
|
78 | + 'lastActivity' => 0, |
|
79 | + 'type' => 0, |
|
80 | + 'canDelete' => false, |
|
81 | + 'current' => true, |
|
82 | + 'scope' => [IToken::SCOPE_FILESYSTEM => true], |
|
83 | + 'canRename' => false, |
|
84 | + ], |
|
85 | + [ |
|
86 | + 'id' => 200, |
|
87 | + 'name' => null, |
|
88 | + 'lastActivity' => 0, |
|
89 | + 'type' => 0, |
|
90 | + 'canDelete' => true, |
|
91 | + 'scope' => [IToken::SCOPE_FILESYSTEM => true], |
|
92 | + 'canRename' => true, |
|
93 | + ], |
|
94 | + ] |
|
95 | + ], |
|
96 | + ['can_create_app_token', true], |
|
97 | + ]; |
|
98 | + $this->initialState->expects($this->exactly(2)) |
|
99 | + ->method('provideInitialState') |
|
100 | + ->willReturnCallback(function () use (&$calls): void { |
|
101 | + $expected = array_shift($calls); |
|
102 | + $this->assertEquals($expected, func_get_args()); |
|
103 | + }); |
|
104 | 104 | |
105 | - $form = $this->section->getForm(); |
|
105 | + $form = $this->section->getForm(); |
|
106 | 106 | |
107 | - $expected = new TemplateResponse('settings', 'settings/personal/security/authtokens'); |
|
108 | - $this->assertEquals($expected, $form); |
|
109 | - } |
|
107 | + $expected = new TemplateResponse('settings', 'settings/personal/security/authtokens'); |
|
108 | + $this->assertEquals($expected, $form); |
|
109 | + } |
|
110 | 110 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | ]; |
98 | 98 | $this->initialState->expects($this->exactly(2)) |
99 | 99 | ->method('provideInitialState') |
100 | - ->willReturnCallback(function () use (&$calls): void { |
|
100 | + ->willReturnCallback(function() use (&$calls): void { |
|
101 | 101 | $expected = array_shift($calls); |
102 | 102 | $this->assertEquals($expected, func_get_args()); |
103 | 103 | }); |
@@ -17,97 +17,97 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class SecurityTest extends TestCase { |
20 | - private Manager $manager; |
|
21 | - private IUserManager $userManager; |
|
22 | - private MandatoryTwoFactor&MockObject $mandatoryTwoFactor; |
|
23 | - private IInitialState&MockObject $initialState; |
|
24 | - private Security $admin; |
|
20 | + private Manager $manager; |
|
21 | + private IUserManager $userManager; |
|
22 | + private MandatoryTwoFactor&MockObject $mandatoryTwoFactor; |
|
23 | + private IInitialState&MockObject $initialState; |
|
24 | + private Security $admin; |
|
25 | 25 | |
26 | - protected function setUp(): void { |
|
27 | - parent::setUp(); |
|
28 | - $this->manager = $this->createMock(Manager::class); |
|
29 | - $this->userManager = $this->createMock(IUserManager::class); |
|
30 | - $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class); |
|
31 | - $this->initialState = $this->createMock(IInitialState::class); |
|
26 | + protected function setUp(): void { |
|
27 | + parent::setUp(); |
|
28 | + $this->manager = $this->createMock(Manager::class); |
|
29 | + $this->userManager = $this->createMock(IUserManager::class); |
|
30 | + $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class); |
|
31 | + $this->initialState = $this->createMock(IInitialState::class); |
|
32 | 32 | |
33 | - $this->admin = new Security( |
|
34 | - $this->manager, |
|
35 | - $this->userManager, |
|
36 | - $this->mandatoryTwoFactor, |
|
37 | - $this->initialState, |
|
38 | - $this->createMock(IURLGenerator::class) |
|
39 | - ); |
|
40 | - } |
|
33 | + $this->admin = new Security( |
|
34 | + $this->manager, |
|
35 | + $this->userManager, |
|
36 | + $this->mandatoryTwoFactor, |
|
37 | + $this->initialState, |
|
38 | + $this->createMock(IURLGenerator::class) |
|
39 | + ); |
|
40 | + } |
|
41 | 41 | |
42 | - public static function encryptionSettingsProvider(): array { |
|
43 | - return [ |
|
44 | - [true], |
|
45 | - [false], |
|
46 | - ]; |
|
47 | - } |
|
42 | + public static function encryptionSettingsProvider(): array { |
|
43 | + return [ |
|
44 | + [true], |
|
45 | + [false], |
|
46 | + ]; |
|
47 | + } |
|
48 | 48 | |
49 | - #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')] |
|
50 | - public function testGetFormWithOnlyOneBackend(bool $enabled): void { |
|
51 | - $this->manager |
|
52 | - ->expects($this->once()) |
|
53 | - ->method('isEnabled') |
|
54 | - ->willReturn($enabled); |
|
55 | - $this->manager |
|
56 | - ->expects($this->once()) |
|
57 | - ->method('isReady') |
|
58 | - ->willReturn($enabled); |
|
59 | - $this->manager |
|
60 | - ->expects($this->once()) |
|
61 | - ->method('getEncryptionModules') |
|
62 | - ->willReturn([]); |
|
63 | - $this->userManager |
|
64 | - ->expects($this->once()) |
|
65 | - ->method('getBackends') |
|
66 | - ->willReturn(['entry']); |
|
67 | - $expected = new TemplateResponse( |
|
68 | - 'settings', |
|
69 | - 'settings/admin/security', |
|
70 | - [], |
|
71 | - '' |
|
72 | - ); |
|
73 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
74 | - } |
|
49 | + #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')] |
|
50 | + public function testGetFormWithOnlyOneBackend(bool $enabled): void { |
|
51 | + $this->manager |
|
52 | + ->expects($this->once()) |
|
53 | + ->method('isEnabled') |
|
54 | + ->willReturn($enabled); |
|
55 | + $this->manager |
|
56 | + ->expects($this->once()) |
|
57 | + ->method('isReady') |
|
58 | + ->willReturn($enabled); |
|
59 | + $this->manager |
|
60 | + ->expects($this->once()) |
|
61 | + ->method('getEncryptionModules') |
|
62 | + ->willReturn([]); |
|
63 | + $this->userManager |
|
64 | + ->expects($this->once()) |
|
65 | + ->method('getBackends') |
|
66 | + ->willReturn(['entry']); |
|
67 | + $expected = new TemplateResponse( |
|
68 | + 'settings', |
|
69 | + 'settings/admin/security', |
|
70 | + [], |
|
71 | + '' |
|
72 | + ); |
|
73 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param bool $enabled |
|
78 | - */ |
|
79 | - #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')] |
|
80 | - public function testGetFormWithMultipleBackends($enabled): void { |
|
81 | - $this->manager |
|
82 | - ->expects($this->once()) |
|
83 | - ->method('isEnabled') |
|
84 | - ->willReturn($enabled); |
|
85 | - $this->manager |
|
86 | - ->expects($this->once()) |
|
87 | - ->method('isReady') |
|
88 | - ->willReturn($enabled); |
|
89 | - $this->manager |
|
90 | - ->expects($this->once()) |
|
91 | - ->method('getEncryptionModules') |
|
92 | - ->willReturn([]); |
|
93 | - $this->userManager |
|
94 | - ->expects($this->once()) |
|
95 | - ->method('getBackends') |
|
96 | - ->willReturn(['entry', 'entry']); |
|
97 | - $expected = new TemplateResponse( |
|
98 | - 'settings', |
|
99 | - 'settings/admin/security', |
|
100 | - [ ], |
|
101 | - '' |
|
102 | - ); |
|
103 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
104 | - } |
|
76 | + /** |
|
77 | + * @param bool $enabled |
|
78 | + */ |
|
79 | + #[\PHPUnit\Framework\Attributes\DataProvider('encryptionSettingsProvider')] |
|
80 | + public function testGetFormWithMultipleBackends($enabled): void { |
|
81 | + $this->manager |
|
82 | + ->expects($this->once()) |
|
83 | + ->method('isEnabled') |
|
84 | + ->willReturn($enabled); |
|
85 | + $this->manager |
|
86 | + ->expects($this->once()) |
|
87 | + ->method('isReady') |
|
88 | + ->willReturn($enabled); |
|
89 | + $this->manager |
|
90 | + ->expects($this->once()) |
|
91 | + ->method('getEncryptionModules') |
|
92 | + ->willReturn([]); |
|
93 | + $this->userManager |
|
94 | + ->expects($this->once()) |
|
95 | + ->method('getBackends') |
|
96 | + ->willReturn(['entry', 'entry']); |
|
97 | + $expected = new TemplateResponse( |
|
98 | + 'settings', |
|
99 | + 'settings/admin/security', |
|
100 | + [ ], |
|
101 | + '' |
|
102 | + ); |
|
103 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
104 | + } |
|
105 | 105 | |
106 | - public function testGetSection(): void { |
|
107 | - $this->assertSame('security', $this->admin->getSection()); |
|
108 | - } |
|
106 | + public function testGetSection(): void { |
|
107 | + $this->assertSame('security', $this->admin->getSection()); |
|
108 | + } |
|
109 | 109 | |
110 | - public function testGetPriority(): void { |
|
111 | - $this->assertSame(10, $this->admin->getPriority()); |
|
112 | - } |
|
110 | + public function testGetPriority(): void { |
|
111 | + $this->assertSame(10, $this->admin->getPriority()); |
|
112 | + } |
|
113 | 113 | } |
@@ -16,80 +16,80 @@ |
||
16 | 16 | |
17 | 17 | class MailTest extends TestCase { |
18 | 18 | |
19 | - private Mail $admin; |
|
20 | - private IConfig&MockObject $config; |
|
21 | - private IL10N&MockObject $l10n; |
|
19 | + private Mail $admin; |
|
20 | + private IConfig&MockObject $config; |
|
21 | + private IL10N&MockObject $l10n; |
|
22 | 22 | |
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
25 | - $this->config = $this->createMock(IConfig::class); |
|
26 | - $this->l10n = $this->createMock(IL10N::class); |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | + $this->config = $this->createMock(IConfig::class); |
|
26 | + $this->l10n = $this->createMock(IL10N::class); |
|
27 | 27 | |
28 | - $this->admin = new Mail( |
|
29 | - $this->config, |
|
30 | - $this->l10n |
|
31 | - ); |
|
32 | - } |
|
28 | + $this->admin = new Mail( |
|
29 | + $this->config, |
|
30 | + $this->l10n |
|
31 | + ); |
|
32 | + } |
|
33 | 33 | |
34 | - public static function dataGetForm(): array { |
|
35 | - return [ |
|
36 | - [true], |
|
37 | - [false], |
|
38 | - ]; |
|
39 | - } |
|
34 | + public static function dataGetForm(): array { |
|
35 | + return [ |
|
36 | + [true], |
|
37 | + [false], |
|
38 | + ]; |
|
39 | + } |
|
40 | 40 | |
41 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForm')] |
|
42 | - public function testGetForm(bool $sendmail) { |
|
43 | - $finder = $this->createMock(IBinaryFinder::class); |
|
44 | - $finder->expects(self::once()) |
|
45 | - ->method('findBinaryPath') |
|
46 | - ->with('sendmail') |
|
47 | - ->willReturn($sendmail ? '/usr/bin/sendmail': false); |
|
48 | - $this->overwriteService(IBinaryFinder::class, $finder); |
|
41 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForm')] |
|
42 | + public function testGetForm(bool $sendmail) { |
|
43 | + $finder = $this->createMock(IBinaryFinder::class); |
|
44 | + $finder->expects(self::once()) |
|
45 | + ->method('findBinaryPath') |
|
46 | + ->with('sendmail') |
|
47 | + ->willReturn($sendmail ? '/usr/bin/sendmail': false); |
|
48 | + $this->overwriteService(IBinaryFinder::class, $finder); |
|
49 | 49 | |
50 | - $this->config |
|
51 | - ->expects($this->any()) |
|
52 | - ->method('getSystemValue') |
|
53 | - ->willReturnMap([ |
|
54 | - ['mail_domain', '', 'mx.nextcloud.com'], |
|
55 | - ['mail_from_address', '', '[email protected]'], |
|
56 | - ['mail_smtpmode', '', 'smtp'], |
|
57 | - ['mail_smtpsecure', '', true], |
|
58 | - ['mail_smtphost', '', 'smtp.nextcloud.com'], |
|
59 | - ['mail_smtpport', '', 25], |
|
60 | - ['mail_smtpauth', false, true], |
|
61 | - ['mail_smtpname', '', 'smtp.sender.com'], |
|
62 | - ['mail_smtppassword', '', 'mypassword'], |
|
63 | - ['mail_sendmailmode', 'smtp', 'smtp'], |
|
64 | - ]); |
|
50 | + $this->config |
|
51 | + ->expects($this->any()) |
|
52 | + ->method('getSystemValue') |
|
53 | + ->willReturnMap([ |
|
54 | + ['mail_domain', '', 'mx.nextcloud.com'], |
|
55 | + ['mail_from_address', '', '[email protected]'], |
|
56 | + ['mail_smtpmode', '', 'smtp'], |
|
57 | + ['mail_smtpsecure', '', true], |
|
58 | + ['mail_smtphost', '', 'smtp.nextcloud.com'], |
|
59 | + ['mail_smtpport', '', 25], |
|
60 | + ['mail_smtpauth', false, true], |
|
61 | + ['mail_smtpname', '', 'smtp.sender.com'], |
|
62 | + ['mail_smtppassword', '', 'mypassword'], |
|
63 | + ['mail_sendmailmode', 'smtp', 'smtp'], |
|
64 | + ]); |
|
65 | 65 | |
66 | - $expected = new TemplateResponse( |
|
67 | - 'settings', |
|
68 | - 'settings/admin/additional-mail', |
|
69 | - [ |
|
70 | - 'sendmail_is_available' => $sendmail, |
|
71 | - 'mail_domain' => 'mx.nextcloud.com', |
|
72 | - 'mail_from_address' => '[email protected]', |
|
73 | - 'mail_smtpmode' => 'smtp', |
|
74 | - 'mail_smtpsecure' => true, |
|
75 | - 'mail_smtphost' => 'smtp.nextcloud.com', |
|
76 | - 'mail_smtpport' => 25, |
|
77 | - 'mail_smtpauth' => true, |
|
78 | - 'mail_smtpname' => 'smtp.sender.com', |
|
79 | - 'mail_smtppassword' => '********', |
|
80 | - 'mail_sendmailmode' => 'smtp', |
|
81 | - ], |
|
82 | - '' |
|
83 | - ); |
|
66 | + $expected = new TemplateResponse( |
|
67 | + 'settings', |
|
68 | + 'settings/admin/additional-mail', |
|
69 | + [ |
|
70 | + 'sendmail_is_available' => $sendmail, |
|
71 | + 'mail_domain' => 'mx.nextcloud.com', |
|
72 | + 'mail_from_address' => '[email protected]', |
|
73 | + 'mail_smtpmode' => 'smtp', |
|
74 | + 'mail_smtpsecure' => true, |
|
75 | + 'mail_smtphost' => 'smtp.nextcloud.com', |
|
76 | + 'mail_smtpport' => 25, |
|
77 | + 'mail_smtpauth' => true, |
|
78 | + 'mail_smtpname' => 'smtp.sender.com', |
|
79 | + 'mail_smtppassword' => '********', |
|
80 | + 'mail_sendmailmode' => 'smtp', |
|
81 | + ], |
|
82 | + '' |
|
83 | + ); |
|
84 | 84 | |
85 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
86 | - } |
|
85 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
86 | + } |
|
87 | 87 | |
88 | - public function testGetSection(): void { |
|
89 | - $this->assertSame('server', $this->admin->getSection()); |
|
90 | - } |
|
88 | + public function testGetSection(): void { |
|
89 | + $this->assertSame('server', $this->admin->getSection()); |
|
90 | + } |
|
91 | 91 | |
92 | - public function testGetPriority(): void { |
|
93 | - $this->assertSame(10, $this->admin->getPriority()); |
|
94 | - } |
|
92 | + public function testGetPriority(): void { |
|
93 | + $this->assertSame(10, $this->admin->getPriority()); |
|
94 | + } |
|
95 | 95 | } |
@@ -17,93 +17,93 @@ |
||
17 | 17 | use Test\TestCase; |
18 | 18 | |
19 | 19 | class SecurityProviderTest extends TestCase { |
20 | - private IFactory&MockObject $l10nFactory; |
|
21 | - private IURLGenerator&MockObject $urlGenerator; |
|
22 | - private IManager&MockObject $activityManager; |
|
23 | - private SecurityProvider $provider; |
|
20 | + private IFactory&MockObject $l10nFactory; |
|
21 | + private IURLGenerator&MockObject $urlGenerator; |
|
22 | + private IManager&MockObject $activityManager; |
|
23 | + private SecurityProvider $provider; |
|
24 | 24 | |
25 | - protected function setUp(): void { |
|
26 | - parent::setUp(); |
|
25 | + protected function setUp(): void { |
|
26 | + parent::setUp(); |
|
27 | 27 | |
28 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
29 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
30 | - $this->activityManager = $this->createMock(IManager::class); |
|
28 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
29 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
30 | + $this->activityManager = $this->createMock(IManager::class); |
|
31 | 31 | |
32 | - $this->provider = new SecurityProvider($this->l10nFactory, $this->urlGenerator, $this->activityManager); |
|
33 | - } |
|
32 | + $this->provider = new SecurityProvider($this->l10nFactory, $this->urlGenerator, $this->activityManager); |
|
33 | + } |
|
34 | 34 | |
35 | - public function testParseUnrelated(): void { |
|
36 | - $lang = 'ru'; |
|
37 | - $event = $this->createMock(IEvent::class); |
|
38 | - $event->expects($this->once()) |
|
39 | - ->method('getType') |
|
40 | - ->willReturn('comments'); |
|
41 | - $this->expectException(UnknownActivityException::class); |
|
35 | + public function testParseUnrelated(): void { |
|
36 | + $lang = 'ru'; |
|
37 | + $event = $this->createMock(IEvent::class); |
|
38 | + $event->expects($this->once()) |
|
39 | + ->method('getType') |
|
40 | + ->willReturn('comments'); |
|
41 | + $this->expectException(UnknownActivityException::class); |
|
42 | 42 | |
43 | - $this->provider->parse($lang, $event); |
|
44 | - } |
|
43 | + $this->provider->parse($lang, $event); |
|
44 | + } |
|
45 | 45 | |
46 | - public static function subjectData(): array { |
|
47 | - return [ |
|
48 | - ['twofactor_success'], |
|
49 | - ['twofactor_failed'], |
|
50 | - ]; |
|
51 | - } |
|
46 | + public static function subjectData(): array { |
|
47 | + return [ |
|
48 | + ['twofactor_success'], |
|
49 | + ['twofactor_failed'], |
|
50 | + ]; |
|
51 | + } |
|
52 | 52 | |
53 | - #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')] |
|
54 | - public function testParse(string $subject): void { |
|
55 | - $lang = 'ru'; |
|
56 | - $event = $this->createMock(IEvent::class); |
|
57 | - $l = $this->createMock(IL10N::class); |
|
53 | + #[\PHPUnit\Framework\Attributes\DataProvider('subjectData')] |
|
54 | + public function testParse(string $subject): void { |
|
55 | + $lang = 'ru'; |
|
56 | + $event = $this->createMock(IEvent::class); |
|
57 | + $l = $this->createMock(IL10N::class); |
|
58 | 58 | |
59 | - $event->expects($this->once()) |
|
60 | - ->method('getType') |
|
61 | - ->willReturn('security'); |
|
62 | - $this->l10nFactory->expects($this->once()) |
|
63 | - ->method('get') |
|
64 | - ->with('settings', $lang) |
|
65 | - ->willReturn($l); |
|
66 | - $this->urlGenerator->expects($this->once()) |
|
67 | - ->method('imagePath') |
|
68 | - ->with('core', 'actions/password.svg') |
|
69 | - ->willReturn('path/to/image'); |
|
70 | - $this->urlGenerator->expects($this->once()) |
|
71 | - ->method('getAbsoluteURL') |
|
72 | - ->with('path/to/image') |
|
73 | - ->willReturn('absolute/path/to/image'); |
|
74 | - $event->expects($this->once()) |
|
75 | - ->method('setIcon') |
|
76 | - ->with('absolute/path/to/image'); |
|
77 | - $event->expects($this->once()) |
|
78 | - ->method('getSubject') |
|
79 | - ->willReturn($subject); |
|
80 | - $event->method('getSubjectParameters') |
|
81 | - ->willReturn([ |
|
82 | - 'provider' => 'myProvider', |
|
83 | - ]); |
|
84 | - $event->expects($this->once()) |
|
85 | - ->method('setParsedSubject'); |
|
59 | + $event->expects($this->once()) |
|
60 | + ->method('getType') |
|
61 | + ->willReturn('security'); |
|
62 | + $this->l10nFactory->expects($this->once()) |
|
63 | + ->method('get') |
|
64 | + ->with('settings', $lang) |
|
65 | + ->willReturn($l); |
|
66 | + $this->urlGenerator->expects($this->once()) |
|
67 | + ->method('imagePath') |
|
68 | + ->with('core', 'actions/password.svg') |
|
69 | + ->willReturn('path/to/image'); |
|
70 | + $this->urlGenerator->expects($this->once()) |
|
71 | + ->method('getAbsoluteURL') |
|
72 | + ->with('path/to/image') |
|
73 | + ->willReturn('absolute/path/to/image'); |
|
74 | + $event->expects($this->once()) |
|
75 | + ->method('setIcon') |
|
76 | + ->with('absolute/path/to/image'); |
|
77 | + $event->expects($this->once()) |
|
78 | + ->method('getSubject') |
|
79 | + ->willReturn($subject); |
|
80 | + $event->method('getSubjectParameters') |
|
81 | + ->willReturn([ |
|
82 | + 'provider' => 'myProvider', |
|
83 | + ]); |
|
84 | + $event->expects($this->once()) |
|
85 | + ->method('setParsedSubject'); |
|
86 | 86 | |
87 | - $this->provider->parse($lang, $event); |
|
88 | - } |
|
87 | + $this->provider->parse($lang, $event); |
|
88 | + } |
|
89 | 89 | |
90 | - public function testParseInvalidSubject(): void { |
|
91 | - $lang = 'ru'; |
|
92 | - $l = $this->createMock(IL10N::class); |
|
93 | - $event = $this->createMock(IEvent::class); |
|
90 | + public function testParseInvalidSubject(): void { |
|
91 | + $lang = 'ru'; |
|
92 | + $l = $this->createMock(IL10N::class); |
|
93 | + $event = $this->createMock(IEvent::class); |
|
94 | 94 | |
95 | - $event->expects($this->once()) |
|
96 | - ->method('getType') |
|
97 | - ->willReturn('security'); |
|
98 | - $this->l10nFactory->expects($this->once()) |
|
99 | - ->method('get') |
|
100 | - ->with('settings', $lang) |
|
101 | - ->willReturn($l); |
|
102 | - $event->expects($this->once()) |
|
103 | - ->method('getSubject') |
|
104 | - ->willReturn('unrelated'); |
|
95 | + $event->expects($this->once()) |
|
96 | + ->method('getType') |
|
97 | + ->willReturn('security'); |
|
98 | + $this->l10nFactory->expects($this->once()) |
|
99 | + ->method('get') |
|
100 | + ->with('settings', $lang) |
|
101 | + ->willReturn($l); |
|
102 | + $event->expects($this->once()) |
|
103 | + ->method('getSubject') |
|
104 | + ->willReturn('unrelated'); |
|
105 | 105 | |
106 | - $this->expectException(UnknownActivityException::class); |
|
107 | - $this->provider->parse($lang, $event); |
|
108 | - } |
|
106 | + $this->expectException(UnknownActivityException::class); |
|
107 | + $this->provider->parse($lang, $event); |
|
108 | + } |
|
109 | 109 | } |
@@ -14,32 +14,32 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class PHPMongoQueryTest extends TestCase { |
17 | - public static function dataExecuteQuery(): array { |
|
18 | - $event = [ |
|
19 | - 'event' => [ |
|
20 | - 'class' => NodeWrittenEvent::class, |
|
21 | - 'node' => [ |
|
22 | - 'id' => 23, |
|
23 | - 'path' => '/tmp/file.txt', |
|
24 | - ], |
|
25 | - ], |
|
26 | - 'user' => [ |
|
27 | - 'uid' => 'bob', |
|
28 | - ], |
|
29 | - ]; |
|
30 | - return [ |
|
31 | - [[], [], true], |
|
32 | - [[], $event, true], |
|
33 | - [['event.class' => NodeWrittenEvent::class], $event, true], |
|
34 | - [['event.class' => NodeWrittenEvent::class, 'user.uid' => 'bob'], $event, true], |
|
35 | - [['event.node.path' => '/.txt$/'], $event, true], |
|
36 | - [['event.node.id' => ['$gte' => 22]], $event, true], |
|
37 | - [['event.class' => 'SomethingElse'], $event, false], |
|
38 | - ]; |
|
39 | - } |
|
17 | + public static function dataExecuteQuery(): array { |
|
18 | + $event = [ |
|
19 | + 'event' => [ |
|
20 | + 'class' => NodeWrittenEvent::class, |
|
21 | + 'node' => [ |
|
22 | + 'id' => 23, |
|
23 | + 'path' => '/tmp/file.txt', |
|
24 | + ], |
|
25 | + ], |
|
26 | + 'user' => [ |
|
27 | + 'uid' => 'bob', |
|
28 | + ], |
|
29 | + ]; |
|
30 | + return [ |
|
31 | + [[], [], true], |
|
32 | + [[], $event, true], |
|
33 | + [['event.class' => NodeWrittenEvent::class], $event, true], |
|
34 | + [['event.class' => NodeWrittenEvent::class, 'user.uid' => 'bob'], $event, true], |
|
35 | + [['event.node.path' => '/.txt$/'], $event, true], |
|
36 | + [['event.node.id' => ['$gte' => 22]], $event, true], |
|
37 | + [['event.class' => 'SomethingElse'], $event, false], |
|
38 | + ]; |
|
39 | + } |
|
40 | 40 | |
41 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteQuery')] |
|
42 | - public function testExecuteQuery(array $query, array $document, bool $matches): void { |
|
43 | - $this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document)); |
|
44 | - } |
|
41 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteQuery')] |
|
42 | + public function testExecuteQuery(array $query, array $document, bool $matches): void { |
|
43 | + $this->assertEquals($matches, PHPMongoQuery::executeQuery($query, $document)); |
|
44 | + } |
|
45 | 45 | } |
@@ -22,139 +22,139 @@ |
||
22 | 22 | use Test\TestCase; |
23 | 23 | |
24 | 24 | class APIControllerTest extends TestCase { |
25 | - private IRequest&MockObject $request; |
|
26 | - private IConfig&MockObject $config; |
|
27 | - private IAppManager&MockObject $appManager; |
|
28 | - private AppFetcher&MockObject $appFetcher; |
|
29 | - private IFactory&MockObject $l10nFactory; |
|
30 | - private IUserSession&MockObject $userSession; |
|
31 | - private Manager&MockObject $manager; |
|
25 | + private IRequest&MockObject $request; |
|
26 | + private IConfig&MockObject $config; |
|
27 | + private IAppManager&MockObject $appManager; |
|
28 | + private AppFetcher&MockObject $appFetcher; |
|
29 | + private IFactory&MockObject $l10nFactory; |
|
30 | + private IUserSession&MockObject $userSession; |
|
31 | + private Manager&MockObject $manager; |
|
32 | 32 | |
33 | - private APIController $apiController; |
|
33 | + private APIController $apiController; |
|
34 | 34 | |
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | 37 | |
38 | - $this->request = $this->createMock(IRequest::class); |
|
39 | - $this->config = $this->createMock(IConfig::class); |
|
40 | - $this->appManager = $this->createMock(IAppManager::class); |
|
41 | - $this->appFetcher = $this->createMock(AppFetcher::class); |
|
42 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
43 | - $this->userSession = $this->createMock(IUserSession::class); |
|
44 | - $this->manager = $this->createMock(Manager::class); |
|
38 | + $this->request = $this->createMock(IRequest::class); |
|
39 | + $this->config = $this->createMock(IConfig::class); |
|
40 | + $this->appManager = $this->createMock(IAppManager::class); |
|
41 | + $this->appFetcher = $this->createMock(AppFetcher::class); |
|
42 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
43 | + $this->userSession = $this->createMock(IUserSession::class); |
|
44 | + $this->manager = $this->createMock(Manager::class); |
|
45 | 45 | |
46 | - $this->apiController = new APIController( |
|
47 | - Application::APP_NAME, |
|
48 | - $this->request, |
|
49 | - $this->config, |
|
50 | - $this->appManager, |
|
51 | - $this->appFetcher, |
|
52 | - $this->l10nFactory, |
|
53 | - $this->userSession, |
|
54 | - $this->manager, |
|
55 | - ); |
|
56 | - } |
|
46 | + $this->apiController = new APIController( |
|
47 | + Application::APP_NAME, |
|
48 | + $this->request, |
|
49 | + $this->config, |
|
50 | + $this->appManager, |
|
51 | + $this->appFetcher, |
|
52 | + $this->l10nFactory, |
|
53 | + $this->userSession, |
|
54 | + $this->manager, |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppChangelog')] |
|
59 | - public function testGetAppChangelogEntry( |
|
60 | - array $params, |
|
61 | - bool $hasChanges, |
|
62 | - array $appInfo, |
|
63 | - array $expected, |
|
64 | - ): void { |
|
65 | - $this->appManager->method('getAppInfo') |
|
66 | - ->with('the-app') |
|
67 | - ->willReturn($appInfo); |
|
68 | - $this->appManager->method('getAppVersion') |
|
69 | - ->with('the-app') |
|
70 | - ->willReturn($appInfo['version']); |
|
71 | - $this->manager->method('getChangelog') |
|
72 | - ->with('the-app', self::anything()) |
|
73 | - ->willReturnCallback(fn ($app, $version) => $hasChanges ? "$app v$version" : null); |
|
58 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppChangelog')] |
|
59 | + public function testGetAppChangelogEntry( |
|
60 | + array $params, |
|
61 | + bool $hasChanges, |
|
62 | + array $appInfo, |
|
63 | + array $expected, |
|
64 | + ): void { |
|
65 | + $this->appManager->method('getAppInfo') |
|
66 | + ->with('the-app') |
|
67 | + ->willReturn($appInfo); |
|
68 | + $this->appManager->method('getAppVersion') |
|
69 | + ->with('the-app') |
|
70 | + ->willReturn($appInfo['version']); |
|
71 | + $this->manager->method('getChangelog') |
|
72 | + ->with('the-app', self::anything()) |
|
73 | + ->willReturnCallback(fn ($app, $version) => $hasChanges ? "$app v$version" : null); |
|
74 | 74 | |
75 | - $result = $this->apiController->getAppChangelogEntry(...$params); |
|
76 | - $this->assertEquals($result->getStatus(), $expected['status']); |
|
77 | - $this->assertEquals($result->getData(), $expected['data']); |
|
78 | - } |
|
75 | + $result = $this->apiController->getAppChangelogEntry(...$params); |
|
76 | + $this->assertEquals($result->getStatus(), $expected['status']); |
|
77 | + $this->assertEquals($result->getData(), $expected['data']); |
|
78 | + } |
|
79 | 79 | |
80 | - public static function dataGetAppChangelog(): array { |
|
81 | - return [ |
|
82 | - 'no changes found' => [ |
|
83 | - ['the-app', null], |
|
84 | - false, |
|
85 | - [ |
|
86 | - 'name' => 'Localized name', |
|
87 | - 'version' => '1.0.0', |
|
88 | - ], |
|
89 | - [ |
|
90 | - 'status' => Http::STATUS_NOT_FOUND, |
|
91 | - 'data' => [], |
|
92 | - ] |
|
93 | - ], |
|
94 | - 'changes with version parameter' => [ |
|
95 | - ['the-app', '1.0.0'], |
|
96 | - true, |
|
97 | - [ |
|
98 | - 'name' => 'Localized name', |
|
99 | - 'version' => '1.2.0', // installed version |
|
100 | - ], |
|
101 | - [ |
|
102 | - 'status' => Http::STATUS_OK, |
|
103 | - 'data' => [ |
|
104 | - 'appName' => 'Localized name', |
|
105 | - 'content' => 'the-app v1.0.0', |
|
106 | - 'version' => '1.0.0', |
|
107 | - ], |
|
108 | - ] |
|
109 | - ], |
|
110 | - 'changes without version parameter' => [ |
|
111 | - ['the-app', null], |
|
112 | - true, |
|
113 | - [ |
|
114 | - 'name' => 'Localized name', |
|
115 | - 'version' => '1.2.0', |
|
116 | - ], |
|
117 | - [ |
|
118 | - 'status' => Http::STATUS_OK, |
|
119 | - 'data' => [ |
|
120 | - 'appName' => 'Localized name', |
|
121 | - 'content' => 'the-app v1.2.0', |
|
122 | - 'version' => '1.2.0', |
|
123 | - ], |
|
124 | - ] |
|
125 | - ], |
|
126 | - 'changes of pre-release version' => [ |
|
127 | - ['the-app', null], |
|
128 | - true, |
|
129 | - [ |
|
130 | - 'name' => 'Localized name', |
|
131 | - 'version' => '1.2.0-alpha.1', |
|
132 | - ], |
|
133 | - [ |
|
134 | - 'status' => Http::STATUS_OK, |
|
135 | - 'data' => [ |
|
136 | - 'appName' => 'Localized name', |
|
137 | - 'content' => 'the-app v1.2.0', |
|
138 | - 'version' => '1.2.0-alpha.1', |
|
139 | - ], |
|
140 | - ] |
|
141 | - ], |
|
142 | - 'changes of pre-release version as parameter' => [ |
|
143 | - ['the-app', '1.2.0-alpha.2'], |
|
144 | - true, |
|
145 | - [ |
|
146 | - 'name' => 'Localized name', |
|
147 | - 'version' => '1.2.0-beta.3', |
|
148 | - ], |
|
149 | - [ |
|
150 | - 'status' => Http::STATUS_OK, |
|
151 | - 'data' => [ |
|
152 | - 'appName' => 'Localized name', |
|
153 | - 'content' => 'the-app v1.2.0', |
|
154 | - 'version' => '1.2.0-alpha.2', |
|
155 | - ], |
|
156 | - ] |
|
157 | - ], |
|
158 | - ]; |
|
159 | - } |
|
80 | + public static function dataGetAppChangelog(): array { |
|
81 | + return [ |
|
82 | + 'no changes found' => [ |
|
83 | + ['the-app', null], |
|
84 | + false, |
|
85 | + [ |
|
86 | + 'name' => 'Localized name', |
|
87 | + 'version' => '1.0.0', |
|
88 | + ], |
|
89 | + [ |
|
90 | + 'status' => Http::STATUS_NOT_FOUND, |
|
91 | + 'data' => [], |
|
92 | + ] |
|
93 | + ], |
|
94 | + 'changes with version parameter' => [ |
|
95 | + ['the-app', '1.0.0'], |
|
96 | + true, |
|
97 | + [ |
|
98 | + 'name' => 'Localized name', |
|
99 | + 'version' => '1.2.0', // installed version |
|
100 | + ], |
|
101 | + [ |
|
102 | + 'status' => Http::STATUS_OK, |
|
103 | + 'data' => [ |
|
104 | + 'appName' => 'Localized name', |
|
105 | + 'content' => 'the-app v1.0.0', |
|
106 | + 'version' => '1.0.0', |
|
107 | + ], |
|
108 | + ] |
|
109 | + ], |
|
110 | + 'changes without version parameter' => [ |
|
111 | + ['the-app', null], |
|
112 | + true, |
|
113 | + [ |
|
114 | + 'name' => 'Localized name', |
|
115 | + 'version' => '1.2.0', |
|
116 | + ], |
|
117 | + [ |
|
118 | + 'status' => Http::STATUS_OK, |
|
119 | + 'data' => [ |
|
120 | + 'appName' => 'Localized name', |
|
121 | + 'content' => 'the-app v1.2.0', |
|
122 | + 'version' => '1.2.0', |
|
123 | + ], |
|
124 | + ] |
|
125 | + ], |
|
126 | + 'changes of pre-release version' => [ |
|
127 | + ['the-app', null], |
|
128 | + true, |
|
129 | + [ |
|
130 | + 'name' => 'Localized name', |
|
131 | + 'version' => '1.2.0-alpha.1', |
|
132 | + ], |
|
133 | + [ |
|
134 | + 'status' => Http::STATUS_OK, |
|
135 | + 'data' => [ |
|
136 | + 'appName' => 'Localized name', |
|
137 | + 'content' => 'the-app v1.2.0', |
|
138 | + 'version' => '1.2.0-alpha.1', |
|
139 | + ], |
|
140 | + ] |
|
141 | + ], |
|
142 | + 'changes of pre-release version as parameter' => [ |
|
143 | + ['the-app', '1.2.0-alpha.2'], |
|
144 | + true, |
|
145 | + [ |
|
146 | + 'name' => 'Localized name', |
|
147 | + 'version' => '1.2.0-beta.3', |
|
148 | + ], |
|
149 | + [ |
|
150 | + 'status' => Http::STATUS_OK, |
|
151 | + 'data' => [ |
|
152 | + 'appName' => 'Localized name', |
|
153 | + 'content' => 'the-app v1.2.0', |
|
154 | + 'version' => '1.2.0-alpha.2', |
|
155 | + ], |
|
156 | + ] |
|
157 | + ], |
|
158 | + ]; |
|
159 | + } |
|
160 | 160 | } |
@@ -29,439 +29,439 @@ |
||
29 | 29 | use Test\TestCase; |
30 | 30 | |
31 | 31 | class AdminTest extends TestCase { |
32 | - private IFactory&MockObject $l10nFactory; |
|
33 | - private IConfig&MockObject $config; |
|
34 | - private IAppConfig&MockObject $appConfig; |
|
35 | - private UpdateChecker&MockObject $updateChecker; |
|
36 | - private IGroupManager&MockObject $groupManager; |
|
37 | - private IDateTimeFormatter&MockObject $dateTimeFormatter; |
|
38 | - private IRegistry&MockObject $subscriptionRegistry; |
|
39 | - private IUserManager&MockObject $userManager; |
|
40 | - private LoggerInterface&MockObject $logger; |
|
41 | - private IInitialState&MockObject $initialState; |
|
42 | - private ServerVersion&MockObject $serverVersion; |
|
43 | - private Admin $admin; |
|
44 | - |
|
45 | - protected function setUp(): void { |
|
46 | - parent::setUp(); |
|
47 | - |
|
48 | - $this->config = $this->createMock(IConfig::class); |
|
49 | - $this->appConfig = $this->createMock(IAppConfig::class); |
|
50 | - $this->updateChecker = $this->createMock(UpdateChecker::class); |
|
51 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
52 | - $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); |
|
53 | - $this->l10nFactory = $this->createMock(IFactory::class); |
|
54 | - $this->subscriptionRegistry = $this->createMock(IRegistry::class); |
|
55 | - $this->userManager = $this->createMock(IUserManager::class); |
|
56 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
57 | - $this->initialState = $this->createMock(IInitialState::class); |
|
58 | - $this->serverVersion = $this->createMock(ServerVersion::class); |
|
59 | - |
|
60 | - $this->admin = new Admin( |
|
61 | - $this->config, |
|
62 | - $this->appConfig, |
|
63 | - $this->updateChecker, |
|
64 | - $this->groupManager, |
|
65 | - $this->dateTimeFormatter, |
|
66 | - $this->l10nFactory, |
|
67 | - $this->subscriptionRegistry, |
|
68 | - $this->userManager, |
|
69 | - $this->logger, |
|
70 | - $this->initialState, |
|
71 | - $this->serverVersion, |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - public function testGetFormWithUpdate(): void { |
|
76 | - $this->serverVersion->expects(self::atLeastOnce()) |
|
77 | - ->method('getChannel') |
|
78 | - ->willReturn('daily'); |
|
79 | - $this->userManager |
|
80 | - ->expects($this->once()) |
|
81 | - ->method('countUsersTotal') |
|
82 | - ->willReturn(5); |
|
83 | - $channels = [ |
|
84 | - 'daily', |
|
85 | - 'beta', |
|
86 | - 'stable', |
|
87 | - 'production', |
|
88 | - ]; |
|
89 | - $this->appConfig |
|
90 | - ->expects($this->once()) |
|
91 | - ->method('getValueInt') |
|
92 | - ->with('core', 'lastupdatedat', 0) |
|
93 | - ->willReturn(12345); |
|
94 | - $this->appConfig |
|
95 | - ->expects($this->once()) |
|
96 | - ->method('getValueArray') |
|
97 | - ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
98 | - ->willReturn(['admin']); |
|
99 | - $this->config |
|
100 | - ->method('getSystemValue') |
|
101 | - ->willReturnMap([ |
|
102 | - ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server/'], |
|
103 | - ['upgrade.disable-web', false, false], |
|
104 | - ]); |
|
105 | - $this->config |
|
106 | - ->expects(self::any()) |
|
107 | - ->method('getSystemValueBool') |
|
108 | - ->with('updatechecker', true) |
|
109 | - ->willReturn(true); |
|
110 | - $this->dateTimeFormatter |
|
111 | - ->expects($this->once()) |
|
112 | - ->method('formatDateTime') |
|
113 | - ->with(12345) |
|
114 | - ->willReturn('LastCheckedReturnValue'); |
|
115 | - $this->updateChecker |
|
116 | - ->expects($this->once()) |
|
117 | - ->method('getUpdateState') |
|
118 | - ->willReturn([ |
|
119 | - 'updateAvailable' => true, |
|
120 | - 'updateVersion' => '8.1.2', |
|
121 | - 'updateVersionString' => 'Nextcloud 8.1.2', |
|
122 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
123 | - 'changes' => [], |
|
124 | - 'updaterEnabled' => true, |
|
125 | - 'versionIsEol' => false, |
|
126 | - ]); |
|
127 | - |
|
128 | - $group = $this->createMock(IGroup::class); |
|
129 | - $group->expects($this->any()) |
|
130 | - ->method('getDisplayName') |
|
131 | - ->willReturn('Administrators'); |
|
132 | - $group->expects($this->any()) |
|
133 | - ->method('getGID') |
|
134 | - ->willReturn('admin'); |
|
135 | - $this->groupManager->expects($this->once()) |
|
136 | - ->method('get') |
|
137 | - ->with('admin') |
|
138 | - ->willReturn($group); |
|
139 | - |
|
140 | - $this->subscriptionRegistry |
|
141 | - ->expects($this->once()) |
|
142 | - ->method('delegateHasValidSubscription') |
|
143 | - ->willReturn(true); |
|
144 | - |
|
145 | - $this->initialState->expects($this->once()) |
|
146 | - ->method('provideInitialState') |
|
147 | - ->with('data', [ |
|
148 | - 'isNewVersionAvailable' => true, |
|
149 | - 'isUpdateChecked' => true, |
|
150 | - 'lastChecked' => 'LastCheckedReturnValue', |
|
151 | - 'currentChannel' => 'daily', |
|
152 | - 'channels' => $channels, |
|
153 | - 'newVersion' => '8.1.2', |
|
154 | - 'newVersionString' => 'Nextcloud 8.1.2', |
|
155 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
156 | - 'changes' => [], |
|
157 | - 'webUpdaterEnabled' => true, |
|
158 | - 'isWebUpdaterRecommended' => true, |
|
159 | - 'updaterEnabled' => true, |
|
160 | - 'versionIsEol' => false, |
|
161 | - 'isDefaultUpdateServerURL' => true, |
|
162 | - 'updateServerURL' => 'https://updates.nextcloud.com/updater_server/', |
|
163 | - 'notifyGroups' => [ |
|
164 | - ['id' => 'admin', 'displayname' => 'Administrators'], |
|
165 | - ], |
|
166 | - 'hasValidSubscription' => true, |
|
167 | - ]); |
|
168 | - |
|
169 | - $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
170 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
171 | - } |
|
172 | - |
|
173 | - public function testGetFormWithUpdateAndChangedUpdateServer(): void { |
|
174 | - $this->serverVersion->expects(self::atLeastOnce()) |
|
175 | - ->method('getChannel') |
|
176 | - ->willReturn('beta'); |
|
177 | - $this->userManager |
|
178 | - ->expects($this->once()) |
|
179 | - ->method('countUsersTotal') |
|
180 | - ->willReturn(5); |
|
181 | - $channels = [ |
|
182 | - 'daily', |
|
183 | - 'beta', |
|
184 | - 'stable', |
|
185 | - 'production', |
|
186 | - ]; |
|
187 | - |
|
188 | - $this->appConfig |
|
189 | - ->expects($this->once()) |
|
190 | - ->method('getValueInt') |
|
191 | - ->with('core', 'lastupdatedat', 0) |
|
192 | - ->willReturn(12345); |
|
193 | - $this->config |
|
194 | - ->expects(self::any()) |
|
195 | - ->method('getSystemValueBool') |
|
196 | - ->with('updatechecker', true) |
|
197 | - ->willReturn(true); |
|
198 | - $this->appConfig |
|
199 | - ->expects($this->once()) |
|
200 | - ->method('getValueArray') |
|
201 | - ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
202 | - ->willReturn(['admin']); |
|
203 | - $this->config |
|
204 | - ->method('getSystemValue') |
|
205 | - ->willReturnMap([ |
|
206 | - ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server_changed/'], |
|
207 | - ['upgrade.disable-web', false, true], |
|
208 | - ]); |
|
209 | - $this->dateTimeFormatter |
|
210 | - ->expects($this->once()) |
|
211 | - ->method('formatDateTime') |
|
212 | - ->with('12345') |
|
213 | - ->willReturn('LastCheckedReturnValue'); |
|
214 | - $this->updateChecker |
|
215 | - ->expects($this->once()) |
|
216 | - ->method('getUpdateState') |
|
217 | - ->willReturn([ |
|
218 | - 'updateAvailable' => true, |
|
219 | - 'updateVersion' => '8.1.2', |
|
220 | - 'updateVersionString' => 'Nextcloud 8.1.2', |
|
221 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
222 | - 'changes' => [], |
|
223 | - 'updaterEnabled' => true, |
|
224 | - 'versionIsEol' => false, |
|
225 | - ]); |
|
226 | - |
|
227 | - $group = $this->createMock(IGroup::class); |
|
228 | - $group->expects($this->any()) |
|
229 | - ->method('getDisplayName') |
|
230 | - ->willReturn('Administrators'); |
|
231 | - $group->expects($this->any()) |
|
232 | - ->method('getGID') |
|
233 | - ->willReturn('admin'); |
|
234 | - $this->groupManager->expects($this->once()) |
|
235 | - ->method('get') |
|
236 | - ->with('admin') |
|
237 | - ->willReturn($group); |
|
238 | - |
|
239 | - $this->subscriptionRegistry |
|
240 | - ->expects($this->once()) |
|
241 | - ->method('delegateHasValidSubscription') |
|
242 | - ->willReturn(true); |
|
243 | - |
|
244 | - $this->initialState->expects($this->once()) |
|
245 | - ->method('provideInitialState') |
|
246 | - ->with('data', [ |
|
247 | - 'isNewVersionAvailable' => true, |
|
248 | - 'isUpdateChecked' => true, |
|
249 | - 'lastChecked' => 'LastCheckedReturnValue', |
|
250 | - 'currentChannel' => 'beta', |
|
251 | - 'channels' => $channels, |
|
252 | - 'newVersion' => '8.1.2', |
|
253 | - 'newVersionString' => 'Nextcloud 8.1.2', |
|
254 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
255 | - 'changes' => [], |
|
256 | - 'webUpdaterEnabled' => false, |
|
257 | - 'isWebUpdaterRecommended' => true, |
|
258 | - 'updaterEnabled' => true, |
|
259 | - 'versionIsEol' => false, |
|
260 | - 'isDefaultUpdateServerURL' => false, |
|
261 | - 'updateServerURL' => 'https://updates.nextcloud.com/updater_server_changed/', |
|
262 | - 'notifyGroups' => [ |
|
263 | - ['id' => 'admin', 'displayname' => 'Administrators'], |
|
264 | - ], |
|
265 | - 'hasValidSubscription' => true, |
|
266 | - ]); |
|
267 | - |
|
268 | - $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
269 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
270 | - } |
|
271 | - |
|
272 | - public function testGetFormWithUpdateAndCustomersUpdateServer(): void { |
|
273 | - $this->serverVersion->expects(self::atLeastOnce()) |
|
274 | - ->method('getChannel') |
|
275 | - ->willReturn('production'); |
|
276 | - $this->userManager |
|
277 | - ->expects($this->once()) |
|
278 | - ->method('countUsersTotal') |
|
279 | - ->willReturn(5); |
|
280 | - $channels = [ |
|
281 | - 'daily', |
|
282 | - 'beta', |
|
283 | - 'stable', |
|
284 | - 'production', |
|
285 | - ]; |
|
286 | - |
|
287 | - $this->appConfig |
|
288 | - ->expects($this->once()) |
|
289 | - ->method('getValueInt') |
|
290 | - ->with('core', 'lastupdatedat', 0) |
|
291 | - ->willReturn(12345); |
|
292 | - $this->config |
|
293 | - ->expects(self::any()) |
|
294 | - ->method('getSystemValueBool') |
|
295 | - ->with('updatechecker', true) |
|
296 | - ->willReturn(true); |
|
297 | - $this->appConfig |
|
298 | - ->expects(self::once()) |
|
299 | - ->method('getValueArray') |
|
300 | - ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
301 | - ->willReturn(['admin']); |
|
302 | - $this->config |
|
303 | - ->method('getSystemValue') |
|
304 | - ->willReturnMap([ |
|
305 | - ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/customers/ABC-DEF/'], |
|
306 | - ['upgrade.disable-web', false, false], |
|
307 | - ]); |
|
308 | - $this->dateTimeFormatter |
|
309 | - ->expects($this->once()) |
|
310 | - ->method('formatDateTime') |
|
311 | - ->with('12345') |
|
312 | - ->willReturn('LastCheckedReturnValue'); |
|
313 | - $this->updateChecker |
|
314 | - ->expects($this->once()) |
|
315 | - ->method('getUpdateState') |
|
316 | - ->willReturn([ |
|
317 | - 'updateAvailable' => true, |
|
318 | - 'updateVersion' => '8.1.2', |
|
319 | - 'updateVersionString' => 'Nextcloud 8.1.2', |
|
320 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
321 | - 'changes' => [], |
|
322 | - 'updaterEnabled' => true, |
|
323 | - 'versionIsEol' => false, |
|
324 | - ]); |
|
325 | - |
|
326 | - $group = $this->createMock(IGroup::class); |
|
327 | - $group->expects($this->any()) |
|
328 | - ->method('getDisplayName') |
|
329 | - ->willReturn('Administrators'); |
|
330 | - $group->expects($this->any()) |
|
331 | - ->method('getGID') |
|
332 | - ->willReturn('admin'); |
|
333 | - $this->groupManager->expects($this->once()) |
|
334 | - ->method('get') |
|
335 | - ->with('admin') |
|
336 | - ->willReturn($group); |
|
337 | - |
|
338 | - $this->subscriptionRegistry |
|
339 | - ->expects($this->once()) |
|
340 | - ->method('delegateHasValidSubscription') |
|
341 | - ->willReturn(true); |
|
342 | - |
|
343 | - $this->initialState->expects($this->once()) |
|
344 | - ->method('provideInitialState') |
|
345 | - ->with('data', [ |
|
346 | - 'isNewVersionAvailable' => true, |
|
347 | - 'isUpdateChecked' => true, |
|
348 | - 'lastChecked' => 'LastCheckedReturnValue', |
|
349 | - 'currentChannel' => 'production', |
|
350 | - 'channels' => $channels, |
|
351 | - 'newVersion' => '8.1.2', |
|
352 | - 'newVersionString' => 'Nextcloud 8.1.2', |
|
353 | - 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
354 | - 'changes' => [], |
|
355 | - 'webUpdaterEnabled' => true, |
|
356 | - 'isWebUpdaterRecommended' => true, |
|
357 | - 'updaterEnabled' => true, |
|
358 | - 'versionIsEol' => false, |
|
359 | - 'isDefaultUpdateServerURL' => true, |
|
360 | - 'updateServerURL' => 'https://updates.nextcloud.com/customers/ABC-DEF/', |
|
361 | - 'notifyGroups' => [ |
|
362 | - ['id' => 'admin', 'displayname' => 'Administrators'], |
|
363 | - ], |
|
364 | - 'hasValidSubscription' => true, |
|
365 | - ]); |
|
366 | - |
|
367 | - $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
368 | - $this->assertEquals($expected, $this->admin->getForm()); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - public function testGetSection(): void { |
|
373 | - $this->config |
|
374 | - ->expects(self::atLeastOnce()) |
|
375 | - ->method('getSystemValueBool') |
|
376 | - ->with('updatechecker', true) |
|
377 | - ->willReturn(true); |
|
378 | - |
|
379 | - $this->assertSame('overview', $this->admin->getSection()); |
|
380 | - } |
|
381 | - |
|
382 | - public function testGetSectionDisabled(): void { |
|
383 | - $this->config |
|
384 | - ->expects(self::atLeastOnce()) |
|
385 | - ->method('getSystemValueBool') |
|
386 | - ->with('updatechecker', true) |
|
387 | - ->willReturn(false); |
|
388 | - |
|
389 | - $this->assertNull($this->admin->getSection()); |
|
390 | - } |
|
391 | - |
|
392 | - public function testGetPriority(): void { |
|
393 | - $this->assertSame(11, $this->admin->getPriority()); |
|
394 | - } |
|
395 | - |
|
396 | - public static function changesProvider(): array { |
|
397 | - return [ |
|
398 | - [ #0, all info, en |
|
399 | - [ |
|
400 | - 'changelogURL' => 'https://go.to.changelog', |
|
401 | - 'whatsNew' => [ |
|
402 | - 'en' => [ |
|
403 | - 'regular' => ['content'], |
|
404 | - ], |
|
405 | - 'de' => [ |
|
406 | - 'regular' => ['inhalt'], |
|
407 | - ] |
|
408 | - ], |
|
409 | - ], |
|
410 | - 'en', |
|
411 | - [ |
|
412 | - 'changelogURL' => 'https://go.to.changelog', |
|
413 | - 'whatsNew' => [ |
|
414 | - 'regular' => ['content'], |
|
415 | - ], |
|
416 | - ] |
|
417 | - ], |
|
418 | - [ #1, all info, de |
|
419 | - [ |
|
420 | - 'changelogURL' => 'https://go.to.changelog', |
|
421 | - 'whatsNew' => [ |
|
422 | - 'en' => [ |
|
423 | - 'regular' => ['content'], |
|
424 | - ], |
|
425 | - 'de' => [ |
|
426 | - 'regular' => ['inhalt'], |
|
427 | - ] |
|
428 | - ], |
|
429 | - ], |
|
430 | - 'de', |
|
431 | - [ |
|
432 | - 'changelogURL' => 'https://go.to.changelog', |
|
433 | - 'whatsNew' => [ |
|
434 | - 'regular' => ['inhalt'], |
|
435 | - ] |
|
436 | - ], |
|
437 | - ], |
|
438 | - [ #2, just changelog |
|
439 | - [ 'changelogURL' => 'https://go.to.changelog' ], |
|
440 | - 'en', |
|
441 | - [ 'changelogURL' => 'https://go.to.changelog' ], |
|
442 | - ], |
|
443 | - [ #3 nothing |
|
444 | - [], |
|
445 | - 'ru', |
|
446 | - [] |
|
447 | - ] |
|
448 | - ]; |
|
449 | - } |
|
450 | - |
|
451 | - #[\PHPUnit\Framework\Attributes\DataProvider('changesProvider')] |
|
452 | - public function testFilterChanges($changes, $userLang, $expectation): void { |
|
453 | - $iterator = $this->createMock(ILanguageIterator::class); |
|
454 | - $iterator->expects($this->any()) |
|
455 | - ->method('current') |
|
456 | - ->willReturnOnConsecutiveCalls('es', $userLang, 'it', 'en'); |
|
457 | - $iterator->expects($this->any()) |
|
458 | - ->method('valid') |
|
459 | - ->willReturn(true); |
|
460 | - |
|
461 | - $this->l10nFactory->expects($this->atMost(1)) |
|
462 | - ->method('getLanguageIterator') |
|
463 | - ->willReturn($iterator); |
|
464 | - $result = $this->invokePrivate($this->admin, 'filterChanges', [$changes]); |
|
465 | - $this->assertSame($expectation, $result); |
|
466 | - } |
|
32 | + private IFactory&MockObject $l10nFactory; |
|
33 | + private IConfig&MockObject $config; |
|
34 | + private IAppConfig&MockObject $appConfig; |
|
35 | + private UpdateChecker&MockObject $updateChecker; |
|
36 | + private IGroupManager&MockObject $groupManager; |
|
37 | + private IDateTimeFormatter&MockObject $dateTimeFormatter; |
|
38 | + private IRegistry&MockObject $subscriptionRegistry; |
|
39 | + private IUserManager&MockObject $userManager; |
|
40 | + private LoggerInterface&MockObject $logger; |
|
41 | + private IInitialState&MockObject $initialState; |
|
42 | + private ServerVersion&MockObject $serverVersion; |
|
43 | + private Admin $admin; |
|
44 | + |
|
45 | + protected function setUp(): void { |
|
46 | + parent::setUp(); |
|
47 | + |
|
48 | + $this->config = $this->createMock(IConfig::class); |
|
49 | + $this->appConfig = $this->createMock(IAppConfig::class); |
|
50 | + $this->updateChecker = $this->createMock(UpdateChecker::class); |
|
51 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
52 | + $this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); |
|
53 | + $this->l10nFactory = $this->createMock(IFactory::class); |
|
54 | + $this->subscriptionRegistry = $this->createMock(IRegistry::class); |
|
55 | + $this->userManager = $this->createMock(IUserManager::class); |
|
56 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
57 | + $this->initialState = $this->createMock(IInitialState::class); |
|
58 | + $this->serverVersion = $this->createMock(ServerVersion::class); |
|
59 | + |
|
60 | + $this->admin = new Admin( |
|
61 | + $this->config, |
|
62 | + $this->appConfig, |
|
63 | + $this->updateChecker, |
|
64 | + $this->groupManager, |
|
65 | + $this->dateTimeFormatter, |
|
66 | + $this->l10nFactory, |
|
67 | + $this->subscriptionRegistry, |
|
68 | + $this->userManager, |
|
69 | + $this->logger, |
|
70 | + $this->initialState, |
|
71 | + $this->serverVersion, |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + public function testGetFormWithUpdate(): void { |
|
76 | + $this->serverVersion->expects(self::atLeastOnce()) |
|
77 | + ->method('getChannel') |
|
78 | + ->willReturn('daily'); |
|
79 | + $this->userManager |
|
80 | + ->expects($this->once()) |
|
81 | + ->method('countUsersTotal') |
|
82 | + ->willReturn(5); |
|
83 | + $channels = [ |
|
84 | + 'daily', |
|
85 | + 'beta', |
|
86 | + 'stable', |
|
87 | + 'production', |
|
88 | + ]; |
|
89 | + $this->appConfig |
|
90 | + ->expects($this->once()) |
|
91 | + ->method('getValueInt') |
|
92 | + ->with('core', 'lastupdatedat', 0) |
|
93 | + ->willReturn(12345); |
|
94 | + $this->appConfig |
|
95 | + ->expects($this->once()) |
|
96 | + ->method('getValueArray') |
|
97 | + ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
98 | + ->willReturn(['admin']); |
|
99 | + $this->config |
|
100 | + ->method('getSystemValue') |
|
101 | + ->willReturnMap([ |
|
102 | + ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server/'], |
|
103 | + ['upgrade.disable-web', false, false], |
|
104 | + ]); |
|
105 | + $this->config |
|
106 | + ->expects(self::any()) |
|
107 | + ->method('getSystemValueBool') |
|
108 | + ->with('updatechecker', true) |
|
109 | + ->willReturn(true); |
|
110 | + $this->dateTimeFormatter |
|
111 | + ->expects($this->once()) |
|
112 | + ->method('formatDateTime') |
|
113 | + ->with(12345) |
|
114 | + ->willReturn('LastCheckedReturnValue'); |
|
115 | + $this->updateChecker |
|
116 | + ->expects($this->once()) |
|
117 | + ->method('getUpdateState') |
|
118 | + ->willReturn([ |
|
119 | + 'updateAvailable' => true, |
|
120 | + 'updateVersion' => '8.1.2', |
|
121 | + 'updateVersionString' => 'Nextcloud 8.1.2', |
|
122 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
123 | + 'changes' => [], |
|
124 | + 'updaterEnabled' => true, |
|
125 | + 'versionIsEol' => false, |
|
126 | + ]); |
|
127 | + |
|
128 | + $group = $this->createMock(IGroup::class); |
|
129 | + $group->expects($this->any()) |
|
130 | + ->method('getDisplayName') |
|
131 | + ->willReturn('Administrators'); |
|
132 | + $group->expects($this->any()) |
|
133 | + ->method('getGID') |
|
134 | + ->willReturn('admin'); |
|
135 | + $this->groupManager->expects($this->once()) |
|
136 | + ->method('get') |
|
137 | + ->with('admin') |
|
138 | + ->willReturn($group); |
|
139 | + |
|
140 | + $this->subscriptionRegistry |
|
141 | + ->expects($this->once()) |
|
142 | + ->method('delegateHasValidSubscription') |
|
143 | + ->willReturn(true); |
|
144 | + |
|
145 | + $this->initialState->expects($this->once()) |
|
146 | + ->method('provideInitialState') |
|
147 | + ->with('data', [ |
|
148 | + 'isNewVersionAvailable' => true, |
|
149 | + 'isUpdateChecked' => true, |
|
150 | + 'lastChecked' => 'LastCheckedReturnValue', |
|
151 | + 'currentChannel' => 'daily', |
|
152 | + 'channels' => $channels, |
|
153 | + 'newVersion' => '8.1.2', |
|
154 | + 'newVersionString' => 'Nextcloud 8.1.2', |
|
155 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
156 | + 'changes' => [], |
|
157 | + 'webUpdaterEnabled' => true, |
|
158 | + 'isWebUpdaterRecommended' => true, |
|
159 | + 'updaterEnabled' => true, |
|
160 | + 'versionIsEol' => false, |
|
161 | + 'isDefaultUpdateServerURL' => true, |
|
162 | + 'updateServerURL' => 'https://updates.nextcloud.com/updater_server/', |
|
163 | + 'notifyGroups' => [ |
|
164 | + ['id' => 'admin', 'displayname' => 'Administrators'], |
|
165 | + ], |
|
166 | + 'hasValidSubscription' => true, |
|
167 | + ]); |
|
168 | + |
|
169 | + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
170 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
171 | + } |
|
172 | + |
|
173 | + public function testGetFormWithUpdateAndChangedUpdateServer(): void { |
|
174 | + $this->serverVersion->expects(self::atLeastOnce()) |
|
175 | + ->method('getChannel') |
|
176 | + ->willReturn('beta'); |
|
177 | + $this->userManager |
|
178 | + ->expects($this->once()) |
|
179 | + ->method('countUsersTotal') |
|
180 | + ->willReturn(5); |
|
181 | + $channels = [ |
|
182 | + 'daily', |
|
183 | + 'beta', |
|
184 | + 'stable', |
|
185 | + 'production', |
|
186 | + ]; |
|
187 | + |
|
188 | + $this->appConfig |
|
189 | + ->expects($this->once()) |
|
190 | + ->method('getValueInt') |
|
191 | + ->with('core', 'lastupdatedat', 0) |
|
192 | + ->willReturn(12345); |
|
193 | + $this->config |
|
194 | + ->expects(self::any()) |
|
195 | + ->method('getSystemValueBool') |
|
196 | + ->with('updatechecker', true) |
|
197 | + ->willReturn(true); |
|
198 | + $this->appConfig |
|
199 | + ->expects($this->once()) |
|
200 | + ->method('getValueArray') |
|
201 | + ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
202 | + ->willReturn(['admin']); |
|
203 | + $this->config |
|
204 | + ->method('getSystemValue') |
|
205 | + ->willReturnMap([ |
|
206 | + ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server_changed/'], |
|
207 | + ['upgrade.disable-web', false, true], |
|
208 | + ]); |
|
209 | + $this->dateTimeFormatter |
|
210 | + ->expects($this->once()) |
|
211 | + ->method('formatDateTime') |
|
212 | + ->with('12345') |
|
213 | + ->willReturn('LastCheckedReturnValue'); |
|
214 | + $this->updateChecker |
|
215 | + ->expects($this->once()) |
|
216 | + ->method('getUpdateState') |
|
217 | + ->willReturn([ |
|
218 | + 'updateAvailable' => true, |
|
219 | + 'updateVersion' => '8.1.2', |
|
220 | + 'updateVersionString' => 'Nextcloud 8.1.2', |
|
221 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
222 | + 'changes' => [], |
|
223 | + 'updaterEnabled' => true, |
|
224 | + 'versionIsEol' => false, |
|
225 | + ]); |
|
226 | + |
|
227 | + $group = $this->createMock(IGroup::class); |
|
228 | + $group->expects($this->any()) |
|
229 | + ->method('getDisplayName') |
|
230 | + ->willReturn('Administrators'); |
|
231 | + $group->expects($this->any()) |
|
232 | + ->method('getGID') |
|
233 | + ->willReturn('admin'); |
|
234 | + $this->groupManager->expects($this->once()) |
|
235 | + ->method('get') |
|
236 | + ->with('admin') |
|
237 | + ->willReturn($group); |
|
238 | + |
|
239 | + $this->subscriptionRegistry |
|
240 | + ->expects($this->once()) |
|
241 | + ->method('delegateHasValidSubscription') |
|
242 | + ->willReturn(true); |
|
243 | + |
|
244 | + $this->initialState->expects($this->once()) |
|
245 | + ->method('provideInitialState') |
|
246 | + ->with('data', [ |
|
247 | + 'isNewVersionAvailable' => true, |
|
248 | + 'isUpdateChecked' => true, |
|
249 | + 'lastChecked' => 'LastCheckedReturnValue', |
|
250 | + 'currentChannel' => 'beta', |
|
251 | + 'channels' => $channels, |
|
252 | + 'newVersion' => '8.1.2', |
|
253 | + 'newVersionString' => 'Nextcloud 8.1.2', |
|
254 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
255 | + 'changes' => [], |
|
256 | + 'webUpdaterEnabled' => false, |
|
257 | + 'isWebUpdaterRecommended' => true, |
|
258 | + 'updaterEnabled' => true, |
|
259 | + 'versionIsEol' => false, |
|
260 | + 'isDefaultUpdateServerURL' => false, |
|
261 | + 'updateServerURL' => 'https://updates.nextcloud.com/updater_server_changed/', |
|
262 | + 'notifyGroups' => [ |
|
263 | + ['id' => 'admin', 'displayname' => 'Administrators'], |
|
264 | + ], |
|
265 | + 'hasValidSubscription' => true, |
|
266 | + ]); |
|
267 | + |
|
268 | + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
269 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
270 | + } |
|
271 | + |
|
272 | + public function testGetFormWithUpdateAndCustomersUpdateServer(): void { |
|
273 | + $this->serverVersion->expects(self::atLeastOnce()) |
|
274 | + ->method('getChannel') |
|
275 | + ->willReturn('production'); |
|
276 | + $this->userManager |
|
277 | + ->expects($this->once()) |
|
278 | + ->method('countUsersTotal') |
|
279 | + ->willReturn(5); |
|
280 | + $channels = [ |
|
281 | + 'daily', |
|
282 | + 'beta', |
|
283 | + 'stable', |
|
284 | + 'production', |
|
285 | + ]; |
|
286 | + |
|
287 | + $this->appConfig |
|
288 | + ->expects($this->once()) |
|
289 | + ->method('getValueInt') |
|
290 | + ->with('core', 'lastupdatedat', 0) |
|
291 | + ->willReturn(12345); |
|
292 | + $this->config |
|
293 | + ->expects(self::any()) |
|
294 | + ->method('getSystemValueBool') |
|
295 | + ->with('updatechecker', true) |
|
296 | + ->willReturn(true); |
|
297 | + $this->appConfig |
|
298 | + ->expects(self::once()) |
|
299 | + ->method('getValueArray') |
|
300 | + ->with(Application::APP_NAME, 'notify_groups', ['admin']) |
|
301 | + ->willReturn(['admin']); |
|
302 | + $this->config |
|
303 | + ->method('getSystemValue') |
|
304 | + ->willReturnMap([ |
|
305 | + ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/customers/ABC-DEF/'], |
|
306 | + ['upgrade.disable-web', false, false], |
|
307 | + ]); |
|
308 | + $this->dateTimeFormatter |
|
309 | + ->expects($this->once()) |
|
310 | + ->method('formatDateTime') |
|
311 | + ->with('12345') |
|
312 | + ->willReturn('LastCheckedReturnValue'); |
|
313 | + $this->updateChecker |
|
314 | + ->expects($this->once()) |
|
315 | + ->method('getUpdateState') |
|
316 | + ->willReturn([ |
|
317 | + 'updateAvailable' => true, |
|
318 | + 'updateVersion' => '8.1.2', |
|
319 | + 'updateVersionString' => 'Nextcloud 8.1.2', |
|
320 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
321 | + 'changes' => [], |
|
322 | + 'updaterEnabled' => true, |
|
323 | + 'versionIsEol' => false, |
|
324 | + ]); |
|
325 | + |
|
326 | + $group = $this->createMock(IGroup::class); |
|
327 | + $group->expects($this->any()) |
|
328 | + ->method('getDisplayName') |
|
329 | + ->willReturn('Administrators'); |
|
330 | + $group->expects($this->any()) |
|
331 | + ->method('getGID') |
|
332 | + ->willReturn('admin'); |
|
333 | + $this->groupManager->expects($this->once()) |
|
334 | + ->method('get') |
|
335 | + ->with('admin') |
|
336 | + ->willReturn($group); |
|
337 | + |
|
338 | + $this->subscriptionRegistry |
|
339 | + ->expects($this->once()) |
|
340 | + ->method('delegateHasValidSubscription') |
|
341 | + ->willReturn(true); |
|
342 | + |
|
343 | + $this->initialState->expects($this->once()) |
|
344 | + ->method('provideInitialState') |
|
345 | + ->with('data', [ |
|
346 | + 'isNewVersionAvailable' => true, |
|
347 | + 'isUpdateChecked' => true, |
|
348 | + 'lastChecked' => 'LastCheckedReturnValue', |
|
349 | + 'currentChannel' => 'production', |
|
350 | + 'channels' => $channels, |
|
351 | + 'newVersion' => '8.1.2', |
|
352 | + 'newVersionString' => 'Nextcloud 8.1.2', |
|
353 | + 'downloadLink' => 'https://downloads.nextcloud.org/server', |
|
354 | + 'changes' => [], |
|
355 | + 'webUpdaterEnabled' => true, |
|
356 | + 'isWebUpdaterRecommended' => true, |
|
357 | + 'updaterEnabled' => true, |
|
358 | + 'versionIsEol' => false, |
|
359 | + 'isDefaultUpdateServerURL' => true, |
|
360 | + 'updateServerURL' => 'https://updates.nextcloud.com/customers/ABC-DEF/', |
|
361 | + 'notifyGroups' => [ |
|
362 | + ['id' => 'admin', 'displayname' => 'Administrators'], |
|
363 | + ], |
|
364 | + 'hasValidSubscription' => true, |
|
365 | + ]); |
|
366 | + |
|
367 | + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); |
|
368 | + $this->assertEquals($expected, $this->admin->getForm()); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + public function testGetSection(): void { |
|
373 | + $this->config |
|
374 | + ->expects(self::atLeastOnce()) |
|
375 | + ->method('getSystemValueBool') |
|
376 | + ->with('updatechecker', true) |
|
377 | + ->willReturn(true); |
|
378 | + |
|
379 | + $this->assertSame('overview', $this->admin->getSection()); |
|
380 | + } |
|
381 | + |
|
382 | + public function testGetSectionDisabled(): void { |
|
383 | + $this->config |
|
384 | + ->expects(self::atLeastOnce()) |
|
385 | + ->method('getSystemValueBool') |
|
386 | + ->with('updatechecker', true) |
|
387 | + ->willReturn(false); |
|
388 | + |
|
389 | + $this->assertNull($this->admin->getSection()); |
|
390 | + } |
|
391 | + |
|
392 | + public function testGetPriority(): void { |
|
393 | + $this->assertSame(11, $this->admin->getPriority()); |
|
394 | + } |
|
395 | + |
|
396 | + public static function changesProvider(): array { |
|
397 | + return [ |
|
398 | + [ #0, all info, en |
|
399 | + [ |
|
400 | + 'changelogURL' => 'https://go.to.changelog', |
|
401 | + 'whatsNew' => [ |
|
402 | + 'en' => [ |
|
403 | + 'regular' => ['content'], |
|
404 | + ], |
|
405 | + 'de' => [ |
|
406 | + 'regular' => ['inhalt'], |
|
407 | + ] |
|
408 | + ], |
|
409 | + ], |
|
410 | + 'en', |
|
411 | + [ |
|
412 | + 'changelogURL' => 'https://go.to.changelog', |
|
413 | + 'whatsNew' => [ |
|
414 | + 'regular' => ['content'], |
|
415 | + ], |
|
416 | + ] |
|
417 | + ], |
|
418 | + [ #1, all info, de |
|
419 | + [ |
|
420 | + 'changelogURL' => 'https://go.to.changelog', |
|
421 | + 'whatsNew' => [ |
|
422 | + 'en' => [ |
|
423 | + 'regular' => ['content'], |
|
424 | + ], |
|
425 | + 'de' => [ |
|
426 | + 'regular' => ['inhalt'], |
|
427 | + ] |
|
428 | + ], |
|
429 | + ], |
|
430 | + 'de', |
|
431 | + [ |
|
432 | + 'changelogURL' => 'https://go.to.changelog', |
|
433 | + 'whatsNew' => [ |
|
434 | + 'regular' => ['inhalt'], |
|
435 | + ] |
|
436 | + ], |
|
437 | + ], |
|
438 | + [ #2, just changelog |
|
439 | + [ 'changelogURL' => 'https://go.to.changelog' ], |
|
440 | + 'en', |
|
441 | + [ 'changelogURL' => 'https://go.to.changelog' ], |
|
442 | + ], |
|
443 | + [ #3 nothing |
|
444 | + [], |
|
445 | + 'ru', |
|
446 | + [] |
|
447 | + ] |
|
448 | + ]; |
|
449 | + } |
|
450 | + |
|
451 | + #[\PHPUnit\Framework\Attributes\DataProvider('changesProvider')] |
|
452 | + public function testFilterChanges($changes, $userLang, $expectation): void { |
|
453 | + $iterator = $this->createMock(ILanguageIterator::class); |
|
454 | + $iterator->expects($this->any()) |
|
455 | + ->method('current') |
|
456 | + ->willReturnOnConsecutiveCalls('es', $userLang, 'it', 'en'); |
|
457 | + $iterator->expects($this->any()) |
|
458 | + ->method('valid') |
|
459 | + ->willReturn(true); |
|
460 | + |
|
461 | + $this->l10nFactory->expects($this->atMost(1)) |
|
462 | + ->method('getLanguageIterator') |
|
463 | + ->willReturn($iterator); |
|
464 | + $result = $this->invokePrivate($this->admin, 'filterChanges', [$changes]); |
|
465 | + $this->assertSame($expectation, $result); |
|
466 | + } |
|
467 | 467 | } |